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