svn-gvsig-desktop / trunk / libraries / libCorePlugin / src / com / iver / core / PreferencesExtension.java @ 9949
History | View | Annotate | Download (4.99 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 | 7676 | caballero | import com.iver.core.preferences.general.ResolutionPage; |
25 | 5792 | caballero | import com.iver.core.preferences.network.FirewallPage; |
26 | import com.iver.core.preferences.network.NetworkPage; |
||
27 | 9644 | jaume | import com.iver.utiles.BrowserControl; |
28 | 6337 | jmvivo | import com.iver.utiles.extensionPoints.ExtensionPoints; |
29 | import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
||
30 | 5792 | caballero | |
31 | 7607 | jaume | /**
|
32 | *
|
||
33 | * <p>
|
||
34 | * Extension that provides support for visual application configuration
|
||
35 | * through a Preferences dialog where the user can specify its own settings for
|
||
36 | * general purpose aspects.
|
||
37 | * </p>
|
||
38 | * <p>
|
||
39 | * Adding new preference pages is made through ExtensionPoints by invoking
|
||
40 | * <b>
|
||
41 | * this.extensionPoints.add("AplicationPreferences","YourIPreferencesClassName", yourIPreferencesPage);
|
||
42 | * </b>
|
||
43 | * and then call <b>DlgPreferences.refreshExtensionPoints();</b>
|
||
44 | * </p>
|
||
45 | *
|
||
46 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
47 | *
|
||
48 | */
|
||
49 | 6661 | caballero | public class PreferencesExtension extends Extension{ |
50 | private ExtensionPoints extensionPoints =
|
||
51 | 6337 | jmvivo | ExtensionPointsSingleton.getInstance(); |
52 | 6661 | caballero | |
53 | 6380 | jmvivo | private boolean initilizedExtensions=false; |
54 | 5792 | caballero | |
55 | public void initialize() { |
||
56 | 6337 | jmvivo | initializeCoreExtensions(); |
57 | 5792 | caballero | } |
58 | |||
59 | public void execute(String actionCommand) { |
||
60 | 6380 | jmvivo | if (!this.initilizedExtensions) { |
61 | initializeExtensions(); |
||
62 | initializeExtensionsConfig(); |
||
63 | this.initilizedExtensions = true; |
||
64 | } |
||
65 | 6661 | caballero | |
66 | 7311 | caballero | DlgPreferences dlgPreferences=PluginServices.getDlgPreferences(); |
67 | dlgPreferences.refreshExtensionPoints(); |
||
68 | PluginServices.getMDIManager().addWindow(dlgPreferences); |
||
69 | 5792 | caballero | } |
70 | public boolean isEnabled() { |
||
71 | return true; |
||
72 | } |
||
73 | |||
74 | public boolean isVisible() { |
||
75 | return true; |
||
76 | } |
||
77 | 6102 | jaume | |
78 | 5792 | caballero | private void initializeCoreExtensions() { |
79 | 6337 | jmvivo | this.extensionPoints.add("AplicationPreferences","GeneralPage", new GeneralPage()); |
80 | this.extensionPoints.add("AplicationPreferences","NetworkPage", new NetworkPage()); |
||
81 | this.extensionPoints.add("AplicationPreferences","FirewallPage", new FirewallPage()); |
||
82 | this.extensionPoints.add("AplicationPreferences","DirExtensionsPage", new DirExtensionsPage()); |
||
83 | this.extensionPoints.add("AplicationPreferences","LanguagePage", new LanguagePage()); |
||
84 | this.extensionPoints.add("AplicationPreferences","ExtensionsPage", new ExtensionsPage()); |
||
85 | this.extensionPoints.add("AplicationPreferences","AppearancePage", new AppearancePage()); |
||
86 | 7204 | jaume | this.extensionPoints.add("AplicationPreferences","FolderingPage", new FolderingPage()); |
87 | 7676 | caballero | this.extensionPoints.add("AplicationPreferences","ResolutionPage", new ResolutionPage()); |
88 | 9644 | jaume | String os = System.getProperty("os.name").toLowerCase(); |
89 | if (os.indexOf("linux") != -1 || os.indexOf("unix")!= -1) |
||
90 | this.extensionPoints.add("AplicationPreferences","BrowserControlPage", new BrowserControlPage()); |
||
91 | 6661 | caballero | |
92 | 5792 | caballero | //Falta los plugin
|
93 | } |
||
94 | 6102 | jaume | |
95 | 5792 | caballero | private void initializeExtensionsConfig() { |
96 | HashMap pc = Launcher.getPluginConfig();
|
||
97 | ArrayList array = new ArrayList(); |
||
98 | Iterator iter = pc.values().iterator();
|
||
99 | |||
100 | while (iter.hasNext()) {
|
||
101 | array.add(((PluginConfig) iter.next()).getExtensions()); |
||
102 | } |
||
103 | |||
104 | Extensions[] exts = (Extensions[]) array.toArray(new Extensions[0]); |
||
105 | for (int i = 0; i < exts.length; i++) { |
||
106 | for (int j = 0; j < exts[i].getExtensionCount(); j++) { |
||
107 | com.iver.andami.plugins.config.generate.Extension ext = exts[i] |
||
108 | .getExtension(j); |
||
109 | String sExt = ext.getClassName().toString();
|
||
110 | 8142 | jaume | // String pn = null;
|
111 | // pn = sExt.substring(0, sExt.lastIndexOf("."));
|
||
112 | // dlgPrefs.addPreferencePage(new PluginsPage(pn));
|
||
113 | // dlgPrefs.addPreferencePage(new ExtensionPage(ext));
|
||
114 | 6383 | jmvivo | this.extensionPoints.add("AplicationPreferences",sExt, new ExtensionPage(ext)); |
115 | 5792 | caballero | } |
116 | } |
||
117 | } |
||
118 | /**
|
||
119 | *
|
||
120 | */
|
||
121 | private void initializeExtensions() { |
||
122 | |||
123 | Iterator i =PluginServices.getExtensions();
|
||
124 | 8142 | jaume | while (i.hasNext()) {
|
125 | ExtensionDecorator extension = (ExtensionDecorator) i.next(); |
||
126 | 5792 | caballero | |
127 | 8142 | jaume | if (extension.getExtension() instanceof IPreferenceExtension) { |
128 | IPreferenceExtension pe=(IPreferenceExtension)extension.getExtension(); |
||
129 | 9634 | caballero | IPreference[] pp=pe.getPreferencesPages();
|
130 | 8142 | jaume | //dlgPrefs.addPreferencePage(pe.getPreferencesPage());
|
131 | 9634 | caballero | for (int j=0;j<pp.length;j++) { |
132 | this.extensionPoints.add("AplicationPreferences",pp[j].getID(), pp[j]); |
||
133 | } |
||
134 | 8142 | jaume | } |
135 | 5792 | caballero | } |
136 | } |
||
137 | } |