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