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