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