Revision 44193 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.exportto.app/org.gvsig.exportto.app.mainplugin/src/main/java/org/gvsig/export/app/extension/ExportPreferences.java

View differences:

ExportPreferences.java
6 6
package org.gvsig.export.app.extension;
7 7

  
8 8
import java.util.HashMap;
9
import java.util.HashSet;
9 10
import java.util.Map;
10 11
import java.util.Set;
11 12
import org.gvsig.andami.PluginsLocator;
12 13
import org.gvsig.andami.PluginsManager;
14
import org.gvsig.export.ExportLocator;
15
import org.gvsig.export.spi.ExportServiceFactory;
16
import org.gvsig.export.spi.ExportServiceManager;
13 17
import org.gvsig.tools.dynobject.DynObject;
14 18

  
15 19
/**
......
21 25
    public static final String PREFERENCE_ENABLED_SERVICES = "enabledProviders";
22 26
    public static final String PREFERENCE_DISABLED_SERVICES = "disabledProviders";
23 27
    
28
    public ExportPreferences() {
29
        this.getPreferences();
30
    }
31
    
24 32
    public boolean exits(String factoryName) {
25 33
        Map<String, Boolean> enabledsState = this.getEnabledState();
26 34
        return enabledsState.containsKey(factoryName);
......
41 49
            PluginsManager pluginManager = PluginsLocator.getManager();
42 50
            
43 51
            this.preferences = pluginManager.getPlugin(ExportPreferencesExtension.class).getPluginProperties();
44

  
52
            
45 53
        }
46 54
        return this.preferences;
47 55
    }
......
49 57
    private Map<String, Boolean> getEnabledState() {
50 58
        Map<String, Boolean> enabledsState = new HashMap<>();
51 59
        Set<String> enableds = (Set<String>) this.getPreferences().getDynValue(PREFERENCE_ENABLED_SERVICES);
52
        for (String enabled : enableds) {
53
            enabledsState.put(enabled, true);
60
        if( enableds==null ) {
61
            ExportServiceManager manager = ExportLocator.getServiceManager();
62
            for (ExportServiceFactory factory : manager.getAllServiceFactories()) {
63
                enabledsState.put(factory.getName(), true);
64
            }
65
        } else {
66
            for (String enabled : enableds) {
67
                enabledsState.put(enabled, true);
68
            }
54 69
        }
55 70
        Set<String> disableds = (Set<String>) this.getPreferences().getDynValue(PREFERENCE_DISABLED_SERVICES);
56
        for (String disabled : disableds) {
57
            enabledsState.put(disabled, false);
71
        if(disableds != null) {
72
            for (String disabled : disableds) {
73
                    enabledsState.put(disabled, false);
74
            }
58 75
        }
76
        
59 77
        return enabledsState;
60 78
    }
61 79
    
62 80
    private void putEnabledState(Map<String, Boolean> enabledsState) {
63 81
        Set<String> enableds = (Set<String>) this.getPreferences().getDynValue(PREFERENCE_ENABLED_SERVICES);
82
        if( enableds==null ) {
83
            enableds = new HashSet<>();
84
            this.getPreferences().setDynValue(PREFERENCE_ENABLED_SERVICES, enableds);
85
        }
64 86
        Set<String> disableds = (Set<String>) this.getPreferences().getDynValue(PREFERENCE_DISABLED_SERVICES);
87
        if( disableds==null ) {
88
            disableds = new HashSet<>();
89
            this.getPreferences().setDynValue(PREFERENCE_DISABLED_SERVICES, disableds);
90
        }
91
        
65 92
        for (Map.Entry<String, Boolean> entry : enabledsState.entrySet()) {
66 93
            if (entry.getValue()) {
67 94
                enableds.add(entry.getKey());
......
71 98
                disableds.add(entry.getKey());
72 99
            }
73 100
        }
101
        this.getPreferences().setDynValue(PREFERENCE_ENABLED_SERVICES, enableds);
102
        this.getPreferences().setDynValue(PREFERENCE_DISABLED_SERVICES, disableds);
103
        
74 104
    }
75 105
    
76 106
}

Also available in: Unified diff