Revision 47841 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.app/org.gvsig.downloader.app.mainplugin/src/main/java/org/gvsig/downloader/app/mainplugin/DownloaderExtension.java

View differences:

DownloaderExtension.java
24 24
package org.gvsig.downloader.app.mainplugin;
25 25

  
26 26
import java.util.ArrayList;
27
import java.util.Collection;
27 28
import java.util.List;
28 29
import org.gvsig.andami.IconThemeHelper;
30
import org.gvsig.andami.PluginsLocator;
31
import org.gvsig.andami.PluginsManager;
29 32
import org.gvsig.andami.plugins.Extension;
30 33
import org.gvsig.andami.preferences.IPreference;
31 34
import org.gvsig.andami.preferences.IPreferenceExtension;
35
import org.gvsig.downloader.DownloaderAuthenticationConfig;
36
import org.gvsig.downloader.DownloaderLocator;
37
import org.gvsig.downloader.DownloaderManager;
38
import org.gvsig.tools.dynobject.DynObject;
32 39

  
33 40
/**
34 41
 *
......
43 50

  
44 51
    @Override
45 52
    public void postInitialize() {
53
        PluginsManager pluginsManager = PluginsLocator.getPluginsManager();
54
        pluginsManager.addShutdownTask(
55
            "saveDownloaderPreferences",
56
            () -> {doSaveDownloaderPreferences();},
57
            false,
58
            100
59
        );
60
        doLoadDownloaderPreferences();
46 61
    }
62
    
63
    private void doSaveDownloaderPreferences() {
64
        DynObject props = this.getPlugin().getPluginProperties();
65
        DownloaderManager downloader = DownloaderLocator.getDownloaderManager();
66
        Collection<DownloaderAuthenticationConfig> serviceConfigs = downloader.getAuthenticationConfigurationServices();
67
        List<DownloaderAuthenticationConfig> x = new ArrayList<>(serviceConfigs);
68
        props.setDynValue("serviceConfigs", x);
69
    }
47 70

  
71
    private void doLoadDownloaderPreferences() {
72
        DynObject props = this.getPlugin().getPluginProperties();
73
        DownloaderManager downloader = DownloaderLocator.getDownloaderManager();
74
        List serviceConfigs = (List) props.getDynValue("serviceConfigs");
75
        if(serviceConfigs == null) {
76
            return;
77
        }
78
        for (Object serviceConfig : serviceConfigs) {
79
            downloader.registerAuthenticationConfigurationService((DownloaderAuthenticationConfig) serviceConfig);
80
        }
81
    }
82

  
48 83
    @Override
49 84
    public void execute(String action) {
50 85
        if( action == null ) {

Also available in: Unified diff