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