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