svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.coreplugin.app / org.gvsig.coreplugin.app.mainplugin / src / main / java / org / gvsig / coreplugin / PreferencesExtension.java @ 40723
History | View | Annotate | Download (9.02 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.coreplugin; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.HashMap; |
28 |
import java.util.Iterator; |
29 |
|
30 |
import org.gvsig.andami.IconThemeHelper; |
31 |
import org.gvsig.andami.Launcher; |
32 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.andami.plugins.Extension; |
34 |
import org.gvsig.andami.plugins.config.generate.Extensions; |
35 |
import org.gvsig.andami.plugins.config.generate.PluginConfig; |
36 |
import org.gvsig.andami.preferences.DlgPreferences; |
37 |
import org.gvsig.andami.preferences.IPreference; |
38 |
import org.gvsig.andami.preferences.IPreferenceExtension; |
39 |
import org.gvsig.coreplugin.preferences.general.AppearancePage; |
40 |
import org.gvsig.coreplugin.preferences.general.BrowserControlPage; |
41 |
import org.gvsig.coreplugin.preferences.general.DirExtensionsPage; |
42 |
import org.gvsig.coreplugin.preferences.general.ExtensionPage; |
43 |
import org.gvsig.coreplugin.preferences.general.ExtensionsPage; |
44 |
import org.gvsig.coreplugin.preferences.general.FolderingPage; |
45 |
import org.gvsig.coreplugin.preferences.general.GeneralPage; |
46 |
import org.gvsig.coreplugin.preferences.general.IconThemePage; |
47 |
import org.gvsig.coreplugin.preferences.general.LanguagePage; |
48 |
import org.gvsig.coreplugin.preferences.general.ScreenSettingsPage; |
49 |
import org.gvsig.coreplugin.preferences.general.SkinPreferences; |
50 |
import org.gvsig.coreplugin.preferences.network.FirewallPage; |
51 |
import org.gvsig.coreplugin.preferences.network.NetworkPage; |
52 |
import org.gvsig.tools.ToolsLocator; |
53 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
54 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
55 |
import org.slf4j.Logger; |
56 |
import org.slf4j.LoggerFactory; |
57 |
|
58 |
|
59 |
/**
|
60 |
*
|
61 |
* <p>
|
62 |
* Extension that provides support for visual application configuration
|
63 |
* through a Preferences dialog where the user can specify its own settings for
|
64 |
* general purpose aspects.
|
65 |
* </p>
|
66 |
* <p>
|
67 |
* Adding new preference pages is made through ExtensionPoints by invoking
|
68 |
* <b>
|
69 |
* this.extensionPoints.add("AplicationPreferences","YourIPreferencesClassName", yourIPreferencesPage);
|
70 |
* </b>
|
71 |
* and then call <b>DlgPreferences.refreshExtensionPoints();</b>
|
72 |
* </p>
|
73 |
*
|
74 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
75 |
*
|
76 |
*/
|
77 |
public class PreferencesExtension extends Extension{ |
78 |
|
79 |
private static Logger logger = LoggerFactory.getLogger(PreferencesExtension.class); |
80 |
private ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager();
|
81 |
|
82 |
private boolean initilizedExtensions=false; |
83 |
|
84 |
public void initialize() { |
85 |
|
86 |
registerIcons(); |
87 |
initializeCoreExtensions(); |
88 |
} |
89 |
|
90 |
private void registerIcons(){ |
91 |
IconThemeHelper.registerIcon("action", "edit-setup", this); |
92 |
|
93 |
// AppearancePage.java
|
94 |
IconThemeHelper.registerIcon("preferences", "edit-setup-appearance", this); |
95 |
// BrowserControlPage.java
|
96 |
IconThemeHelper.registerIcon("preferences", "edit-setup-browsercontrol", this); |
97 |
// DirExtensionPage.java
|
98 |
IconThemeHelper.registerIcon("preferences", "edit-setup-dirextension", this); |
99 |
// ExtensionPage.java
|
100 |
IconThemeHelper.registerIcon("preferences", "edit-setup-extension", this); |
101 |
// ExtensionsPage.java
|
102 |
IconThemeHelper.registerIcon("preferences", "edit-setup-extensions", this); |
103 |
// GeneralPage.java
|
104 |
IconThemeHelper.registerIcon("preferences", "edit-setup-general", this); |
105 |
// FolderingPage.java
|
106 |
IconThemeHelper.registerIcon("preferences", "edit-setup-foldering", this); |
107 |
// LanguagePage.java
|
108 |
IconThemeHelper.registerIcon("preferences", "edit-setup-language", this); |
109 |
// ScreenSettingsPage.java
|
110 |
IconThemeHelper.registerIcon("preferences", "edit-setup-screensetting", this); |
111 |
// FirewallPage.java
|
112 |
IconThemeHelper.registerIcon("preferences", "edit-setup-firewall", this); |
113 |
// NetworkPage.java
|
114 |
IconThemeHelper.registerIcon("preferences", "edit-setup-network", this); |
115 |
// SkinPreferences.java
|
116 |
IconThemeHelper.registerIcon("preferences", "edit-setup-skin", this); |
117 |
IconThemeHelper.registerIcon("preferences", "edit-setup-icontheme", this); |
118 |
} |
119 |
|
120 |
public void execute(String actionCommand) { |
121 |
if (!this.initilizedExtensions) { |
122 |
initializeExtensions(); |
123 |
initializeExtensionsConfig(); |
124 |
this.initilizedExtensions = true; |
125 |
} |
126 |
if ("edit-setup".equalsIgnoreCase(actionCommand)) { |
127 |
DlgPreferences dlgPreferences = PluginServices.getDlgPreferences(); |
128 |
dlgPreferences.refreshExtensionPoints(); |
129 |
PluginServices.getMDIManager().addWindow(dlgPreferences); |
130 |
} |
131 |
} |
132 |
public boolean isEnabled() { |
133 |
return true; |
134 |
} |
135 |
|
136 |
public boolean isVisible() { |
137 |
return true; |
138 |
} |
139 |
|
140 |
private void initializeCoreExtensions() { |
141 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
142 |
ep.append("GeneralPage", "", new GeneralPage()); |
143 |
ep.append("NetworkPage", "", new NetworkPage()); |
144 |
ep.append("FirewallPage", "", new FirewallPage()); |
145 |
ep.append("DirExtensionsPage", "", new DirExtensionsPage()); |
146 |
ep.append("LanguagePage", "", new LanguagePage()); |
147 |
ep.append("ExtensionsPage", "", new ExtensionsPage()); |
148 |
ep.append("AppearancePage", "", new AppearancePage()); |
149 |
ep.append("FolderingPage", "", new FolderingPage()); |
150 |
ep.append("ScreenSettingsPage", "", new ScreenSettingsPage()); |
151 |
ep.append("SkinPreferences", "", new SkinPreferences()); |
152 |
ep.append("IconThemePage", "", new IconThemePage()); |
153 |
|
154 |
// this.extensionPoints.add("AplicationPreferences","GeneralPage", new GeneralPage());
|
155 |
// this.extensionPoints.add("AplicationPreferences","NetworkPage", new NetworkPage());
|
156 |
// this.extensionPoints.add("AplicationPreferences","FirewallPage", new FirewallPage());
|
157 |
// this.extensionPoints.add("AplicationPreferences","DirExtensionsPage", new DirExtensionsPage());
|
158 |
// this.extensionPoints.add("AplicationPreferences","LanguagePage", new LanguagePage());
|
159 |
// this.extensionPoints.add("AplicationPreferences","ExtensionsPage", new ExtensionsPage());
|
160 |
// this.extensionPoints.add("AplicationPreferences","AppearancePage", new AppearancePage());
|
161 |
// this.extensionPoints.add("AplicationPreferences","FolderingPage", new FolderingPage());
|
162 |
// this.extensionPoints.add("AplicationPreferences","ResolutionPage", new ScreenSettingsPage());
|
163 |
// this.extensionPoints.add("AplicationPreferences","SkinPreferences", new SkinPreferences());
|
164 |
String os = System.getProperty("os.name").toLowerCase(); |
165 |
if (os.indexOf("linux") != -1 || os.indexOf("unix")!= -1) { |
166 |
ep.append("BrowserControlPage", "", new BrowserControlPage()); |
167 |
// this.extensionPoints.add("AplicationPreferences","BrowserControlPage", new BrowserControlPage());
|
168 |
} |
169 |
|
170 |
//Falta los plugin
|
171 |
} |
172 |
|
173 |
private void initializeExtensionsConfig() { |
174 |
HashMap pc = Launcher.getPluginConfig();
|
175 |
ArrayList array = new ArrayList(); |
176 |
Iterator iter = pc.values().iterator();
|
177 |
|
178 |
while (iter.hasNext()) {
|
179 |
array.add(((PluginConfig) iter.next()).getExtensions()); |
180 |
} |
181 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
182 |
|
183 |
Extensions[] exts = (Extensions[]) array.toArray(new Extensions[0]); |
184 |
for (int i = 0; i < exts.length; i++) { |
185 |
for (int j = 0; j < exts[i].getExtensionCount(); j++) { |
186 |
org.gvsig.andami.plugins.config.generate.Extension ext = exts[i] |
187 |
.getExtension(j); |
188 |
String sExt = ext.getClassName().toString();
|
189 |
// String pn = null;
|
190 |
// pn = sExt.substring(0, sExt.lastIndexOf("."));
|
191 |
// dlgPrefs.addPreferencePage(new PluginsPage(pn));
|
192 |
// dlgPrefs.addPreferencePage(new ExtensionPage(ext));
|
193 |
ep.append(sExt, "", new ExtensionPage(ext)); |
194 |
} |
195 |
} |
196 |
} |
197 |
/**
|
198 |
*
|
199 |
*/
|
200 |
private void initializeExtensions() { |
201 |
Iterator i = Launcher.getExtensionIterator();
|
202 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
203 |
|
204 |
while (i.hasNext()) {
|
205 |
Object extension = i.next();
|
206 |
|
207 |
if (extension instanceof IPreferenceExtension) { |
208 |
IPreferenceExtension pe = (IPreferenceExtension) extension; |
209 |
IPreference[] pp = pe.getPreferencesPages();
|
210 |
|
211 |
if (pp == null) { |
212 |
logger.info("Preferences page is NULL. Extension "
|
213 |
+ extension.getClass().getName() |
214 |
+ " implements IPreferenceExtension but does not provide pref. pages. ");
|
215 |
} else {
|
216 |
for (int j = 0; j < pp.length; j++) { |
217 |
ep.append(pp[j].getID(), "", pp[j]);
|
218 |
pp[j].initializeValues(); |
219 |
} |
220 |
} |
221 |
} |
222 |
} |
223 |
} |
224 |
|
225 |
public void postInitialize() { |
226 |
super.postInitialize();
|
227 |
DlgPreferences dlgPreferences=PluginServices.getDlgPreferences(); |
228 |
dlgPreferences.refreshExtensionPoints(); |
229 |
dlgPreferences.storeValues(); |
230 |
} |
231 |
} |