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 @ 42775
History | View | Annotate | Download (10.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.io.BufferedReader; |
26 |
import java.io.InputStream; |
27 |
import java.io.InputStreamReader; |
28 |
import java.io.StringWriter; |
29 |
import java.util.HashMap; |
30 |
import java.util.Map; |
31 |
import java.util.Properties; |
32 |
import javax.swing.JOptionPane; |
33 |
import org.apache.commons.lang3.BooleanUtils; |
34 |
import org.apache.commons.lang3.StringUtils; |
35 |
|
36 |
import org.gvsig.andami.IconThemeHelper; |
37 |
import org.gvsig.andami.PluginServices; |
38 |
import org.gvsig.andami.PluginsLocator; |
39 |
import org.gvsig.andami.PluginsManager; |
40 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
41 |
import org.gvsig.andami.plugins.Extension; |
42 |
import org.gvsig.app.ApplicationLocator; |
43 |
import org.gvsig.app.ApplicationManager; |
44 |
import org.gvsig.app.project.documents.view.toolListeners.InfoListener; |
45 |
import org.gvsig.app.util.BaseOpenErrorHandler; |
46 |
import org.gvsig.fmap.dal.DALLocator; |
47 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
48 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
49 |
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
50 |
import org.gvsig.installer.lib.api.InstallerLocator; |
51 |
import org.gvsig.installer.lib.api.InstallerManager; |
52 |
import org.gvsig.installer.lib.api.PackageInfo; |
53 |
import org.gvsig.tools.ToolsLocator; |
54 |
import org.gvsig.tools.dynobject.DynObject; |
55 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
56 |
import org.gvsig.tools.i18n.I18nManager; |
57 |
import org.slf4j.Logger; |
58 |
import org.slf4j.LoggerFactory; |
59 |
|
60 |
public class InitializeApplicationExtension extends Extension { |
61 |
|
62 |
private static final Logger logger = LoggerFactory |
63 |
.getLogger(InitializeApplicationExtension.class); |
64 |
|
65 |
private OpenErrorHandler openErrorHandler = null; |
66 |
|
67 |
public void initialize() { |
68 |
|
69 |
DALLocator.getDataManager().registerDefaultEvaluator(SQLJEPEvaluator.class); |
70 |
DALLocator.registerFeatureTypeDefinitionsManager(DefaultFeatureTypeDefinitionsManager.class); |
71 |
|
72 |
InfoListener.initializeExtensionPoint(); |
73 |
|
74 |
registerIcons(); |
75 |
|
76 |
} |
77 |
|
78 |
public void postInitialize() { |
79 |
openErrorHandler = new BaseOpenErrorHandler();
|
80 |
ApplicationLocator.getManager().getDataManager().setOpenErrorHandler(openErrorHandler); |
81 |
|
82 |
DALLocator.getResourceManager().startResourceCollector( |
83 |
3 * (60 * 1000), // minutes --> miliseconds |
84 |
null);
|
85 |
// showAddOnManagerOnStartIfNeed();
|
86 |
} |
87 |
|
88 |
private void showAddOnManagerOnStartIfNeed() { |
89 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
90 |
PluginServices plugin = pluginManager.getPlugin(this);
|
91 |
DynObject pluginProperties = plugin.getPluginProperties(); |
92 |
Map<String,Boolean> showAddOnmanagerOnStart = null; |
93 |
try {
|
94 |
showAddOnmanagerOnStart = (Map<String,Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
95 |
} catch(Exception ex) { |
96 |
// Do nothing
|
97 |
} |
98 |
if( showAddOnmanagerOnStart==null ) { |
99 |
showAddOnmanagerOnStart = new HashMap<String, Boolean>(); |
100 |
pluginProperties.setDynValue("showAddOnmanagerOnStart",showAddOnmanagerOnStart);
|
101 |
} |
102 |
Boolean showAddOnmanagerOnStartForCurrentVersion = (Boolean)showAddOnmanagerOnStart.get(pluginManager.getApplicationVersion().fullFormat()); |
103 |
|
104 |
if( showAddOnmanagerOnStartForCurrentVersion==null || showAddOnmanagerOnStartForCurrentVersion.booleanValue() ) { |
105 |
pluginManager.addStartupTask( |
106 |
"showAddOnmanagerOnStart",
|
107 |
new ShowAddOnManagerOnStart(),
|
108 |
true,
|
109 |
500
|
110 |
); |
111 |
} |
112 |
} |
113 |
|
114 |
private static class ShowAddOnManagerOnStart implements Runnable { |
115 |
|
116 |
public void run() { |
117 |
ApplicationManager application = ApplicationLocator.getManager(); |
118 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
119 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
120 |
PluginServices plugin = pluginManager.getPlugin(this);
|
121 |
DynObject pluginProperties = plugin.getPluginProperties(); |
122 |
|
123 |
String msg = i18nManager.getTranslation("_Instalar_complementos_adicionales_no_disponibles_durante_el_proceso_de_instalacion"); |
124 |
int resp = application.confirmDialog(
|
125 |
msg, |
126 |
i18nManager.getTranslation("_Finalizando_proceso_de_instalacion"),
|
127 |
JOptionPane.YES_NO_OPTION,
|
128 |
JOptionPane.QUESTION_MESSAGE
|
129 |
); |
130 |
if( resp == JOptionPane.YES_OPTION ) { |
131 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
132 |
actionManager.execute( |
133 |
"tools-addonsmanager",
|
134 |
new Object[] {"skipBundleSelection"} |
135 |
); |
136 |
} |
137 |
Map<String,Boolean> showAddOnmanagerOnStart = (Map<String,Boolean>) pluginProperties.getDynValue("showAddOnmanagerOnStart"); |
138 |
showAddOnmanagerOnStart.put(pluginManager.getApplicationVersion().fullFormat(), Boolean.FALSE);
|
139 |
} |
140 |
} |
141 |
|
142 |
private void registerIcons() { |
143 |
IconThemeHelper.registerIcon("action", "edit-clear", this); |
144 |
IconThemeHelper.registerIcon("action", "edit-copy", this); |
145 |
IconThemeHelper.registerIcon("action", "edit-cut", this); |
146 |
IconThemeHelper.registerIcon("action", "edit-delete", this); |
147 |
IconThemeHelper.registerIcon("action", "edit-find", this); |
148 |
IconThemeHelper.registerIcon("action", "edit-find-replace", this); |
149 |
IconThemeHelper.registerIcon("action", "edit-paste", this); |
150 |
IconThemeHelper.registerIcon("action", "edit-redo", this); |
151 |
IconThemeHelper.registerIcon("action", "edit-select-all", this); |
152 |
IconThemeHelper.registerIcon("action", "edit-undo", this); |
153 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions", this); |
154 |
IconThemeHelper.registerIcon("action", "document-print", this); |
155 |
|
156 |
IconThemeHelper.registerIcon("toolbar-go", "go-next", this); |
157 |
IconThemeHelper.registerIcon("toolbar-go", "go-previous", this); |
158 |
IconThemeHelper.registerIcon("toolbar-go", "go-next-fast", this); |
159 |
IconThemeHelper.registerIcon("toolbar-go", "go-previous-fast", this); |
160 |
IconThemeHelper.registerIcon("toolbar-go", "go-first", this); |
161 |
IconThemeHelper.registerIcon("toolbar-go", "go-last", this); |
162 |
|
163 |
} |
164 |
|
165 |
public void execute(String actionCommand) { |
166 |
|
167 |
} |
168 |
|
169 |
public boolean isEnabled() { |
170 |
return false; |
171 |
} |
172 |
|
173 |
public boolean isVisible() { |
174 |
return false; |
175 |
} |
176 |
|
177 |
private void addToLogInfo() { |
178 |
String info[] = this.getStringInfo().split("\n"); |
179 |
for (int i = 0; i < info.length; i++) { |
180 |
logger.info(info[i]); |
181 |
} |
182 |
} |
183 |
|
184 |
public String getStringInfo() { |
185 |
ApplicationManager application = ApplicationLocator.getManager(); |
186 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
187 |
InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
188 |
|
189 |
StringWriter writer = new StringWriter(); |
190 |
|
191 |
Properties props = System.getProperties(); |
192 |
|
193 |
// OS information
|
194 |
String osName = props.getProperty("os.name"); |
195 |
writer.write("OS\n");
|
196 |
writer.write(" name : " + osName + "\n"); |
197 |
writer.write(" arch : " + props.get("os.arch") + "\n"); |
198 |
writer.write(" version: " + props.get("os.version") + "\n"); |
199 |
if (osName.startsWith("Linux")) { |
200 |
try {
|
201 |
String[] command = {"lsb_release", "-a"}; |
202 |
Process p = Runtime.getRuntime().exec(command); |
203 |
InputStream is = p.getInputStream();
|
204 |
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
205 |
String line;
|
206 |
while ((line = reader.readLine()) != null) { |
207 |
writer.write(" " + line + "\n"); |
208 |
} |
209 |
} catch (Exception ex) { |
210 |
writer.write("Can't get detailled os information (lsb_release -a).");
|
211 |
} |
212 |
} |
213 |
|
214 |
// JRE information
|
215 |
writer.write("JRE\n");
|
216 |
writer.write(" vendor : " + props.get("java.vendor") + "\n"); |
217 |
writer.write(" version: " + props.get("java.version") + "\n"); |
218 |
writer.write(" home : " + props.get("java.home") + "\n"); |
219 |
|
220 |
writer.write("gvSIG\n");
|
221 |
writer.write(" version : " + application.getVersion().getLongFormat() + "\n"); |
222 |
writer.write(" locale language : " + application.getLocaleLanguage() + "\n"); |
223 |
writer.write(" application forlder : " + pluginmgr.getApplicationFolder() + "\n"); |
224 |
writer.write(" install forlder : " + pluginmgr.getInstallFolder() + "\n"); |
225 |
writer.write(" application home forlder: " + pluginmgr.getApplicationHomeFolder() + "\n"); |
226 |
writer.write(" plugins forlder : " + StringUtils.join(pluginmgr.getPluginsFolders()) + "\n"); |
227 |
|
228 |
try {
|
229 |
PackageInfo[] pkgs = installmgr.getInstalledPackages();
|
230 |
writer.write("Installed packages\n");
|
231 |
for (int i = 0; i < pkgs.length; i++) { |
232 |
writer.write(" ");
|
233 |
writer.write(pkgs[i].toStringCompact()); |
234 |
writer.write("\n");
|
235 |
} |
236 |
} catch (Throwable e) { |
237 |
writer.write("Can't get installed package information.");
|
238 |
} |
239 |
return writer.toString();
|
240 |
} |
241 |
|
242 |
public void terminate() { |
243 |
ResourceManager resMan = DALLocator.getResourceManager(); |
244 |
resMan.stopResourceCollector(); |
245 |
try {
|
246 |
resMan.dispose(); |
247 |
} catch (DisposeResorceManagerException e) {
|
248 |
logger.warn(e.getMessageStack()); |
249 |
} |
250 |
super.terminate();
|
251 |
} |
252 |
} |