Statistics
| Revision:

svn-gvsig-desktop / 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 @ 37887

History | View | Annotate | Download (5.39 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.PluginServices;
32
import org.gvsig.andami.plugins.Extension;
33
import org.gvsig.exportto.app.extension.preferences.ExporttoPreferencesPage;
34
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderFactory;
35
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderLocator;
36
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderManager;
37
import org.gvsig.i18n.Messages;
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 ExportTo preferences panel.
46
 * 
47
 * @author gvSIG Team
48
 * @version $Id$
49
 */
50
public class ExporttoPreferencesExtension extends Extension {
51

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

    
55
    /**
56
     * The name of the preferences property with the names of the hidden
57
     * ExporttoSwingProviderFactory.
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.exportto.app.extension.i18n.text",
70
            ExporttoLayerExtension.class.getClassLoader(),
71
            ExporttoLayerExtension.class.getClass().getName());
72

    
73
        ExporttoSwingProviderManager providerManager =
74
            ExporttoSwingProviderLocator.getManager();
75
        // Load from preferences the list of Exportto 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
                ExporttoSwingProviderFactory factory;
85
                String providerName = null;
86
                try {
87
                    providerName = iterator.next();
88
                    factory =
89
                        providerManager
90
                            .getExporttoSwingProviderFactory(providerName);
91
                    providerManager.enableProvider(factory, Boolean.FALSE);
92
                } catch (ServiceException e) {
93
                    LOG.warn("Disabled exportto swing 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
                ExporttoSwingProviderFactory factory;
105
                String providerName = null;
106
                try {
107
                    providerName = iterator.next();
108
                    factory =
109
                        providerManager
110
                            .getExporttoSwingProviderFactory(providerName);
111
                    providerManager.enableProvider(factory, Boolean.TRUE);
112
                } catch (ServiceException e) {
113
                    LOG.warn("Enabled exportto swing 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
        PluginServices.getIconTheme().registerDefault(
125
            "exportto-properties",
126
            ExporttoPreferencesPage.class.getClassLoader().getResource(
127
                "images/document-save-as.png"));
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
}