svn-gvsig-desktop / 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 @ 47841
History | View | Annotate | Download (3.93 KB)
1 | 47821 | jjdelcerro | /**
|
---|---|---|---|
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.downloader.app.mainplugin; |
||
25 | |||
26 | import java.util.ArrayList; |
||
27 | 47841 | fdiaz | import java.util.Collection; |
28 | 47821 | jjdelcerro | import java.util.List; |
29 | import org.gvsig.andami.IconThemeHelper; |
||
30 | 47841 | fdiaz | import org.gvsig.andami.PluginsLocator; |
31 | import org.gvsig.andami.PluginsManager; |
||
32 | 47821 | jjdelcerro | import org.gvsig.andami.plugins.Extension; |
33 | import org.gvsig.andami.preferences.IPreference; |
||
34 | import org.gvsig.andami.preferences.IPreferenceExtension; |
||
35 | 47841 | fdiaz | import org.gvsig.downloader.DownloaderAuthenticationConfig; |
36 | import org.gvsig.downloader.DownloaderLocator; |
||
37 | import org.gvsig.downloader.DownloaderManager; |
||
38 | import org.gvsig.tools.dynobject.DynObject; |
||
39 | 47821 | jjdelcerro | |
40 | /**
|
||
41 | *
|
||
42 | * @author jjdelcerro
|
||
43 | */
|
||
44 | public class DownloaderExtension extends Extension implements IPreferenceExtension { |
||
45 | |||
46 | @Override
|
||
47 | public void initialize() { |
||
48 | IconThemeHelper.registerIcon("preferences", "downloadmanager-preferences", this); |
||
49 | } |
||
50 | |||
51 | @Override
|
||
52 | public void postInitialize() { |
||
53 | 47841 | fdiaz | PluginsManager pluginsManager = PluginsLocator.getPluginsManager(); |
54 | pluginsManager.addShutdownTask( |
||
55 | "saveDownloaderPreferences",
|
||
56 | () -> {doSaveDownloaderPreferences();}, |
||
57 | false,
|
||
58 | 100
|
||
59 | ); |
||
60 | doLoadDownloaderPreferences(); |
||
61 | 47821 | jjdelcerro | } |
62 | 47841 | fdiaz | |
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 | } |
||
70 | 47821 | jjdelcerro | |
71 | 47841 | fdiaz | 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 | |||
83 | 47821 | jjdelcerro | @Override
|
84 | public void execute(String action) { |
||
85 | if( action == null ) { |
||
86 | return;
|
||
87 | } |
||
88 | switch(action.toLowerCase()) {
|
||
89 | // case "tools-xml2db-createdbfromxml":
|
||
90 | // createdbFromXml();
|
||
91 | // return;
|
||
92 | // case "tools-xml2db-importxml2db":
|
||
93 | // importXml2db();
|
||
94 | // return;
|
||
95 | // case "tools-xml2db-copyxml2db":
|
||
96 | // copyXml2db();
|
||
97 | } |
||
98 | } |
||
99 | |||
100 | @Override
|
||
101 | public boolean isEnabled() { |
||
102 | return true; |
||
103 | } |
||
104 | |||
105 | @Override
|
||
106 | public boolean isVisible() { |
||
107 | return false; |
||
108 | } |
||
109 | |||
110 | @Override
|
||
111 | public IPreference[] getPreferencesPages() { |
||
112 | List<IPreference> prefs = new ArrayList<>(); |
||
113 | prefs.add(new DownloaderAuthenticatePreferencesPage());
|
||
114 | |||
115 | return prefs.toArray(new IPreference[prefs.size()]); |
||
116 | } |
||
117 | } |