svn-gvsig-desktop / tags / v1_1_Build_914 / libraries / libCorePlugin / src / com / iver / core / PreferencesExtension.java @ 11873
History | View | Annotate | Download (5.09 KB)
1 | 5792 | caballero | package com.iver.core; |
---|---|---|---|
2 | |||
3 | 11142 | jmvivo | import java.io.File; |
4 | 5792 | caballero | import java.util.HashMap; |
5 | import java.util.Iterator; |
||
6 | 11142 | jmvivo | import java.util.Map.Entry; |
7 | 5792 | caballero | |
8 | import com.iver.andami.Launcher; |
||
9 | import com.iver.andami.PluginServices; |
||
10 | import com.iver.andami.plugins.Extension; |
||
11 | import com.iver.andami.plugins.ExtensionDecorator; |
||
12 | import com.iver.andami.plugins.config.generate.Extensions; |
||
13 | import com.iver.andami.plugins.config.generate.PluginConfig; |
||
14 | 7195 | caballero | import com.iver.andami.preferences.DlgPreferences; |
15 | 6337 | jmvivo | import com.iver.andami.preferences.IPreference; |
16 | 5792 | caballero | import com.iver.andami.preferences.IPreferenceExtension; |
17 | 6102 | jaume | import com.iver.core.preferences.general.AppearancePage; |
18 | 11021 | jaume | import com.iver.core.preferences.general.BrowserControlPage; |
19 | 5792 | caballero | import com.iver.core.preferences.general.DirExtensionsPage; |
20 | import com.iver.core.preferences.general.ExtensionPage; |
||
21 | import com.iver.core.preferences.general.ExtensionsPage; |
||
22 | 7143 | jaume | import com.iver.core.preferences.general.FolderingPage; |
23 | 5792 | caballero | import com.iver.core.preferences.general.GeneralPage; |
24 | import com.iver.core.preferences.general.LanguagePage; |
||
25 | 8765 | jjdelcerro | import com.iver.core.preferences.general.ResolutionPage; |
26 | 5792 | caballero | import com.iver.core.preferences.network.FirewallPage; |
27 | import com.iver.core.preferences.network.NetworkPage; |
||
28 | 6337 | jmvivo | import com.iver.utiles.extensionPoints.ExtensionPoints; |
29 | import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
||
30 | 5792 | caballero | |
31 | 8765 | jjdelcerro | /**
|
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 | 7195 | 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 | 11021 | jaume | |
79 | 5792 | caballero | private void initializeCoreExtensions() { |
80 | 6337 | jmvivo | this.extensionPoints.add("AplicationPreferences","GeneralPage", new GeneralPage()); |
81 | this.extensionPoints.add("AplicationPreferences","NetworkPage", new NetworkPage()); |
||
82 | this.extensionPoints.add("AplicationPreferences","FirewallPage", new FirewallPage()); |
||
83 | this.extensionPoints.add("AplicationPreferences","DirExtensionsPage", new DirExtensionsPage()); |
||
84 | this.extensionPoints.add("AplicationPreferences","LanguagePage", new LanguagePage()); |
||
85 | this.extensionPoints.add("AplicationPreferences","ExtensionsPage", new ExtensionsPage()); |
||
86 | this.extensionPoints.add("AplicationPreferences","AppearancePage", new AppearancePage()); |
||
87 | 7143 | jaume | this.extensionPoints.add("AplicationPreferences","FolderingPage", new FolderingPage()); |
88 | 8765 | jjdelcerro | this.extensionPoints.add("AplicationPreferences","ResolutionPage", new ResolutionPage()); |
89 | 11021 | jaume | String os = System.getProperty("os.name").toLowerCase(); |
90 | if (os.indexOf("linux") != -1 || os.indexOf("unix")!= -1) |
||
91 | this.extensionPoints.add("AplicationPreferences","BrowserControlPage", new BrowserControlPage()); |
||
92 | 6661 | caballero | |
93 | 5792 | caballero | //Falta los plugin
|
94 | } |
||
95 | 6102 | jaume | |
96 | 5792 | caballero | private void initializeExtensionsConfig() { |
97 | HashMap pc = Launcher.getPluginConfig();
|
||
98 | 11142 | jmvivo | String pluginDirectory=Launcher.getAndamiConfig().getPluginsDirectory();
|
99 | |||
100 | Iterator iter = pc.entrySet().iterator();
|
||
101 | Entry entry; |
||
102 | String pluginName;
|
||
103 | Extensions extensions; |
||
104 | String extensionName;
|
||
105 | com.iver.andami.plugins.config.generate.Extension ext; |
||
106 | File configFile;
|
||
107 | ExtensionPage extensionPage; |
||
108 | 5792 | caballero | while (iter.hasNext()) {
|
109 | 11142 | jmvivo | entry = (Entry)iter.next(); |
110 | pluginName = (String)entry.getKey();
|
||
111 | configFile = new File(pluginDirectory + File.separator + |
||
112 | pluginName + File.separator + "config.xml"); |
||
113 | extensions = ((PluginConfig) entry.getValue()).getExtensions(); |
||
114 | for (int j = 0; j < extensions.getExtensionCount(); j++) { |
||
115 | ext = extensions.getExtension(j); |
||
116 | extensionName = ext.getClassName().toString(); |
||
117 | extensionPage =new ExtensionPage(ext);
|
||
118 | extensionPage.setReadOnly(!configFile.canWrite()); |
||
119 | this.extensionPoints.add("AplicationPreferences",extensionName, extensionPage); |
||
120 | } |
||
121 | 5792 | caballero | } |
122 | |||
123 | 11142 | jmvivo | |
124 | 5792 | caballero | } |
125 | /**
|
||
126 | *
|
||
127 | */
|
||
128 | private void initializeExtensions() { |
||
129 | |||
130 | Iterator i =PluginServices.getExtensions();
|
||
131 | 8765 | jjdelcerro | while (i.hasNext()) {
|
132 | ExtensionDecorator extension = (ExtensionDecorator) i.next(); |
||
133 | 5792 | caballero | |
134 | 8765 | jjdelcerro | if (extension.getExtension() instanceof IPreferenceExtension) { |
135 | IPreferenceExtension pe=(IPreferenceExtension)extension.getExtension(); |
||
136 | IPreference pp=pe.getPreferencesPage(); |
||
137 | //dlgPrefs.addPreferencePage(pe.getPreferencesPage());
|
||
138 | this.extensionPoints.add("AplicationPreferences",pp.getID(), pp); |
||
139 | } |
||
140 | 5792 | caballero | } |
141 | } |
||
142 | } |