root / branches / v2_0_0_prep / extensions / org.gvsig.exportto.app / org.gvsig.exportto.app.extension / src / main / java / org / gvsig / exportto / app / extension / ExporttoPreferencesExtension.java @ 38564
History | View | Annotate | Download (5.31 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; |
23 |
|
24 |
import java.util.Iterator; |
25 |
import java.util.Locale; |
26 |
import java.util.Set; |
27 |
|
28 |
import org.slf4j.Logger; |
29 |
import org.slf4j.LoggerFactory; |
30 |
|
31 |
import org.gvsig.andami.IconThemeHelper; |
32 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.andami.plugins.Extension; |
34 |
import org.gvsig.exportto.app.extension.preferences.ExporttoPreferencesPage; |
35 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderFactory; |
36 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderLocator; |
37 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderManager; |
38 |
import org.gvsig.i18n.Messages; |
39 |
import org.gvsig.tools.ToolsLocator; |
40 |
import org.gvsig.tools.dynobject.DynObject; |
41 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
42 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
43 |
import org.gvsig.tools.service.ServiceException; |
44 |
|
45 |
/**
|
46 |
* Andami extension to register the ExportTo preferences panel.
|
47 |
*
|
48 |
* @author gvSIG Team
|
49 |
* @version $Id$
|
50 |
*/
|
51 |
public class ExporttoPreferencesExtension extends Extension { |
52 |
|
53 |
private static final Logger LOG = LoggerFactory |
54 |
.getLogger(ExporttoPreferencesExtension.class); |
55 |
|
56 |
/**
|
57 |
* The name of the preferences property with the names of the hidden
|
58 |
* ExporttoSwingProviderFactory.
|
59 |
*/
|
60 |
public static final String PREFERENCE_DISABLED_PROVIDERS = |
61 |
"disabledProviders";
|
62 |
public static final String PREFERENCE_ENABLED_PROVIDERS = |
63 |
"enabledProviders";
|
64 |
|
65 |
public void initialize() { |
66 |
if (!Messages.hasLocales()) {
|
67 |
Messages.addLocale(Locale.getDefault());
|
68 |
} |
69 |
Messages.addResourceFamily( |
70 |
"org.gvsig.exportto.app.extension.i18n.text",
|
71 |
ExporttoLayerExtension.class.getClassLoader(), |
72 |
ExporttoLayerExtension.class.getClass().getName()); |
73 |
|
74 |
ExporttoSwingProviderManager providerManager = |
75 |
ExporttoSwingProviderLocator.getManager(); |
76 |
// Load from preferences the list of Exportto Providers to ignore.
|
77 |
DynObject preferences = this.getPlugin().getPluginProperties();
|
78 |
@SuppressWarnings("unchecked") |
79 |
Set<String> disabledProviders = |
80 |
(Set<String>) preferences |
81 |
.getDynValue(PREFERENCE_DISABLED_PROVIDERS); |
82 |
if (disabledProviders != null) { |
83 |
for (Iterator<String> iterator = disabledProviders.iterator(); iterator |
84 |
.hasNext();) { |
85 |
ExporttoSwingProviderFactory factory; |
86 |
String providerName = null; |
87 |
try {
|
88 |
providerName = iterator.next(); |
89 |
factory = |
90 |
providerManager |
91 |
.getExporttoSwingProviderFactory(providerName); |
92 |
providerManager.enableProvider(factory, Boolean.FALSE);
|
93 |
} catch (ServiceException e) {
|
94 |
LOG.warn("Disabled exportto swing provider " + providerName
|
95 |
+ " is not available", e);
|
96 |
} |
97 |
} |
98 |
} |
99 |
@SuppressWarnings("unchecked") |
100 |
Set<String> enabledProviders = |
101 |
(Set<String>) preferences.getDynValue(PREFERENCE_ENABLED_PROVIDERS); |
102 |
if (enabledProviders != null) { |
103 |
for (Iterator<String> iterator = enabledProviders.iterator(); iterator |
104 |
.hasNext();) { |
105 |
ExporttoSwingProviderFactory factory; |
106 |
String providerName = null; |
107 |
try {
|
108 |
providerName = iterator.next(); |
109 |
factory = |
110 |
providerManager |
111 |
.getExporttoSwingProviderFactory(providerName); |
112 |
providerManager.enableProvider(factory, Boolean.TRUE);
|
113 |
} catch (ServiceException e) {
|
114 |
LOG.warn("Enabled exportto swing provider " + providerName
|
115 |
+ " is not available", e);
|
116 |
} |
117 |
} |
118 |
} |
119 |
|
120 |
// Register preferences page
|
121 |
ExtensionPointManager extensionPoints = |
122 |
ToolsLocator.getExtensionPointManager(); |
123 |
ExtensionPoint ep = extensionPoints.add("AplicationPreferences", ""); |
124 |
|
125 |
IconThemeHelper.registerIcon("preferences", "export-to-preferences", this); |
126 |
|
127 |
ep.append("ExporttoPreferencesPage", "", new ExporttoPreferencesPage()); |
128 |
} |
129 |
|
130 |
public void execute(String actionCommand) { |
131 |
// Nothing to do
|
132 |
} |
133 |
|
134 |
public boolean isEnabled() { |
135 |
return true; |
136 |
} |
137 |
|
138 |
public boolean isVisible() { |
139 |
return false; |
140 |
} |
141 |
|
142 |
} |