root / tags / v2_0_0_Build_2049 / applications / appgvSIG / src / org / gvsig / app / extension / InitializeApplicationExtension.java @ 38460
History | View | Annotate | Download (7.64 KB)
1 |
package org.gvsig.app.extension; |
---|---|
2 |
|
3 |
import java.io.BufferedReader; |
4 |
import java.io.InputStream; |
5 |
import java.io.InputStreamReader; |
6 |
import java.io.StringWriter; |
7 |
import java.util.Properties; |
8 |
|
9 |
import org.slf4j.Logger; |
10 |
import org.slf4j.LoggerFactory; |
11 |
|
12 |
import org.gvsig.andami.PluginServices; |
13 |
import org.gvsig.andami.PluginsLocator; |
14 |
import org.gvsig.andami.PluginsManager; |
15 |
import org.gvsig.andami.plugins.Extension; |
16 |
import org.gvsig.app.ApplicationLocator; |
17 |
import org.gvsig.app.ApplicationManager; |
18 |
import org.gvsig.app.gui.preferencespage.AppSymbolPreferences; |
19 |
import org.gvsig.app.project.documents.view.toolListeners.InfoListener; |
20 |
import org.gvsig.app.tools.swing.serv.field.crs.JCRSDynFieldComponentFactory; |
21 |
import org.gvsig.app.util.BaseOpenErrorHandler; |
22 |
import org.gvsig.fmap.dal.DALLocator; |
23 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
24 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
25 |
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
26 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
27 |
import org.gvsig.installer.lib.api.InstallerLocator; |
28 |
import org.gvsig.installer.lib.api.InstallerManager; |
29 |
import org.gvsig.installer.lib.api.PackageInfo; |
30 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
31 |
import org.gvsig.tools.service.spi.ServiceManager; |
32 |
import org.gvsig.tools.swing.spi.ToolsSwingServiceLocator; |
33 |
|
34 |
public class InitializeApplicationExtension extends Extension { |
35 |
private static final Logger logger = LoggerFactory |
36 |
.getLogger(InitializeApplicationExtension.class); |
37 |
// private Observer dbPasswordResorceObserver;
|
38 |
|
39 |
private OpenErrorHandler openErrorHandler = null; |
40 |
|
41 |
public void initialize() { |
42 |
|
43 |
// Register default expression parser
|
44 |
DALLocator.getDataManager().registerDefaultEvaluator( |
45 |
SQLJEPEvaluator.class); |
46 |
|
47 |
InfoListener.initializeExtensionPoint(); |
48 |
// addToLogInfo();
|
49 |
registerIcons(); |
50 |
} |
51 |
|
52 |
public void postInitialize(){ |
53 |
// Validate there is any implementation registered.
|
54 |
ServiceManager dsManager = ToolsSwingServiceLocator.getServiceManager(); |
55 |
|
56 |
openErrorHandler = new BaseOpenErrorHandler();
|
57 |
ApplicationLocator.getManager().getDataManager().setOpenErrorHandler(openErrorHandler); |
58 |
|
59 |
//CRS Definition
|
60 |
dsManager.addServiceFactory(new JCRSDynFieldComponentFactory());
|
61 |
|
62 |
registerObservers(); |
63 |
|
64 |
DALLocator.getResourceManager().startResourceCollector( |
65 |
3 * (60 * 1000), // minutes --> miliseconds |
66 |
null);
|
67 |
|
68 |
MapContextLocator.getSymbolManager().setSymbolPreferences(new AppSymbolPreferences());
|
69 |
|
70 |
} |
71 |
|
72 |
private void registerObservers() { |
73 |
// FIXME
|
74 |
// ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
|
75 |
// dbPasswordResorceObserver = new DBResourceManager();
|
76 |
// resMan.addObserver(dbPasswordResorceObserver);
|
77 |
} |
78 |
|
79 |
//Registro en esta extension los iconos que no se donde registrarlos.
|
80 |
private void registerIcons(){ |
81 |
|
82 |
PluginServices.getIconTheme().registerDefault( |
83 |
"view-add-event-layer",
|
84 |
this.getClass().getClassLoader().getResource("images/addeventtheme.png") |
85 |
); |
86 |
PluginServices.getIconTheme().registerDefault( |
87 |
"gvsig-logo-icon",
|
88 |
this.getClass().getClassLoader().getResource("images/icon_gvsig.png") |
89 |
); |
90 |
|
91 |
|
92 |
|
93 |
PluginServices.getIconTheme().registerDefault( |
94 |
"mapa-icono",
|
95 |
this.getClass().getClassLoader().getResource("images/mapas.png") |
96 |
); |
97 |
|
98 |
PluginServices.getIconTheme().registerDefault( |
99 |
"layout-insert-view",
|
100 |
this.getClass().getClassLoader().getResource("images/MapaVista.png") |
101 |
); |
102 |
|
103 |
PluginServices.getIconTheme().registerDefault( |
104 |
"vista-icono",
|
105 |
this.getClass().getClassLoader().getResource("images/Vista.png") |
106 |
); |
107 |
|
108 |
PluginServices.getIconTheme().registerDefault( |
109 |
"hand-icono",
|
110 |
this.getClass().getClassLoader().getResource("images/Hand.png") |
111 |
); |
112 |
|
113 |
PluginServices.getIconTheme().registerDefault( |
114 |
"add-layer-icono",
|
115 |
this.getClass().getClassLoader().getResource("images/add-layer.png") |
116 |
); |
117 |
|
118 |
PluginServices.getIconTheme().registerDefault( |
119 |
"delete-icono",
|
120 |
this.getClass().getClassLoader().getResource("images/delete.png") |
121 |
); |
122 |
|
123 |
PluginServices.getIconTheme().registerDefault( |
124 |
"arrow-up-icono",
|
125 |
this.getClass().getClassLoader().getResource("images/up-arrow.png") |
126 |
); |
127 |
|
128 |
PluginServices.getIconTheme().registerDefault( |
129 |
"arrow-down-icono",
|
130 |
this.getClass().getClassLoader().getResource("images/down-arrow.png") |
131 |
); |
132 |
// PluginServices.getIconTheme().register(
|
133 |
// "arrow-down-icono",
|
134 |
// PrintPropertiesPage.class.getClassLoader().getResource("images/prepare-page.png")
|
135 |
// );
|
136 |
PluginServices.getIconTheme().registerDefault( |
137 |
"editdelete-icon",
|
138 |
this.getClass().getClassLoader().getResource("images/editdelete.png") |
139 |
); |
140 |
|
141 |
} |
142 |
|
143 |
public void execute(String actionCommand) { |
144 |
|
145 |
} |
146 |
|
147 |
public boolean isEnabled() { |
148 |
return false; |
149 |
} |
150 |
|
151 |
public boolean isVisible() { |
152 |
return false; |
153 |
} |
154 |
|
155 |
private void addToLogInfo() { |
156 |
String info[] = this.getStringInfo().split("\n"); |
157 |
for (int i=0;i< info.length;i++) { |
158 |
logger.info(info[i]); |
159 |
} |
160 |
} |
161 |
|
162 |
public String getStringInfo() { |
163 |
ApplicationManager application = ApplicationLocator.getManager(); |
164 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
165 |
InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
166 |
|
167 |
StringWriter writer = new StringWriter(); |
168 |
|
169 |
Properties props = System.getProperties(); |
170 |
|
171 |
// OS information
|
172 |
String osName = props.getProperty("os.name"); |
173 |
writer.write("OS\n");
|
174 |
writer.write(" name : " + osName + "\n"); |
175 |
writer.write(" arch : " + props.get("os.arch") + "\n"); |
176 |
writer.write(" version: " + props.get("os.version") + "\n"); |
177 |
if (osName.startsWith("Linux")) { |
178 |
try {
|
179 |
String[] command = {"lsb_release", "-a"}; |
180 |
Process p = Runtime.getRuntime().exec(command); |
181 |
InputStream is = p.getInputStream();
|
182 |
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
183 |
String line;
|
184 |
while ( (line = reader.readLine()) != null) { |
185 |
writer.write(" "+line+"\n"); |
186 |
} |
187 |
} catch (Exception ex) { |
188 |
writer.write("Can't get detailled os information (lsb_release -a).");
|
189 |
} |
190 |
} |
191 |
|
192 |
// JRE information
|
193 |
writer.write("JRE\n");
|
194 |
writer.write(" vendor : " + props.get("java.vendor") + "\n"); |
195 |
writer.write(" version: " +props.get("java.version")+ "\n"); |
196 |
writer.write(" home : " + props.get("java.home") + "\n"); |
197 |
|
198 |
|
199 |
writer.write("gvSIG\n");
|
200 |
writer.write(" version : " + application.getVersion().getLongFormat() + "\n"); |
201 |
writer.write(" locale language : " + application.getLocaleLanguage()+ "\n"); |
202 |
writer.write(" application forlder : " + pluginmgr.getApplicationFolder()+ "\n"); |
203 |
writer.write(" install forlder : " + pluginmgr.getInstallFolder()+ "\n"); |
204 |
writer.write(" application home forlder: " + pluginmgr.getApplicationHomeFolder()+ "\n"); |
205 |
writer.write(" plugins forlder : " + pluginmgr.getPluginsFolder()+ "\n"); |
206 |
|
207 |
try {
|
208 |
PackageInfo[] pkgs = installmgr.getInstalledPackages(pluginmgr.getPluginsFolder());
|
209 |
writer.write("Installed packages\n");
|
210 |
for( int i=0; i<pkgs.length; i++) { |
211 |
writer.write(" ");
|
212 |
writer.write(pkgs[i].toStringCompact()); |
213 |
writer.write("\n");
|
214 |
} |
215 |
} catch(Throwable e) { |
216 |
writer.write("Can't get installed package information.");
|
217 |
} |
218 |
return writer.toString();
|
219 |
} |
220 |
|
221 |
public void terminate() { |
222 |
// XXX: Need a TerminateApplicationExtension ???
|
223 |
ResourceManager resMan = DALLocator.getResourceManager(); |
224 |
resMan.stopResourceCollector(); |
225 |
try {
|
226 |
resMan.dispose(); |
227 |
} catch (DisposeResorceManagerException e) {
|
228 |
logger.error("Exceptions at dispose Resource Manager", e);
|
229 |
} |
230 |
|
231 |
super.terminate();
|
232 |
// try {
|
233 |
// LayerFactory.getDataSourceFactory().finalizeThis();
|
234 |
// } catch (Exception e) {
|
235 |
// //e.printStackTrace();
|
236 |
// }
|
237 |
|
238 |
} |
239 |
} |