svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.exportto.app / org.gvsig.exportto.app.extension / src / main / java / org / gvsig / exportto / app / extension / preferences / ExporttoPreferencesPage.java @ 37888
History | View | Annotate | Download (4.53 KB)
1 |
/* 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.exportto.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 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.andami.PluginsLocator; |
34 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
35 |
import org.gvsig.andami.preferences.StoreException; |
36 |
import org.gvsig.exportto.app.extension.ExporttoPreferencesExtension; |
37 |
import org.gvsig.exportto.swing.preferences.ExporttoSwingPreferencesComponent; |
38 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderFactory; |
39 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderLocator; |
40 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderManager; |
41 |
import org.gvsig.i18n.Messages; |
42 |
import org.gvsig.tools.dynobject.DynObject; |
43 |
|
44 |
/**
|
45 |
* Exportto related preferences page.
|
46 |
*
|
47 |
* @author gvSIG Team
|
48 |
* @version $Id$
|
49 |
*/
|
50 |
public class ExporttoPreferencesPage extends AbstractPreferencePage { |
51 |
|
52 |
private static final long serialVersionUID = -5751805016601819817L; |
53 |
|
54 |
private ImageIcon icon; |
55 |
|
56 |
private ExporttoSwingProviderManager manager;
|
57 |
|
58 |
private ExporttoSwingPreferencesComponent preferences;
|
59 |
|
60 |
/**
|
61 |
* Constructor.
|
62 |
*/
|
63 |
public ExporttoPreferencesPage() {
|
64 |
icon = PluginServices.getIconTheme().get("exportto-properties");
|
65 |
|
66 |
manager = ExporttoSwingProviderLocator.getManager(); |
67 |
addComponent(new JLabel( |
68 |
Messages.getText("exportto_preferences_panel_description")));
|
69 |
preferences = manager.createExporttoSwingProvidersPreferences(); |
70 |
addComponent(preferences.asJComponent()); |
71 |
} |
72 |
|
73 |
public String getID() { |
74 |
return getClass().getName();
|
75 |
} |
76 |
|
77 |
public String getTitle() { |
78 |
return Messages.getText("exportto_preferences"); |
79 |
} |
80 |
|
81 |
public JPanel getPanel() { |
82 |
return this; |
83 |
} |
84 |
|
85 |
public void initializeValues() { |
86 |
// Nothing to do
|
87 |
} |
88 |
|
89 |
public void initializeDefaults() { |
90 |
preferences.initializeDefaults(); |
91 |
} |
92 |
|
93 |
public ImageIcon getIcon() { |
94 |
return icon;
|
95 |
} |
96 |
|
97 |
public boolean isValueChanged() { |
98 |
return preferences.isValueChanged();
|
99 |
} |
100 |
|
101 |
@Override
|
102 |
public void storeValues() throws StoreException { |
103 |
// Update manager values
|
104 |
List<ExporttoSwingProviderFactory> providers =
|
105 |
manager.getProviderFactories(); |
106 |
@SuppressWarnings({ "unchecked" }) |
107 |
Set<ExporttoSwingProviderFactory> disabledProviders =
|
108 |
(Set<ExporttoSwingProviderFactory>) preferences
|
109 |
.getDisabledProviders(); |
110 |
Set<String> enabledNames = new HashSet<String>(); |
111 |
Set<String> disabledNames = |
112 |
new HashSet<String>(disabledProviders.size()); |
113 |
for (int i = 0; i < providers.size(); i++) { |
114 |
ExporttoSwingProviderFactory provider = providers.get(i); |
115 |
boolean disabled = disabledProviders.contains(provider);
|
116 |
provider.setEnabled(!disabled); |
117 |
if (disabled) {
|
118 |
disabledNames.add(provider.getName()); |
119 |
} else {
|
120 |
enabledNames.add(provider.getName()); |
121 |
} |
122 |
} |
123 |
// Persist them
|
124 |
DynObject preferences = |
125 |
PluginsLocator.getManager() |
126 |
.getPlugin("org.gvsig.exportto.app.extension")
|
127 |
.getPluginProperties(); |
128 |
preferences.setDynValue( |
129 |
ExporttoPreferencesExtension.PREFERENCE_ENABLED_PROVIDERS, |
130 |
enabledNames); |
131 |
preferences.setDynValue( |
132 |
ExporttoPreferencesExtension.PREFERENCE_DISABLED_PROVIDERS, |
133 |
disabledNames); |
134 |
} |
135 |
|
136 |
@Override
|
137 |
public void setChangesApplied() { |
138 |
preferences.setChangesApplied(); |
139 |
} |
140 |
|
141 |
} |