Statistics
| Revision:

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 / ExporttoPreferencesExtension.java @ 40557

History | View | Annotate | Download (5.36 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;
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.exportto.app.extension.preferences.ExporttoPreferencesPage;
37
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderFactory;
38
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderLocator;
39
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderManager;
40
import org.gvsig.i18n.Messages;
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 ExportTo preferences panel.
49
 * 
50
 * @author gvSIG Team
51
 * @version $Id$
52
 */
53
public class ExporttoPreferencesExtension extends Extension {
54

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

    
58
    /**
59
     * The name of the preferences property with the names of the hidden
60
     * ExporttoSwingProviderFactory.
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.exportto.app.extension.i18n.text",
73
            ExporttoLayerExtension.class.getClassLoader(),
74
            ExporttoLayerExtension.class.getClass().getName());
75

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

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

    
127
        IconThemeHelper.registerIcon("preferences", "export-to-preferences", this);
128

    
129
        ep.append("ExporttoPreferencesPage", "", new ExporttoPreferencesPage());
130
    }
131

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

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

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

    
144
}