root / branches / v10 / libraries / libCorePlugin / src / com / iver / core / PreferencesExtension.java @ 11142
History | View | Annotate | Download (5.09 KB)
1 |
package com.iver.core; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.HashMap; |
5 |
import java.util.Iterator; |
6 |
import java.util.Map.Entry; |
7 |
|
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 |
import com.iver.andami.preferences.DlgPreferences; |
15 |
import com.iver.andami.preferences.IPreference; |
16 |
import com.iver.andami.preferences.IPreferenceExtension; |
17 |
import com.iver.core.preferences.general.AppearancePage; |
18 |
import com.iver.core.preferences.general.BrowserControlPage; |
19 |
import com.iver.core.preferences.general.DirExtensionsPage; |
20 |
import com.iver.core.preferences.general.ExtensionPage; |
21 |
import com.iver.core.preferences.general.ExtensionsPage; |
22 |
import com.iver.core.preferences.general.FolderingPage; |
23 |
import com.iver.core.preferences.general.GeneralPage; |
24 |
import com.iver.core.preferences.general.LanguagePage; |
25 |
import com.iver.core.preferences.general.ResolutionPage; |
26 |
import com.iver.core.preferences.network.FirewallPage; |
27 |
import com.iver.core.preferences.network.NetworkPage; |
28 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
29 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
30 |
|
31 |
/**
|
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 |
public class PreferencesExtension extends Extension{ |
50 |
private ExtensionPoints extensionPoints =
|
51 |
ExtensionPointsSingleton.getInstance(); |
52 |
|
53 |
private boolean initilizedExtensions=false; |
54 |
|
55 |
public void initialize() { |
56 |
initializeCoreExtensions(); |
57 |
} |
58 |
|
59 |
public void execute(String actionCommand) { |
60 |
if (!this.initilizedExtensions) { |
61 |
initializeExtensions(); |
62 |
initializeExtensionsConfig(); |
63 |
this.initilizedExtensions = true; |
64 |
} |
65 |
|
66 |
DlgPreferences dlgPreferences=PluginServices.getDlgPreferences(); |
67 |
dlgPreferences.refreshExtensionPoints(); |
68 |
PluginServices.getMDIManager().addWindow(dlgPreferences); |
69 |
} |
70 |
public boolean isEnabled() { |
71 |
return true; |
72 |
} |
73 |
|
74 |
public boolean isVisible() { |
75 |
return true; |
76 |
} |
77 |
|
78 |
|
79 |
private void initializeCoreExtensions() { |
80 |
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 |
this.extensionPoints.add("AplicationPreferences","FolderingPage", new FolderingPage()); |
88 |
this.extensionPoints.add("AplicationPreferences","ResolutionPage", new ResolutionPage()); |
89 |
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 |
|
93 |
//Falta los plugin
|
94 |
} |
95 |
|
96 |
private void initializeExtensionsConfig() { |
97 |
HashMap pc = Launcher.getPluginConfig();
|
98 |
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 |
while (iter.hasNext()) {
|
109 |
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 |
} |
122 |
|
123 |
|
124 |
} |
125 |
/**
|
126 |
*
|
127 |
*/
|
128 |
private void initializeExtensions() { |
129 |
|
130 |
Iterator i =PluginServices.getExtensions();
|
131 |
while (i.hasNext()) {
|
132 |
ExtensionDecorator extension = (ExtensionDecorator) i.next(); |
133 |
|
134 |
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 |
} |
141 |
} |
142 |
} |