root / branches / v2_0_0_prep / extensions / org.gvsig.newlayer.app / org.gvsig.newlayer.app.extension / src / main / java / org / gvsig / newlayer / app / extension / preferences / NewLayerPreferencesPage.java @ 38564
History | View | Annotate | Download (4.42 KB)
1 | 37891 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.newlayer.app.extension.preferences; |
||
23 | |||
24 | import java.util.HashSet; |
||
25 | import java.util.List; |
||
26 | import java.util.Set; |
||
27 | |||
28 | import javax.swing.ImageIcon; |
||
29 | import javax.swing.JLabel; |
||
30 | import javax.swing.JPanel; |
||
31 | |||
32 | 38564 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
33 | 37891 | cordinyana | import org.gvsig.andami.PluginsLocator; |
34 | import org.gvsig.andami.preferences.AbstractPreferencePage; |
||
35 | import org.gvsig.andami.preferences.StoreException; |
||
36 | import org.gvsig.i18n.Messages; |
||
37 | import org.gvsig.newlayer.NewLayerLocator; |
||
38 | import org.gvsig.newlayer.NewLayerManager; |
||
39 | import org.gvsig.newlayer.NewLayerProviderFactory; |
||
40 | import org.gvsig.newlayer.app.extension.NewLayerPreferencesExtension; |
||
41 | import org.gvsig.newlayer.preferences.NewLayerPreferencesComponent; |
||
42 | import org.gvsig.tools.dynobject.DynObject; |
||
43 | |||
44 | /**
|
||
45 | * NewLayer related preferences page.
|
||
46 | *
|
||
47 | * @author gvSIG Team
|
||
48 | * @version $Id$
|
||
49 | */
|
||
50 | public class NewLayerPreferencesPage extends AbstractPreferencePage { |
||
51 | |||
52 | private static final long serialVersionUID = -5751805016601819817L; |
||
53 | |||
54 | 38564 | jjdelcerro | // private ImageIcon icon;
|
55 | 37891 | cordinyana | |
56 | private NewLayerManager manager;
|
||
57 | |||
58 | private NewLayerPreferencesComponent preferences;
|
||
59 | |||
60 | /**
|
||
61 | * Constructor.
|
||
62 | */
|
||
63 | public NewLayerPreferencesPage() {
|
||
64 | 38564 | jjdelcerro | // icon = PluginServices.getIconTheme().get("newlayer-properties");
|
65 | 37891 | cordinyana | |
66 | manager = NewLayerLocator.getManager(); |
||
67 | addComponent(new JLabel( |
||
68 | Messages.getText("newlayer_preferences_panel_description")));
|
||
69 | preferences = manager.createNewLayerProvidersPreferences(); |
||
70 | addComponent(preferences.asJComponent()); |
||
71 | |||
72 | // setParentID("org.gvsig.app.gui.preferencespage.ViewPage");
|
||
73 | } |
||
74 | |||
75 | public String getID() { |
||
76 | return getClass().getName();
|
||
77 | } |
||
78 | |||
79 | public String getTitle() { |
||
80 | return Messages.getText("newlayer_preferences"); |
||
81 | } |
||
82 | |||
83 | public JPanel getPanel() { |
||
84 | return this; |
||
85 | } |
||
86 | |||
87 | public void initializeValues() { |
||
88 | // Nothing to do
|
||
89 | } |
||
90 | |||
91 | public void initializeDefaults() { |
||
92 | preferences.initializeDefaults(); |
||
93 | } |
||
94 | |||
95 | public ImageIcon getIcon() { |
||
96 | 38564 | jjdelcerro | return IconThemeHelper.getImageIcon("newlayer-preferences"); |
97 | 37891 | cordinyana | } |
98 | |||
99 | public boolean isValueChanged() { |
||
100 | return preferences.isValueChanged();
|
||
101 | } |
||
102 | |||
103 | @Override
|
||
104 | public void storeValues() throws StoreException { |
||
105 | // Update manager values
|
||
106 | List<NewLayerProviderFactory> providers = manager.getProviders();
|
||
107 | Set<NewLayerProviderFactory> disabledProviders =
|
||
108 | preferences.getDisabledProviders(); |
||
109 | Set<String> enabledNames = new HashSet<String>(); |
||
110 | Set<String> disabledNames = |
||
111 | new HashSet<String>(disabledProviders.size()); |
||
112 | for (int i = 0; i < providers.size(); i++) { |
||
113 | NewLayerProviderFactory provider = providers.get(i); |
||
114 | boolean disabled = disabledProviders.contains(provider);
|
||
115 | provider.setEnabled(!disabled); |
||
116 | if (disabled) {
|
||
117 | disabledNames.add(provider.getName()); |
||
118 | } else {
|
||
119 | enabledNames.add(provider.getName()); |
||
120 | } |
||
121 | } |
||
122 | // Persist them
|
||
123 | DynObject preferences = |
||
124 | PluginsLocator.getManager() |
||
125 | .getPlugin("org.gvsig.newlayer.app.extension")
|
||
126 | .getPluginProperties(); |
||
127 | preferences.setDynValue( |
||
128 | NewLayerPreferencesExtension.PREFERENCE_ENABLED_PROVIDERS, |
||
129 | enabledNames); |
||
130 | preferences.setDynValue( |
||
131 | NewLayerPreferencesExtension.PREFERENCE_DISABLED_PROVIDERS, |
||
132 | disabledNames); |
||
133 | } |
||
134 | |||
135 | @Override
|
||
136 | public void setChangesApplied() { |
||
137 | preferences.setChangesApplied(); |
||
138 | } |
||
139 | |||
140 | } |