Revision 43100 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
PreferencesExtension.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 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.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 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.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 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. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.coreplugin; |
25 | 24 |
|
... | ... | |
58 | 57 |
import org.slf4j.Logger; |
59 | 58 |
import org.slf4j.LoggerFactory; |
60 | 59 |
|
61 |
|
|
62 | 60 |
/** |
63 | 61 |
* |
64 | 62 |
* <p> |
65 |
* Extension that provides support for visual application configuration |
|
66 |
* through a Preferences dialog where the user can specify its own settings for
|
|
67 |
* general purpose aspects.
|
|
63 |
* Extension that provides support for visual application configuration through
|
|
64 |
* a Preferences dialog where the user can specify its own settings for general
|
|
65 |
* purpose aspects. |
|
68 | 66 |
* </p> |
69 | 67 |
* <p> |
70 | 68 |
* Adding new preference pages is made through ExtensionPoints by invoking |
71 | 69 |
* <b> |
72 |
* this.extensionPoints.add("AplicationPreferences","YourIPreferencesClassName", yourIPreferencesPage); |
|
70 |
* this.extensionPoints.add("AplicationPreferences","YourIPreferencesClassName", |
|
71 |
* yourIPreferencesPage); |
|
73 | 72 |
* </b> |
74 | 73 |
* and then call <b>DlgPreferences.refreshExtensionPoints();</b> |
75 | 74 |
* </p> |
... | ... | |
77 | 76 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
78 | 77 |
* |
79 | 78 |
*/ |
80 |
public class PreferencesExtension extends Extension{ |
|
79 |
public class PreferencesExtension extends Extension {
|
|
81 | 80 |
|
82 |
private static Logger logger = LoggerFactory.getLogger(PreferencesExtension.class);
|
|
83 |
private ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager();
|
|
81 |
private static final Logger logger = LoggerFactory.getLogger(PreferencesExtension.class);
|
|
82 |
private final ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
|
|
84 | 83 |
|
85 |
private boolean initilizedExtensions=false;
|
|
84 |
private boolean initilizedExtensions = false;
|
|
86 | 85 |
|
87 |
public void initialize() { |
|
86 |
@Override |
|
87 |
public void initialize() { |
|
88 | 88 |
|
89 |
registerIcons();
|
|
90 |
initializeCoreExtensions();
|
|
91 |
}
|
|
89 |
registerIcons();
|
|
90 |
initializeCoreExtensions();
|
|
91 |
}
|
|
92 | 92 |
|
93 |
private void registerIcons(){
|
|
94 |
IconThemeHelper.registerIcon("action", "edit-setup", this);
|
|
95 |
IconThemeHelper.registerIcon("action", "application-exit", this);
|
|
93 |
private void registerIcons() {
|
|
94 |
IconThemeHelper.registerIcon("action", "edit-setup", this);
|
|
95 |
IconThemeHelper.registerIcon("action", "application-exit", this);
|
|
96 | 96 |
|
97 |
// AppearancePage.java |
|
98 |
IconThemeHelper.registerIcon("preferences", "edit-setup-appearance", this); |
|
99 |
// BrowserControlPage.java |
|
100 |
IconThemeHelper.registerIcon("preferences", "edit-setup-browsercontrol", this); |
|
101 |
// DirExtensionPage.java |
|
102 |
IconThemeHelper.registerIcon("preferences", "edit-setup-dirextension", this); |
|
103 |
// ExtensionPage.java |
|
104 |
IconThemeHelper.registerIcon("preferences", "edit-setup-extension", this); |
|
105 |
// ExtensionsPage.java |
|
106 |
IconThemeHelper.registerIcon("preferences", "edit-setup-extensions", this); |
|
107 |
// GeneralPage.java |
|
108 |
IconThemeHelper.registerIcon("preferences", "edit-setup-general", this); |
|
109 |
// FolderingPage.java |
|
110 |
IconThemeHelper.registerIcon("preferences", "edit-setup-foldering", this); |
|
111 |
// LanguagePage.java |
|
112 |
IconThemeHelper.registerIcon("preferences", "edit-setup-language", this); |
|
113 |
// ScreenSettingsPage.java |
|
114 |
IconThemeHelper.registerIcon("preferences", "edit-setup-screensetting", this); |
|
115 |
// FirewallPage.java |
|
116 |
IconThemeHelper.registerIcon("preferences", "edit-setup-firewall", this); |
|
117 |
// NetworkPage.java |
|
118 |
IconThemeHelper.registerIcon("preferences", "edit-setup-network", this); |
|
119 |
// SkinPreferences.java |
|
120 |
IconThemeHelper.registerIcon("preferences", "edit-setup-skin", this); |
|
121 |
IconThemeHelper.registerIcon("preferences", "edit-setup-icontheme", this); |
|
122 |
} |
|
97 | 123 |
|
98 |
// AppearancePage.java |
|
99 |
IconThemeHelper.registerIcon("preferences", "edit-setup-appearance", this); |
|
100 |
// BrowserControlPage.java |
|
101 |
IconThemeHelper.registerIcon("preferences", "edit-setup-browsercontrol", this); |
|
102 |
// DirExtensionPage.java |
|
103 |
IconThemeHelper.registerIcon("preferences", "edit-setup-dirextension", this); |
|
104 |
// ExtensionPage.java |
|
105 |
IconThemeHelper.registerIcon("preferences", "edit-setup-extension", this); |
|
106 |
// ExtensionsPage.java |
|
107 |
IconThemeHelper.registerIcon("preferences", "edit-setup-extensions", this); |
|
108 |
// GeneralPage.java |
|
109 |
IconThemeHelper.registerIcon("preferences", "edit-setup-general", this); |
|
110 |
// FolderingPage.java |
|
111 |
IconThemeHelper.registerIcon("preferences", "edit-setup-foldering", this); |
|
112 |
// LanguagePage.java |
|
113 |
IconThemeHelper.registerIcon("preferences", "edit-setup-language", this); |
|
114 |
// ScreenSettingsPage.java |
|
115 |
IconThemeHelper.registerIcon("preferences", "edit-setup-screensetting", this); |
|
116 |
// FirewallPage.java |
|
117 |
IconThemeHelper.registerIcon("preferences", "edit-setup-firewall", this); |
|
118 |
// NetworkPage.java |
|
119 |
IconThemeHelper.registerIcon("preferences", "edit-setup-network", this); |
|
120 |
// SkinPreferences.java |
|
121 |
IconThemeHelper.registerIcon("preferences", "edit-setup-skin", this); |
|
122 |
IconThemeHelper.registerIcon("preferences", "edit-setup-icontheme", this); |
|
123 |
} |
|
124 |
|
|
125 |
public void execute(String actionCommand) { |
|
126 |
if (!this.initilizedExtensions) { |
|
127 |
initializeExtensions(); |
|
128 |
initializeExtensionsConfig(); |
|
129 |
this.initilizedExtensions = true; |
|
130 |
} |
|
131 |
if ("edit-setup".equalsIgnoreCase(actionCommand)) { |
|
132 |
DlgPreferences dlgPreferences = PluginServices.getDlgPreferences(); |
|
133 |
dlgPreferences.refreshExtensionPoints(); |
|
134 |
PluginServices.getMDIManager().addWindow(dlgPreferences); |
|
135 |
} else if ( "application-exit".equalsIgnoreCase(actionCommand) ) { |
|
124 |
@Override |
|
125 |
public void execute(String actionCommand) { |
|
126 |
if (!this.initilizedExtensions) { |
|
127 |
initializeExtensions(); |
|
128 |
initializeExtensionsConfig(); |
|
129 |
this.initilizedExtensions = true; |
|
130 |
} |
|
131 |
if ("edit-setup".equalsIgnoreCase(actionCommand)) { |
|
132 |
DlgPreferences dlgPreferences = PluginServices.getDlgPreferences(); |
|
133 |
dlgPreferences.refreshExtensionPoints(); |
|
134 |
PluginServices.getMDIManager().addWindow(dlgPreferences); |
|
135 |
} else if ("application-exit".equalsIgnoreCase(actionCommand)) { |
|
136 | 136 |
Launcher.closeApplication(); |
137 | 137 |
} |
138 |
} |
|
139 |
public boolean isEnabled() { |
|
140 |
return true; |
|
141 |
} |
|
138 |
} |
|
142 | 139 |
|
143 |
public boolean isVisible() { |
|
144 |
return true; |
|
145 |
} |
|
140 |
@Override |
|
141 |
public boolean isEnabled() { |
|
142 |
return true; |
|
143 |
} |
|
146 | 144 |
|
147 |
private void initializeCoreExtensions() { |
|
148 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
|
149 |
ep.append("GeneralPage", "", new GeneralPage()); |
|
150 |
ep.append("NetworkPage", "", new NetworkPage()); |
|
151 |
ep.append("FirewallPage", "", new FirewallPage()); |
|
152 |
ep.append("LanguagePage", "", new LanguagePage()); |
|
153 |
ep.append("ExtensionsPage", "", new ExtensionsPage()); |
|
154 |
ep.append("AppearancePage", "", new AppearancePage()); |
|
155 |
ep.append("FolderingPage", "", new FolderingPage()); |
|
156 |
ep.append("ScreenSettingsPage", "", new ScreenSettingsPage()); |
|
157 |
ep.append("SkinPreferences", "", new SkinPreferences()); |
|
158 |
ep.append("IconThemePage", "", new IconThemePage()); |
|
145 |
@Override |
|
146 |
public boolean isVisible() { |
|
147 |
return true; |
|
148 |
} |
|
159 | 149 |
|
160 |
ep.append("NotificationsPage", "", new NotificationsPage()); |
|
150 |
private void initializeCoreExtensions() { |
|
151 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
|
152 |
ep.append("GeneralPage", "", new GeneralPage()); |
|
153 |
ep.append("NetworkPage", "", new NetworkPage()); |
|
154 |
ep.append("FirewallPage", "", new FirewallPage()); |
|
155 |
ep.append("LanguagePage", "", new LanguagePage()); |
|
156 |
ep.append("ExtensionsPage", "", new ExtensionsPage()); |
|
157 |
ep.append("AppearancePage", "", new AppearancePage()); |
|
158 |
ep.append("FolderingPage", "", new FolderingPage()); |
|
159 |
ep.append("ScreenSettingsPage", "", new ScreenSettingsPage()); |
|
160 |
ep.append("SkinPreferences", "", new SkinPreferences()); |
|
161 |
ep.append("IconThemePage", "", new IconThemePage()); |
|
161 | 162 |
|
163 |
ep.append("NotificationsPage", "", new NotificationsPage()); |
|
164 |
|
|
162 | 165 |
// this.extensionPoints.add("AplicationPreferences","GeneralPage", new GeneralPage()); |
163 | 166 |
// this.extensionPoints.add("AplicationPreferences","NetworkPage", new NetworkPage()); |
164 | 167 |
// this.extensionPoints.add("AplicationPreferences","FirewallPage", new FirewallPage()); |
... | ... | |
168 | 171 |
// this.extensionPoints.add("AplicationPreferences","FolderingPage", new FolderingPage()); |
169 | 172 |
// this.extensionPoints.add("AplicationPreferences","ResolutionPage", new ScreenSettingsPage()); |
170 | 173 |
// this.extensionPoints.add("AplicationPreferences","SkinPreferences", new SkinPreferences()); |
171 |
String os = System.getProperty("os.name").toLowerCase();
|
|
172 |
if (os.indexOf("linux") != -1 || os.indexOf("unix")!= -1) {
|
|
173 |
ep.append("BrowserControlPage", "", new BrowserControlPage());
|
|
174 |
String os = System.getProperty("os.name").toLowerCase();
|
|
175 |
if (os.contains("linux") || os.contains("unix")) {
|
|
176 |
ep.append("BrowserControlPage", "", new BrowserControlPage());
|
|
174 | 177 |
// this.extensionPoints.add("AplicationPreferences","BrowserControlPage", new BrowserControlPage()); |
175 |
}
|
|
178 |
}
|
|
176 | 179 |
|
177 |
//Falta los plugin
|
|
178 |
}
|
|
180 |
//Falta los plugin
|
|
181 |
}
|
|
179 | 182 |
|
180 |
private void initializeExtensionsConfig() {
|
|
181 |
HashMap pc = Launcher.getPluginConfig();
|
|
182 |
ArrayList array = new ArrayList();
|
|
183 |
Iterator iter = pc.values().iterator();
|
|
183 |
private void initializeExtensionsConfig() {
|
|
184 |
HashMap pc = Launcher.getPluginConfig();
|
|
185 |
ArrayList array = new ArrayList();
|
|
186 |
Iterator iter = pc.values().iterator();
|
|
184 | 187 |
|
185 |
while (iter.hasNext()) {
|
|
186 |
array.add(((PluginConfig) iter.next()).getExtensions());
|
|
187 |
}
|
|
188 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", "");
|
|
188 |
while (iter.hasNext()) {
|
|
189 |
array.add(((PluginConfig) iter.next()).getExtensions());
|
|
190 |
}
|
|
191 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", "");
|
|
189 | 192 |
|
190 |
Extensions[] exts = (Extensions[]) array.toArray(new Extensions[0]);
|
|
191 |
for (int i = 0; i < exts.length; i++) {
|
|
192 |
for (int j = 0; j < exts[i].getExtensionCount(); j++) {
|
|
193 |
org.gvsig.andami.plugins.config.generate.Extension ext = exts[i]
|
|
194 |
.getExtension(j);
|
|
195 |
String sExt = ext.getClassName().toString();
|
|
193 |
Extensions[] exts = (Extensions[]) array.toArray(new Extensions[0]);
|
|
194 |
for (int i = 0; i < exts.length; i++) {
|
|
195 |
for (int j = 0; j < exts[i].getExtensionCount(); j++) {
|
|
196 |
org.gvsig.andami.plugins.config.generate.Extension ext = exts[i]
|
|
197 |
.getExtension(j);
|
|
198 |
String sExt = ext.getClassName();
|
|
196 | 199 |
// String pn = null; |
197 |
// pn = sExt.substring(0, sExt.lastIndexOf(".")); |
|
198 |
// dlgPrefs.addPreferencePage(new PluginsPage(pn)); |
|
199 |
// dlgPrefs.addPreferencePage(new ExtensionPage(ext)); |
|
200 |
ep.append(sExt, "", new ExtensionPage(ext)); |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
/** |
|
205 |
* |
|
206 |
*/ |
|
207 |
private void initializeExtensions() { |
|
208 |
Iterator i = Launcher.getExtensionIterator(); |
|
209 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
|
210 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
200 |
// pn = sExt.substring(0, sExt.lastIndexOf(".")); |
|
201 |
// dlgPrefs.addPreferencePage(new PluginsPage(pn)); |
|
202 |
// dlgPrefs.addPreferencePage(new ExtensionPage(ext)); |
|
203 |
ep.append(sExt, "", new ExtensionPage(ext)); |
|
204 |
} |
|
205 |
} |
|
206 |
} |
|
211 | 207 |
|
212 |
while (i.hasNext()) { |
|
213 |
Object extension = i.next(); |
|
208 |
/** |
|
209 |
* |
|
210 |
*/ |
|
211 |
private void initializeExtensions() { |
|
212 |
Iterator i = Launcher.getExtensionIterator(); |
|
213 |
ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
|
214 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
214 | 215 |
|
215 |
if (extension instanceof IPreferenceExtension) { |
|
216 |
IPreferenceExtension pe = (IPreferenceExtension) extension; |
|
217 |
IPreference[] pp = null; |
|
218 |
try{ |
|
219 |
pp = pe.getPreferencesPages(); |
|
220 |
} catch (Throwable th){ |
|
221 |
//Do nothing |
|
222 |
} |
|
216 |
while (i.hasNext()) { |
|
217 |
Object extension = i.next(); |
|
223 | 218 |
|
224 |
if (pp == null) { |
|
225 |
String msg = "Preferences page is NULL. Extension " |
|
226 |
+ extension.getClass().getName() |
|
227 |
+ " implements IPreferenceExtension but does not provide pref. pages. "; |
|
228 |
logger.info(msg); |
|
229 |
String[] params = {extension.getClass().getName()}; |
|
230 |
NotificationManager.addInfo(i18nManager.getTranslation("extension_does_not_provide_preferences_pages",params)); |
|
231 |
} else { |
|
232 |
for (int j = 0; j < pp.length; j++) { |
|
233 |
try { |
|
234 |
pp[j].initializeValues(); |
|
235 |
ep.append(pp[j].getID(), "", pp[j]); |
|
219 |
if (extension instanceof IPreferenceExtension) { |
|
220 |
IPreferenceExtension pe = (IPreferenceExtension) extension; |
|
221 |
IPreference[] pp = null; |
|
222 |
try { |
|
223 |
pp = pe.getPreferencesPages(); |
|
224 |
} catch (Throwable th) { |
|
225 |
logger.warn("Can't get preference pages from '"+extension.getClass().getName()+"'.",th); |
|
226 |
continue; |
|
227 |
} |
|
228 |
|
|
229 |
if (pp == null) { |
|
230 |
String msg = "Preferences page is NULL. Extension " |
|
231 |
+ extension.getClass().getName() |
|
232 |
+ " implements IPreferenceExtension but does not provide pref. pages. "; |
|
233 |
logger.info(msg); |
|
234 |
// String[] params = {extension.getClass().getName()}; |
|
235 |
// NotificationManager.addInfo(i18nManager.getTranslation("extension_does_not_provide_preferences_pages", params)); |
|
236 |
} else { |
|
237 |
for (int j = 0; j < pp.length; j++) { |
|
238 |
try { |
|
239 |
pp[j].initializeValues(); |
|
240 |
ep.append(pp[j].getID(), "", pp[j]); |
|
236 | 241 |
} catch (Throwable th) { |
237 | 242 |
String msg = "cant_initialize_values_for_{0}_page_in_{1}"; |
238 | 243 |
String[] params = {pp[j].getTitle(), extension.getClass().getName()}; |
239 |
NotificationManager.addWarning(i18nManager.getTranslation(msg,params),th);
|
|
244 |
NotificationManager.addWarning(i18nManager.getTranslation(msg, params), th);
|
|
240 | 245 |
} |
241 |
}
|
|
242 |
}
|
|
243 |
}
|
|
244 |
}
|
|
245 |
}
|
|
246 |
}
|
|
247 |
}
|
|
248 |
}
|
|
249 |
}
|
|
250 |
}
|
|
246 | 251 |
|
247 |
public void postInitialize() { |
|
248 |
super.postInitialize(); |
|
249 |
DlgPreferences dlgPreferences=PluginServices.getDlgPreferences(); |
|
250 |
dlgPreferences.refreshExtensionPoints(); |
|
251 |
dlgPreferences.storeValues(); |
|
252 |
} |
|
252 |
@Override |
|
253 |
public void postInitialize() { |
|
254 |
super.postInitialize(); |
|
255 |
DlgPreferences dlgPreferences = PluginServices.getDlgPreferences(); |
|
256 |
dlgPreferences.refreshExtensionPoints(); |
|
257 |
dlgPreferences.storeValues(); |
|
258 |
} |
|
253 | 259 |
} |
Also available in: Unified diff