Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.newlayer.app / org.gvsig.newlayer.app.extension / src / main / java / org / gvsig / newlayer / app / extension / NewLayerPreferencesExtension.java @ 38550

History | View | Annotate | Download (5.27 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.PluginServices;
32
import org.gvsig.andami.plugins.Extension;
33
import org.gvsig.i18n.Messages;
34
import org.gvsig.newlayer.NewLayerLocator;
35
import org.gvsig.newlayer.NewLayerManager;
36
import org.gvsig.newlayer.NewLayerProviderFactory;
37
import org.gvsig.newlayer.app.extension.preferences.NewLayerPreferencesPage;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dynobject.DynObject;
40
import org.gvsig.tools.extensionpoint.ExtensionPoint;
41
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
42
import org.gvsig.tools.service.ServiceException;
43

    
44
/**
45
 * Andami extension to register the NewLayer preferences panel.
46
 * 
47
 * @author gvSIG Team
48
 * @version $Id$
49
 */
50
public class NewLayerPreferencesExtension extends Extension {
51

    
52
    private static final Logger LOG = LoggerFactory
53
        .getLogger(NewLayerPreferencesExtension.class);
54

    
55
    /**
56
     * The name of the preferences property with the names of the hidden
57
     * NewLayerSwingProviderFactory.
58
     */
59
    public static final String PREFERENCE_DISABLED_PROVIDERS =
60
        "disabledProviders";
61
    public static final String PREFERENCE_ENABLED_PROVIDERS =
62
        "enabledProviders";
63

    
64
    public void initialize() {
65
        if (!Messages.hasLocales()) {
66
            Messages.addLocale(Locale.getDefault());
67
        }
68
        Messages.addResourceFamily(
69
            "org.gvsig.newlayer.app.extension.i18n.text",
70
            NewLayerPreferencesExtension.class.getClassLoader(),
71
            NewLayerPreferencesExtension.class.getClass().getName());
72

    
73
        NewLayerManager providerManager = NewLayerLocator.getManager();
74
        // Load from preferences the list of NewLayer Providers to ignore.
75
        DynObject preferences = this.getPlugin().getPluginProperties();
76
        @SuppressWarnings("unchecked")
77
        Set<String> disabledProviders =
78
            (Set<String>) preferences
79
                .getDynValue(PREFERENCE_DISABLED_PROVIDERS);
80
        if (disabledProviders != null) {
81
            for (Iterator<String> iterator = disabledProviders.iterator(); iterator
82
                .hasNext();) {
83
                NewLayerProviderFactory factory;
84
                String providerName = null;
85
                try {
86
                    providerName = iterator.next();
87
                    factory =
88
                        providerManager
89
                            .getNewLayerProviderFactory(providerName);
90
                    providerManager.enableProvider(factory, Boolean.FALSE);
91
                } catch (ServiceException e) {
92
                    LOG.warn("Disabled NewLayer provider " + providerName
93
                        + " is not available", e);
94
                }
95
            }
96
        }
97
        @SuppressWarnings("unchecked")
98
        Set<String> enabledProviders =
99
            (Set<String>) preferences.getDynValue(PREFERENCE_ENABLED_PROVIDERS);
100
        if (enabledProviders != null) {
101
            for (Iterator<String> iterator = enabledProviders.iterator(); iterator
102
                .hasNext();) {
103
                NewLayerProviderFactory factory;
104
                String providerName = null;
105
                try {
106
                    providerName = iterator.next();
107
                    factory =
108
                        providerManager
109
                            .getNewLayerProviderFactory(providerName);
110
                    providerManager.enableProvider(factory, Boolean.TRUE);
111
                } catch (ServiceException e) {
112
                    LOG.warn("Enabled NewLayer provider " + providerName
113
                        + " is not available", e);
114
                }
115
            }
116
        }
117

    
118
        // Register preferences page
119
        ExtensionPointManager extensionPoints =
120
            ToolsLocator.getExtensionPointManager();
121
        ExtensionPoint ep = extensionPoints.add("AplicationPreferences", "");
122

    
123
        PluginServices.getIconTheme().registerDefault(
124
            "newlayer-properties",
125
            NewLayerPreferencesPage.class.getClassLoader().getResource(
126
                "images/document-new.png"));
127

    
128
        ep.append("NewLayerPreferencesPage", "", new NewLayerPreferencesPage());
129
    }
130

    
131
    public void execute(String actionCommand) {
132
        // Nothing to do
133
    }
134

    
135
    public boolean isEnabled() {
136
        return true;
137
    }
138

    
139
    public boolean isVisible() {
140
        return false;
141
    }
142

    
143
}