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 @ 43305
History | View | Annotate | Download (9.76 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 43100 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
11 | 43100 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
16 | 43100 | jjdelcerro | * 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.
|
||
19 | 40558 | jjdelcerro | *
|
20 | 43100 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40558 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.coreplugin; |
24 | |||
25 | import java.util.ArrayList; |
||
26 | import java.util.HashMap; |
||
27 | import java.util.Iterator; |
||
28 | |||
29 | 43305 | fdiaz | import org.slf4j.Logger; |
30 | import org.slf4j.LoggerFactory; |
||
31 | |||
32 | 40435 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
33 | import org.gvsig.andami.Launcher; |
||
34 | import org.gvsig.andami.PluginServices; |
||
35 | 43256 | jjdelcerro | import org.gvsig.andami.PluginsLocator; |
36 | import org.gvsig.andami.PluginsManager; |
||
37 | 40435 | jjdelcerro | import org.gvsig.andami.plugins.Extension; |
38 | import org.gvsig.andami.plugins.config.generate.Extensions; |
||
39 | import org.gvsig.andami.plugins.config.generate.PluginConfig; |
||
40 | import org.gvsig.andami.preferences.DlgPreferences; |
||
41 | import org.gvsig.andami.preferences.IPreference; |
||
42 | import org.gvsig.andami.preferences.IPreferenceExtension; |
||
43 | import org.gvsig.coreplugin.preferences.general.BrowserControlPage; |
||
44 | import org.gvsig.coreplugin.preferences.general.ExtensionPage; |
||
45 | import org.gvsig.coreplugin.preferences.general.ExtensionsPage; |
||
46 | import org.gvsig.coreplugin.preferences.general.FolderingPage; |
||
47 | import org.gvsig.coreplugin.preferences.general.GeneralPage; |
||
48 | import org.gvsig.coreplugin.preferences.general.IconThemePage; |
||
49 | 41282 | jjdelcerro | import org.gvsig.coreplugin.preferences.general.NotificationsPage; |
50 | 40435 | jjdelcerro | import org.gvsig.coreplugin.preferences.general.ScreenSettingsPage; |
51 | import org.gvsig.coreplugin.preferences.general.SkinPreferences; |
||
52 | 43256 | jjdelcerro | import org.gvsig.coreplugin.preferences.general.appearance.AppearancePage; |
53 | 40435 | jjdelcerro | import org.gvsig.coreplugin.preferences.network.FirewallPage; |
54 | import org.gvsig.coreplugin.preferences.network.NetworkPage; |
||
55 | import org.gvsig.tools.ToolsLocator; |
||
56 | 43256 | jjdelcerro | import org.gvsig.tools.dynobject.DynObject; |
57 | 40435 | jjdelcerro | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
58 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
59 | 42141 | fdiaz | import org.gvsig.tools.i18n.I18nManager; |
60 | 43256 | jjdelcerro | import org.gvsig.tools.util.ToolsUtilLocator; |
61 | 42141 | fdiaz | |
62 | 40435 | jjdelcerro | /**
|
63 | *
|
||
64 | * <p>
|
||
65 | 43100 | jjdelcerro | * Extension that provides support for visual application configuration through
|
66 | * a Preferences dialog where the user can specify its own settings for general
|
||
67 | * purpose aspects.
|
||
68 | 40435 | jjdelcerro | * </p>
|
69 | * <p>
|
||
70 | * Adding new preference pages is made through ExtensionPoints by invoking
|
||
71 | * <b>
|
||
72 | 43100 | jjdelcerro | * this.extensionPoints.add("AplicationPreferences","YourIPreferencesClassName",
|
73 | * yourIPreferencesPage);
|
||
74 | 40435 | jjdelcerro | * </b>
|
75 | * and then call <b>DlgPreferences.refreshExtensionPoints();</b>
|
||
76 | * </p>
|
||
77 | *
|
||
78 | *
|
||
79 | */
|
||
80 | 43100 | jjdelcerro | public class PreferencesExtension extends Extension { |
81 | 42141 | fdiaz | |
82 | 43100 | jjdelcerro | private static final Logger logger = LoggerFactory.getLogger(PreferencesExtension.class); |
83 | private final ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
||
84 | 40435 | jjdelcerro | |
85 | 43100 | jjdelcerro | private boolean initilizedExtensions = false; |
86 | 40435 | jjdelcerro | |
87 | 43100 | jjdelcerro | @Override
|
88 | public void initialize() { |
||
89 | 43256 | jjdelcerro | initializeUseNativeFileChooser(); |
90 | 43100 | jjdelcerro | registerIcons(); |
91 | initializeCoreExtensions(); |
||
92 | } |
||
93 | 40435 | jjdelcerro | |
94 | 43256 | jjdelcerro | private void initializeUseNativeFileChooser() { |
95 | PluginsManager pluginsManager = PluginsLocator.getManager(); |
||
96 | PluginServices plugin = pluginsManager.getPlugin(PreferencesExtension.class); |
||
97 | |||
98 | DynObject pluginProperties = plugin.getPluginProperties(); |
||
99 | |||
100 | boolean useNativeFileChooser = (Boolean) pluginProperties.getDynValue("useNativeFileChooser"); |
||
101 | ToolsUtilLocator.getFileDialogChooserManager().setUseNativeFileChooser(useNativeFileChooser); |
||
102 | } |
||
103 | 43305 | fdiaz | |
104 | 43100 | jjdelcerro | private void registerIcons() { |
105 | IconThemeHelper.registerIcon("action", "edit-setup", this); |
||
106 | IconThemeHelper.registerIcon("action", "application-exit", this); |
||
107 | 40435 | jjdelcerro | |
108 | 43100 | jjdelcerro | // AppearancePage.java
|
109 | IconThemeHelper.registerIcon("preferences", "edit-setup-appearance", this); |
||
110 | // BrowserControlPage.java
|
||
111 | IconThemeHelper.registerIcon("preferences", "edit-setup-browsercontrol", this); |
||
112 | // DirExtensionPage.java
|
||
113 | IconThemeHelper.registerIcon("preferences", "edit-setup-dirextension", this); |
||
114 | // ExtensionPage.java
|
||
115 | IconThemeHelper.registerIcon("preferences", "edit-setup-extension", this); |
||
116 | // ExtensionsPage.java
|
||
117 | IconThemeHelper.registerIcon("preferences", "edit-setup-extensions", this); |
||
118 | // GeneralPage.java
|
||
119 | IconThemeHelper.registerIcon("preferences", "edit-setup-general", this); |
||
120 | // FolderingPage.java
|
||
121 | IconThemeHelper.registerIcon("preferences", "edit-setup-foldering", this); |
||
122 | // LanguagePage.java
|
||
123 | IconThemeHelper.registerIcon("preferences", "edit-setup-language", this); |
||
124 | // ScreenSettingsPage.java
|
||
125 | IconThemeHelper.registerIcon("preferences", "edit-setup-screensetting", this); |
||
126 | // FirewallPage.java
|
||
127 | IconThemeHelper.registerIcon("preferences", "edit-setup-firewall", this); |
||
128 | // NetworkPage.java
|
||
129 | IconThemeHelper.registerIcon("preferences", "edit-setup-network", this); |
||
130 | // SkinPreferences.java
|
||
131 | IconThemeHelper.registerIcon("preferences", "edit-setup-skin", this); |
||
132 | IconThemeHelper.registerIcon("preferences", "edit-setup-icontheme", this); |
||
133 | } |
||
134 | 41048 | jldominguez | |
135 | 43100 | jjdelcerro | @Override
|
136 | public void execute(String actionCommand) { |
||
137 | if (!this.initilizedExtensions) { |
||
138 | initializeExtensions(); |
||
139 | initializeExtensionsConfig(); |
||
140 | this.initilizedExtensions = true; |
||
141 | } |
||
142 | if ("edit-setup".equalsIgnoreCase(actionCommand)) { |
||
143 | DlgPreferences dlgPreferences = PluginServices.getDlgPreferences(); |
||
144 | dlgPreferences.refreshExtensionPoints(); |
||
145 | PluginServices.getMDIManager().addWindow(dlgPreferences); |
||
146 | } else if ("application-exit".equalsIgnoreCase(actionCommand)) { |
||
147 | 40893 | jjdelcerro | Launcher.closeApplication(); |
148 | } |
||
149 | 43100 | jjdelcerro | } |
150 | 40435 | jjdelcerro | |
151 | 43100 | jjdelcerro | @Override
|
152 | public boolean isEnabled() { |
||
153 | return true; |
||
154 | } |
||
155 | 40435 | jjdelcerro | |
156 | 43100 | jjdelcerro | @Override
|
157 | public boolean isVisible() { |
||
158 | return true; |
||
159 | } |
||
160 | 40435 | jjdelcerro | |
161 | 43100 | jjdelcerro | private void initializeCoreExtensions() { |
162 | 43110 | jjdelcerro | addPreferencesPage(new GeneralPage());
|
163 | addPreferencesPage(new NetworkPage());
|
||
164 | addPreferencesPage(new FirewallPage());
|
||
165 | addPreferencesPage(new ExtensionsPage());
|
||
166 | addPreferencesPage(new AppearancePage());
|
||
167 | addPreferencesPage(new FolderingPage());
|
||
168 | addPreferencesPage(new ScreenSettingsPage());
|
||
169 | addPreferencesPage(new SkinPreferences());
|
||
170 | addPreferencesPage(new IconThemePage());
|
||
171 | addPreferencesPage(new NotificationsPage());
|
||
172 | 43100 | jjdelcerro | String os = System.getProperty("os.name").toLowerCase(); |
173 | if (os.contains("linux") || os.contains("unix")) { |
||
174 | 43110 | jjdelcerro | addPreferencesPage(new BrowserControlPage());
|
175 | 43100 | jjdelcerro | } |
176 | } |
||
177 | 40435 | jjdelcerro | |
178 | 43100 | jjdelcerro | private void initializeExtensionsConfig() { |
179 | HashMap pc = Launcher.getPluginConfig();
|
||
180 | ArrayList array = new ArrayList(); |
||
181 | Iterator iter = pc.values().iterator();
|
||
182 | 40435 | jjdelcerro | |
183 | 43100 | jjdelcerro | while (iter.hasNext()) {
|
184 | array.add(((PluginConfig) iter.next()).getExtensions()); |
||
185 | } |
||
186 | Extensions[] exts = (Extensions[]) array.toArray(new Extensions[0]); |
||
187 | 43110 | jjdelcerro | for (Extensions ext1 : exts) {
|
188 | for (int j = 0; j < ext1.getExtensionCount(); j++) { |
||
189 | org.gvsig.andami.plugins.config.generate.Extension ext = ext1.getExtension(j); |
||
190 | addPreferencesPage(new ExtensionPage(ext));
|
||
191 | 43100 | jjdelcerro | } |
192 | } |
||
193 | } |
||
194 | 40435 | jjdelcerro | |
195 | 43100 | jjdelcerro | private void initializeExtensions() { |
196 | Iterator i = Launcher.getExtensionIterator();
|
||
197 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
198 | 40435 | jjdelcerro | |
199 | 43100 | jjdelcerro | while (i.hasNext()) {
|
200 | Object extension = i.next();
|
||
201 | 40435 | jjdelcerro | |
202 | 43100 | jjdelcerro | if (extension instanceof IPreferenceExtension) { |
203 | IPreferenceExtension pe = (IPreferenceExtension) extension; |
||
204 | 43110 | jjdelcerro | IPreference[] pp;
|
205 | 43100 | jjdelcerro | try {
|
206 | pp = pe.getPreferencesPages(); |
||
207 | } catch (Throwable th) { |
||
208 | logger.warn("Can't get preference pages from '"+extension.getClass().getName()+"'.",th); |
||
209 | continue;
|
||
210 | } |
||
211 | if (pp == null) { |
||
212 | String msg = "Preferences page is NULL. Extension " |
||
213 | + extension.getClass().getName() |
||
214 | + " implements IPreferenceExtension but does not provide pref. pages. ";
|
||
215 | logger.info(msg); |
||
216 | } else {
|
||
217 | 43110 | jjdelcerro | for (IPreference pp1 : pp) {
|
218 | 43100 | jjdelcerro | try {
|
219 | 43110 | jjdelcerro | addPreferencesPage(pp1); |
220 | 42141 | fdiaz | } catch (Throwable th) { |
221 | String msg = "cant_initialize_values_for_{0}_page_in_{1}"; |
||
222 | 43110 | jjdelcerro | String[] params = {pp1.getTitle(), extension.getClass().getName()}; |
223 | logger.warn(i18nManager.getTranslation(msg, params), th); |
||
224 | 42141 | fdiaz | } |
225 | 43100 | jjdelcerro | } |
226 | } |
||
227 | } |
||
228 | } |
||
229 | } |
||
230 | 40435 | jjdelcerro | |
231 | 43110 | jjdelcerro | public void addPreferencesPage(IPreference pp) { |
232 | ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
||
233 | pp.initializeValues(); |
||
234 | ep.append(pp.getID(), "", pp);
|
||
235 | } |
||
236 | 43305 | fdiaz | |
237 | 43100 | jjdelcerro | @Override
|
238 | public void postInitialize() { |
||
239 | super.postInitialize();
|
||
240 | DlgPreferences dlgPreferences = PluginServices.getDlgPreferences(); |
||
241 | dlgPreferences.refreshExtensionPoints(); |
||
242 | dlgPreferences.storeValues(); |
||
243 | } |
||
244 | 40435 | jjdelcerro | } |