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