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