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 @ 43328
History | View | Annotate | Download (12.2 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.SQLJEPEvaluator; |
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(SQLJEPEvaluator.class); |
78 |
DALLocator.registerFeatureTypeDefinitionsManager(DefaultFeatureTypeDefinitionsManager.class); |
79 |
|
80 |
InfoListener.initializeExtensionPoint(); |
81 |
|
82 |
registerIcons(); |
83 |
|
84 |
} |
85 |
|
86 |
@Override
|
87 |
public void postInitialize() { |
88 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
89 |
|
90 |
openErrorHandler = new BaseOpenErrorHandler();
|
91 |
ApplicationLocator.getManager().getDataManager().setOpenErrorHandler(openErrorHandler); |
92 |
|
93 |
DALLocator.getResourceManager().startResourceCollector( |
94 |
3 * (60 * 1000), // minutes --> miliseconds |
95 |
null);
|
96 |
|
97 |
// showAddOnManagerOnStartIfNeed();
|
98 |
ProjectPreferences projectPreferences = ApplicationLocator.getProjectManager().getProjectPreferences(); |
99 |
if (projectPreferences.getOpenWithANewMaximizedView()) {
|
100 |
pluginManager.addStartupTask( |
101 |
"showNewViewMaximized",
|
102 |
new ShowNewMaximizedView(),
|
103 |
true,
|
104 |
500
|
105 |
); |
106 |
} |
107 |
pluginManager.addStartupTask("OpenLayerOnStart", new OpenLayerOnStart(), true, 0); |
108 |
|
109 |
} |
110 |
|
111 |
private void showAddOnManagerOnStartIfNeed() { |
112 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
113 |
PluginServices plugin = pluginManager.getPlugin(this);
|
114 |
DynObject pluginProperties = plugin.getPluginProperties(); |
115 |
Map<String, Boolean> showAddOnmanagerOnStart = null; |
116 |
try {
|
117 |
showAddOnmanagerOnStart = (Map<String, Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
118 |
} catch (Exception ex) { |
119 |
// Do nothing
|
120 |
} |
121 |
if (showAddOnmanagerOnStart == null) { |
122 |
showAddOnmanagerOnStart = new HashMap<>(); |
123 |
pluginProperties.setDynValue("showAddOnmanagerOnStart", showAddOnmanagerOnStart);
|
124 |
} |
125 |
Boolean showAddOnmanagerOnStartForCurrentVersion = showAddOnmanagerOnStart.get(pluginManager.getApplicationVersion().fullFormat());
|
126 |
|
127 |
if (showAddOnmanagerOnStartForCurrentVersion == null || showAddOnmanagerOnStartForCurrentVersion) { |
128 |
pluginManager.addStartupTask( |
129 |
"showAddOnmanagerOnStart",
|
130 |
new ShowAddOnManagerOnStart(),
|
131 |
true,
|
132 |
500
|
133 |
); |
134 |
} |
135 |
} |
136 |
|
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 |
private static class ShowAddOnManagerOnStart implements Runnable { |
161 |
|
162 |
@Override
|
163 |
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 |
String msg = i18nManager.getTranslation("_Instalar_complementos_adicionales_no_disponibles_durante_el_proceso_de_instalacion"); |
171 |
int resp = application.confirmDialog(
|
172 |
msg, |
173 |
i18nManager.getTranslation("_Finalizando_proceso_de_instalacion"),
|
174 |
JOptionPane.YES_NO_OPTION,
|
175 |
JOptionPane.QUESTION_MESSAGE
|
176 |
); |
177 |
if (resp == JOptionPane.YES_OPTION) { |
178 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
179 |
actionManager.execute( |
180 |
"tools-addonsmanager",
|
181 |
new Object[]{"skipBundleSelection"} |
182 |
); |
183 |
} |
184 |
Map<String, Boolean> showAddOnmanagerOnStart = (Map<String, Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
185 |
showAddOnmanagerOnStart.put(pluginManager.getApplicationVersion().fullFormat(), Boolean.FALSE);
|
186 |
} |
187 |
} |
188 |
|
189 |
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 |
|
203 |
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 |
|
210 |
} |
211 |
|
212 |
@Override
|
213 |
public void execute(String actionCommand) { |
214 |
|
215 |
} |
216 |
|
217 |
@Override
|
218 |
public boolean isEnabled() { |
219 |
return false; |
220 |
} |
221 |
|
222 |
@Override
|
223 |
public boolean isVisible() { |
224 |
return false; |
225 |
} |
226 |
|
227 |
private void addToLogInfo() { |
228 |
String info[] = this.getStringInfo().split("\n"); |
229 |
for (String line : info) { |
230 |
logger.info(line); |
231 |
} |
232 |
} |
233 |
|
234 |
public String getStringInfo() { |
235 |
ApplicationManager application = ApplicationLocator.getManager(); |
236 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
237 |
InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
238 |
|
239 |
StringWriter writer = new StringWriter(); |
240 |
|
241 |
Properties props = System.getProperties(); |
242 |
|
243 |
// 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 |
|
264 |
// 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 |
|
270 |
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 |
writer.write(" plugins forlder : " + StringUtils.join(pluginmgr.getPluginsFolders()) + "\n"); |
277 |
|
278 |
try {
|
279 |
PackageInfo[] pkgs = installmgr.getInstalledPackages();
|
280 |
writer.write("Installed packages\n");
|
281 |
for (PackageInfo pkg : pkgs) {
|
282 |
writer.write(" ");
|
283 |
writer.write(pkg.toStringCompact()); |
284 |
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 |
@Override
|
293 |
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 |
} |