|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
|
2 |
*
|
|
3 |
* Copyright (C) 2004-2007 IVER T.I. and Generalitat Valenciana.
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or
|
|
6 |
* modify it under the terms of the GNU General Public License
|
|
7 |
* as published by the Free Software Foundation; either version 2
|
|
8 |
* of the License, or (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
|
18 |
*
|
|
19 |
* For more information, contact:
|
|
20 |
*
|
|
21 |
* Generalitat Valenciana
|
|
22 |
* Conselleria d'Infraestructures i Transport
|
|
23 |
* Av. Blasco Ib��ez, 50
|
|
24 |
* 46010 VALENCIA
|
|
25 |
* SPAIN
|
|
26 |
*
|
|
27 |
* +34 963862235
|
|
28 |
* gvsig@gva.es
|
|
29 |
* www.gvsig.gva.es
|
|
30 |
*
|
|
31 |
* or
|
|
32 |
*
|
|
33 |
* IVER T.I. S.A
|
|
34 |
* Salamanca 50
|
|
35 |
* 46005 Valencia
|
|
36 |
* Spain
|
|
37 |
*
|
|
38 |
* +34 963163400
|
|
39 |
* dac@iver.es
|
|
40 |
*/
|
|
41 |
package com.iver.andami;
|
|
42 |
|
|
43 |
import java.awt.Component;
|
|
44 |
import java.awt.Dimension;
|
|
45 |
import java.awt.EventQueue;
|
|
46 |
import java.awt.Frame;
|
|
47 |
import java.awt.KeyboardFocusManager;
|
|
48 |
import java.awt.Point;
|
|
49 |
import java.awt.Toolkit;
|
|
50 |
import java.io.BufferedOutputStream;
|
|
51 |
import java.io.BufferedReader;
|
|
52 |
import java.io.File;
|
|
53 |
import java.io.FileFilter;
|
|
54 |
import java.io.FileInputStream;
|
|
55 |
import java.io.FileNotFoundException;
|
|
56 |
import java.io.FileOutputStream;
|
|
57 |
import java.io.FileReader;
|
|
58 |
import java.io.IOException;
|
|
59 |
import java.io.InputStream;
|
|
60 |
import java.io.InputStreamReader;
|
|
61 |
import java.io.OutputStreamWriter;
|
|
62 |
import java.io.Reader;
|
|
63 |
import java.net.Authenticator;
|
|
64 |
import java.net.MalformedURLException;
|
|
65 |
import java.net.PasswordAuthentication;
|
|
66 |
import java.net.URL;
|
|
67 |
import java.net.URLConnection;
|
|
68 |
import java.nio.channels.FileChannel;
|
|
69 |
import java.security.AllPermission;
|
|
70 |
import java.security.CodeSource;
|
|
71 |
import java.security.PermissionCollection;
|
|
72 |
import java.security.Permissions;
|
|
73 |
import java.security.Policy;
|
|
74 |
import java.util.ArrayList;
|
|
75 |
import java.util.Comparator;
|
|
76 |
import java.util.Date;
|
|
77 |
import java.util.HashMap;
|
|
78 |
import java.util.HashSet;
|
|
79 |
import java.util.Iterator;
|
|
80 |
import java.util.Locale;
|
|
81 |
import java.util.Properties;
|
|
82 |
import java.util.TreeMap;
|
|
83 |
import java.util.prefs.Preferences;
|
|
84 |
|
|
85 |
import javax.jnlp.BasicService;
|
|
86 |
import javax.jnlp.ServiceManager;
|
|
87 |
import javax.jnlp.UnavailableServiceException;
|
|
88 |
import javax.swing.ImageIcon;
|
|
89 |
import javax.swing.JButton;
|
|
90 |
import javax.swing.JComponent;
|
|
91 |
import javax.swing.JOptionPane;
|
|
92 |
import javax.swing.JPopupMenu;
|
|
93 |
import javax.swing.SwingUtilities;
|
|
94 |
import javax.swing.UIManager;
|
|
95 |
|
|
96 |
import org.apache.log4j.Logger;
|
|
97 |
import org.apache.log4j.PatternLayout;
|
|
98 |
import org.apache.log4j.PropertyConfigurator;
|
|
99 |
import org.apache.log4j.RollingFileAppender;
|
|
100 |
import org.exolab.castor.xml.MarshalException;
|
|
101 |
import org.exolab.castor.xml.ValidationException;
|
|
102 |
|
|
103 |
import com.iver.andami.authentication.IAuthentication;
|
|
104 |
import com.iver.andami.authentication.LoginUI;
|
|
105 |
import com.iver.andami.config.generate.Andami;
|
|
106 |
import com.iver.andami.config.generate.AndamiConfig;
|
|
107 |
import com.iver.andami.config.generate.Plugin;
|
|
108 |
import com.iver.andami.iconthemes.IIconTheme;
|
|
109 |
import com.iver.andami.iconthemes.IconThemeManager;
|
|
110 |
import com.iver.andami.messages.Messages;
|
|
111 |
import com.iver.andami.messages.NotificationManager;
|
|
112 |
import com.iver.andami.plugins.ExclusiveUIExtension;
|
|
113 |
import com.iver.andami.plugins.ExtensionDecorator;
|
|
114 |
import com.iver.andami.plugins.IExtension;
|
|
115 |
import com.iver.andami.plugins.PluginClassLoader;
|
|
116 |
import com.iver.andami.plugins.config.generate.ActionTool;
|
|
117 |
import com.iver.andami.plugins.config.generate.ComboButton;
|
|
118 |
import com.iver.andami.plugins.config.generate.ComboButtonElement;
|
|
119 |
import com.iver.andami.plugins.config.generate.ComboScale;
|
|
120 |
import com.iver.andami.plugins.config.generate.Depends;
|
|
121 |
import com.iver.andami.plugins.config.generate.Extension;
|
|
122 |
import com.iver.andami.plugins.config.generate.Extensions;
|
|
123 |
import com.iver.andami.plugins.config.generate.LabelSet;
|
|
124 |
import com.iver.andami.plugins.config.generate.Menu;
|
|
125 |
import com.iver.andami.plugins.config.generate.PluginConfig;
|
|
126 |
import com.iver.andami.plugins.config.generate.PopupMenu;
|
|
127 |
import com.iver.andami.plugins.config.generate.PopupMenus;
|
|
128 |
import com.iver.andami.plugins.config.generate.SelectableTool;
|
|
129 |
import com.iver.andami.plugins.config.generate.SkinExtension;
|
|
130 |
import com.iver.andami.plugins.config.generate.SkinExtensionType;
|
|
131 |
import com.iver.andami.plugins.config.generate.ToolBar;
|
|
132 |
import com.iver.andami.plugins.status.IExtensionStatus;
|
|
133 |
import com.iver.andami.plugins.status.IUnsavedData;
|
|
134 |
import com.iver.andami.ui.AndamiEventQueue;
|
|
135 |
import com.iver.andami.ui.MDIManagerLoadException;
|
|
136 |
import com.iver.andami.ui.fonts.FontUtils;
|
|
137 |
import com.iver.andami.ui.mdiFrame.MDIFrame;
|
|
138 |
import com.iver.andami.ui.mdiFrame.NewStatusBar;
|
|
139 |
import com.iver.andami.ui.mdiManager.MDIManager;
|
|
140 |
import com.iver.andami.ui.mdiManager.MDIManagerFactory;
|
|
141 |
import com.iver.andami.ui.splash.MultiSplashWindow;
|
|
142 |
import com.iver.andami.ui.theme.Theme;
|
|
143 |
import com.iver.andami.ui.wizard.UnsavedDataPanel;
|
|
144 |
import com.iver.utiles.DateTime;
|
|
145 |
import com.iver.utiles.XMLEntity;
|
|
146 |
import com.iver.utiles.xml.XMLEncodingUtils;
|
|
147 |
import com.iver.utiles.xmlEntity.generate.XmlTag;
|
|
148 |
|
|
149 |
|
|
150 |
/**
|
|
151 |
* <p>
|
|
152 |
* Andami's launching class. This is the class used to create the Andami's plugin environment.<br>
|
|
153 |
* </p>
|
|
154 |
*
|
|
155 |
* <p>
|
|
156 |
* <b>Syntax:</b>
|
|
157 |
* <br>
|
|
158 |
* java [-Xmx512M (for 512MB of RAM)] [-classpath={a colon-separated(unix) or semicolon-separated(windows) list of files containg base library of classes}]
|
|
159 |
* [-Djava.library.path=PATH_TO_NATIVE_LIBRARIES]
|
|
160 |
* PATH_TO_APPLICATION_HOME_DIRECTORY PATH_TO_APPLICATION_PLUGINS_DIRECTORY
|
|
161 |
* [{list of additional custom application arguments separated by spaces}]
|
|
162 |
* </p>
|
|
163 |
*
|
|
164 |
*
|
|
165 |
* @author $author$
|
|
166 |
* @version $Revision$
|
|
167 |
*/
|
|
168 |
public class Launcher {
|
|
169 |
private static Logger logger = Logger.getLogger(Launcher.class.getName());
|
|
170 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.connection" );
|
|
171 |
private static AndamiConfig andamiConfig;
|
|
172 |
private static MultiSplashWindow splashWindow;
|
|
173 |
private static String appName;
|
|
174 |
private static Locale locale;
|
|
175 |
private static HashMap pluginsConfig = new HashMap();
|
|
176 |
private static HashMap pluginsServices = new HashMap();
|
|
177 |
private static MDIFrame frame;
|
|
178 |
private static HashMap classesExtensions = new HashMap();
|
|
179 |
private static String andamiConfigPath;
|
|
180 |
private static String pluginsPersistencePath;
|
|
181 |
private static final String nonWinDefaultLookAndFeel = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
|
|
182 |
|
|
183 |
private static ArrayList pluginsOrdered = new ArrayList();
|
|
184 |
private static ArrayList extensions=new ArrayList();
|
|
185 |
private static String appHomeDir = null;
|
|
186 |
// it seems castor uses this encoding
|
|
187 |
private static final String CASTORENCODING = "UTF8";
|
|
188 |
|
|
189 |
private static final class ProxyAuth extends Authenticator {
|
|
190 |
private PasswordAuthentication auth;
|
|
191 |
|
|
192 |
private ProxyAuth(String user, String pass) {
|
|
193 |
auth = new PasswordAuthentication(user, pass.toCharArray());
|
|
194 |
}
|
|
195 |
|
|
196 |
protected PasswordAuthentication getPasswordAuthentication() {
|
|
197 |
return auth;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
public static void main(String[] args) throws Exception {
|
|
202 |
try{
|
|
203 |
|
|
204 |
if (!validJVM()){
|
|
205 |
System.exit(-1);
|
|
206 |
}
|
|
207 |
|
|
208 |
if (args.length < 1) {
|
|
209 |
System.err.println("Uso: Launcher appName plugins-directory [language=locale]");
|
|
210 |
}
|
|
211 |
|
|
212 |
// Clean temporal files
|
|
213 |
Utilities.cleanUpTempFiles();
|
|
214 |
|
|
215 |
appName = args[0];
|
|
216 |
|
|
217 |
//Se crea el directorio de configuraci�n de la aplicaci�n
|
|
218 |
appHomeDir = System.getProperty(args[0]+".home");
|
|
219 |
if (appHomeDir == null)
|
|
220 |
appHomeDir = System.getProperty("user.home");
|
|
221 |
|
|
222 |
appHomeDir += File.separator + args[0] + File.separator;
|
|
223 |
File parent = new File( appHomeDir );
|
|
224 |
parent.mkdirs();
|
|
225 |
|
|
226 |
andamiConfigPath = appHomeDir + "andami-config.xml";
|
|
227 |
pluginsPersistencePath = appHomeDir +
|
|
228 |
"plugins-persistence.xml";
|
|
229 |
|
|
230 |
// Configurar el log4j
|
|
231 |
PropertyConfigurator.configure(Launcher.class.getClassLoader()
|
|
232 |
.getResource("log4j.properties"));
|
|
233 |
|
|
234 |
PatternLayout l = new PatternLayout("%p %t %C - %m%n");
|
|
235 |
RollingFileAppender fa = new RollingFileAppender(l,
|
|
236 |
appHomeDir + args[0] + ".log", false);
|
|
237 |
fa.setMaxFileSize("512KB");
|
|
238 |
fa.setMaxBackupIndex(3);
|
|
239 |
Logger.getRootLogger().addAppender(fa);
|
|
240 |
|
|
241 |
// Leer el fichero de configuraci�n de andami (andami-config.xsd)
|
|
242 |
// locale
|
|
243 |
// Buscar actualizaci�nes al comenzar
|
|
244 |
// Andami
|
|
245 |
// Plugins
|
|
246 |
// Directorio de las extensiones
|
|
247 |
andamiConfigFromXML(andamiConfigPath);
|
|
248 |
andamiConfig.setPluginsDirectory(args[1]);
|
|
249 |
|
|
250 |
// Hacemos visibles los argumentos como una propiedad est�tica
|
|
251 |
// de plugin services para quien lo quiera usar (por ejemplo, para
|
|
252 |
// cargar un proyecto por l�nea de comandos)
|
|
253 |
PluginServices.setArguments(args);
|
|
254 |
|
|
255 |
configureLocales(args);
|
|
256 |
|
|
257 |
//Se pone el lookAndFeel
|
|
258 |
try {
|
|
259 |
String lookAndFeel = getAndamiConfig().getLookAndFeel();
|
|
260 |
if (lookAndFeel == null)
|
|
261 |
lookAndFeel = getDefaultLookAndFeel();
|
|
262 |
UIManager.setLookAndFeel(lookAndFeel);
|
|
263 |
} catch (Exception e) {
|
|
264 |
logger.warn(Messages.getString("Launcher.look_and_feel"), e);
|
|
265 |
}
|
|
266 |
FontUtils.initFonts();
|
|
267 |
|
|
268 |
// Solucionamos el problema de permisos que se produc�a con Java Web Start con este c�digo.
|
|
269 |
// System.setSecurityManager(null);
|
|
270 |
Policy.setPolicy(new Policy() {
|
|
271 |
public PermissionCollection getPermissions(CodeSource codesource) {
|
|
272 |
Permissions perms = new Permissions();
|
|
273 |
perms.add(new AllPermission());
|
|
274 |
return (perms);
|
|
275 |
}
|
|
276 |
public void
|
|
277 |
refresh() {}
|
|
278 |
});
|
|
279 |
|
|
280 |
initIconThemes();
|
|
281 |
// Registramos los iconos base
|
|
282 |
registerIcons();
|
|
283 |
validate();
|
|
284 |
|
|
285 |
// Obtener la personalizaci?n de la aplicaci?n.
|
|
286 |
Theme theme=getTheme();
|
|
287 |
|
|
288 |
// Mostrar la ventana de inicio
|
|
289 |
Frame f=new Frame();
|
|
290 |
splashWindow=new MultiSplashWindow(f,theme, 190);
|
|
291 |
|
|
292 |
// 1. Ponemos los datos del proxy
|
|
293 |
splashWindow.process(10,
|
|
294 |
PluginServices.getText(Launcher.class, "SplashWindow.configuring_proxy"));
|
|
295 |
configureProxy();
|
|
296 |
|
|
297 |
// 2. TODO Buscar actualizaciones de los plugins
|
|
298 |
splashWindow.process(20,
|
|
299 |
PluginServices.getText(Launcher.class, "SplashWindow.looking_for_updates"));
|
|
300 |
downloadExtensions(andamiConfig.getPluginsDirectory());
|
|
301 |
|
|
302 |
// 3. Se leen los config.xml de los plugins -----++++
|
|
303 |
splashWindow.process(30,
|
|
304 |
PluginServices.getText(Launcher.class, "SplashWindow.reading_plugins_config.xml"));
|
|
305 |
loadPlugins(andamiConfig.getPluginsDirectory());
|
|
306 |
|
|
307 |
// 4. Se configura el classloader del plugin
|
|
308 |
splashWindow.process(40,
|
|
309 |
PluginServices.getText(Launcher.class, "SplashWindow.setting_up_class_loaders"));
|
|
310 |
pluginsClassLoaders();
|
|
311 |
|
|
312 |
// 5. Se carga un Skin si alguno de los plugins trae informaci?n para ello
|
|
313 |
splashWindow.process(50,
|
|
314 |
PluginServices.getText(Launcher.class, "SplashWindow.looking_for_a_skin"));
|
|
315 |
// skinPlugin( "com.iver.core.mdiManager.NewSkin");
|
|
316 |
skinPlugin(null);
|
|
317 |
|
|
318 |
// 6. Se configura la cola de eventos
|
|
319 |
splashWindow.process(60,
|
|
320 |
PluginServices.getText(Launcher.class, "setting_up_event_queue"));
|
|
321 |
EventQueue waitQueue = new AndamiEventQueue();
|
|
322 |
Toolkit.getDefaultToolkit().getSystemEventQueue().push(waitQueue);
|
|
323 |
|
|
324 |
// 7. Se configura la mensajer?a del plugin
|
|
325 |
splashWindow.process(70,
|
|
326 |
PluginServices.getText(Launcher.class, "SplashWindow.starting_plugin_internationalization_system"));
|
|
327 |
pluginsMessages();
|
|
328 |
|
|
329 |
// 8. Se modifica el andami-config con los plugins nuevos
|
|
330 |
splashWindow.process(80,
|
|
331 |
PluginServices.getText(Launcher.class, "SplashWindow.looking_for_a_skin"));
|
|
332 |
updateAndamiConfig();
|
|
333 |
|
|
334 |
|
|
335 |
frame = new MDIFrame();
|
|
336 |
// 9. Se configura el nombre e icono de la aplicaci?n
|
|
337 |
splashWindow.process(90,
|
|
338 |
PluginServices.getText(Launcher.class, "SplashWindow.setting_up_applications_name_and_icons"));
|
|
339 |
frameIcon(theme);
|
|
340 |
|
|
341 |
// 10. Se prepara el MainFrame para albergar las extensiones
|
|
342 |
splashWindow.process(100,
|
|
343 |
PluginServices.getText(Launcher.class, "SplashWindow.preparing_workbench"));
|
|
344 |
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
|
345 |
|
|
346 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
347 |
public void run() {
|
|
348 |
frame.init();
|
|
349 |
}
|
|
350 |
});
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
// 11. Leer el fichero de persistencia
|
|
355 |
// info de los plugins
|
|
356 |
// bookmarks de los plugins
|
|
357 |
splashWindow.process(110,
|
|
358 |
PluginServices.getText(Launcher.class, "SplashWindow.loading_plugin_settings"));
|
|
359 |
loadPluginsPersistence();
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
// Se instalan los controles del skin
|
|
364 |
// 12. Se inicializan todas las extensiones de todos los plugins
|
|
365 |
splashWindow.process(120,
|
|
366 |
PluginServices.getText(Launcher.class, "SplashWindow.initializing_extensions"));
|
|
367 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
368 |
public void run() {
|
|
369 |
initializeExtensions();
|
|
370 |
}
|
|
371 |
});
|
|
372 |
|
|
373 |
// 13. Se inicializan la extensi?n exclusiva
|
|
374 |
splashWindow.process(130,
|
|
375 |
PluginServices.getText(Launcher.class, "SplashWindow.setting_up_master_extension"));
|
|
376 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
377 |
public void run() {
|
|
378 |
initializeExclusiveUIExtension();
|
|
379 |
}
|
|
380 |
});
|
|
381 |
frame.setClassesExtensions(classesExtensions);
|
|
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
// 14. Se instalan los controles de las extensiones de los plugins
|
|
388 |
splashWindow.process(140,
|
|
389 |
PluginServices.getText(Launcher.class, "SplashWindow.installing_extensions_controls"));
|
|
390 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
391 |
public void run() {
|
|
392 |
installPluginsControls();
|
|
393 |
|
|
394 |
}
|
|
395 |
});
|
|
396 |
|
|
397 |
// 15. Se instalan los menus de las extensiones de los plugins
|
|
398 |
splashWindow.process(150,
|
|
399 |
PluginServices.getText(Launcher.class, "SplashWindow.installing_extensions_menus"));
|
|
400 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
401 |
public void run() {
|
|
402 |
installPluginsMenus();
|
|
403 |
|
|
404 |
}
|
|
405 |
});
|
|
406 |
|
|
407 |
// 16. Se instalan las etiquetas de las extensiones de los plugins
|
|
408 |
splashWindow.process(160,
|
|
409 |
PluginServices.getText(Launcher.class, "SplashWindow.installing_extensions_labels"));
|
|
410 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
411 |
public void run() {
|
|
412 |
installPluginsLabels();
|
|
413 |
|
|
414 |
}
|
|
415 |
});
|
|
416 |
|
|
417 |
|
|
418 |
// 17. Se instalan los bookmarks de los plugins
|
|
419 |
|
|
420 |
// 18. Se muestra el frame principal
|
|
421 |
splashWindow.process(180,
|
|
422 |
PluginServices.getText(Launcher.class, "creating_main_window"));
|
|
423 |
frame.setVisible(true);
|
|
424 |
|
|
425 |
// 19. Se ejecuta el postInitialize
|
|
426 |
splashWindow.process(190,
|
|
427 |
PluginServices.getText(Launcher.class, "SplashWindow.post_initializing_extensions"));
|
|
428 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
429 |
public void run() {
|
|
430 |
postInitializeExtensions();
|
|
431 |
|
|
432 |
}
|
|
433 |
});
|
|
434 |
|
|
435 |
|
|
436 |
// Definimos un KeyEventDispatcher global para que las extensiones
|
|
437 |
// puedan registrar sus "teclas r?pidas".
|
|
438 |
GlobalKeyEventDispatcher keyDispatcher = GlobalKeyEventDispatcher.getInstance();
|
|
439 |
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);
|
|
440 |
|
|
441 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
442 |
public void run() {
|
|
443 |
frame.enableControls();
|
|
444 |
}
|
|
445 |
});
|
|
446 |
splashWindow.close();
|
|
447 |
}catch(Exception e){
|
|
448 |
logger.error("excepci?n al arrancar", e);
|
|
449 |
System.exit(-1);
|
|
450 |
}
|
|
451 |
|
|
452 |
}
|
|
453 |
|
|
454 |
private static void registerIcons(){
|
|
455 |
PluginServices.getIconTheme().registerDefault(
|
|
456 |
"login-gvsig",
|
|
457 |
LoginUI.class.getClassLoader().getResource("images/login_gvsig.png")
|
|
458 |
);
|
|
459 |
PluginServices.getIconTheme().registerDefault(
|
|
460 |
"splash-gvsig",
|
|
461 |
MultiSplashWindow.class.getClassLoader().getResource("images/splash.png")
|
|
462 |
);
|
|
463 |
PluginServices.getIconTheme().registerDefault(
|
|
464 |
"info-icon",
|
|
465 |
NewStatusBar.class.getClassLoader().getResource("images/info.gif")
|
|
466 |
);
|
|
467 |
PluginServices.getIconTheme().registerDefault(
|
|
468 |
"error-icon",
|
|
469 |
NewStatusBar.class.getClassLoader().getResource("images/error.gif")
|
|
470 |
);
|
|
471 |
PluginServices.getIconTheme().registerDefault(
|
|
472 |
"warning-icon",
|
|
473 |
NewStatusBar.class.getClassLoader().getResource("images/warning.gif")
|
|
474 |
);
|
|
475 |
PluginServices.getIconTheme().registerDefault(
|
|
476 |
"no-icon",
|
|
477 |
NewStatusBar.class.getClassLoader().getResource("images/no_icon.png")
|
|
478 |
);
|
|
479 |
}
|
|
480 |
|
|
481 |
/**
|
|
482 |
* Obtiene la personalizaci?n de los iconos, splash, fondo y el nombre de
|
|
483 |
* la aplicaci?n.
|
|
484 |
*
|
|
485 |
* @return Theme
|
|
486 |
*/
|
|
487 |
private static Theme getTheme() {
|
|
488 |
Theme theme=new Theme();
|
|
489 |
String name=PluginServices.getArgumentByName("andamiTheme");
|
|
490 |
//File file=new File("theme/andami-theme.xml");
|
|
491 |
File file;
|
|
492 |
if (name==null){
|
|
493 |
file=new File("theme/andami-theme.xml");
|
|
494 |
}else{
|
|
495 |
file=new File(name);
|
|
496 |
}
|
|
497 |
|
|
498 |
if (file.exists()) {
|
|
499 |
theme.readTheme(file);
|
|
500 |
}
|
|
501 |
return theme;
|
|
502 |
}
|
|
503 |
/**
|
|
504 |
*Establece los datos que ten?amos guardados respecto de la configuraci?n
|
|
505 |
*del proxy.
|
|
506 |
*/
|
|
507 |
private static void configureProxy() {
|
|
508 |
String host = prefs.get("firewall.http.host", "");
|
|
509 |
String port = prefs.get("firewall.http.port", "");
|
|
510 |
|
|
511 |
System.getProperties().put("http.proxyHost", host);
|
|
512 |
System.getProperties().put("http.proxyPort", port);
|
|
513 |
|
|
514 |
// Ponemos el usuario y clave del proxy, si existe
|
|
515 |
String proxyUser = prefs.get("firewall.http.user",null);
|
|
516 |
String proxyPassword = prefs.get("firewall.http.password", null);
|
|
517 |
if (proxyUser != null )
|
|
518 |
{
|
|
519 |
System.getProperties().put("http.proxyUserName", proxyUser);
|
|
520 |
System.getProperties().put("http.proxyPassword", proxyPassword);
|
|
521 |
|
|
522 |
Authenticator.setDefault(new ProxyAuth(proxyUser,
|
|
523 |
proxyPassword));
|
|
524 |
} else {
|
|
525 |
Authenticator.setDefault(new ProxyAuth("", ""));
|
|
526 |
}
|
|
527 |
}
|
|
528 |
|
|
529 |
/**
|
|
530 |
* Recupera la geometr?a (tama?o, posic?n y estado) de la ventana principal de Andami.
|
|
531 |
* TODO Pendiente de ver como se asigna un pluginServices para el launcher.
|
|
532 |
* @author LWS
|
|
533 |
*/
|
|
534 |
private static void restoreMDIStatus(XMLEntity xml) {
|
|
535 |
if (xml == null) xml = new XMLEntity();
|
|
536 |
// restore frame size
|
|
537 |
Dimension sz = new Dimension(700,580);
|
|
538 |
if (xml.contains("MDIFrameSize")) {
|
|
539 |
int [] wh = xml.getIntArrayProperty("MDIFrameSize");
|
|
540 |
sz = new Dimension(wh[0], wh[1]);
|
|
541 |
}
|
|
542 |
frame.setSize(sz);
|
|
543 |
// restore frame location
|
|
544 |
Point pos = new Point(10,10);
|
|
545 |
if (xml.contains("MDIFramePos")) {
|
|
546 |
int [] xy = xml.getIntArrayProperty("MDIFramePos");
|
|
547 |
pos = new Point(xy[0], xy[1]);
|
|
548 |
}
|
|
549 |
frame.setLocation(pos);
|
|
550 |
|
|
551 |
// restore frame status (Maximized, minimized, etc);
|
|
552 |
int state = java.awt.Frame.MAXIMIZED_BOTH;
|
|
553 |
if (xml.contains("MDIFrameState")) {
|
|
554 |
state = xml.getIntProperty("MDIFrameState");
|
|
555 |
}
|
|
556 |
frame.setExtendedState(state);
|
|
557 |
}
|
|
558 |
|
|
559 |
private static XMLEntity saveMDIStatus() {
|
|
560 |
XMLEntity xml = new XMLEntity();
|
|
561 |
// save frame size
|
|
562 |
int [] wh = new int[2];
|
|
563 |
wh[0] = frame.getWidth();
|
|
564 |
wh[1] = frame.getHeight();
|
|
565 |
xml.putProperty("MDIFrameSize", wh);
|
|
566 |
// save frame location
|
|
567 |
int [] xy = new int[2];
|
|
568 |
xy[0] = frame.getX();
|
|
569 |
xy[1] = frame.getY();
|
|
570 |
xml.putProperty("MDIFramePos", xy);
|
|
571 |
// save frame status
|
|
572 |
xml.putProperty("MDIFrameState", frame.getExtendedState());
|
|
573 |
return xml;
|
|
574 |
}
|
|
575 |
|
|
576 |
private static boolean validJVM() {
|
|
577 |
char thirdCharacter = System.getProperty("java.version").charAt(2);
|
|
578 |
if (thirdCharacter < '4'){
|
|
579 |
return false;
|
|
580 |
}else{
|
|
581 |
return true;
|
|
582 |
}
|
|
583 |
}
|
|
584 |
|
|
585 |
private static void loadPluginsPersistence() throws ConfigurationException {
|
|
586 |
XMLEntity entity = persistenceFromXML();
|
|
587 |
|
|
588 |
for (int i = 0; i < entity.getChildrenCount(); i++) {
|
|
589 |
XMLEntity plugin = entity.getChild(i);
|
|
590 |
String pName = plugin.getStringProperty(
|
|
591 |
"com.iver.andami.pluginName");
|
|
592 |
if (pluginsServices.get(pName)!= null){
|
|
593 |
((PluginServices) pluginsServices.get(pName)).setPersistentXML(plugin);
|
|
594 |
} else {
|
|
595 |
if (pName.startsWith("Andami.Launcher"))
|
|
596 |
restoreMDIStatus(plugin);
|
|
597 |
}
|
|
598 |
}
|
|
599 |
}
|
|
600 |
|
|
601 |
/**
|
|
602 |
* Salva la persistencia de los plugins.
|
|
603 |
* @author LWS
|
|
604 |
*/
|
|
605 |
private static void savePluginPersistence() {
|
|
606 |
Iterator i = pluginsConfig.keySet().iterator();
|
|
607 |
|
|
608 |
XMLEntity entity = new XMLEntity();
|
|
609 |
|
|
610 |
while (i.hasNext()) {
|
|
611 |
String pName = (String) i.next();
|
|
612 |
PluginServices ps = (PluginServices) pluginsServices.get(pName);
|
|
613 |
XMLEntity ent = ps.getPersistentXML();
|
|
614 |
|
|
615 |
if (ent != null) {
|
|
616 |
ent.putProperty("com.iver.andami.pluginName", pName);
|
|
617 |
entity.addChild(ent);
|
|
618 |
}
|
|
619 |
}
|
|
620 |
XMLEntity ent = saveMDIStatus();
|
|
621 |
if (ent != null) {
|
|
622 |
ent.putProperty("com.iver.andami.pluginName", "Andami.Launcher");
|
|
623 |
entity.addChild(ent);
|
|
624 |
}
|
|
625 |
try {
|
|
626 |
persistenceToXML(entity);
|
|
627 |
} catch (ConfigurationException e1) {
|
|
628 |
logger.error(Messages.getString(
|
|
629 |
"Launcher.Se_produjo_un_error_guardando_la_configuracion_de_los_plugins"),
|
|
630 |
e1);
|
|
631 |
}
|
|
632 |
}
|
|
633 |
|
|
634 |
private static void installPluginsLabels() {
|
|
635 |
Iterator i = pluginsConfig.keySet().iterator();
|
|
636 |
|
|
637 |
while (i.hasNext()) {
|
|
638 |
String name = (String) i.next();
|
|
639 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(name);
|
|
640 |
PluginServices ps = (PluginServices) pluginsServices.get(name);
|
|
641 |
|
|
642 |
LabelSet[] ls = pc.getLabelSet();
|
|
643 |
|
|
644 |
for (int j = 0; j < ls.length; j++) {
|
|
645 |
PluginClassLoader loader = ps.getClassLoader();
|
|
646 |
|
|
647 |
try {
|
|
648 |
Class clase = loader.loadClass(ls[j].getClassName());
|
|
649 |
frame.setStatusBarLabels(clase, ls[j].getLabel());
|
|
650 |
} catch (ClassNotFoundException e) {
|
|
651 |
logger.error(Messages.getString("Launcher.labelset_class"),
|
|
652 |
e);
|
|
653 |
}
|
|
654 |
}
|
|
655 |
}
|
|
656 |
}
|
|
657 |
|
|
658 |
private static String configureSkin(XMLEntity xml,String defaultSkin) {
|
|
659 |
if (defaultSkin == null){
|
|
660 |
for (int i = 0; i < xml.getChildrenCount(); i++) {
|
|
661 |
if (xml.getChild(i).contains("Skin-Selected")) {
|
|
662 |
String className = xml.getChild(i).getStringProperty(
|
|
663 |
"Skin-Selected");
|
|
664 |
return className;
|
|
665 |
}
|
|
666 |
}
|
|
667 |
}
|
|
668 |
return "com.iver.core.mdiManager.NewSkin";
|
|
669 |
// return defaultSkin;
|
|
670 |
}
|
|
671 |
|
|
672 |
private static void fixSkin(SkinExtension skinExtension,PluginClassLoader pluginClassLoader) throws MDIManagerLoadException{
|
|
673 |
// now insert the skin selected.
|
|
674 |
MDIManagerFactory.setSkinExtension(skinExtension, pluginClassLoader);
|
|
675 |
// MDIManagerFactory.setSkinExtension(se,
|
|
676 |
// ps.getClassLoader());
|
|
677 |
|
|
678 |
Class skinClass;
|
|
679 |
|
|
680 |
try {
|
|
681 |
skinClass = pluginClassLoader.loadClass(
|
|
682 |
skinExtension.getClassName());
|
|
683 |
|
|
684 |
com.iver.andami.plugins.IExtension skinInstance = (com.iver.andami.plugins.IExtension) skinClass
|
|
685 |
.newInstance();
|
|
686 |
// classesExtensions.put(skinClass, skinInstance);
|
|
687 |
// jaume
|
|
688 |
ExtensionDecorator newExtensionDecorator = new ExtensionDecorator(
|
|
689 |
skinInstance, ExtensionDecorator.INACTIVE);
|
|
690 |
classesExtensions.put(skinClass, newExtensionDecorator);
|
|
691 |
} catch (ClassNotFoundException e) {
|
|
692 |
logger
|
|
693 |
.error(
|
|
694 |
Messages
|
|
695 |
.getString("Launcher.No_se_encontro_la_clase_mdi_manager"),
|
|
696 |
e);
|
|
697 |
throw new MDIManagerLoadException(e);
|
|
698 |
} catch (InstantiationException e) {
|
|
699 |
logger
|
|
700 |
.error(
|
|
701 |
Messages
|
|
702 |
.getString("Launcher.No_se_pudo_instanciar_la_clase_mdi_manager"),
|
|
703 |
e);
|
|
704 |
throw new MDIManagerLoadException(e);
|
|
705 |
} catch (IllegalAccessException e) {
|
|
706 |
logger
|
|
707 |
.error(
|
|
708 |
Messages
|
|
709 |
.getString("Launcher.No_se_pudo_acceder_a_la_clase_mdi_manager"),
|
|
710 |
e);
|
|
711 |
throw new MDIManagerLoadException(e);
|
|
712 |
}
|
|
713 |
|
|
714 |
}
|
|
715 |
/**
|
|
716 |
* DOCUMENT ME!
|
|
717 |
*
|
|
718 |
* @throws MDIManagerLoadException
|
|
719 |
*/
|
|
720 |
private static void skinPlugin(String defaultSkin) throws MDIManagerLoadException {
|
|
721 |
XMLEntity entity =null;
|
|
722 |
try {
|
|
723 |
entity = persistenceFromXML();
|
|
724 |
} catch (ConfigurationException e1) {
|
|
725 |
// TODO Auto-generated catch block
|
|
726 |
e1.printStackTrace();
|
|
727 |
}
|
|
728 |
Iterator i = pluginsConfig.keySet().iterator();
|
|
729 |
|
|
730 |
SkinExtension skinExtension = null;
|
|
731 |
PluginClassLoader pluginClassLoader = null;
|
|
732 |
|
|
733 |
while (i.hasNext()) {
|
|
734 |
String name = (String) i.next();
|
|
735 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(name);
|
|
736 |
PluginServices ps = (PluginServices) pluginsServices.get(name);
|
|
737 |
|
|
738 |
if (pc.getExtensions().getSkinExtension() != null) {
|
|
739 |
// if (MDIManagerFactory.getSkinExtension() != null) {
|
|
740 |
// logger.warn(Messages.getString(
|
|
741 |
// "Launcher.Dos_skin_extension"));
|
|
742 |
// }
|
|
743 |
|
|
744 |
SkinExtension[] se = pc.getExtensions().getSkinExtension();
|
|
745 |
|
|
746 |
for (int j=0;j<se.length;j++){
|
|
747 |
if (Launcher.configureSkin(entity,defaultSkin).equals(se[j].getClassName())) {
|
|
748 |
skinExtension = se[j];
|
|
749 |
pluginClassLoader = ps.getClassLoader();
|
|
750 |
}
|
|
751 |
}
|
|
752 |
}
|
|
753 |
}
|
|
754 |
|
|
755 |
if ((skinExtension != null) && (pluginClassLoader != null)) {
|
|
756 |
fixSkin(skinExtension, pluginClassLoader);
|
|
757 |
} else {
|
|
758 |
if (defaultSkin.equals("com.iver.core.mdiManager.NewSkin")){
|
|
759 |
throw new MDIManagerLoadException();
|
|
760 |
}else{
|
|
761 |
skinPlugin("com.iver.core.mdiManager.NewSkin");
|
|
762 |
}
|
|
763 |
}
|
|
764 |
|
|
765 |
}
|
|
766 |
|
|
767 |
private static void frameIcon(Theme theme) {
|
|
768 |
Iterator i = pluginsConfig.keySet().iterator();
|
|
769 |
|
|
770 |
while (i.hasNext()) {
|
|
771 |
String pName = (String) i.next();
|
|
772 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
|
|
773 |
PluginServices ps = (PluginServices) pluginsServices.get(pName);
|
|
774 |
if (pc.getIcon() != null) {
|
|
775 |
if (theme.getIcon() != null) {
|
|
776 |
frame.setIconImage(theme.getIcon().getImage());
|
|
777 |
} else {
|
|
778 |
|
|
779 |
ImageIcon icon = PluginServices.getIconTheme().get(pc.getIcon().getSrc());
|
|
780 |
frame.setIconImage(icon.getImage());
|
|
781 |
|
|
782 |
}
|
|
783 |
if (theme.getName() != null) {
|
|
784 |
frame.setTitlePrefix(theme.getName());
|
|
785 |
} else {
|
|
786 |
frame.setTitlePrefix(pc.getIcon().getText());
|
|
787 |
}
|
|
788 |
if (theme.getBackgroundImage() != null) {
|
|
789 |
|
|
790 |
PluginServices.getMDIManager().setBackgroundImage(theme.getBackgroundImage(),theme.getTypeDesktop());
|
|
791 |
}
|
|
792 |
}
|
|
793 |
}
|
|
794 |
}
|
|
795 |
|
|
796 |
private static void initializeExtensions() {
|
|
797 |
Iterator i = pluginsOrdered.iterator();
|
|
798 |
|
|
799 |
while (i.hasNext()) {
|
|
800 |
String pName = (String) i.next();
|
|
801 |
logger.debug("Initializing extensions from " + pName);
|
|
802 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
|
|
803 |
PluginServices ps = (PluginServices) pluginsServices.get(pName);
|
|
804 |
|
|
805 |
Extension[] exts = pc.getExtensions().getExtension();
|
|
806 |
|
|
807 |
TreeMap orderedExtensions = new TreeMap(new ExtensionComparator());
|
|
808 |
|
|
809 |
for (int j = 0; j < exts.length; j++) {
|
|
810 |
if (!exts[j].getActive()) {
|
|
811 |
continue;
|
|
812 |
}
|
|
813 |
|
|
814 |
if (orderedExtensions.containsKey(exts[j])) {
|
|
815 |
logger.warn(Messages.getString(
|
|
816 |
"Launcher.Two_extensions_with_the_same_priority") +
|
|
817 |
exts[j].getClassName());
|
|
818 |
}
|
|
819 |
|
|
820 |
orderedExtensions.put(exts[j], null);
|
|
821 |
}
|
|
822 |
|
|
823 |
Iterator e = orderedExtensions.keySet().iterator();
|
|
824 |
|
|
825 |
while (e.hasNext()) {
|
|
826 |
Extension extension = (Extension) e.next();
|
|
827 |
com.iver.andami.plugins.IExtension extensionInstance;
|
|
828 |
|
|
829 |
try {
|
|
830 |
Class extensionClass = ps.getClassLoader().loadClass(extension.getClassName());
|
|
831 |
extensionInstance = (com.iver.andami.plugins.IExtension) extensionClass.newInstance();
|
|
832 |
|
|
833 |
// CON DECORATOR
|
|
834 |
// ANTES: classesExtensions.put(extensionClass, extensionInstance);
|
|
835 |
// AHORA: CREAMOS UNA ExtensionDecorator y asignamos esta instancia para
|
|
836 |
// poder ampliar con nuevas propiedades (AlwaysVisible, por ejemplo)
|
|
837 |
// Para crear la nueva clase ExtensionDecorator, le pasamos como par�metro
|
|
838 |
// la extensi�n original que acabamos de crear
|
|
839 |
// 0-> Inactivo, controla la extension
|
|
840 |
// 1-> Siempre visible
|
|
841 |
// 2-> Invisible
|
|
842 |
ExtensionDecorator newExtensionDecorator = new ExtensionDecorator(extensionInstance, ExtensionDecorator.INACTIVE);
|
|
843 |
classesExtensions.put(extensionClass, newExtensionDecorator);
|
|
844 |
logger.info("Initializing " + extension.getClassName()+"...");
|
|
845 |
// logger.debug("Initializing " + extension.getClassName());
|
|
846 |
extensionInstance.initialize();
|
|
847 |
extensions.add(extensionInstance);
|
|
848 |
// logger.debug(extension.getClassName() + " initialized.");
|
|
849 |
|
|
850 |
} catch (InstantiationException e1) {
|
|
851 |
logger.error(Messages.getString(
|
|
852 |
"Launcher.Error_instanciando_la_extension") +
|
|
853 |
extension.getClassName(), e1);
|
|
854 |
} catch (IllegalAccessException e1) {
|
|
855 |
logger.error(Messages.getString(
|
|
856 |
"Launcher.Error_instanciando_la_extension") +
|
|
857 |
extension.getClassName(), e1);
|
|
858 |
} catch (ClassNotFoundException e1) {
|
|
859 |
logger.error(Messages.getString(
|
|
860 |
"Launcher.No_se_encontro_la_clase_de_la_extension") +
|
|
861 |
extension.getClassName(), e1);
|
|
862 |
} catch (NoClassDefFoundError e1) {
|
|
863 |
logger.error(Messages.getString(
|
|
864 |
"Launcher.Error_localizando_la_clase_de_la_extension") +
|
|
865 |
extension.getClassName(), e1);
|
|
866 |
}
|
|
867 |
}
|
|
868 |
}
|
|
869 |
}
|
|
870 |
|
|
871 |
private static void postInitializeExtensions() {
|
|
872 |
for (int i=0;i<extensions.size();i++) {
|
|
873 |
com.iver.andami.plugins.IExtension extensionInstance=(com.iver.andami.plugins.IExtension)extensions.get(i);
|
|
874 |
extensionInstance.postInitialize();
|
|
875 |
}
|
|
876 |
}
|
|
877 |
|
|
878 |
private static void installPluginsMenus() {
|
|
879 |
TreeMap orderedMenus = new TreeMap(new MenuComparator());
|
|
880 |
|
|
881 |
Iterator i = pluginsConfig.keySet().iterator();
|
|
882 |
|
|
883 |
while (i.hasNext()) {
|
|
884 |
String pName = (String) i.next();
|
|
885 |
PluginServices ps = (PluginServices) pluginsServices.get(pName);
|
|
886 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
|
|
887 |
|
|
888 |
Extension[] exts = pc.getExtensions().getExtension();
|
|
889 |
|
|
890 |
for (int j = 0; j < exts.length; j++) {
|
|
891 |
if (!exts[j].getActive()) {
|
|
892 |
continue;
|
|
893 |
}
|
|
894 |
|
|
895 |
Menu[] menus = exts[j].getMenu();
|
|
896 |
|
|
897 |
for (int k = 0; k < menus.length; k++) {
|
|
898 |
SortableMenu sm = new SortableMenu(ps.getClassLoader(),
|
|
899 |
exts[j], menus[k]);
|
|
900 |
|
|
901 |
if (orderedMenus.containsKey(sm)) {
|
|
902 |
logger.error(Messages.getString(
|
|
903 |
"Launcher.Two_menus_with_the_same_position") + " - " +
|
|
904 |
menus[k].getText()+ " - " + exts[j].getClassName());
|
|
905 |
}
|
|
906 |
|
|
907 |
orderedMenus.put(sm, null);
|
|
908 |
}
|
|
909 |
}
|
|
910 |
|
|
911 |
// Se instalan las extensiones de MDI
|
|
912 |
SkinExtension[] skinExts = pc.getExtensions().getSkinExtension();
|
|
913 |
for (int j = 0; j < skinExts.length; j++) {
|
|
914 |
|
|
915 |
|
|
916 |
if (skinExts[j] != null) {
|
|
917 |
Menu[] menu = skinExts[j].getMenu();
|
|
918 |
|
|
919 |
for (int k = 0; k < menu.length; k++) {
|
|
920 |
SortableMenu sm = new SortableMenu(ps.getClassLoader(),
|
|
921 |
skinExts[j], menu[k]);
|
|
922 |
|
|
923 |
if (orderedMenus.containsKey(sm)) {
|
|
924 |
logger.error(Messages.getString(
|
|
925 |
"Launcher.Two_menus_with_the_same_position") +
|
|
926 |
skinExts[j].getClassName());
|
|
927 |
}
|
|
928 |
|
|
929 |
orderedMenus.put(sm, null);
|
|
930 |
}
|
|
931 |
}
|
|
932 |
}
|
|
933 |
}
|
|
934 |
|
|
935 |
//Se itera por los menus ordenados
|
|
936 |
Iterator e = orderedMenus.keySet().iterator();
|
|
937 |
|
|
938 |
// Se ordenan los menues
|
|
939 |
while (e.hasNext()) {
|
|
940 |
try {
|
|
941 |
SortableMenu sm = (SortableMenu) e.next();
|
|
942 |
|
|
943 |
frame.addMenu(sm.loader, sm.extension, sm.menu);
|
|
944 |
} catch (ClassNotFoundException ex) {
|
|
945 |
logger.error(Messages.getString(
|
|
946 |
"Launcher.No_se_encontro_la_clase_de_la_extension"), ex);
|
|
947 |
}
|
|
948 |
}
|
|
949 |
}
|
|
950 |
|
|
951 |
/**
|
|
952 |
* Installs the menus, toolbars, actiontools, selectable toolbars and combos.
|
|
953 |
* The order in which they are shown is determined here.
|
|
954 |
*/
|
|
955 |
private static void installPluginsControls() {
|
|
956 |
Iterator i = pluginsConfig.keySet().iterator();
|
|
957 |
|
|
958 |
HashMap extensionPluginServices = new HashMap();
|
|
959 |
HashMap extensionPluginConfig = new HashMap();
|
|
960 |
TreeMap orderedExtensions = new TreeMap(new ExtensionComparator());
|
|
961 |
|
|
962 |
// First of all, sort the extensions.
|
|
963 |
// We need to iterate on the plugins, and iterate on each plugin's extensions
|
|
964 |
// (each plugin may contain one or more extensions)
|
|
965 |
while (i.hasNext()) { // iterate on the plugins
|
|
966 |
String pName = (String) i.next();
|
|
967 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
|
|
968 |
PluginServices ps = (PluginServices) pluginsServices.get(pName);
|
|
969 |
|
|
970 |
Extension[] exts = pc.getExtensions().getExtension();
|
|
971 |
|
|
972 |
for (int j = 0; j < exts.length; j++) { // iterate on the extensions
|
|
973 |
if (exts[j].getActive()) {
|
|
974 |
if (orderedExtensions.containsKey(exts[j])) {
|
|
975 |
logger.error(Messages.getString(
|
|
976 |
"Launcher.Two_extensions_with_the_same_priority") +
|
|
977 |
exts[j].getClassName());
|
|
978 |
}
|
|
979 |
|
|
980 |
orderedExtensions.put(exts[j], null);
|
|
981 |
extensionPluginServices.put(exts[j], ps);
|
|
982 |
extensionPluginConfig.put(exts[j], pc);
|
|
983 |
}
|
|
984 |
}
|
|
985 |
}
|
|
986 |
|
|
987 |
TreeMap orderedTools = new TreeMap(new ToolComparator());
|
|
988 |
Iterator e = orderedExtensions.keySet().iterator();
|
|
989 |
|
|
990 |
// sort the toolbars and tools from 'normal' extensions (actiontools, selectabletools)
|
|
991 |
// and load the combo-scales and combo-buttons for the status bar
|
|
992 |
while (e.hasNext()) {
|
|
993 |
Extension ext = (Extension) e.next();
|
|
994 |
|
|
995 |
ToolBar[] toolbars = ext.getToolBar();
|
|
996 |
|
|
997 |
// get tools from toolbars
|
|
998 |
for (int k = 0; k < toolbars.length; k++) {
|
|
999 |
ActionTool[] tools = toolbars[k].getActionTool();
|
|
1000 |
|
|
1001 |
for (int t = 0; t < tools.length; t++) {
|
|
1002 |
SortableTool sm = new SortableTool(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
|
|
1003 |
toolbars[k], tools[t]);
|
|
1004 |
orderedTools.put(sm, null);
|
|
1005 |
}
|
|
1006 |
|
|
1007 |
SelectableTool[] sTools = toolbars[k].getSelectableTool();
|
|
1008 |
|
|
1009 |
for (int t = 0; t < sTools.length; t++) {
|
|
1010 |
SortableTool sm=new SortableTool(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
|
|
1011 |
toolbars[k], sTools[t]);
|
|
1012 |
orderedTools.put(sm, null);
|
|
1013 |
}
|
|
1014 |
}
|
|
1015 |
|
|
1016 |
// get controls for statusBar
|
|
1017 |
PluginServices ps = (PluginServices) extensionPluginServices.get(ext);
|
|
1018 |
PluginClassLoader loader = ps.getClassLoader();
|
|
1019 |
|
|
1020 |
//ArrayList componentList = new ArrayList();
|
|
1021 |
ComboScale[] comboScaleArray = ext.getComboScale();
|
|
1022 |
for (int k=0; k < comboScaleArray.length; k++) {
|
|
1023 |
org.gvsig.gui.beans.controls.comboscale.ComboScale combo = new org.gvsig.gui.beans.controls.comboscale.ComboScale();
|
|
1024 |
String label = comboScaleArray[k].getLabel();
|
|
1025 |
if (label!=null)
|
|
1026 |
combo.setLabel(label);
|
|
1027 |
String name = comboScaleArray[k].getName();
|
|
1028 |
if (name!=null)
|
|
1029 |
combo.setName(name);
|
|
1030 |
String[] elementsString = ((String)comboScaleArray[k].getElements()).split(";");
|
|
1031 |
long[] elements = new long[elementsString.length];
|
|
1032 |
for (int currentElem=0; currentElem<elementsString.length; currentElem++) {
|
|
1033 |
try {
|
|
1034 |
elements[currentElem] = Long.parseLong(elementsString[currentElem]);
|
|
1035 |
}
|
|
1036 |
catch (NumberFormatException nfex1) {
|
|
1037 |
logger.error(ext.getClassName()+" -- "+Messages.getString( "error_parsing_comboscale_elements"));
|
|
1038 |
elements[currentElem] = 0;
|
|
1039 |
}
|
|
1040 |
}
|
|
1041 |
combo.setItems(elements);
|
|
1042 |
try {
|
|
1043 |
long value = Long.parseLong((String)comboScaleArray[k].getValue());
|
|
1044 |
combo.setScale(value);
|
|
1045 |
}
|
|
1046 |
catch (NumberFormatException nfex2) {
|
|
1047 |
logger.error(ext.getClassName()+" -- "+Messages.getString( "error_parsing_comboscale_value"));
|
|
1048 |
}
|
|
1049 |
try {
|
|
1050 |
frame.addStatusBarControl(loader.loadClass(ext.getClassName()),combo);
|
|
1051 |
} catch (ClassNotFoundException e1) {
|
|
1052 |
logger.error(Messages.getString("Launcher.error_getting_class_loader_for_status_bar_control"), e1);
|
|
1053 |
}
|
|
1054 |
}
|
|
1055 |
|
|
1056 |
ComboButton[] comboButtonArray = ext.getComboButton();
|
|
1057 |
for (int k=0; k < comboButtonArray.length; k++) {
|
|
1058 |
ComboButtonElement[] elementList = comboButtonArray[k].getComboButtonElement();
|
|
1059 |
org.gvsig.gui.beans.controls.combobutton.ComboButton combo = new org.gvsig.gui.beans.controls.combobutton.ComboButton();
|
|
1060 |
String name = comboButtonArray[k].getName();
|
|
1061 |
if (name!=null)
|
|
1062 |
combo.setName(name);
|
|
1063 |
for (int currentElement=0; currentElement<elementList.length; currentElement++) {
|
|
1064 |
ComboButtonElement element = elementList[currentElement];
|
|
1065 |
ImageIcon icon;
|
|
1066 |
URL iconLocation = loader.getResource(element.getIcon());
|
|
1067 |
if (iconLocation==null)
|
|
1068 |
logger.error(Messages.getString("Icon_not_found_")+element.getIcon());
|
|
1069 |
else {
|
|
1070 |
icon = new ImageIcon(iconLocation);
|
|
1071 |
JButton button = new JButton(icon);
|
|
1072 |
combo.addButton(button);
|
|
1073 |
button.setActionCommand(element.getActionCommand());
|
|
1074 |
}
|
|
1075 |
}
|
|
1076 |
try {
|
|
1077 |
frame.addStatusBarControl(loader.loadClass(ext.getClassName()), combo);
|
|
1078 |
} catch (ClassNotFoundException e1) {
|
|
1079 |
logger.error(Messages.getString("Launcher.error_getting_class_loader_for_status_bar_control"), e1);
|
|
1080 |
}
|
|
1081 |
}
|
|
1082 |
}
|
|
1083 |
|
|
1084 |
// Add the tools from MDI extensions to the ordered tool-list, so that we get a sorted list containing all the tools
|
|
1085 |
i = pluginsConfig.keySet().iterator();
|
|
1086 |
while (i.hasNext()) {
|
|
1087 |
String pName = (String) i.next();
|
|
1088 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
|
|
1089 |
PluginServices ps = (PluginServices) pluginsServices.get(pName);
|
|
1090 |
|
|
1091 |
SkinExtension[] skinExts = pc.getExtensions().getSkinExtension();
|
|
1092 |
for (int j = 0; j < skinExts.length; j++) {
|
|
1093 |
|
|
1094 |
|
|
1095 |
if (skinExts[j] != null) {
|
|
1096 |
ToolBar[] toolbars = skinExts[j].getToolBar();
|
|
1097 |
|
|
1098 |
for (int k = 0; k < toolbars.length; k++) {
|
|
1099 |
ActionTool[] tools = toolbars[k].getActionTool();
|
|
1100 |
|
|
1101 |
for (int t = 0; t < tools.length; t++) {
|
|
1102 |
SortableTool stb=new SortableTool(ps.getClassLoader(), skinExts[j],
|
|
1103 |
toolbars[k], tools[t]);
|
|
1104 |
orderedTools.put(stb,null);
|
|
1105 |
}
|
|
1106 |
|
|
1107 |
SelectableTool[] sTools = toolbars[k].getSelectableTool();
|
|
1108 |
|
|
1109 |
for (int t = 0; t < sTools.length; t++) {
|
|
1110 |
SortableTool stb=new SortableTool(ps.getClassLoader(), skinExts[j],
|
|
1111 |
toolbars[k], sTools[t]);
|
|
1112 |
orderedTools.put(stb,null);
|
|
1113 |
}
|
|
1114 |
}
|
|
1115 |
}
|
|
1116 |
}
|
|
1117 |
// Install popup menus
|
|
1118 |
PopupMenus pus = pc.getPopupMenus();
|
|
1119 |
|
|
1120 |
if (pus != null) {
|
|
1121 |
PopupMenu[] menus = pus.getPopupMenu();
|
|
1122 |
|
|
1123 |
for (int j = 0; j < menus.length; j++) {
|
|
1124 |
frame.addPopupMenu(ps.getClassLoader(), menus[j]);
|
|
1125 |
}
|
|
1126 |
}
|
|
1127 |
}
|
|
1128 |
|
|
1129 |
// loop on the ordered extension list, to add them to the interface in an ordered way
|
|
1130 |
Iterator t = orderedTools.keySet().iterator();
|
|
1131 |
while (t.hasNext()) {
|
|
1132 |
try {
|
|
1133 |
SortableTool stb = (SortableTool) t.next();
|
|
1134 |
if (stb.actiontool!=null)
|
|
1135 |
frame.addTool(stb.loader, stb.extension,stb.toolbar, stb.actiontool);
|
|
1136 |
else
|
|
1137 |
frame.addTool(stb.loader, stb.extension,stb.toolbar, stb.selectabletool);
|
|
1138 |
} catch (ClassNotFoundException ex) {
|
|
1139 |
logger.error(Messages.getString(
|
|
1140 |
"Launcher.No_se_encontro_la_clase_de_la_extension"), ex);
|
|
1141 |
}
|
|
1142 |
}
|
|
1143 |
}
|
|
1144 |
|
|
1145 |
/**
|
|
1146 |
* Adds new plugins to the the andami-config file.
|
|
1147 |
*/
|
|
1148 |
private static void updateAndamiConfig() {
|
|
1149 |
HashSet olds = new HashSet();
|
|
1150 |
|
|
1151 |
Plugin[] plugins = andamiConfig.getPlugin();
|
|
1152 |
|
|
1153 |
for (int i = 0; i < plugins.length; i++) {
|
|
1154 |
olds.add(plugins[i].getName());
|
|
1155 |
}
|
|
1156 |
|
|
1157 |
Iterator i = pluginsServices.values().iterator();
|
|
1158 |
|
|
1159 |
while (i.hasNext()) {
|
|
1160 |
PluginServices ps = (PluginServices) i.next();
|
|
1161 |
|
|
1162 |
if (!olds.contains(ps.getPluginName())) {
|
|
1163 |
Plugin p = new Plugin();
|
|
1164 |
p.setName(ps.getPluginName());
|
|
1165 |
p.setUpdate(false);
|
|
1166 |
|
|
1167 |
andamiConfig.addPlugin(p);
|
|
1168 |
}
|
|
1169 |
}
|
|
1170 |
}
|
|
1171 |
|
|
1172 |
private static void pluginsClassLoaders() {
|
|
1173 |
HashSet instalados = new HashSet();
|