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