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