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 @ 44238
History | View | Annotate | Download (14.9 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 | 41735 | jjdelcerro | import java.util.HashMap; |
33 | import java.util.Map; |
||
34 | 40435 | jjdelcerro | import java.util.Properties; |
35 | 44238 | jjdelcerro | import java.util.prefs.Preferences; |
36 | 41620 | jjdelcerro | import javax.swing.JOptionPane; |
37 | 41706 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
38 | 40435 | jjdelcerro | |
39 | import org.gvsig.andami.IconThemeHelper; |
||
40 | 41620 | jjdelcerro | import org.gvsig.andami.PluginServices; |
41 | 40435 | jjdelcerro | import org.gvsig.andami.PluginsLocator; |
42 | import org.gvsig.andami.PluginsManager; |
||
43 | 41620 | jjdelcerro | import org.gvsig.andami.actioninfo.ActionInfoManager; |
44 | 40435 | jjdelcerro | import org.gvsig.andami.plugins.Extension; |
45 | 43095 | jjdelcerro | import org.gvsig.andami.ui.mdiManager.IWindow; |
46 | 40435 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
47 | import org.gvsig.app.ApplicationManager; |
||
48 | 44238 | jjdelcerro | import static org.gvsig.app.extension.ProjectExtension.PROJECT_FILE_CHOOSER_ID; |
49 | 43095 | jjdelcerro | import org.gvsig.app.project.ProjectManager; |
50 | import org.gvsig.app.project.ProjectPreferences; |
||
51 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
52 | import org.gvsig.app.project.documents.view.ViewManager; |
||
53 | import org.gvsig.app.project.documents.view.gui.IView; |
||
54 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.toolListeners.InfoListener; |
55 | import org.gvsig.app.util.BaseOpenErrorHandler; |
||
56 | import org.gvsig.fmap.dal.DALLocator; |
||
57 | 44129 | jjdelcerro | import org.gvsig.fmap.dal.DataManager; |
58 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.OpenErrorHandler; |
59 | 44189 | jjdelcerro | import org.gvsig.fmap.dal.feature.AbstractDataProfile; |
60 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.resource.ResourceManager; |
61 | import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
||
62 | 44238 | jjdelcerro | import static org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanelController.OPEN_LAYER_FILE_CHOOSER_ID; |
63 | 40435 | jjdelcerro | import org.gvsig.installer.lib.api.InstallerLocator; |
64 | import org.gvsig.installer.lib.api.InstallerManager; |
||
65 | import org.gvsig.installer.lib.api.PackageInfo; |
||
66 | 41620 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
67 | import org.gvsig.tools.dynobject.DynObject; |
||
68 | 44238 | jjdelcerro | import org.gvsig.tools.folders.FoldersManager; |
69 | 41620 | jjdelcerro | import org.gvsig.tools.i18n.I18nManager; |
70 | 44129 | jjdelcerro | import org.gvsig.tools.swing.api.SimpleImage; |
71 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
72 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
73 | 40435 | jjdelcerro | import org.slf4j.Logger; |
74 | import org.slf4j.LoggerFactory; |
||
75 | |||
76 | public class InitializeApplicationExtension extends Extension { |
||
77 | 41576 | jjdelcerro | |
78 | 40435 | jjdelcerro | private static final Logger logger = LoggerFactory |
79 | .getLogger(InitializeApplicationExtension.class); |
||
80 | |||
81 | 44238 | jjdelcerro | // Copiadas de org.gvsig.coreplugin.PreferencesExtension
|
82 | public static final String PROJECTS_FOLDER_PROPERTY_NAME = "ProjectsFolder"; |
||
83 | public static final String DATA_FOLDER_PROPERTY_NAME = "DataFolder"; |
||
84 | public static final String TEMPLATES_FOLDER_PROPERTY_NAME = "TemplatesFolder"; |
||
85 | public static final String SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME = "SymbolLibraryFolder"; |
||
86 | 40435 | jjdelcerro | |
87 | 44238 | jjdelcerro | private OpenErrorHandler openErrorHandler = null; |
88 | |||
89 | 44189 | jjdelcerro | private static class SimpleImageDataProfile extends AbstractDataProfile { |
90 | |||
91 | public SimpleImageDataProfile() {
|
||
92 | super("Image", SimpleImage.class); |
||
93 | } |
||
94 | |||
95 | @Override
|
||
96 | public Object createData(Object data) { |
||
97 | final ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
|
||
98 | SimpleImage image = toolsSwingManager.createSimpleImage(data); |
||
99 | return image;
|
||
100 | } |
||
101 | } |
||
102 | |||
103 | 43095 | jjdelcerro | @Override
|
104 | 41576 | jjdelcerro | public void initialize() { |
105 | 42775 | jjdelcerro | DALLocator.registerFeatureTypeDefinitionsManager(DefaultFeatureTypeDefinitionsManager.class); |
106 | 44129 | jjdelcerro | |
107 | DataManager dataManager = DALLocator.getDataManager(); |
||
108 | 44189 | jjdelcerro | dataManager.registerDataProfile(new SimpleImageDataProfile());
|
109 | 44129 | jjdelcerro | |
110 | 41576 | jjdelcerro | InfoListener.initializeExtensionPoint(); |
111 | 44238 | jjdelcerro | |
112 | initLastPath(); |
||
113 | 41576 | jjdelcerro | registerIcons(); |
114 | 40435 | jjdelcerro | |
115 | 41576 | jjdelcerro | } |
116 | 44238 | jjdelcerro | |
117 | private void initLastPath() { |
||
118 | Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
||
119 | FoldersManager folderManager = ToolsLocator.getFoldersManager(); |
||
120 | String v;
|
||
121 | |||
122 | v = prefs.get(DATA_FOLDER_PROPERTY_NAME, folderManager.getHome().getAbsolutePath()); |
||
123 | folderManager.setLastPath(OPEN_LAYER_FILE_CHOOSER_ID, new File(v)); |
||
124 | 40435 | jjdelcerro | |
125 | 44238 | jjdelcerro | v = prefs.get(PROJECTS_FOLDER_PROPERTY_NAME, folderManager.getHome().getAbsolutePath()); |
126 | folderManager.setLastPath(PROJECT_FILE_CHOOSER_ID, new File(v)); |
||
127 | |||
128 | v = prefs.get("LegendsFolder", folderManager.getHome().getAbsolutePath());
|
||
129 | folderManager.setLastPath("LegendsFolder", new File(v)); |
||
130 | } |
||
131 | |||
132 | 43095 | jjdelcerro | @Override
|
133 | 41576 | jjdelcerro | public void postInitialize() { |
134 | 43095 | jjdelcerro | PluginsManager pluginManager = PluginsLocator.getManager(); |
135 | |||
136 | 40435 | jjdelcerro | openErrorHandler = new BaseOpenErrorHandler();
|
137 | ApplicationLocator.getManager().getDataManager().setOpenErrorHandler(openErrorHandler); |
||
138 | 41564 | jjdelcerro | |
139 | 41576 | jjdelcerro | DALLocator.getResourceManager().startResourceCollector( |
140 | 3 * (60 * 1000), // minutes --> miliseconds |
||
141 | null);
|
||
142 | 43095 | jjdelcerro | |
143 | 41913 | jjdelcerro | // showAddOnManagerOnStartIfNeed();
|
144 | 43095 | jjdelcerro | ProjectPreferences projectPreferences = ApplicationLocator.getProjectManager().getProjectPreferences(); |
145 | if (projectPreferences.getOpenWithANewMaximizedView()) {
|
||
146 | pluginManager.addStartupTask( |
||
147 | "showNewViewMaximized",
|
||
148 | new ShowNewMaximizedView(),
|
||
149 | true,
|
||
150 | 44075 | jjdelcerro | 750
|
151 | 43095 | jjdelcerro | ); |
152 | } |
||
153 | 44075 | jjdelcerro | pluginManager.addStartupTask("OpenLayerOnStart", new OpenLayerOnStart(), true, 740); |
154 | |||
155 | pluginManager.addStartupTask("ApplicationStartedMessage", new Runnable() { |
||
156 | @Override
|
||
157 | public void run() { |
||
158 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
159 | ApplicationManager application = ApplicationLocator.getManager(); |
||
160 | application.message( |
||
161 | i18n.getTranslation("StatusBar.Aplicacion_iniciada"),
|
||
162 | JOptionPane.INFORMATION_MESSAGE
|
||
163 | ); |
||
164 | } |
||
165 | }, true, -1); |
||
166 | 43095 | jjdelcerro | |
167 | 41913 | jjdelcerro | } |
168 | |||
169 | private void showAddOnManagerOnStartIfNeed() { |
||
170 | 41620 | jjdelcerro | PluginsManager pluginManager = PluginsLocator.getManager(); |
171 | PluginServices plugin = pluginManager.getPlugin(this);
|
||
172 | DynObject pluginProperties = plugin.getPluginProperties(); |
||
173 | 43095 | jjdelcerro | Map<String, Boolean> showAddOnmanagerOnStart = null; |
174 | 41735 | jjdelcerro | try {
|
175 | 43095 | jjdelcerro | showAddOnmanagerOnStart = (Map<String, Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
176 | } catch (Exception ex) { |
||
177 | 41735 | jjdelcerro | // Do nothing
|
178 | } |
||
179 | 43095 | jjdelcerro | if (showAddOnmanagerOnStart == null) { |
180 | showAddOnmanagerOnStart = new HashMap<>(); |
||
181 | pluginProperties.setDynValue("showAddOnmanagerOnStart", showAddOnmanagerOnStart);
|
||
182 | 41735 | jjdelcerro | } |
183 | 43095 | jjdelcerro | Boolean showAddOnmanagerOnStartForCurrentVersion = showAddOnmanagerOnStart.get(pluginManager.getApplicationVersion().fullFormat());
|
184 | |||
185 | if (showAddOnmanagerOnStartForCurrentVersion == null || showAddOnmanagerOnStartForCurrentVersion) { |
||
186 | 41620 | jjdelcerro | pluginManager.addStartupTask( |
187 | 43095 | jjdelcerro | "showAddOnmanagerOnStart",
|
188 | 41620 | jjdelcerro | new ShowAddOnManagerOnStart(),
|
189 | 43095 | jjdelcerro | true,
|
190 | 41620 | jjdelcerro | 500
|
191 | ); |
||
192 | } |
||
193 | 41576 | jjdelcerro | } |
194 | 43095 | jjdelcerro | |
195 | private static class ShowNewMaximizedView implements Runnable { |
||
196 | |||
197 | @Override
|
||
198 | public void run() { |
||
199 | ApplicationManager application = ApplicationLocator.getManager(); |
||
200 | ProjectManager projectManager = application.getProjectManager(); |
||
201 | |||
202 | ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME); |
||
203 | ViewDocument view = (ViewDocument) viewManager.createDocument(); |
||
204 | projectManager.getCurrentProject().add(view); |
||
205 | |||
206 | IView viewWindow = (IView) viewManager.getMainWindow(view); |
||
207 | |||
208 | application.getUIManager().addWindow(viewWindow, GridBagConstraints.CENTER);
|
||
209 | try {
|
||
210 | application.getUIManager().setMaximum((IWindow) viewWindow, true);
|
||
211 | } catch (PropertyVetoException e) { |
||
212 | logger.info("Can't maximize view.", e);
|
||
213 | } |
||
214 | } |
||
215 | |||
216 | } |
||
217 | |||
218 | 41620 | jjdelcerro | private static class ShowAddOnManagerOnStart implements Runnable { |
219 | |||
220 | 43095 | jjdelcerro | @Override
|
221 | 41620 | jjdelcerro | public void run() { |
222 | ApplicationManager application = ApplicationLocator.getManager(); |
||
223 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
224 | PluginsManager pluginManager = PluginsLocator.getManager(); |
||
225 | PluginServices plugin = pluginManager.getPlugin(this);
|
||
226 | DynObject pluginProperties = plugin.getPluginProperties(); |
||
227 | |||
228 | 41723 | jjdelcerro | String msg = i18nManager.getTranslation("_Instalar_complementos_adicionales_no_disponibles_durante_el_proceso_de_instalacion"); |
229 | 41620 | jjdelcerro | int resp = application.confirmDialog(
|
230 | 43095 | jjdelcerro | msg, |
231 | i18nManager.getTranslation("_Finalizando_proceso_de_instalacion"),
|
||
232 | JOptionPane.YES_NO_OPTION,
|
||
233 | 41620 | jjdelcerro | JOptionPane.QUESTION_MESSAGE
|
234 | ); |
||
235 | 43095 | jjdelcerro | if (resp == JOptionPane.YES_OPTION) { |
236 | 41620 | jjdelcerro | ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
237 | actionManager.execute( |
||
238 | "tools-addonsmanager",
|
||
239 | 43095 | jjdelcerro | new Object[]{"skipBundleSelection"} |
240 | 41620 | jjdelcerro | ); |
241 | } |
||
242 | 43095 | jjdelcerro | Map<String, Boolean> showAddOnmanagerOnStart = (Map<String, Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
243 | 41735 | jjdelcerro | showAddOnmanagerOnStart.put(pluginManager.getApplicationVersion().fullFormat(), Boolean.FALSE);
|
244 | 41620 | jjdelcerro | } |
245 | } |
||
246 | 43095 | jjdelcerro | |
247 | 41576 | jjdelcerro | private void registerIcons() { |
248 | IconThemeHelper.registerIcon("action", "edit-clear", this); |
||
249 | IconThemeHelper.registerIcon("action", "edit-copy", this); |
||
250 | IconThemeHelper.registerIcon("action", "edit-cut", this); |
||
251 | IconThemeHelper.registerIcon("action", "edit-delete", this); |
||
252 | IconThemeHelper.registerIcon("action", "edit-find", this); |
||
253 | IconThemeHelper.registerIcon("action", "edit-find-replace", this); |
||
254 | IconThemeHelper.registerIcon("action", "edit-paste", this); |
||
255 | IconThemeHelper.registerIcon("action", "edit-redo", this); |
||
256 | IconThemeHelper.registerIcon("action", "edit-select-all", this); |
||
257 | IconThemeHelper.registerIcon("action", "edit-undo", this); |
||
258 | IconThemeHelper.registerIcon("action", "edit-undo-redo-actions", this); |
||
259 | IconThemeHelper.registerIcon("action", "document-print", this); |
||
260 | 40435 | jjdelcerro | |
261 | 41576 | jjdelcerro | IconThemeHelper.registerIcon("toolbar-go", "go-next", this); |
262 | IconThemeHelper.registerIcon("toolbar-go", "go-previous", this); |
||
263 | IconThemeHelper.registerIcon("toolbar-go", "go-next-fast", this); |
||
264 | IconThemeHelper.registerIcon("toolbar-go", "go-previous-fast", this); |
||
265 | IconThemeHelper.registerIcon("toolbar-go", "go-first", this); |
||
266 | IconThemeHelper.registerIcon("toolbar-go", "go-last", this); |
||
267 | 40435 | jjdelcerro | |
268 | 41576 | jjdelcerro | } |
269 | 40435 | jjdelcerro | |
270 | 43095 | jjdelcerro | @Override
|
271 | 41576 | jjdelcerro | public void execute(String actionCommand) { |
272 | 40435 | jjdelcerro | |
273 | 41576 | jjdelcerro | } |
274 | 40435 | jjdelcerro | |
275 | 43095 | jjdelcerro | @Override
|
276 | 41576 | jjdelcerro | public boolean isEnabled() { |
277 | return false; |
||
278 | } |
||
279 | 40435 | jjdelcerro | |
280 | 43095 | jjdelcerro | @Override
|
281 | 41576 | jjdelcerro | public boolean isVisible() { |
282 | return false; |
||
283 | } |
||
284 | 40435 | jjdelcerro | |
285 | 41576 | jjdelcerro | private void addToLogInfo() { |
286 | String info[] = this.getStringInfo().split("\n"); |
||
287 | 43095 | jjdelcerro | for (String line : info) { |
288 | logger.info(line); |
||
289 | 41576 | jjdelcerro | } |
290 | } |
||
291 | 40435 | jjdelcerro | |
292 | 41576 | jjdelcerro | public String getStringInfo() { |
293 | ApplicationManager application = ApplicationLocator.getManager(); |
||
294 | PluginsManager pluginmgr = PluginsLocator.getManager(); |
||
295 | InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
||
296 | 40435 | jjdelcerro | |
297 | 41576 | jjdelcerro | StringWriter writer = new StringWriter(); |
298 | 40435 | jjdelcerro | |
299 | 41576 | jjdelcerro | Properties props = System.getProperties(); |
300 | 40435 | jjdelcerro | |
301 | 41576 | jjdelcerro | // OS information
|
302 | String osName = props.getProperty("os.name"); |
||
303 | writer.write("OS\n");
|
||
304 | writer.write(" name : " + osName + "\n"); |
||
305 | writer.write(" arch : " + props.get("os.arch") + "\n"); |
||
306 | writer.write(" version: " + props.get("os.version") + "\n"); |
||
307 | if (osName.startsWith("Linux")) { |
||
308 | try {
|
||
309 | String[] command = {"lsb_release", "-a"}; |
||
310 | Process p = Runtime.getRuntime().exec(command); |
||
311 | InputStream is = p.getInputStream();
|
||
312 | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
||
313 | String line;
|
||
314 | while ((line = reader.readLine()) != null) { |
||
315 | writer.write(" " + line + "\n"); |
||
316 | } |
||
317 | } catch (Exception ex) { |
||
318 | writer.write("Can't get detailled os information (lsb_release -a).");
|
||
319 | } |
||
320 | } |
||
321 | 40435 | jjdelcerro | |
322 | 41576 | jjdelcerro | // JRE information
|
323 | writer.write("JRE\n");
|
||
324 | writer.write(" vendor : " + props.get("java.vendor") + "\n"); |
||
325 | writer.write(" version: " + props.get("java.version") + "\n"); |
||
326 | writer.write(" home : " + props.get("java.home") + "\n"); |
||
327 | 40435 | jjdelcerro | |
328 | 41576 | jjdelcerro | writer.write("gvSIG\n");
|
329 | writer.write(" version : " + application.getVersion().getLongFormat() + "\n"); |
||
330 | writer.write(" locale language : " + application.getLocaleLanguage() + "\n"); |
||
331 | writer.write(" application forlder : " + pluginmgr.getApplicationFolder() + "\n"); |
||
332 | writer.write(" install forlder : " + pluginmgr.getInstallFolder() + "\n"); |
||
333 | writer.write(" application home forlder: " + pluginmgr.getApplicationHomeFolder() + "\n"); |
||
334 | 41706 | jjdelcerro | writer.write(" plugins forlder : " + StringUtils.join(pluginmgr.getPluginsFolders()) + "\n"); |
335 | 41576 | jjdelcerro | |
336 | try {
|
||
337 | 41706 | jjdelcerro | PackageInfo[] pkgs = installmgr.getInstalledPackages();
|
338 | 41576 | jjdelcerro | writer.write("Installed packages\n");
|
339 | 43095 | jjdelcerro | for (PackageInfo pkg : pkgs) {
|
340 | 41576 | jjdelcerro | writer.write(" ");
|
341 | 43095 | jjdelcerro | writer.write(pkg.toStringCompact()); |
342 | 41576 | jjdelcerro | writer.write("\n");
|
343 | } |
||
344 | } catch (Throwable e) { |
||
345 | writer.write("Can't get installed package information.");
|
||
346 | } |
||
347 | return writer.toString();
|
||
348 | } |
||
349 | |||
350 | 43095 | jjdelcerro | @Override
|
351 | 41576 | jjdelcerro | public void terminate() { |
352 | ResourceManager resMan = DALLocator.getResourceManager(); |
||
353 | resMan.stopResourceCollector(); |
||
354 | try {
|
||
355 | resMan.dispose(); |
||
356 | } catch (DisposeResorceManagerException e) {
|
||
357 | logger.warn(e.getMessageStack()); |
||
358 | } |
||
359 | super.terminate();
|
||
360 | } |
||
361 | 40435 | jjdelcerro | } |