svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / InitializeApplicationExtension.java @ 44535
History | View | Annotate | Download (19 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 41576 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40558 | jjdelcerro | *
|
11 | 41576 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40558 | jjdelcerro | *
|
16 | 41576 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40558 | jjdelcerro | *
|
20 | 41576 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40558 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.app.extension; |
24 | |||
25 | 43095 | jjdelcerro | import java.awt.GridBagConstraints; |
26 | import java.beans.PropertyVetoException; |
||
27 | 40435 | jjdelcerro | import java.io.BufferedReader; |
28 | 44238 | jjdelcerro | import java.io.File; |
29 | 40435 | jjdelcerro | import java.io.InputStream; |
30 | import java.io.InputStreamReader; |
||
31 | import java.io.StringWriter; |
||
32 | 44404 | omartinez | import java.util.ArrayList; |
33 | 41735 | jjdelcerro | import java.util.HashMap; |
34 | 44404 | omartinez | import java.util.List; |
35 | 41735 | jjdelcerro | import java.util.Map; |
36 | 40435 | jjdelcerro | import java.util.Properties; |
37 | 44238 | jjdelcerro | import java.util.prefs.Preferences; |
38 | 41620 | jjdelcerro | import javax.swing.JOptionPane; |
39 | 41706 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
40 | 40435 | jjdelcerro | |
41 | import org.gvsig.andami.IconThemeHelper; |
||
42 | 41620 | jjdelcerro | import org.gvsig.andami.PluginServices; |
43 | 40435 | jjdelcerro | import org.gvsig.andami.PluginsLocator; |
44 | import org.gvsig.andami.PluginsManager; |
||
45 | 41620 | jjdelcerro | import org.gvsig.andami.actioninfo.ActionInfoManager; |
46 | 40435 | jjdelcerro | import org.gvsig.andami.plugins.Extension; |
47 | 43095 | jjdelcerro | import org.gvsig.andami.ui.mdiManager.IWindow; |
48 | 40435 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
49 | import org.gvsig.app.ApplicationManager; |
||
50 | 44238 | jjdelcerro | import static org.gvsig.app.extension.ProjectExtension.PROJECT_FILE_CHOOSER_ID; |
51 | 43095 | jjdelcerro | import org.gvsig.app.project.ProjectManager; |
52 | import org.gvsig.app.project.ProjectPreferences; |
||
53 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
54 | import org.gvsig.app.project.documents.view.ViewManager; |
||
55 | import org.gvsig.app.project.documents.view.gui.IView; |
||
56 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.toolListeners.InfoListener; |
57 | import org.gvsig.app.util.BaseOpenErrorHandler; |
||
58 | 44404 | omartinez | import org.gvsig.expressionevaluator.Expression; |
59 | import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
||
60 | import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
||
61 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
62 | 44129 | jjdelcerro | import org.gvsig.fmap.dal.DataManager; |
63 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.OpenErrorHandler; |
64 | 44189 | jjdelcerro | import org.gvsig.fmap.dal.feature.AbstractDataProfile; |
65 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.resource.ResourceManager; |
66 | import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
||
67 | 44238 | jjdelcerro | import static org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanelController.OPEN_LAYER_FILE_CHOOSER_ID; |
68 | 40435 | jjdelcerro | import org.gvsig.installer.lib.api.InstallerLocator; |
69 | import org.gvsig.installer.lib.api.InstallerManager; |
||
70 | import org.gvsig.installer.lib.api.PackageInfo; |
||
71 | 41620 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
72 | 44404 | omartinez | import org.gvsig.tools.bookmarksandhistory.Bookmark; |
73 | import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
||
74 | import org.gvsig.tools.bookmarksandhistory.History; |
||
75 | 44448 | jjdelcerro | import org.gvsig.tools.dataTypes.CoercionException; |
76 | import org.gvsig.tools.dataTypes.DataType; |
||
77 | import org.gvsig.tools.dataTypes.DataTypes; |
||
78 | 41620 | jjdelcerro | import org.gvsig.tools.dynobject.DynObject; |
79 | 44253 | jjdelcerro | import org.gvsig.tools.dynobject.Tags; |
80 | 44238 | jjdelcerro | import org.gvsig.tools.folders.FoldersManager; |
81 | 41620 | jjdelcerro | import org.gvsig.tools.i18n.I18nManager; |
82 | 44129 | jjdelcerro | import org.gvsig.tools.swing.api.SimpleImage; |
83 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
84 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
85 | 40435 | jjdelcerro | import org.slf4j.Logger; |
86 | import org.slf4j.LoggerFactory; |
||
87 | |||
88 | public class InitializeApplicationExtension extends Extension { |
||
89 | 41576 | jjdelcerro | |
90 | 40435 | jjdelcerro | private static final Logger logger = LoggerFactory |
91 | .getLogger(InitializeApplicationExtension.class); |
||
92 | |||
93 | 44238 | jjdelcerro | // Copiadas de org.gvsig.coreplugin.PreferencesExtension
|
94 | public static final String PROJECTS_FOLDER_PROPERTY_NAME = "ProjectsFolder"; |
||
95 | public static final String DATA_FOLDER_PROPERTY_NAME = "DataFolder"; |
||
96 | public static final String TEMPLATES_FOLDER_PROPERTY_NAME = "TemplatesFolder"; |
||
97 | public static final String SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME = "SymbolLibraryFolder"; |
||
98 | 40435 | jjdelcerro | |
99 | 44404 | omartinez | private OpenErrorHandler openErrorHandler = null; |
100 | 44238 | jjdelcerro | |
101 | 44189 | jjdelcerro | private static class SimpleImageDataProfile extends AbstractDataProfile { |
102 | |||
103 | public SimpleImageDataProfile() {
|
||
104 | super("Image", SimpleImage.class); |
||
105 | } |
||
106 | 44404 | omartinez | |
107 | 44189 | jjdelcerro | @Override
|
108 | 44253 | jjdelcerro | public Object createData(Object data, Tags tags) { |
109 | 44189 | jjdelcerro | final ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
|
110 | SimpleImage image = toolsSwingManager.createSimpleImage(data); |
||
111 | return image;
|
||
112 | } |
||
113 | 44448 | jjdelcerro | |
114 | @Override
|
||
115 | public Object coerce(DataType dataType, Object data, Tags tags) throws CoercionException { |
||
116 | final ToolsSwingManager toolsSwingManager;
|
||
117 | final SimpleImage image;
|
||
118 | try {
|
||
119 | switch(dataType.getType()) {
|
||
120 | case DataTypes.BYTEARRAY:
|
||
121 | toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
||
122 | image = toolsSwingManager.createSimpleImage(data); |
||
123 | return image.toBytearray();
|
||
124 | case DataTypes.STRING:
|
||
125 | toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
||
126 | image = toolsSwingManager.createSimpleImage(data); |
||
127 | return image.toString();
|
||
128 | default:
|
||
129 | break;
|
||
130 | } |
||
131 | } catch(Exception ex) { |
||
132 | throw new CoercionException("Can't convert imagen to "+dataType.getName(), ex); |
||
133 | } |
||
134 | throw new CoercionException("Can't convert imagen to "+dataType.getName()); |
||
135 | } |
||
136 | |||
137 | 44189 | jjdelcerro | } |
138 | 44404 | omartinez | |
139 | 43095 | jjdelcerro | @Override
|
140 | 41576 | jjdelcerro | public void initialize() { |
141 | 42775 | jjdelcerro | DALLocator.registerFeatureTypeDefinitionsManager(DefaultFeatureTypeDefinitionsManager.class); |
142 | 44404 | omartinez | |
143 | 44129 | jjdelcerro | DataManager dataManager = DALLocator.getDataManager(); |
144 | 44189 | jjdelcerro | dataManager.registerDataProfile(new SimpleImageDataProfile());
|
145 | 44404 | omartinez | |
146 | 41576 | jjdelcerro | InfoListener.initializeExtensionPoint(); |
147 | 44404 | omartinez | |
148 | 44238 | jjdelcerro | initLastPath(); |
149 | 41576 | jjdelcerro | registerIcons(); |
150 | 44404 | omartinez | loadExpressionBookmarks(); |
151 | loadExpressionHistory(); |
||
152 | } |
||
153 | 40435 | jjdelcerro | |
154 | 44404 | omartinez | public void loadExpressionHistory() { |
155 | PluginsManager pluginManager = PluginsLocator.getManager(); |
||
156 | final PluginServices plugin = pluginManager.getPlugin(this); |
||
157 | DynObject pluginProperties = plugin.getPluginProperties(); |
||
158 | List<Expression> dynBookmarks = (List<Expression>) pluginProperties.getDynValue("expressionHistory"); |
||
159 | if (dynBookmarks == null) { |
||
160 | return;
|
||
161 | } |
||
162 | final ExpressionEvaluatorManager expressionManager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager();
|
||
163 | History<Expression> history = expressionManager.getHistory();
|
||
164 | for (Expression expression : dynBookmarks) { |
||
165 | history.add(expression); |
||
166 | } |
||
167 | pluginManager.addShutdownTask("saveExpressionHistory", new Runnable() { |
||
168 | @Override
|
||
169 | public void run() { |
||
170 | DynObject properties = plugin.getPluginProperties(); |
||
171 | ArrayList<Expression> var = new ArrayList<>(); |
||
172 | for (Expression expression : history) { |
||
173 | var.add(expression); |
||
174 | } |
||
175 | properties.setDynValue("expressionHistory", var);
|
||
176 | } |
||
177 | }, false, 100); |
||
178 | |||
179 | 41576 | jjdelcerro | } |
180 | 44404 | omartinez | |
181 | public void loadExpressionBookmarks() { |
||
182 | PluginsManager pluginManager = PluginsLocator.getManager(); |
||
183 | final PluginServices plugin = pluginManager.getPlugin(this); |
||
184 | DynObject pluginProperties = plugin.getPluginProperties(); |
||
185 | Map<String, Expression> dynBookmarks = (Map<String, Expression>) pluginProperties.getDynValue("expressionBookmarks"); |
||
186 | if (dynBookmarks == null) { |
||
187 | return;
|
||
188 | } |
||
189 | final ExpressionEvaluatorManager expressionManager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager();
|
||
190 | Bookmarks<Expression> bookmarks = expressionManager.getBookmarks();
|
||
191 | for (String key : dynBookmarks.keySet()) { |
||
192 | Expression bookmark = dynBookmarks.get(key);
|
||
193 | bookmarks.add(bookmark); |
||
194 | } |
||
195 | pluginManager.addShutdownTask("saveExpressionBookmarks", new Runnable() { |
||
196 | @Override
|
||
197 | public void run() { |
||
198 | DynObject properties = plugin.getPluginProperties(); |
||
199 | Map<String, Expression> var = new HashMap<>(); |
||
200 | for (Bookmark<Expression> bookmark : bookmarks) { |
||
201 | var.put(bookmark.getName(), bookmark.getValue()); |
||
202 | } |
||
203 | properties.setDynValue("expressionBookmarks", var);
|
||
204 | } |
||
205 | }, false, 100); |
||
206 | |||
207 | } |
||
208 | |||
209 | 44238 | jjdelcerro | private void initLastPath() { |
210 | 44404 | omartinez | Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
211 | 44238 | jjdelcerro | FoldersManager folderManager = ToolsLocator.getFoldersManager(); |
212 | String v;
|
||
213 | 44404 | omartinez | |
214 | 44238 | jjdelcerro | v = prefs.get(DATA_FOLDER_PROPERTY_NAME, folderManager.getHome().getAbsolutePath()); |
215 | folderManager.setLastPath(OPEN_LAYER_FILE_CHOOSER_ID, new File(v)); |
||
216 | 40435 | jjdelcerro | |
217 | 44238 | jjdelcerro | v = prefs.get(PROJECTS_FOLDER_PROPERTY_NAME, folderManager.getHome().getAbsolutePath()); |
218 | folderManager.setLastPath(PROJECT_FILE_CHOOSER_ID, new File(v)); |
||
219 | |||
220 | v = prefs.get("LegendsFolder", folderManager.getHome().getAbsolutePath());
|
||
221 | folderManager.setLastPath("LegendsFolder", new File(v)); |
||
222 | } |
||
223 | |||
224 | 43095 | jjdelcerro | @Override
|
225 | 41576 | jjdelcerro | public void postInitialize() { |
226 | 43095 | jjdelcerro | PluginsManager pluginManager = PluginsLocator.getManager(); |
227 | |||
228 | 40435 | jjdelcerro | openErrorHandler = new BaseOpenErrorHandler();
|
229 | ApplicationLocator.getManager().getDataManager().setOpenErrorHandler(openErrorHandler); |
||
230 | 41564 | jjdelcerro | |
231 | 41576 | jjdelcerro | DALLocator.getResourceManager().startResourceCollector( |
232 | 3 * (60 * 1000), // minutes --> miliseconds |
||
233 | null);
|
||
234 | 43095 | jjdelcerro | |
235 | 41913 | jjdelcerro | // showAddOnManagerOnStartIfNeed();
|
236 | 43095 | jjdelcerro | ProjectPreferences projectPreferences = ApplicationLocator.getProjectManager().getProjectPreferences(); |
237 | if (projectPreferences.getOpenWithANewMaximizedView()) {
|
||
238 | pluginManager.addStartupTask( |
||
239 | "showNewViewMaximized",
|
||
240 | new ShowNewMaximizedView(),
|
||
241 | true,
|
||
242 | 44075 | jjdelcerro | 750
|
243 | 43095 | jjdelcerro | ); |
244 | } |
||
245 | 44075 | jjdelcerro | pluginManager.addStartupTask("OpenLayerOnStart", new OpenLayerOnStart(), true, 740); |
246 | 44404 | omartinez | |
247 | 44075 | jjdelcerro | pluginManager.addStartupTask("ApplicationStartedMessage", new Runnable() { |
248 | @Override
|
||
249 | public void run() { |
||
250 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
251 | ApplicationManager application = ApplicationLocator.getManager(); |
||
252 | application.message( |
||
253 | 44404 | omartinez | i18n.getTranslation("StatusBar.Aplicacion_iniciada"),
|
254 | 44075 | jjdelcerro | JOptionPane.INFORMATION_MESSAGE
|
255 | ); |
||
256 | } |
||
257 | }, true, -1); |
||
258 | 43095 | jjdelcerro | |
259 | 41913 | jjdelcerro | } |
260 | |||
261 | private void showAddOnManagerOnStartIfNeed() { |
||
262 | 41620 | jjdelcerro | PluginsManager pluginManager = PluginsLocator.getManager(); |
263 | PluginServices plugin = pluginManager.getPlugin(this);
|
||
264 | DynObject pluginProperties = plugin.getPluginProperties(); |
||
265 | 43095 | jjdelcerro | Map<String, Boolean> showAddOnmanagerOnStart = null; |
266 | 41735 | jjdelcerro | try {
|
267 | 43095 | jjdelcerro | showAddOnmanagerOnStart = (Map<String, Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
268 | } catch (Exception ex) { |
||
269 | 41735 | jjdelcerro | // Do nothing
|
270 | } |
||
271 | 43095 | jjdelcerro | if (showAddOnmanagerOnStart == null) { |
272 | showAddOnmanagerOnStart = new HashMap<>(); |
||
273 | pluginProperties.setDynValue("showAddOnmanagerOnStart", showAddOnmanagerOnStart);
|
||
274 | 41735 | jjdelcerro | } |
275 | 43095 | jjdelcerro | Boolean showAddOnmanagerOnStartForCurrentVersion = showAddOnmanagerOnStart.get(pluginManager.getApplicationVersion().fullFormat());
|
276 | |||
277 | if (showAddOnmanagerOnStartForCurrentVersion == null || showAddOnmanagerOnStartForCurrentVersion) { |
||
278 | 41620 | jjdelcerro | pluginManager.addStartupTask( |
279 | 43095 | jjdelcerro | "showAddOnmanagerOnStart",
|
280 | 41620 | jjdelcerro | new ShowAddOnManagerOnStart(),
|
281 | 43095 | jjdelcerro | true,
|
282 | 41620 | jjdelcerro | 500
|
283 | ); |
||
284 | } |
||
285 | 41576 | jjdelcerro | } |
286 | 43095 | jjdelcerro | |
287 | private static class ShowNewMaximizedView implements Runnable { |
||
288 | |||
289 | @Override
|
||
290 | public void run() { |
||
291 | ApplicationManager application = ApplicationLocator.getManager(); |
||
292 | ProjectManager projectManager = application.getProjectManager(); |
||
293 | |||
294 | ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME); |
||
295 | ViewDocument view = (ViewDocument) viewManager.createDocument(); |
||
296 | projectManager.getCurrentProject().add(view); |
||
297 | |||
298 | IView viewWindow = (IView) viewManager.getMainWindow(view); |
||
299 | |||
300 | application.getUIManager().addWindow(viewWindow, GridBagConstraints.CENTER);
|
||
301 | try {
|
||
302 | application.getUIManager().setMaximum((IWindow) viewWindow, true);
|
||
303 | } catch (PropertyVetoException e) { |
||
304 | logger.info("Can't maximize view.", e);
|
||
305 | } |
||
306 | } |
||
307 | |||
308 | } |
||
309 | |||
310 | 41620 | jjdelcerro | private static class ShowAddOnManagerOnStart implements Runnable { |
311 | |||
312 | 43095 | jjdelcerro | @Override
|
313 | 41620 | jjdelcerro | public void run() { |
314 | ApplicationManager application = ApplicationLocator.getManager(); |
||
315 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
316 | PluginsManager pluginManager = PluginsLocator.getManager(); |
||
317 | PluginServices plugin = pluginManager.getPlugin(this);
|
||
318 | DynObject pluginProperties = plugin.getPluginProperties(); |
||
319 | |||
320 | 41723 | jjdelcerro | String msg = i18nManager.getTranslation("_Instalar_complementos_adicionales_no_disponibles_durante_el_proceso_de_instalacion"); |
321 | 41620 | jjdelcerro | int resp = application.confirmDialog(
|
322 | 43095 | jjdelcerro | msg, |
323 | i18nManager.getTranslation("_Finalizando_proceso_de_instalacion"),
|
||
324 | JOptionPane.YES_NO_OPTION,
|
||
325 | 41620 | jjdelcerro | JOptionPane.QUESTION_MESSAGE
|
326 | ); |
||
327 | 43095 | jjdelcerro | if (resp == JOptionPane.YES_OPTION) { |
328 | 41620 | jjdelcerro | ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
329 | actionManager.execute( |
||
330 | "tools-addonsmanager",
|
||
331 | 43095 | jjdelcerro | new Object[]{"skipBundleSelection"} |
332 | 41620 | jjdelcerro | ); |
333 | } |
||
334 | 43095 | jjdelcerro | Map<String, Boolean> showAddOnmanagerOnStart = (Map<String, Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
335 | 41735 | jjdelcerro | showAddOnmanagerOnStart.put(pluginManager.getApplicationVersion().fullFormat(), Boolean.FALSE);
|
336 | 41620 | jjdelcerro | } |
337 | } |
||
338 | 43095 | jjdelcerro | |
339 | 41576 | jjdelcerro | private void registerIcons() { |
340 | IconThemeHelper.registerIcon("action", "edit-clear", this); |
||
341 | IconThemeHelper.registerIcon("action", "edit-copy", this); |
||
342 | IconThemeHelper.registerIcon("action", "edit-cut", this); |
||
343 | IconThemeHelper.registerIcon("action", "edit-delete", this); |
||
344 | IconThemeHelper.registerIcon("action", "edit-find", this); |
||
345 | IconThemeHelper.registerIcon("action", "edit-find-replace", this); |
||
346 | IconThemeHelper.registerIcon("action", "edit-paste", this); |
||
347 | IconThemeHelper.registerIcon("action", "edit-redo", this); |
||
348 | IconThemeHelper.registerIcon("action", "edit-select-all", this); |
||
349 | IconThemeHelper.registerIcon("action", "edit-undo", this); |
||
350 | IconThemeHelper.registerIcon("action", "edit-undo-redo-actions", this); |
||
351 | IconThemeHelper.registerIcon("action", "document-print", this); |
||
352 | 40435 | jjdelcerro | |
353 | 41576 | jjdelcerro | IconThemeHelper.registerIcon("toolbar-go", "go-next", this); |
354 | IconThemeHelper.registerIcon("toolbar-go", "go-previous", this); |
||
355 | IconThemeHelper.registerIcon("toolbar-go", "go-next-fast", this); |
||
356 | IconThemeHelper.registerIcon("toolbar-go", "go-previous-fast", this); |
||
357 | IconThemeHelper.registerIcon("toolbar-go", "go-first", this); |
||
358 | IconThemeHelper.registerIcon("toolbar-go", "go-last", this); |
||
359 | 40435 | jjdelcerro | |
360 | 41576 | jjdelcerro | } |
361 | 40435 | jjdelcerro | |
362 | 43095 | jjdelcerro | @Override
|
363 | 41576 | jjdelcerro | public void execute(String actionCommand) { |
364 | 40435 | jjdelcerro | |
365 | 41576 | jjdelcerro | } |
366 | 40435 | jjdelcerro | |
367 | 43095 | jjdelcerro | @Override
|
368 | 41576 | jjdelcerro | public boolean isEnabled() { |
369 | return false; |
||
370 | } |
||
371 | 40435 | jjdelcerro | |
372 | 43095 | jjdelcerro | @Override
|
373 | 41576 | jjdelcerro | public boolean isVisible() { |
374 | return false; |
||
375 | } |
||
376 | 40435 | jjdelcerro | |
377 | 41576 | jjdelcerro | private void addToLogInfo() { |
378 | String info[] = this.getStringInfo().split("\n"); |
||
379 | 43095 | jjdelcerro | for (String line : info) { |
380 | logger.info(line); |
||
381 | 41576 | jjdelcerro | } |
382 | } |
||
383 | 40435 | jjdelcerro | |
384 | 41576 | jjdelcerro | public String getStringInfo() { |
385 | ApplicationManager application = ApplicationLocator.getManager(); |
||
386 | PluginsManager pluginmgr = PluginsLocator.getManager(); |
||
387 | InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
||
388 | 40435 | jjdelcerro | |
389 | 41576 | jjdelcerro | StringWriter writer = new StringWriter(); |
390 | 40435 | jjdelcerro | |
391 | 41576 | jjdelcerro | Properties props = System.getProperties(); |
392 | 40435 | jjdelcerro | |
393 | 41576 | jjdelcerro | // OS information
|
394 | String osName = props.getProperty("os.name"); |
||
395 | writer.write("OS\n");
|
||
396 | writer.write(" name : " + osName + "\n"); |
||
397 | writer.write(" arch : " + props.get("os.arch") + "\n"); |
||
398 | writer.write(" version: " + props.get("os.version") + "\n"); |
||
399 | if (osName.startsWith("Linux")) { |
||
400 | try {
|
||
401 | String[] command = {"lsb_release", "-a"}; |
||
402 | Process p = Runtime.getRuntime().exec(command); |
||
403 | InputStream is = p.getInputStream();
|
||
404 | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
||
405 | String line;
|
||
406 | while ((line = reader.readLine()) != null) { |
||
407 | writer.write(" " + line + "\n"); |
||
408 | } |
||
409 | } catch (Exception ex) { |
||
410 | writer.write("Can't get detailled os information (lsb_release -a).");
|
||
411 | } |
||
412 | } |
||
413 | 40435 | jjdelcerro | |
414 | 41576 | jjdelcerro | // JRE information
|
415 | writer.write("JRE\n");
|
||
416 | writer.write(" vendor : " + props.get("java.vendor") + "\n"); |
||
417 | writer.write(" version: " + props.get("java.version") + "\n"); |
||
418 | writer.write(" home : " + props.get("java.home") + "\n"); |
||
419 | 40435 | jjdelcerro | |
420 | 41576 | jjdelcerro | writer.write("gvSIG\n");
|
421 | writer.write(" version : " + application.getVersion().getLongFormat() + "\n"); |
||
422 | writer.write(" locale language : " + application.getLocaleLanguage() + "\n"); |
||
423 | writer.write(" application forlder : " + pluginmgr.getApplicationFolder() + "\n"); |
||
424 | writer.write(" install forlder : " + pluginmgr.getInstallFolder() + "\n"); |
||
425 | writer.write(" application home forlder: " + pluginmgr.getApplicationHomeFolder() + "\n"); |
||
426 | 41706 | jjdelcerro | writer.write(" plugins forlder : " + StringUtils.join(pluginmgr.getPluginsFolders()) + "\n"); |
427 | 41576 | jjdelcerro | |
428 | try {
|
||
429 | 41706 | jjdelcerro | PackageInfo[] pkgs = installmgr.getInstalledPackages();
|
430 | 41576 | jjdelcerro | writer.write("Installed packages\n");
|
431 | 43095 | jjdelcerro | for (PackageInfo pkg : pkgs) {
|
432 | 41576 | jjdelcerro | writer.write(" ");
|
433 | 43095 | jjdelcerro | writer.write(pkg.toStringCompact()); |
434 | 41576 | jjdelcerro | writer.write("\n");
|
435 | } |
||
436 | } catch (Throwable e) { |
||
437 | writer.write("Can't get installed package information.");
|
||
438 | } |
||
439 | return writer.toString();
|
||
440 | } |
||
441 | |||
442 | 43095 | jjdelcerro | @Override
|
443 | 41576 | jjdelcerro | public void terminate() { |
444 | ResourceManager resMan = DALLocator.getResourceManager(); |
||
445 | resMan.stopResourceCollector(); |
||
446 | try {
|
||
447 | resMan.dispose(); |
||
448 | } catch (DisposeResorceManagerException e) {
|
||
449 | logger.warn(e.getMessageStack()); |
||
450 | } |
||
451 | super.terminate();
|
||
452 | } |
||
453 | 40435 | jjdelcerro | } |