svn-gvsig-desktop / trunk / libraries / libCorePlugin / src / com / iver / core / PreferencesExtension.java @ 15512
History | View | Annotate | Download (7.44 KB)
1 |
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 |
import com.iver.andami.preferences.DlgPreferences; |
14 |
import com.iver.andami.preferences.IPreference; |
15 |
import com.iver.andami.preferences.IPreferenceExtension; |
16 |
import com.iver.core.preferences.general.AppearancePage; |
17 |
import com.iver.core.preferences.general.BrowserControlPage; |
18 |
import com.iver.core.preferences.general.DirExtensionsPage; |
19 |
import com.iver.core.preferences.general.ExtensionPage; |
20 |
import com.iver.core.preferences.general.ExtensionsPage; |
21 |
import com.iver.core.preferences.general.FolderingPage; |
22 |
import com.iver.core.preferences.general.GeneralPage; |
23 |
import com.iver.core.preferences.general.LanguagePage; |
24 |
import com.iver.core.preferences.general.ScreenSettingsPage; |
25 |
import com.iver.core.preferences.network.FirewallPage; |
26 |
import com.iver.core.preferences.network.NetworkPage; |
27 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
28 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
29 |
|
30 |
/**
|
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 |
public class PreferencesExtension extends Extension{ |
49 |
private ExtensionPoints extensionPoints =
|
50 |
ExtensionPointsSingleton.getInstance(); |
51 |
|
52 |
private boolean initilizedExtensions=false; |
53 |
|
54 |
public void initialize() { |
55 |
|
56 |
registerIcons(); |
57 |
initializeCoreExtensions(); |
58 |
} |
59 |
|
60 |
private void registerIcons(){ |
61 |
PluginServices.getIconTheme().register( |
62 |
"application-preferences",
|
63 |
this.getClass().getClassLoader().getResource("images/config.png") |
64 |
); |
65 |
|
66 |
// AppearancePage.java
|
67 |
PluginServices.getIconTheme().register( |
68 |
"aplication-preferences-appearance",
|
69 |
this.getClass().getClassLoader().getResource("images/gnome-settings-theme.png") |
70 |
); |
71 |
|
72 |
// BrowserControlPage.java
|
73 |
PluginServices.getIconTheme().register( |
74 |
"aplication-preferences-browsercontrol",
|
75 |
this.getClass().getClassLoader().getResource("images/browser.png") |
76 |
); |
77 |
|
78 |
|
79 |
// DirExtensionPage.java
|
80 |
PluginServices.getIconTheme().register( |
81 |
"aplication-preferences-dirextension",
|
82 |
this.getClass().getClassLoader().getResource("images/file-manager.png") |
83 |
); |
84 |
|
85 |
// ExtensionPage.java
|
86 |
PluginServices.getIconTheme().register( |
87 |
"aplication-preferences-extension",
|
88 |
this.getClass().getClassLoader().getResource("images/emblem-work.png") |
89 |
); |
90 |
|
91 |
// ExtensionsPage.java
|
92 |
PluginServices.getIconTheme().register( |
93 |
"aplication-preferences-extensions",
|
94 |
this.getClass().getClassLoader().getResource("images/bonobo-component-browser.png") |
95 |
); |
96 |
|
97 |
// FolderingPage.java
|
98 |
PluginServices.getIconTheme().register( |
99 |
"aplication-preferences-foldering",
|
100 |
this.getClass().getClassLoader().getResource("images/folder.png") |
101 |
); |
102 |
|
103 |
// GeneralPage.java
|
104 |
// PluginServices.getIconTheme().register(
|
105 |
// "aplication-preferences-general",
|
106 |
// this.getClass().getClassLoader().getResource("images/emblem-work.png")
|
107 |
// );
|
108 |
|
109 |
// LanguagePage.java
|
110 |
PluginServices.getIconTheme().register( |
111 |
"aplication-preferences-language",
|
112 |
this.getClass().getClassLoader().getResource("images/babel.png") |
113 |
); |
114 |
|
115 |
// ScreenSettingsPage.java
|
116 |
PluginServices.getIconTheme().register( |
117 |
"aplication-preferences-screensetting",
|
118 |
this.getClass().getClassLoader().getResource("images/resolution.png") |
119 |
); |
120 |
// FirewallPage.java
|
121 |
PluginServices.getIconTheme().register( |
122 |
"aplication-preferences-firewall",
|
123 |
this.getClass().getClassLoader().getResource("images/shield.png") |
124 |
); |
125 |
|
126 |
// NetworkPage.java
|
127 |
PluginServices.getIconTheme().register( |
128 |
"aplication-preferences-network",
|
129 |
this.getClass().getClassLoader().getResource("images/network.png") |
130 |
); |
131 |
|
132 |
} |
133 |
|
134 |
public void execute(String actionCommand) { |
135 |
if (!this.initilizedExtensions) { |
136 |
initializeExtensions(); |
137 |
initializeExtensionsConfig(); |
138 |
this.initilizedExtensions = true; |
139 |
} |
140 |
|
141 |
DlgPreferences dlgPreferences=PluginServices.getDlgPreferences(); |
142 |
dlgPreferences.refreshExtensionPoints(); |
143 |
PluginServices.getMDIManager().addWindow(dlgPreferences); |
144 |
} |
145 |
public boolean isEnabled() { |
146 |
return true; |
147 |
} |
148 |
|
149 |
public boolean isVisible() { |
150 |
return true; |
151 |
} |
152 |
|
153 |
private void initializeCoreExtensions() { |
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 |
String os = System.getProperty("os.name").toLowerCase(); |
164 |
if (os.indexOf("linux") != -1 || os.indexOf("unix")!= -1) |
165 |
this.extensionPoints.add("AplicationPreferences","BrowserControlPage", new BrowserControlPage()); |
166 |
|
167 |
//Falta los plugin
|
168 |
} |
169 |
|
170 |
private void initializeExtensionsConfig() { |
171 |
HashMap pc = Launcher.getPluginConfig();
|
172 |
ArrayList array = new ArrayList(); |
173 |
Iterator iter = pc.values().iterator();
|
174 |
|
175 |
while (iter.hasNext()) {
|
176 |
array.add(((PluginConfig) iter.next()).getExtensions()); |
177 |
} |
178 |
|
179 |
Extensions[] exts = (Extensions[]) array.toArray(new Extensions[0]); |
180 |
for (int i = 0; i < exts.length; i++) { |
181 |
for (int j = 0; j < exts[i].getExtensionCount(); j++) { |
182 |
com.iver.andami.plugins.config.generate.Extension ext = exts[i] |
183 |
.getExtension(j); |
184 |
String sExt = ext.getClassName().toString();
|
185 |
// String pn = null;
|
186 |
// pn = sExt.substring(0, sExt.lastIndexOf("."));
|
187 |
// dlgPrefs.addPreferencePage(new PluginsPage(pn));
|
188 |
// dlgPrefs.addPreferencePage(new ExtensionPage(ext));
|
189 |
this.extensionPoints.add("AplicationPreferences",sExt, new ExtensionPage(ext)); |
190 |
} |
191 |
} |
192 |
} |
193 |
/**
|
194 |
*
|
195 |
*/
|
196 |
private void initializeExtensions() { |
197 |
|
198 |
Iterator i =PluginServices.getExtensions();
|
199 |
while (i.hasNext()) {
|
200 |
ExtensionDecorator extension = (ExtensionDecorator) i.next(); |
201 |
|
202 |
if (extension.getExtension() instanceof IPreferenceExtension) { |
203 |
IPreferenceExtension pe=(IPreferenceExtension)extension.getExtension(); |
204 |
IPreference[] pp=pe.getPreferencesPages();
|
205 |
//dlgPrefs.addPreferencePage(pe.getPreferencesPage());
|
206 |
for (int j=0;j<pp.length;j++) { |
207 |
this.extensionPoints.add("AplicationPreferences",pp[j].getID(), pp[j]); |
208 |
} |
209 |
} |
210 |
} |
211 |
} |
212 |
|
213 |
@Override
|
214 |
public void postInitialize() { |
215 |
super.postInitialize();
|
216 |
DlgPreferences dlgPreferences=PluginServices.getDlgPreferences(); |
217 |
dlgPreferences.refreshExtensionPoints(); |
218 |
} |
219 |
} |