root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / InitializeApplicationExtension.java @ 38564
History | View | Annotate | Download (6.94 KB)
1 | 29596 | jpiera | package org.gvsig.app.extension; |
---|---|---|---|
2 | 6764 | jmvivo | |
3 | 9897 | cesar | import java.io.BufferedReader; |
4 | import java.io.InputStream; |
||
5 | import java.io.InputStreamReader; |
||
6 | 8185 | jmvivo | import java.io.StringWriter; |
7 | import java.util.Properties; |
||
8 | 6790 | jmvivo | |
9 | 38564 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
10 | 35978 | jjdelcerro | import org.gvsig.andami.PluginsLocator; |
11 | import org.gvsig.andami.PluginsManager; |
||
12 | 29596 | jpiera | import org.gvsig.andami.plugins.Extension; |
13 | 31496 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
14 | 35978 | jjdelcerro | import org.gvsig.app.ApplicationManager; |
15 | 38442 | nbrodin | import org.gvsig.app.gui.preferencespage.AppSymbolPreferences; |
16 | 35485 | jjdelcerro | import org.gvsig.app.project.documents.view.toolListeners.InfoListener; |
17 | 33654 | cmartin | import org.gvsig.app.tools.swing.serv.field.crs.JCRSDynFieldComponentFactory; |
18 | 35763 | fdiaz | import org.gvsig.app.util.BaseOpenErrorHandler; |
19 | 24759 | jmvivo | import org.gvsig.fmap.dal.DALLocator; |
20 | 35763 | fdiaz | import org.gvsig.fmap.dal.OpenErrorHandler; |
21 | 28072 | jmvivo | import org.gvsig.fmap.dal.resource.ResourceManager; |
22 | import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
||
23 | 38442 | nbrodin | import org.gvsig.fmap.mapcontext.MapContextLocator; |
24 | 35978 | jjdelcerro | import org.gvsig.installer.lib.api.InstallerLocator; |
25 | import org.gvsig.installer.lib.api.InstallerManager; |
||
26 | import org.gvsig.installer.lib.api.PackageInfo; |
||
27 | 25250 | jmvivo | import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
28 | 33654 | cmartin | import org.gvsig.tools.service.spi.ServiceManager; |
29 | import org.gvsig.tools.swing.spi.ToolsSwingServiceLocator; |
||
30 | 38564 | jjdelcerro | import org.slf4j.Logger; |
31 | import org.slf4j.LoggerFactory; |
||
32 | 8185 | jmvivo | |
33 | 25578 | vcaballero | public class InitializeApplicationExtension extends Extension { |
34 | 28033 | cordinyana | private static final Logger logger = LoggerFactory |
35 | .getLogger(InitializeApplicationExtension.class); |
||
36 | 34002 | jjdelcerro | // private Observer dbPasswordResorceObserver;
|
37 | 25250 | jmvivo | |
38 | 35763 | fdiaz | private OpenErrorHandler openErrorHandler = null; |
39 | 25250 | jmvivo | |
40 | 8185 | jmvivo | public void initialize() { |
41 | 14821 | jmvivo | |
42 | 27108 | jmvivo | // Register default expression parser
|
43 | 25250 | jmvivo | DALLocator.getDataManager().registerDefaultEvaluator( |
44 | SQLJEPEvaluator.class); |
||
45 | |||
46 | 35485 | jjdelcerro | InfoListener.initializeExtensionPoint(); |
47 | 35978 | jjdelcerro | // addToLogInfo();
|
48 | 14821 | jmvivo | registerIcons(); |
49 | 6764 | jmvivo | } |
50 | 30580 | cordinyana | |
51 | 23176 | vcaballero | public void postInitialize(){ |
52 | 33654 | cmartin | // Validate there is any implementation registered.
|
53 | ServiceManager dsManager = ToolsSwingServiceLocator.getServiceManager(); |
||
54 | 25250 | jmvivo | |
55 | 35763 | fdiaz | openErrorHandler = new BaseOpenErrorHandler();
|
56 | ApplicationLocator.getManager().getDataManager().setOpenErrorHandler(openErrorHandler); |
||
57 | |||
58 | 33654 | cmartin | //CRS Definition
|
59 | dsManager.addServiceFactory(new JCRSDynFieldComponentFactory());
|
||
60 | |||
61 | 38564 | jjdelcerro | // registerObservers();
|
62 | 30580 | cordinyana | |
63 | 28072 | jmvivo | DALLocator.getResourceManager().startResourceCollector( |
64 | 3 * (60 * 1000), // minutes --> miliseconds |
||
65 | null);
|
||
66 | 38442 | nbrodin | |
67 | MapContextLocator.getSymbolManager().setSymbolPreferences(new AppSymbolPreferences());
|
||
68 | 28072 | jmvivo | |
69 | 23176 | vcaballero | } |
70 | 30580 | cordinyana | |
71 | 38564 | jjdelcerro | // private void registerObservers() {
|
72 | //// FIXME
|
||
73 | //// ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
|
||
74 | //// dbPasswordResorceObserver = new DBResourceManager();
|
||
75 | //// resMan.addObserver(dbPasswordResorceObserver);
|
||
76 | // }
|
||
77 | 6764 | jmvivo | |
78 | 14821 | jmvivo | private void registerIcons(){ |
79 | 38564 | jjdelcerro | IconThemeHelper.registerIcon("action", "edit-clear", this); |
80 | IconThemeHelper.registerIcon("action", "edit-copy", this); |
||
81 | IconThemeHelper.registerIcon("action", "edit-cut", this); |
||
82 | IconThemeHelper.registerIcon("action", "edit-delete", this); |
||
83 | IconThemeHelper.registerIcon("action", "edit-find", this); |
||
84 | IconThemeHelper.registerIcon("action", "edit-find-replace", this); |
||
85 | IconThemeHelper.registerIcon("action", "edit-paste", this); |
||
86 | IconThemeHelper.registerIcon("action", "edit-redo", this); |
||
87 | IconThemeHelper.registerIcon("action", "edit-select-all", this); |
||
88 | IconThemeHelper.registerIcon("action", "edit-undo", this); |
||
89 | IconThemeHelper.registerIcon("action", "edit-undo-redo-actions", this); |
||
90 | IconThemeHelper.registerIcon("action", "document-print", this); |
||
91 | |||
92 | IconThemeHelper.registerIcon("toolbar-go", "go-next", this); |
||
93 | IconThemeHelper.registerIcon("toolbar-go", "go-previous", this); |
||
94 | IconThemeHelper.registerIcon("toolbar-go", "go-next-fast", this); |
||
95 | IconThemeHelper.registerIcon("toolbar-go", "go-previous-fast", this); |
||
96 | IconThemeHelper.registerIcon("toolbar-go", "go-first", this); |
||
97 | IconThemeHelper.registerIcon("toolbar-go", "go-last", this); |
||
98 | 15912 | jmvivo | |
99 | 14821 | jmvivo | } |
100 | |||
101 | 6764 | jmvivo | public void execute(String actionCommand) { |
102 | |||
103 | } |
||
104 | |||
105 | public boolean isEnabled() { |
||
106 | return false; |
||
107 | } |
||
108 | |||
109 | public boolean isVisible() { |
||
110 | return false; |
||
111 | } |
||
112 | 14821 | jmvivo | |
113 | 8185 | jmvivo | private void addToLogInfo() { |
114 | String info[] = this.getStringInfo().split("\n"); |
||
115 | for (int i=0;i< info.length;i++) { |
||
116 | logger.info(info[i]); |
||
117 | } |
||
118 | } |
||
119 | 14821 | jmvivo | |
120 | 8185 | jmvivo | public String getStringInfo() { |
121 | 35978 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
122 | PluginsManager pluginmgr = PluginsLocator.getManager(); |
||
123 | InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
||
124 | |||
125 | 8185 | jmvivo | StringWriter writer = new StringWriter(); |
126 | 14821 | jmvivo | |
127 | 8233 | jmvivo | Properties props = System.getProperties(); |
128 | 14821 | jmvivo | |
129 | 35978 | jjdelcerro | // OS information
|
130 | 9897 | cesar | String osName = props.getProperty("os.name"); |
131 | 35978 | jjdelcerro | writer.write("OS\n");
|
132 | writer.write(" name : " + osName + "\n"); |
||
133 | writer.write(" arch : " + props.get("os.arch") + "\n"); |
||
134 | writer.write(" version: " + props.get("os.version") + "\n"); |
||
135 | 9897 | cesar | if (osName.startsWith("Linux")) { |
136 | try {
|
||
137 | String[] command = {"lsb_release", "-a"}; |
||
138 | Process p = Runtime.getRuntime().exec(command); |
||
139 | InputStream is = p.getInputStream();
|
||
140 | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
||
141 | String line;
|
||
142 | 24759 | jmvivo | while ( (line = reader.readLine()) != null) { |
143 | 9897 | cesar | writer.write(" "+line+"\n"); |
144 | 24759 | jmvivo | } |
145 | 35978 | jjdelcerro | } catch (Exception ex) { |
146 | writer.write("Can't get detailled os information (lsb_release -a).");
|
||
147 | 9897 | cesar | } |
148 | 35978 | jjdelcerro | } |
149 | 14821 | jmvivo | |
150 | 35978 | jjdelcerro | // JRE information
|
151 | writer.write("JRE\n");
|
||
152 | writer.write(" vendor : " + props.get("java.vendor") + "\n"); |
||
153 | writer.write(" version: " +props.get("java.version")+ "\n"); |
||
154 | writer.write(" home : " + props.get("java.home") + "\n"); |
||
155 | |||
156 | |||
157 | writer.write("gvSIG\n");
|
||
158 | writer.write(" version : " + application.getVersion().getLongFormat() + "\n"); |
||
159 | writer.write(" locale language : " + application.getLocaleLanguage()+ "\n"); |
||
160 | writer.write(" application forlder : " + pluginmgr.getApplicationFolder()+ "\n"); |
||
161 | writer.write(" install forlder : " + pluginmgr.getInstallFolder()+ "\n"); |
||
162 | writer.write(" application home forlder: " + pluginmgr.getApplicationHomeFolder()+ "\n"); |
||
163 | writer.write(" plugins forlder : " + pluginmgr.getPluginsFolder()+ "\n"); |
||
164 | |||
165 | try {
|
||
166 | PackageInfo[] pkgs = installmgr.getInstalledPackages(pluginmgr.getPluginsFolder());
|
||
167 | writer.write("Installed packages\n");
|
||
168 | for( int i=0; i<pkgs.length; i++) { |
||
169 | writer.write(" ");
|
||
170 | writer.write(pkgs[i].toStringCompact()); |
||
171 | writer.write("\n");
|
||
172 | 9897 | cesar | } |
173 | 35978 | jjdelcerro | } catch(Throwable e) { |
174 | writer.write("Can't get installed package information.");
|
||
175 | 9897 | cesar | } |
176 | 8185 | jmvivo | return writer.toString();
|
177 | } |
||
178 | 14821 | jmvivo | |
179 | 9295 | jmvivo | public void terminate() { |
180 | 28072 | jmvivo | // XXX: Need a TerminateApplicationExtension ???
|
181 | ResourceManager resMan = DALLocator.getResourceManager(); |
||
182 | resMan.stopResourceCollector(); |
||
183 | try {
|
||
184 | resMan.dispose(); |
||
185 | } catch (DisposeResorceManagerException e) {
|
||
186 | logger.error("Exceptions at dispose Resource Manager", e);
|
||
187 | } |
||
188 | 14821 | jmvivo | |
189 | 9295 | jmvivo | super.terminate();
|
190 | 21743 | vcaballero | // try {
|
191 | // LayerFactory.getDataSourceFactory().finalizeThis();
|
||
192 | // } catch (Exception e) {
|
||
193 | // //e.printStackTrace();
|
||
194 | // }
|
||
195 | 14821 | jmvivo | |
196 | 9295 | jmvivo | } |
197 | 6764 | jmvivo | } |