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