Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.newlayer.app / org.gvsig.newlayer.app.mainplugin / src / main / java / org / gvsig / newlayer / app / extension / NewLayerPreferencesExtension.java @ 40557

History | View | Annotate | Download (5.25 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.newlayer.app.extension;
25

    
26
import java.util.Iterator;
27
import java.util.Locale;
28
import java.util.Set;
29

    
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

    
33
import org.gvsig.andami.IconThemeHelper;
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.plugins.Extension;
36
import org.gvsig.i18n.Messages;
37
import org.gvsig.newlayer.NewLayerLocator;
38
import org.gvsig.newlayer.NewLayerManager;
39
import org.gvsig.newlayer.NewLayerProviderFactory;
40
import org.gvsig.newlayer.app.extension.preferences.NewLayerPreferencesPage;
41
import org.gvsig.tools.ToolsLocator;
42
import org.gvsig.tools.dynobject.DynObject;
43
import org.gvsig.tools.extensionpoint.ExtensionPoint;
44
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
45
import org.gvsig.tools.service.ServiceException;
46

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

    
55
    private static final Logger LOG = LoggerFactory
56
        .getLogger(NewLayerPreferencesExtension.class);
57

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

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

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

    
121
        // Register preferences page
122
        ExtensionPointManager extensionPoints =
123
            ToolsLocator.getExtensionPointManager();
124
        ExtensionPoint ep = extensionPoints.add("AplicationPreferences", "");
125

    
126
        IconThemeHelper.registerIcon("preferences", "newlayer-preferences", this);
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
}