root / tags / v2_0_0_Build_2047 / libraries / libCorePlugin / src / org / gvsig / coreplugin / PreferencesExtension.java @ 38279
History | View | Annotate | Download (9.91 KB)
1 | 29630 | jpiera | package org.gvsig.coreplugin; |
---|---|---|---|
2 | 5792 | caballero | |
3 | import java.util.ArrayList; |
||
4 | import java.util.HashMap; |
||
5 | import java.util.Iterator; |
||
6 | |||
7 | 29630 | jpiera | import org.gvsig.andami.Launcher; |
8 | import org.gvsig.andami.PluginServices; |
||
9 | import org.gvsig.andami.plugins.Extension; |
||
10 | import org.gvsig.andami.plugins.config.generate.Extensions; |
||
11 | import org.gvsig.andami.plugins.config.generate.PluginConfig; |
||
12 | import org.gvsig.andami.preferences.DlgPreferences; |
||
13 | import org.gvsig.andami.preferences.IPreference; |
||
14 | import org.gvsig.andami.preferences.IPreferenceExtension; |
||
15 | import org.gvsig.coreplugin.preferences.general.AppearancePage; |
||
16 | import org.gvsig.coreplugin.preferences.general.BrowserControlPage; |
||
17 | import org.gvsig.coreplugin.preferences.general.DirExtensionsPage; |
||
18 | import org.gvsig.coreplugin.preferences.general.ExtensionPage; |
||
19 | import org.gvsig.coreplugin.preferences.general.ExtensionsPage; |
||
20 | import org.gvsig.coreplugin.preferences.general.FolderingPage; |
||
21 | import org.gvsig.coreplugin.preferences.general.GeneralPage; |
||
22 | import org.gvsig.coreplugin.preferences.general.LanguagePage; |
||
23 | import org.gvsig.coreplugin.preferences.general.ScreenSettingsPage; |
||
24 | import org.gvsig.coreplugin.preferences.general.SkinPreferences; |
||
25 | import org.gvsig.coreplugin.preferences.network.FirewallPage; |
||
26 | import org.gvsig.coreplugin.preferences.network.NetworkPage; |
||
27 | 26882 | vcaballero | import org.gvsig.tools.ToolsLocator; |
28 | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
||
29 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
30 | 38224 | jldominguez | import org.slf4j.Logger; |
31 | import org.slf4j.LoggerFactory; |
||
32 | 26882 | vcaballero | |
33 | 5792 | caballero | |
34 | 7607 | jaume | /**
|
35 | *
|
||
36 | * <p>
|
||
37 | * Extension that provides support for visual application configuration
|
||
38 | * through a Preferences dialog where the user can specify its own settings for
|
||
39 | * general purpose aspects.
|
||
40 | * </p>
|
||
41 | * <p>
|
||
42 | * Adding new preference pages is made through ExtensionPoints by invoking
|
||
43 | * <b>
|
||
44 | * this.extensionPoints.add("AplicationPreferences","YourIPreferencesClassName", yourIPreferencesPage);
|
||
45 | * </b>
|
||
46 | * and then call <b>DlgPreferences.refreshExtensionPoints();</b>
|
||
47 | * </p>
|
||
48 | *
|
||
49 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
50 | *
|
||
51 | */
|
||
52 | 6661 | caballero | public class PreferencesExtension extends Extension{ |
53 | 38224 | jldominguez | |
54 | private static Logger logger = LoggerFactory.getLogger(PreferencesExtension.class); |
||
55 | 26882 | vcaballero | private ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager();
|
56 | 6661 | caballero | |
57 | 6380 | jmvivo | private boolean initilizedExtensions=false; |
58 | 5792 | caballero | |
59 | public void initialize() { |
||
60 | 14808 | jmvivo | |
61 | registerIcons(); |
||
62 | 6337 | jmvivo | initializeCoreExtensions(); |
63 | 5792 | caballero | } |
64 | |||
65 | 14808 | jmvivo | private void registerIcons(){ |
66 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
67 | 14808 | jmvivo | "application-preferences",
|
68 | this.getClass().getClassLoader().getResource("images/config.png") |
||
69 | ); |
||
70 | |||
71 | // AppearancePage.java
|
||
72 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
73 | 14808 | jmvivo | "aplication-preferences-appearance",
|
74 | this.getClass().getClassLoader().getResource("images/gnome-settings-theme.png") |
||
75 | ); |
||
76 | |||
77 | // BrowserControlPage.java
|
||
78 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
79 | 14808 | jmvivo | "aplication-preferences-browsercontrol",
|
80 | this.getClass().getClassLoader().getResource("images/browser.png") |
||
81 | ); |
||
82 | |||
83 | |||
84 | // DirExtensionPage.java
|
||
85 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
86 | 14808 | jmvivo | "aplication-preferences-dirextension",
|
87 | this.getClass().getClassLoader().getResource("images/file-manager.png") |
||
88 | ); |
||
89 | |||
90 | // ExtensionPage.java
|
||
91 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
92 | 14808 | jmvivo | "aplication-preferences-extension",
|
93 | this.getClass().getClassLoader().getResource("images/emblem-work.png") |
||
94 | ); |
||
95 | |||
96 | // ExtensionsPage.java
|
||
97 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
98 | 14808 | jmvivo | "aplication-preferences-extensions",
|
99 | this.getClass().getClassLoader().getResource("images/bonobo-component-browser.png") |
||
100 | ); |
||
101 | |||
102 | // FolderingPage.java
|
||
103 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
104 | 14808 | jmvivo | "aplication-preferences-foldering",
|
105 | this.getClass().getClassLoader().getResource("images/folder.png") |
||
106 | ); |
||
107 | |||
108 | // LanguagePage.java
|
||
109 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
110 | 14808 | jmvivo | "aplication-preferences-language",
|
111 | this.getClass().getClassLoader().getResource("images/babel.png") |
||
112 | ); |
||
113 | |||
114 | // ScreenSettingsPage.java
|
||
115 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
116 | 14808 | jmvivo | "aplication-preferences-screensetting",
|
117 | this.getClass().getClassLoader().getResource("images/resolution.png") |
||
118 | ); |
||
119 | // FirewallPage.java
|
||
120 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
121 | 14808 | jmvivo | "aplication-preferences-firewall",
|
122 | this.getClass().getClassLoader().getResource("images/shield.png") |
||
123 | ); |
||
124 | |||
125 | // NetworkPage.java
|
||
126 | 15786 | jmvivo | //
|
127 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
128 | 14808 | jmvivo | "aplication-preferences-network",
|
129 | this.getClass().getClassLoader().getResource("images/network.png") |
||
130 | ); |
||
131 | 15635 | jmvivo | PluginServices.getIconTheme().registerDefault( |
132 | "application-console",
|
||
133 | this.getClass().getClassLoader().getResource("images/console.png") |
||
134 | ); |
||
135 | PluginServices.getIconTheme().registerDefault( |
||
136 | "gnome-settings-theme",
|
||
137 | this.getClass().getClassLoader().getResource("images/gnome-settings-theme.png") |
||
138 | ); |
||
139 | PluginServices.getIconTheme().registerDefault( |
||
140 | "browser-icon",
|
||
141 | this.getClass().getClassLoader().getResource("images/browser.png") |
||
142 | ); |
||
143 | PluginServices.getIconTheme().registerDefault( |
||
144 | "file-manager",
|
||
145 | this.getClass().getClassLoader().getResource("images/file-manager.png") |
||
146 | ); |
||
147 | PluginServices.getIconTheme().registerDefault( |
||
148 | "emblem-work",
|
||
149 | this.getClass().getClassLoader().getResource("images/emblem-work.png") |
||
150 | ); |
||
151 | PluginServices.getIconTheme().registerDefault( |
||
152 | "folder-icon",
|
||
153 | this.getClass().getClassLoader().getResource("images/folder.png") |
||
154 | ); |
||
155 | PluginServices.getIconTheme().registerDefault( |
||
156 | "kde-network-online-icon",
|
||
157 | this.getClass().getClassLoader().getResource("images/kde-network-online.png") |
||
158 | ); |
||
159 | PluginServices.getIconTheme().registerDefault( |
||
160 | "kde-network-offline-icon",
|
||
161 | this.getClass().getClassLoader().getResource("images/kde-network-offline.png") |
||
162 | ); |
||
163 | 14808 | jmvivo | |
164 | 15635 | jmvivo | |
165 | |||
166 | 14808 | jmvivo | } |
167 | |||
168 | 5792 | caballero | public void execute(String actionCommand) { |
169 | 6380 | jmvivo | if (!this.initilizedExtensions) { |
170 | initializeExtensions(); |
||
171 | initializeExtensionsConfig(); |
||
172 | this.initilizedExtensions = true; |
||
173 | } |
||
174 | 6661 | caballero | |
175 | 7311 | caballero | DlgPreferences dlgPreferences=PluginServices.getDlgPreferences(); |
176 | dlgPreferences.refreshExtensionPoints(); |
||
177 | PluginServices.getMDIManager().addWindow(dlgPreferences); |
||
178 | 5792 | caballero | } |
179 | public boolean isEnabled() { |
||
180 | return true; |
||
181 | } |
||
182 | |||
183 | public boolean isVisible() { |
||
184 | return true; |
||
185 | } |
||
186 | 6102 | jaume | |
187 | 5792 | caballero | private void initializeCoreExtensions() { |
188 | 26882 | vcaballero | ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
189 | 26905 | jmvivo | ep.append("GeneralPage", "", new GeneralPage()); |
190 | ep.append("NetworkPage", "", new NetworkPage()); |
||
191 | ep.append("FirewallPage", "", new FirewallPage()); |
||
192 | ep.append("DirExtensionsPage", "", new DirExtensionsPage()); |
||
193 | ep.append("LanguagePage", "", new LanguagePage()); |
||
194 | ep.append("ExtensionsPage", "", new ExtensionsPage()); |
||
195 | ep.append("AppearancePage", "", new AppearancePage()); |
||
196 | ep.append("FolderingPage", "", new FolderingPage()); |
||
197 | ep.append("ScreenSettingsPage", "", new ScreenSettingsPage()); |
||
198 | ep.append("SkinPreferences", "", new SkinPreferences()); |
||
199 | 26882 | vcaballero | |
200 | // this.extensionPoints.add("AplicationPreferences","GeneralPage", new GeneralPage());
|
||
201 | // this.extensionPoints.add("AplicationPreferences","NetworkPage", new NetworkPage());
|
||
202 | // this.extensionPoints.add("AplicationPreferences","FirewallPage", new FirewallPage());
|
||
203 | // this.extensionPoints.add("AplicationPreferences","DirExtensionsPage", new DirExtensionsPage());
|
||
204 | // this.extensionPoints.add("AplicationPreferences","LanguagePage", new LanguagePage());
|
||
205 | // this.extensionPoints.add("AplicationPreferences","ExtensionsPage", new ExtensionsPage());
|
||
206 | // this.extensionPoints.add("AplicationPreferences","AppearancePage", new AppearancePage());
|
||
207 | // this.extensionPoints.add("AplicationPreferences","FolderingPage", new FolderingPage());
|
||
208 | // this.extensionPoints.add("AplicationPreferences","ResolutionPage", new ScreenSettingsPage());
|
||
209 | // this.extensionPoints.add("AplicationPreferences","SkinPreferences", new SkinPreferences());
|
||
210 | 9644 | jaume | String os = System.getProperty("os.name").toLowerCase(); |
211 | 26905 | jmvivo | if (os.indexOf("linux") != -1 || os.indexOf("unix")!= -1) { |
212 | ep.append("BrowserControlPage", "", new BrowserControlPage()); |
||
213 | 26882 | vcaballero | // this.extensionPoints.add("AplicationPreferences","BrowserControlPage", new BrowserControlPage());
|
214 | 26905 | jmvivo | } |
215 | 6661 | caballero | |
216 | 5792 | caballero | //Falta los plugin
|
217 | } |
||
218 | 6102 | jaume | |
219 | 5792 | caballero | private void initializeExtensionsConfig() { |
220 | HashMap pc = Launcher.getPluginConfig();
|
||
221 | ArrayList array = new ArrayList(); |
||
222 | Iterator iter = pc.values().iterator();
|
||
223 | |||
224 | while (iter.hasNext()) {
|
||
225 | array.add(((PluginConfig) iter.next()).getExtensions()); |
||
226 | } |
||
227 | 26882 | vcaballero | ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
228 | 5792 | caballero | |
229 | Extensions[] exts = (Extensions[]) array.toArray(new Extensions[0]); |
||
230 | for (int i = 0; i < exts.length; i++) { |
||
231 | for (int j = 0; j < exts[i].getExtensionCount(); j++) { |
||
232 | 29630 | jpiera | org.gvsig.andami.plugins.config.generate.Extension ext = exts[i] |
233 | 5792 | caballero | .getExtension(j); |
234 | String sExt = ext.getClassName().toString();
|
||
235 | 8142 | jaume | // String pn = null;
|
236 | // pn = sExt.substring(0, sExt.lastIndexOf("."));
|
||
237 | // dlgPrefs.addPreferencePage(new PluginsPage(pn));
|
||
238 | // dlgPrefs.addPreferencePage(new ExtensionPage(ext));
|
||
239 | 26882 | vcaballero | ep.append(sExt, "", new ExtensionPage(ext)); |
240 | 5792 | caballero | } |
241 | } |
||
242 | } |
||
243 | /**
|
||
244 | *
|
||
245 | */
|
||
246 | private void initializeExtensions() { |
||
247 | 28994 | cmartinez | Iterator i = Launcher.getExtensionIterator();
|
248 | 26882 | vcaballero | ExtensionPoint ep = this.extensionPoints.add("AplicationPreferences", ""); |
249 | |||
250 | 8142 | jaume | while (i.hasNext()) {
|
251 | 28994 | cmartinez | Object extension = i.next();
|
252 | 5792 | caballero | |
253 | 28994 | cmartinez | if (extension instanceof IPreferenceExtension) { |
254 | 38224 | jldominguez | IPreferenceExtension pe = (IPreferenceExtension) extension; |
255 | IPreference[] pp = pe.getPreferencesPages();
|
||
256 | |||
257 | if (pp == null) { |
||
258 | logger.info("Preferences page is NULL. Extension "
|
||
259 | + extension.getClass().getName() |
||
260 | + " implements IPreferenceExtension but does not provide pref. pages. ");
|
||
261 | } else {
|
||
262 | for (int j = 0; j < pp.length; j++) { |
||
263 | ep.append(pp[j].getID(), "", pp[j]);
|
||
264 | pp[j].initializeValues(); |
||
265 | } |
||
266 | 9634 | caballero | } |
267 | 8142 | jaume | } |
268 | 5792 | caballero | } |
269 | } |
||
270 | 15512 | vcaballero | |
271 | public void postInitialize() { |
||
272 | super.postInitialize();
|
||
273 | DlgPreferences dlgPreferences=PluginServices.getDlgPreferences(); |
||
274 | dlgPreferences.refreshExtensionPoints(); |
||
275 | 16921 | vcaballero | dlgPreferences.storeValues(); |
276 | 15512 | vcaballero | } |
277 | 5792 | caballero | } |