root / tags / v2_0_0_Build_2051 / extensions / org.gvsig.newlayer.app / org.gvsig.newlayer.app.extension / src / main / java / org / gvsig / newlayer / app / extension / NewLayerPreferencesExtension.java @ 38757
History | View | Annotate | Download (5.2 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.newlayer.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.i18n.Messages; |
35 |
import org.gvsig.newlayer.NewLayerLocator; |
36 |
import org.gvsig.newlayer.NewLayerManager; |
37 |
import org.gvsig.newlayer.NewLayerProviderFactory; |
38 |
import org.gvsig.newlayer.app.extension.preferences.NewLayerPreferencesPage; |
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 NewLayer preferences panel.
|
47 |
*
|
48 |
* @author gvSIG Team
|
49 |
* @version $Id$
|
50 |
*/
|
51 |
public class NewLayerPreferencesExtension extends Extension { |
52 |
|
53 |
private static final Logger LOG = LoggerFactory |
54 |
.getLogger(NewLayerPreferencesExtension.class); |
55 |
|
56 |
/**
|
57 |
* The name of the preferences property with the names of the hidden
|
58 |
* NewLayerSwingProviderFactory.
|
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.newlayer.app.extension.i18n.text",
|
71 |
NewLayerPreferencesExtension.class.getClassLoader(), |
72 |
NewLayerPreferencesExtension.class.getClass().getName()); |
73 |
|
74 |
NewLayerManager providerManager = NewLayerLocator.getManager(); |
75 |
// Load from preferences the list of NewLayer Providers to ignore.
|
76 |
DynObject preferences = this.getPlugin().getPluginProperties();
|
77 |
@SuppressWarnings("unchecked") |
78 |
Set<String> disabledProviders = |
79 |
(Set<String>) preferences |
80 |
.getDynValue(PREFERENCE_DISABLED_PROVIDERS); |
81 |
if (disabledProviders != null) { |
82 |
for (Iterator<String> iterator = disabledProviders.iterator(); iterator |
83 |
.hasNext();) { |
84 |
NewLayerProviderFactory factory; |
85 |
String providerName = null; |
86 |
try {
|
87 |
providerName = iterator.next(); |
88 |
factory = |
89 |
providerManager |
90 |
.getNewLayerProviderFactory(providerName); |
91 |
providerManager.enableProvider(factory, Boolean.FALSE);
|
92 |
} catch (ServiceException e) {
|
93 |
LOG.warn("Disabled NewLayer provider " + providerName
|
94 |
+ " is not available", e);
|
95 |
} |
96 |
} |
97 |
} |
98 |
@SuppressWarnings("unchecked") |
99 |
Set<String> enabledProviders = |
100 |
(Set<String>) preferences.getDynValue(PREFERENCE_ENABLED_PROVIDERS); |
101 |
if (enabledProviders != null) { |
102 |
for (Iterator<String> iterator = enabledProviders.iterator(); iterator |
103 |
.hasNext();) { |
104 |
NewLayerProviderFactory factory; |
105 |
String providerName = null; |
106 |
try {
|
107 |
providerName = iterator.next(); |
108 |
factory = |
109 |
providerManager |
110 |
.getNewLayerProviderFactory(providerName); |
111 |
providerManager.enableProvider(factory, Boolean.TRUE);
|
112 |
} catch (ServiceException e) {
|
113 |
LOG.warn("Enabled NewLayer provider " + providerName
|
114 |
+ " is not available", e);
|
115 |
} |
116 |
} |
117 |
} |
118 |
|
119 |
// Register preferences page
|
120 |
ExtensionPointManager extensionPoints = |
121 |
ToolsLocator.getExtensionPointManager(); |
122 |
ExtensionPoint ep = extensionPoints.add("AplicationPreferences", ""); |
123 |
|
124 |
IconThemeHelper.registerIcon("preferences", "newlayer-preferences", this); |
125 |
|
126 |
ep.append("NewLayerPreferencesPage", "", new NewLayerPreferencesPage()); |
127 |
} |
128 |
|
129 |
public void execute(String actionCommand) { |
130 |
// Nothing to do
|
131 |
} |
132 |
|
133 |
public boolean isEnabled() { |
134 |
return true; |
135 |
} |
136 |
|
137 |
public boolean isVisible() { |
138 |
return false; |
139 |
} |
140 |
|
141 |
} |