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