svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / InitializeApplicationExtension.java @ 41564
History | View | Annotate | Download (7.4 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.extension; |
25 |
|
26 |
import java.io.BufferedReader; |
27 |
import java.io.InputStream; |
28 |
import java.io.InputStreamReader; |
29 |
import java.io.StringWriter; |
30 |
import java.util.Properties; |
31 |
|
32 |
import org.gvsig.andami.IconThemeHelper; |
33 |
import org.gvsig.andami.PluginsLocator; |
34 |
import org.gvsig.andami.PluginsManager; |
35 |
import org.gvsig.andami.plugins.Extension; |
36 |
import org.gvsig.app.ApplicationLocator; |
37 |
import org.gvsig.app.ApplicationManager; |
38 |
import org.gvsig.app.gui.preferencespage.AppSymbolPreferences; |
39 |
import org.gvsig.app.project.documents.view.toolListeners.InfoListener; |
40 |
import org.gvsig.app.util.BaseOpenErrorHandler; |
41 |
import org.gvsig.fmap.dal.DALLocator; |
42 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
43 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
44 |
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
45 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
46 |
import org.gvsig.installer.lib.api.InstallerLocator; |
47 |
import org.gvsig.installer.lib.api.InstallerManager; |
48 |
import org.gvsig.installer.lib.api.PackageInfo; |
49 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
50 |
import org.gvsig.tools.service.spi.ServiceManager; |
51 |
import org.slf4j.Logger; |
52 |
import org.slf4j.LoggerFactory; |
53 |
|
54 |
public class InitializeApplicationExtension extends Extension { |
55 |
private static final Logger logger = LoggerFactory |
56 |
.getLogger(InitializeApplicationExtension.class); |
57 |
// private Observer dbPasswordResorceObserver;
|
58 |
|
59 |
private OpenErrorHandler openErrorHandler = null; |
60 |
|
61 |
public void initialize() { |
62 |
|
63 |
// Next line moved to ApplicationLibrary
|
64 |
// MapContextLocator.getSymbolManager().setSymbolPreferences(new AppSymbolPreferences());
|
65 |
|
66 |
// Register default expression parser
|
67 |
DALLocator.getDataManager().registerDefaultEvaluator( |
68 |
SQLJEPEvaluator.class); |
69 |
|
70 |
InfoListener.initializeExtensionPoint(); |
71 |
// addToLogInfo();
|
72 |
registerIcons(); |
73 |
|
74 |
} |
75 |
|
76 |
public void postInitialize(){ |
77 |
// Validate there is any implementation registered.
|
78 |
|
79 |
openErrorHandler = new BaseOpenErrorHandler();
|
80 |
ApplicationLocator.getManager().getDataManager().setOpenErrorHandler(openErrorHandler); |
81 |
|
82 |
// registerObservers();
|
83 |
|
84 |
DALLocator.getResourceManager().startResourceCollector( |
85 |
3 * (60 * 1000), // minutes --> miliseconds |
86 |
null);
|
87 |
} |
88 |
|
89 |
// private void registerObservers() {
|
90 |
//// FIXME
|
91 |
//// ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
|
92 |
//// dbPasswordResorceObserver = new DBResourceManager();
|
93 |
//// resMan.addObserver(dbPasswordResorceObserver);
|
94 |
// }
|
95 |
|
96 |
private void registerIcons(){ |
97 |
IconThemeHelper.registerIcon("action", "edit-clear", this); |
98 |
IconThemeHelper.registerIcon("action", "edit-copy", this); |
99 |
IconThemeHelper.registerIcon("action", "edit-cut", this); |
100 |
IconThemeHelper.registerIcon("action", "edit-delete", this); |
101 |
IconThemeHelper.registerIcon("action", "edit-find", this); |
102 |
IconThemeHelper.registerIcon("action", "edit-find-replace", this); |
103 |
IconThemeHelper.registerIcon("action", "edit-paste", this); |
104 |
IconThemeHelper.registerIcon("action", "edit-redo", this); |
105 |
IconThemeHelper.registerIcon("action", "edit-select-all", this); |
106 |
IconThemeHelper.registerIcon("action", "edit-undo", this); |
107 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions", this); |
108 |
IconThemeHelper.registerIcon("action", "document-print", this); |
109 |
|
110 |
IconThemeHelper.registerIcon("toolbar-go", "go-next", this); |
111 |
IconThemeHelper.registerIcon("toolbar-go", "go-previous", this); |
112 |
IconThemeHelper.registerIcon("toolbar-go", "go-next-fast", this); |
113 |
IconThemeHelper.registerIcon("toolbar-go", "go-previous-fast", this); |
114 |
IconThemeHelper.registerIcon("toolbar-go", "go-first", this); |
115 |
IconThemeHelper.registerIcon("toolbar-go", "go-last", this); |
116 |
|
117 |
} |
118 |
|
119 |
public void execute(String actionCommand) { |
120 |
|
121 |
} |
122 |
|
123 |
public boolean isEnabled() { |
124 |
return false; |
125 |
} |
126 |
|
127 |
public boolean isVisible() { |
128 |
return false; |
129 |
} |
130 |
|
131 |
private void addToLogInfo() { |
132 |
String info[] = this.getStringInfo().split("\n"); |
133 |
for (int i=0;i< info.length;i++) { |
134 |
logger.info(info[i]); |
135 |
} |
136 |
} |
137 |
|
138 |
public String getStringInfo() { |
139 |
ApplicationManager application = ApplicationLocator.getManager(); |
140 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
141 |
InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
142 |
|
143 |
StringWriter writer = new StringWriter(); |
144 |
|
145 |
Properties props = System.getProperties(); |
146 |
|
147 |
// OS information
|
148 |
String osName = props.getProperty("os.name"); |
149 |
writer.write("OS\n");
|
150 |
writer.write(" name : " + osName + "\n"); |
151 |
writer.write(" arch : " + props.get("os.arch") + "\n"); |
152 |
writer.write(" version: " + props.get("os.version") + "\n"); |
153 |
if (osName.startsWith("Linux")) { |
154 |
try {
|
155 |
String[] command = {"lsb_release", "-a"}; |
156 |
Process p = Runtime.getRuntime().exec(command); |
157 |
InputStream is = p.getInputStream();
|
158 |
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
159 |
String line;
|
160 |
while ( (line = reader.readLine()) != null) { |
161 |
writer.write(" "+line+"\n"); |
162 |
} |
163 |
} catch (Exception ex) { |
164 |
writer.write("Can't get detailled os information (lsb_release -a).");
|
165 |
} |
166 |
} |
167 |
|
168 |
// JRE information
|
169 |
writer.write("JRE\n");
|
170 |
writer.write(" vendor : " + props.get("java.vendor") + "\n"); |
171 |
writer.write(" version: " +props.get("java.version")+ "\n"); |
172 |
writer.write(" home : " + props.get("java.home") + "\n"); |
173 |
|
174 |
|
175 |
writer.write("gvSIG\n");
|
176 |
writer.write(" version : " + application.getVersion().getLongFormat() + "\n"); |
177 |
writer.write(" locale language : " + application.getLocaleLanguage()+ "\n"); |
178 |
writer.write(" application forlder : " + pluginmgr.getApplicationFolder()+ "\n"); |
179 |
writer.write(" install forlder : " + pluginmgr.getInstallFolder()+ "\n"); |
180 |
writer.write(" application home forlder: " + pluginmgr.getApplicationHomeFolder()+ "\n"); |
181 |
writer.write(" plugins forlder : " + pluginmgr.getPluginsFolder()+ "\n"); |
182 |
|
183 |
try {
|
184 |
PackageInfo[] pkgs = installmgr.getInstalledPackages(pluginmgr.getPluginsFolder());
|
185 |
writer.write("Installed packages\n");
|
186 |
for( int i=0; i<pkgs.length; i++) { |
187 |
writer.write(" ");
|
188 |
writer.write(pkgs[i].toStringCompact()); |
189 |
writer.write("\n");
|
190 |
} |
191 |
} catch(Throwable e) { |
192 |
writer.write("Can't get installed package information.");
|
193 |
} |
194 |
return writer.toString();
|
195 |
} |
196 |
|
197 |
public void terminate() { |
198 |
ResourceManager resMan = DALLocator.getResourceManager(); |
199 |
resMan.stopResourceCollector(); |
200 |
try {
|
201 |
resMan.dispose(); |
202 |
} catch (DisposeResorceManagerException e) {
|
203 |
logger.warn(e.getMessageStack()); |
204 |
} |
205 |
super.terminate();
|
206 |
} |
207 |
} |