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 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* 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 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.extension; |
24 |
|
25 |
import java.awt.GridBagConstraints; |
26 |
import java.beans.PropertyVetoException; |
27 |
import java.io.BufferedReader; |
28 |
import java.io.InputStream; |
29 |
import java.io.InputStreamReader; |
30 |
import java.io.StringWriter; |
31 |
import java.util.HashMap; |
32 |
import java.util.Map; |
33 |
import java.util.Properties; |
34 |
import javax.swing.JOptionPane; |
35 |
import org.apache.commons.lang3.StringUtils; |
36 |
|
37 |
import org.gvsig.andami.IconThemeHelper; |
38 |
import org.gvsig.andami.PluginServices; |
39 |
import org.gvsig.andami.PluginsLocator; |
40 |
import org.gvsig.andami.PluginsManager; |
41 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
42 |
import org.gvsig.andami.plugins.Extension; |
43 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
44 |
import org.gvsig.app.ApplicationLocator; |
45 |
import org.gvsig.app.ApplicationManager; |
46 |
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 |
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 |
import org.gvsig.tools.ToolsLocator; |
61 |
import org.gvsig.tools.dynobject.DynObject; |
62 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluatorFactory; |
63 |
import org.gvsig.tools.i18n.I18nManager; |
64 |
import org.slf4j.Logger; |
65 |
import org.slf4j.LoggerFactory; |
66 |
|
67 |
public class InitializeApplicationExtension extends Extension { |
68 |
|
69 |
private static final Logger logger = LoggerFactory |
70 |
.getLogger(InitializeApplicationExtension.class); |
71 |
|
72 |
private OpenErrorHandler openErrorHandler = null; |
73 |
|
74 |
@Override
|
75 |
public void initialize() { |
76 |
|
77 |
DALLocator.getDataManager().registerDefaultEvaluator(new SQLJEPEvaluatorFactory());
|
78 |
|
79 |
DALLocator.registerFeatureTypeDefinitionsManager(DefaultFeatureTypeDefinitionsManager.class); |
80 |
|
81 |
InfoListener.initializeExtensionPoint(); |
82 |
|
83 |
registerIcons(); |
84 |
|
85 |
} |
86 |
|
87 |
@Override
|
88 |
public void postInitialize() { |
89 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
90 |
|
91 |
openErrorHandler = new BaseOpenErrorHandler();
|
92 |
ApplicationLocator.getManager().getDataManager().setOpenErrorHandler(openErrorHandler); |
93 |
|
94 |
DALLocator.getResourceManager().startResourceCollector( |
95 |
3 * (60 * 1000), // minutes --> miliseconds |
96 |
null);
|
97 |
|
98 |
// showAddOnManagerOnStartIfNeed();
|
99 |
ProjectPreferences projectPreferences = ApplicationLocator.getProjectManager().getProjectPreferences(); |
100 |
if (projectPreferences.getOpenWithANewMaximizedView()) {
|
101 |
pluginManager.addStartupTask( |
102 |
"showNewViewMaximized",
|
103 |
new ShowNewMaximizedView(),
|
104 |
true,
|
105 |
500
|
106 |
); |
107 |
} |
108 |
pluginManager.addStartupTask("OpenLayerOnStart", new OpenLayerOnStart(), true, 0); |
109 |
|
110 |
} |
111 |
|
112 |
private void showAddOnManagerOnStartIfNeed() { |
113 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
114 |
PluginServices plugin = pluginManager.getPlugin(this);
|
115 |
DynObject pluginProperties = plugin.getPluginProperties(); |
116 |
Map<String, Boolean> showAddOnmanagerOnStart = null; |
117 |
try {
|
118 |
showAddOnmanagerOnStart = (Map<String, Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
119 |
} catch (Exception ex) { |
120 |
// Do nothing
|
121 |
} |
122 |
if (showAddOnmanagerOnStart == null) { |
123 |
showAddOnmanagerOnStart = new HashMap<>(); |
124 |
pluginProperties.setDynValue("showAddOnmanagerOnStart", showAddOnmanagerOnStart);
|
125 |
} |
126 |
Boolean showAddOnmanagerOnStartForCurrentVersion = showAddOnmanagerOnStart.get(pluginManager.getApplicationVersion().fullFormat());
|
127 |
|
128 |
if (showAddOnmanagerOnStartForCurrentVersion == null || showAddOnmanagerOnStartForCurrentVersion) { |
129 |
pluginManager.addStartupTask( |
130 |
"showAddOnmanagerOnStart",
|
131 |
new ShowAddOnManagerOnStart(),
|
132 |
true,
|
133 |
500
|
134 |
); |
135 |
} |
136 |
} |
137 |
|
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 |
private static class ShowAddOnManagerOnStart implements Runnable { |
162 |
|
163 |
@Override
|
164 |
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 |
String msg = i18nManager.getTranslation("_Instalar_complementos_adicionales_no_disponibles_durante_el_proceso_de_instalacion"); |
172 |
int resp = application.confirmDialog(
|
173 |
msg, |
174 |
i18nManager.getTranslation("_Finalizando_proceso_de_instalacion"),
|
175 |
JOptionPane.YES_NO_OPTION,
|
176 |
JOptionPane.QUESTION_MESSAGE
|
177 |
); |
178 |
if (resp == JOptionPane.YES_OPTION) { |
179 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
180 |
actionManager.execute( |
181 |
"tools-addonsmanager",
|
182 |
new Object[]{"skipBundleSelection"} |
183 |
); |
184 |
} |
185 |
Map<String, Boolean> showAddOnmanagerOnStart = (Map<String, Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
186 |
showAddOnmanagerOnStart.put(pluginManager.getApplicationVersion().fullFormat(), Boolean.FALSE);
|
187 |
} |
188 |
} |
189 |
|
190 |
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 |
|
204 |
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 |
|
211 |
} |
212 |
|
213 |
@Override
|
214 |
public void execute(String actionCommand) { |
215 |
|
216 |
} |
217 |
|
218 |
@Override
|
219 |
public boolean isEnabled() { |
220 |
return false; |
221 |
} |
222 |
|
223 |
@Override
|
224 |
public boolean isVisible() { |
225 |
return false; |
226 |
} |
227 |
|
228 |
private void addToLogInfo() { |
229 |
String info[] = this.getStringInfo().split("\n"); |
230 |
for (String line : info) { |
231 |
logger.info(line); |
232 |
} |
233 |
} |
234 |
|
235 |
public String getStringInfo() { |
236 |
ApplicationManager application = ApplicationLocator.getManager(); |
237 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
238 |
InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
239 |
|
240 |
StringWriter writer = new StringWriter(); |
241 |
|
242 |
Properties props = System.getProperties(); |
243 |
|
244 |
// 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 |
|
265 |
// 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 |
|
271 |
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 |
writer.write(" plugins forlder : " + StringUtils.join(pluginmgr.getPluginsFolders()) + "\n"); |
278 |
|
279 |
try {
|
280 |
PackageInfo[] pkgs = installmgr.getInstalledPackages();
|
281 |
writer.write("Installed packages\n");
|
282 |
for (PackageInfo pkg : pkgs) {
|
283 |
writer.write(" ");
|
284 |
writer.write(pkg.toStringCompact()); |
285 |
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 |
@Override
|
294 |
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 |
} |