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 @ 40623

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

    
114
        // Register preferences page
115
        ExtensionPointManager extensionPoints =
116
            ToolsLocator.getExtensionPointManager();
117
        ExtensionPoint ep = extensionPoints.add("AplicationPreferences", "");
118

    
119
        IconThemeHelper.registerIcon("preferences", "export-to-preferences", this);
120

    
121
        ep.append("ExporttoPreferencesPage", "", new ExporttoPreferencesPage());
122
    }
123

    
124
    public void execute(String actionCommand) {
125
        // Nothing to do
126
    }
127

    
128
    public boolean isEnabled() {
129
        return true;
130
    }
131

    
132
    public boolean isVisible() {
133
        return false;
134
    }
135

    
136
}