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 |
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.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 |
import org.gvsig.fmap.dal.DALLocator; |
19 |
import org.gvsig.fmap.dal.DataTypes; |
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 |
|
36 |
public void initialize() { |
37 |
|
38 |
// Register default expression parser
|
39 |
DALLocator.getDataManager().registerDefaultEvaluator( |
40 |
SQLJEPEvaluator.class); |
41 |
|
42 |
addToLogInfo(); |
43 |
registerIcons(); |
44 |
} |
45 |
|
46 |
public void postInitialize(){ |
47 |
// Validate there is any implementation registered.
|
48 |
ServiceManager dsManager = ToolsSwingServiceLocator.getServiceManager(); |
49 |
|
50 |
//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 |
registerObservers(); |
74 |
|
75 |
DALLocator.getResourceManager().startResourceCollector( |
76 |
3 * (60 * 1000), // minutes --> miliseconds |
77 |
null);
|
78 |
|
79 |
ApplicationLocator.getManager().registerAddTableWizard("File",
|
80 |
"File Table", FilesystemExplorerTableWizardPanel.class);
|
81 |
|
82 |
} |
83 |
|
84 |
private void registerObservers() { |
85 |
// FIXME
|
86 |
// ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
|
87 |
// dbPasswordResorceObserver = new DBResourceManager();
|
88 |
// resMan.addObserver(dbPasswordResorceObserver);
|
89 |
} |
90 |
|
91 |
//Registro en esta extension los iconos que no se donde registrarlos.
|
92 |
private void registerIcons(){ |
93 |
|
94 |
PluginServices.getIconTheme().registerDefault( |
95 |
"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 |
"mapa-icono",
|
107 |
this.getClass().getClassLoader().getResource("images/mapas.png") |
108 |
); |
109 |
|
110 |
PluginServices.getIconTheme().registerDefault( |
111 |
"layout-insert-view",
|
112 |
this.getClass().getClassLoader().getResource("images/MapaVista.png") |
113 |
); |
114 |
|
115 |
PluginServices.getIconTheme().registerDefault( |
116 |
"vista-icono",
|
117 |
this.getClass().getClassLoader().getResource("images/Vista.png") |
118 |
); |
119 |
|
120 |
PluginServices.getIconTheme().registerDefault( |
121 |
"hand-icono",
|
122 |
this.getClass().getClassLoader().getResource("images/Hand.png") |
123 |
); |
124 |
|
125 |
PluginServices.getIconTheme().registerDefault( |
126 |
"add-layer-icono",
|
127 |
this.getClass().getClassLoader().getResource("images/add-layer.png") |
128 |
); |
129 |
|
130 |
PluginServices.getIconTheme().registerDefault( |
131 |
"delete-icono",
|
132 |
this.getClass().getClassLoader().getResource("images/delete.png") |
133 |
); |
134 |
|
135 |
PluginServices.getIconTheme().registerDefault( |
136 |
"arrow-up-icono",
|
137 |
this.getClass().getClassLoader().getResource("images/up-arrow.png") |
138 |
); |
139 |
|
140 |
PluginServices.getIconTheme().registerDefault( |
141 |
"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 |
PluginServices.getIconTheme().registerDefault( |
149 |
"editdelete-icon",
|
150 |
this.getClass().getClassLoader().getResource("images/editdelete.png") |
151 |
); |
152 |
|
153 |
} |
154 |
|
155 |
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 |
|
167 |
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 |
|
174 |
public String getStringInfo() { |
175 |
StringWriter writer = new StringWriter(); |
176 |
String andamiPath;
|
177 |
String extensionsPath;
|
178 |
// String jaiVersion;
|
179 |
|
180 |
Properties props = System.getProperties(); |
181 |
|
182 |
try {
|
183 |
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 |
} |
191 |
try {
|
192 |
try {
|
193 |
extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getCanonicalPath(); |
194 |
} catch (IOException e) { |
195 |
extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getAbsolutePath(); |
196 |
} |
197 |
} catch (Exception e1) { |
198 |
extensionsPath = "???";
|
199 |
} |
200 |
|
201 |
|
202 |
|
203 |
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 |
String osName = props.getProperty("os.name"); |
209 |
writer.write("OS name: " + osName + "\n"); |
210 |
writer.write(" arch:" + props.get("os.arch") + "\n"); |
211 |
writer.write(" version:"+ props.get("os.version") + "\n"); |
212 |
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 |
while ( (line = reader.readLine()) != null) { |
220 |
writer.write(" "+line+"\n"); |
221 |
} |
222 |
} |
223 |
catch (Exception ex) { |
224 |
|
225 |
} |
226 |
} |
227 |
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 |
|
233 |
public void terminate() { |
234 |
// 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 |
|
243 |
super.terminate();
|
244 |
// try {
|
245 |
// LayerFactory.getDataSourceFactory().finalizeThis();
|
246 |
// } catch (Exception e) {
|
247 |
// //e.printStackTrace();
|
248 |
// }
|
249 |
|
250 |
} |
251 |
} |