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