root / trunk / frameworks / _fwAndami / src / com / iver / andami / Launcher.java @ 8884
History | View | Annotate | Download (60.7 KB)
1 | 1104 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 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 | 598 | fernando | package com.iver.andami; |
42 | |||
43 | 4306 | ldiaz | import java.awt.Component; |
44 | 4299 | luisw2 | import java.awt.Dimension; |
45 | 1153 | fernando | import java.awt.EventQueue; |
46 | 7303 | caballero | import java.awt.Frame; |
47 | 5817 | fjp | import java.awt.KeyboardFocusManager; |
48 | 4299 | luisw2 | import java.awt.Point; |
49 | 1153 | fernando | import java.awt.Toolkit; |
50 | 6951 | cesar | import java.io.BufferedReader; |
51 | 598 | fernando | import java.io.File; |
52 | 1110 | fernando | import java.io.FileFilter; |
53 | 2332 | fjp | import java.io.FileInputStream; |
54 | 598 | fernando | import java.io.FileNotFoundException; |
55 | 2332 | fjp | import java.io.FileOutputStream; |
56 | 598 | fernando | import java.io.FileReader; |
57 | import java.io.FileWriter; |
||
58 | import java.io.FilenameFilter; |
||
59 | import java.io.IOException; |
||
60 | 2332 | fjp | import java.io.InputStream; |
61 | 6951 | cesar | import java.io.InputStreamReader; |
62 | 8752 | cesar | import java.io.Reader; |
63 | 598 | fernando | import java.lang.reflect.InvocationTargetException; |
64 | 8884 | fjp | import java.net.Authenticator; |
65 | 598 | fernando | import java.net.MalformedURLException; |
66 | 8884 | fjp | import java.net.PasswordAuthentication; |
67 | 598 | fernando | import java.net.URL; |
68 | 2332 | fjp | import java.net.URLConnection; |
69 | 7514 | caballero | 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 | 598 | fernando | import java.util.ArrayList; |
75 | import java.util.Comparator; |
||
76 | 2332 | fjp | import java.util.Date; |
77 | 598 | fernando | import java.util.HashMap; |
78 | import java.util.HashSet; |
||
79 | import java.util.Iterator; |
||
80 | import java.util.Locale; |
||
81 | 2332 | fjp | import java.util.Properties; |
82 | 598 | fernando | import java.util.TreeMap; |
83 | 8884 | fjp | import java.util.prefs.Preferences; |
84 | 598 | fernando | |
85 | 2332 | fjp | import javax.jnlp.BasicService; |
86 | import javax.jnlp.ServiceManager; |
||
87 | import javax.jnlp.UnavailableServiceException; |
||
88 | 598 | fernando | import javax.swing.ImageIcon; |
89 | 6589 | cesar | import javax.swing.JButton; |
90 | 598 | fernando | import javax.swing.JComponent; |
91 | 4306 | ldiaz | import javax.swing.JOptionPane; |
92 | 598 | fernando | import javax.swing.SwingUtilities; |
93 | import javax.swing.UIManager; |
||
94 | |||
95 | 2112 | fernando | import org.apache.log4j.Logger; |
96 | import org.apache.log4j.PatternLayout; |
||
97 | import org.apache.log4j.PropertyConfigurator; |
||
98 | import org.apache.log4j.RollingFileAppender; |
||
99 | import org.exolab.castor.xml.MarshalException; |
||
100 | import org.exolab.castor.xml.ValidationException; |
||
101 | 598 | fernando | |
102 | 4306 | ldiaz | import com.iver.andami.authentication.IAuthentication; |
103 | 2112 | fernando | import com.iver.andami.config.generate.Andami; |
104 | import com.iver.andami.config.generate.AndamiConfig; |
||
105 | import com.iver.andami.config.generate.Plugin; |
||
106 | import com.iver.andami.messages.Messages; |
||
107 | 2332 | fjp | import com.iver.andami.messages.NotificationManager; |
108 | 2862 | jaume | import com.iver.andami.plugins.ExtensionDecorator; |
109 | 2112 | fernando | import com.iver.andami.plugins.PluginClassLoader; |
110 | import com.iver.andami.plugins.config.generate.ActionTool; |
||
111 | 6589 | cesar | import com.iver.andami.plugins.config.generate.ComboButton; |
112 | import com.iver.andami.plugins.config.generate.ComboButtonElement; |
||
113 | import com.iver.andami.plugins.config.generate.ComboScale; |
||
114 | 2112 | fernando | import com.iver.andami.plugins.config.generate.Depends; |
115 | import com.iver.andami.plugins.config.generate.Extension; |
||
116 | import com.iver.andami.plugins.config.generate.Extensions; |
||
117 | import com.iver.andami.plugins.config.generate.LabelSet; |
||
118 | import com.iver.andami.plugins.config.generate.Menu; |
||
119 | import com.iver.andami.plugins.config.generate.PluginConfig; |
||
120 | import com.iver.andami.plugins.config.generate.PopupMenu; |
||
121 | import com.iver.andami.plugins.config.generate.PopupMenus; |
||
122 | import com.iver.andami.plugins.config.generate.SelectableTool; |
||
123 | import com.iver.andami.plugins.config.generate.SkinExtension; |
||
124 | import com.iver.andami.plugins.config.generate.SkinExtensionType; |
||
125 | import com.iver.andami.plugins.config.generate.ToolBar; |
||
126 | import com.iver.andami.ui.AndamiEventQueue; |
||
127 | import com.iver.andami.ui.MDIManagerLoadException; |
||
128 | import com.iver.andami.ui.mdiFrame.MDIFrame; |
||
129 | import com.iver.andami.ui.mdiManager.MDIManagerFactory; |
||
130 | 7303 | caballero | import com.iver.andami.ui.splash.MultiSplashWindow; |
131 | 2112 | fernando | import com.iver.utiles.XMLEntity; |
132 | import com.iver.utiles.xmlEntity.generate.XmlTag; |
||
133 | |||
134 | |||
135 | 598 | fernando | /**
|
136 | * DOCUMENT ME!
|
||
137 | *
|
||
138 | * @author $author$
|
||
139 | * @version $Revision$
|
||
140 | */
|
||
141 | public class Launcher { |
||
142 | 1067 | fernando | private static Logger logger = Logger.getLogger(Launcher.class.getName()); |
143 | 8884 | fjp | private static Preferences prefs = Preferences.userRoot().node( "gvsig.connection" ); |
144 | 1067 | fernando | private static AndamiConfig andamiConfig; |
145 | 7303 | caballero | private static MultiSplashWindow splashWindow; |
146 | 1067 | fernando | private static String appName; |
147 | private static Locale locale; |
||
148 | private static HashMap pluginsConfig = new HashMap(); |
||
149 | private static HashMap pluginsServices = new HashMap(); |
||
150 | private static MDIFrame frame; |
||
151 | private static HashMap classesExtensions = new HashMap(); |
||
152 | private static String andamiConfigPath; |
||
153 | private static String pluginsPersistencePath; |
||
154 | 6101 | jaume | private static final String nonWinDefaultLookAndFeel = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"; |
155 | |||
156 | 2828 | fjp | private static ArrayList pluginsOrdered = new ArrayList(); |
157 | 7303 | caballero | private static ArrayList extensions=new ArrayList(); |
158 | 8120 | jmvivo | private static String appHomeDir = null; |
159 | 8884 | fjp | |
160 | private static final class ProxyAuth extends Authenticator { |
||
161 | private PasswordAuthentication auth; |
||
162 | |||
163 | private ProxyAuth(String user, String pass) { |
||
164 | auth = new PasswordAuthentication(user, pass.toCharArray()); |
||
165 | } |
||
166 | |||
167 | protected PasswordAuthentication getPasswordAuthentication() { |
||
168 | return auth;
|
||
169 | } |
||
170 | } |
||
171 | |||
172 | 1067 | fernando | /**
|
173 | * DOCUMENT ME!
|
||
174 | *
|
||
175 | * @param args DOCUMENT ME!
|
||
176 | 2142 | fernando | * @throws Exception
|
177 | 1067 | fernando | *
|
178 | * @throws InterruptedException
|
||
179 | * @throws InvocationTargetException
|
||
180 | * @throws ConfigurationException
|
||
181 | * @throws MDIManagerLoadException
|
||
182 | * @throws IOException
|
||
183 | */
|
||
184 | 7303 | caballero | public static void main(String[] args) throws Exception { |
185 | try{
|
||
186 | 2142 | fernando | |
187 | 7303 | caballero | if (!validJVM()){
|
188 | System.exit(-1); |
||
189 | } |
||
190 | 6101 | jaume | |
191 | 7303 | caballero | if (args.length < 1) { |
192 | System.err.println("Uso: Launcher appName plugins-directory [language=locale]"); |
||
193 | } |
||
194 | 598 | fernando | |
195 | 7303 | caballero | // Clean temporal files
|
196 | Utilities.cleanUpTempFiles();
|
||
197 | 4607 | ldiaz | |
198 | 7303 | caballero | appName = args[0];
|
199 | 1236 | fernando | |
200 | 7303 | caballero | //Se crea el directorio de configuraci?n de la aplicaci?n
|
201 | 8120 | jmvivo | appHomeDir = System.getProperty(args[0]+".home"); |
202 | if (appHomeDir == null) |
||
203 | appHomeDir = System.getProperty("user.home"); |
||
204 | 8382 | cesar | //System.err.println("LWS: "+args[0]+".home"+"="+appHomeDir);
|
205 | 8120 | jmvivo | appHomeDir += File.separator + args[0] + File.separator; |
206 | File parent = new File( appHomeDir ); |
||
207 | 7303 | caballero | parent.mkdirs(); |
208 | 598 | fernando | |
209 | 8120 | jmvivo | andamiConfigPath = appHomeDir + "andami-config.xml";
|
210 | pluginsPersistencePath = appHomeDir + |
||
211 | 7303 | caballero | "plugins-persistence.xml";
|
212 | 598 | fernando | |
213 | 7303 | caballero | // Configurar el log4j
|
214 | PropertyConfigurator.configure(Launcher.class.getClassLoader() |
||
215 | .getResource("log4j.properties"));
|
||
216 | 598 | fernando | |
217 | 7303 | caballero | PatternLayout l = new PatternLayout("%p %t %C - %m%n"); |
218 | RollingFileAppender fa = new RollingFileAppender(l,
|
||
219 | 8120 | jmvivo | appHomeDir + args[0] + ".log", false); |
220 | 7303 | caballero | fa.setMaxFileSize("512KB");
|
221 | fa.setMaxBackupIndex(3);
|
||
222 | Logger.getRootLogger().addAppender(fa);
|
||
223 | 598 | fernando | |
224 | 7303 | caballero | // Leer el fichero de configuraci?n de andami (andami-config.xsd)
|
225 | // locale
|
||
226 | // Buscar actualizaci?nes al comenzar
|
||
227 | // Andami
|
||
228 | // Plugins
|
||
229 | // Directorio de las extensiones
|
||
230 | andamiConfigFromXML(andamiConfigPath); |
||
231 | andamiConfig.setPluginsDirectory(args[1]);
|
||
232 | 6101 | jaume | |
233 | 7303 | caballero | // Hacemos visibles los argumentos como una propiedad est?tica
|
234 | // de plugin services para quien lo quiera usar (por ejemplo, para
|
||
235 | // cargar un proyecto por l?nea de comandos)
|
||
236 | PluginServices.setArguments(args); |
||
237 | 598 | fernando | |
238 | 7303 | caballero | configureLocales(args); |
239 | 598 | fernando | |
240 | 7303 | caballero | //Se pone el lookAndFeel
|
241 | try {
|
||
242 | String lookAndFeel = getAndamiConfig().getLookAndFeel();
|
||
243 | if (lookAndFeel == null) |
||
244 | lookAndFeel = getDefaultLookAndFeel(); |
||
245 | UIManager.setLookAndFeel(lookAndFeel);
|
||
246 | } catch (Exception e) { |
||
247 | logger.warn(Messages.getString("Launcher.look_and_feel"), e);
|
||
248 | } |
||
249 | 7514 | caballero | // Solucionamos el problema de permisos que se produc?a con Java Web Start con este c?digo.
|
250 | // System.setSecurityManager(null);
|
||
251 | Policy.setPolicy(new Policy() { |
||
252 | public PermissionCollection getPermissions(CodeSource codesource) { |
||
253 | Permissions perms = new Permissions(); |
||
254 | perms.add(new AllPermission()); |
||
255 | return (perms);
|
||
256 | } |
||
257 | public void |
||
258 | refresh() {} |
||
259 | }); |
||
260 | 6101 | jaume | |
261 | 7483 | caballero | validate(); |
262 | 7303 | caballero | // Mostrar la ventana de inicio
|
263 | Frame f=new Frame(); |
||
264 | splashWindow=new MultiSplashWindow(f);
|
||
265 | 8884 | fjp | |
266 | // Ponemos los datos del proxy
|
||
267 | String host = prefs.get("firewall.http.host", ""); |
||
268 | String port = prefs.get("firewall.http.port", ""); |
||
269 | 598 | fernando | |
270 | 8884 | fjp | System.getProperties().put("http.proxyHost", host); |
271 | System.getProperties().put("http.proxyPort", port); |
||
272 | |||
273 | // Ponemos el usuario y clave del proxy, si existe
|
||
274 | String proxyUser = prefs.get("firewall.http.user",null); |
||
275 | String proxyPassword = prefs.get("firewall.http.password", null); |
||
276 | if (proxyUser != null ) |
||
277 | { |
||
278 | System.getProperties().put("http.proxyUserName", proxyUser); |
||
279 | System.getProperties().put("http.proxyPassword", proxyPassword); |
||
280 | |||
281 | Authenticator.setDefault(new ProxyAuth(proxyUser, |
||
282 | proxyPassword)); |
||
283 | } else {
|
||
284 | Authenticator.setDefault(new ProxyAuth("", "")); |
||
285 | } |
||
286 | |||
287 | |||
288 | 7303 | caballero | // TODO Buscar actualizaciones de los plugins
|
289 | downloadExtensions(andamiConfig.getPluginsDirectory()); |
||
290 | 598 | fernando | |
291 | 7303 | caballero | // Se leen los config.xml de los plugins -----++++
|
292 | loadPlugins(andamiConfig.getPluginsDirectory()); |
||
293 | 598 | fernando | |
294 | 7303 | caballero | // Se configura el classloader del plugin
|
295 | pluginsClassLoaders(); |
||
296 | 1153 | fernando | |
297 | 7303 | caballero | // Se carga un Skin si alguno de los plugins trae informaci?n para ello
|
298 | skinPlugin(); |
||
299 | 598 | fernando | |
300 | 7303 | caballero | //Se configura la cola de eventos
|
301 | EventQueue waitQueue = new AndamiEventQueue(); |
||
302 | Toolkit.getDefaultToolkit().getSystemEventQueue().push(waitQueue);
|
||
303 | 598 | fernando | |
304 | 7303 | caballero | // Se configura la mensajer?a del plugin
|
305 | pluginsMessages(); |
||
306 | 598 | fernando | |
307 | 7303 | caballero | // Se modifica el andami-config con los plugins nuevos
|
308 | updateAndamiConfig(); |
||
309 | 598 | fernando | |
310 | 7303 | caballero | // Se prepara el MainFrame para albergar las extensiones
|
311 | frame = new MDIFrame();
|
||
312 | 598 | fernando | |
313 | 7303 | caballero | // Se configura el nombre e icono de la aplicaci?n
|
314 | frameIcon(); |
||
315 | 598 | fernando | |
316 | 7303 | caballero | SwingUtilities.invokeAndWait(new Runnable() { |
317 | public void run() { |
||
318 | frame.init(); |
||
319 | } |
||
320 | }); |
||
321 | 1013 | fjp | |
322 | 7303 | caballero | // Se instalan los controles de las extensiones de los plugins
|
323 | SwingUtilities.invokeAndWait(new Runnable() { |
||
324 | public void run() { |
||
325 | installPluginsControls(); |
||
326 | installPluginsMenus(); |
||
327 | installPluginsLabels(); |
||
328 | } |
||
329 | }); |
||
330 | 1067 | fernando | |
331 | 7303 | caballero | // Leer el fichero de persistencia
|
332 | // info de los plugins
|
||
333 | // bookmarks de los plugins
|
||
334 | loadPluginsPersistence(); |
||
335 | 1067 | fernando | |
336 | 7303 | caballero | // Se instalan los controles del skin
|
337 | // Se inicializan todas las extensiones de todos los plugins
|
||
338 | SwingUtilities.invokeAndWait(new Runnable() { |
||
339 | public void run() { |
||
340 | initializeExtensions(); |
||
341 | postInitializeExtensions(); |
||
342 | } |
||
343 | }); |
||
344 | frame.setClassesExtensions(classesExtensions); |
||
345 | 6101 | jaume | |
346 | 7303 | caballero | // Se instalan los bookmarks de los plugins
|
347 | 1067 | fernando | |
348 | 7303 | caballero | //Se muestra el frame principal
|
349 | frame.show(); |
||
350 | 6101 | jaume | |
351 | 7303 | caballero | // Definimos un KeyEventDispatcher global para que las extensiones
|
352 | // puedan registrar sus "teclas r?pidas".
|
||
353 | GlobalKeyEventDispatcher keyDispatcher = GlobalKeyEventDispatcher.getInstance(); |
||
354 | KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);
|
||
355 | 6101 | jaume | |
356 | 7303 | caballero | SwingUtilities.invokeAndWait(new Runnable() { |
357 | public void run() { |
||
358 | frame.enableControls(); |
||
359 | } |
||
360 | }); |
||
361 | splashWindow.close(); |
||
362 | }catch(Exception e){ |
||
363 | logger.error("excepci?n al arrancar", e);
|
||
364 | System.exit(-1); |
||
365 | } |
||
366 | |||
367 | } |
||
368 | |||
369 | 4299 | luisw2 | /**
|
370 | * Recupera la geometr?a (tama?o, posici?n y estado) de la ventana principal de Andami.
|
||
371 | * TODO Pendiente de ver como se asigna un pluginServices para el launcher.
|
||
372 | * @author LWS
|
||
373 | */
|
||
374 | private static void restoreMDIStatus(XMLEntity xml) { |
||
375 | //System.err.println("Launcher: restoreMDIStatus()");
|
||
376 | if (xml == null) xml = new XMLEntity(); |
||
377 | // restore frame size
|
||
378 | Dimension sz = new Dimension(700,580); |
||
379 | if (xml.contains("MDIFrameSize")) { |
||
380 | int [] wh = xml.getIntArrayProperty("MDIFrameSize"); |
||
381 | sz = new Dimension(wh[0], wh[1]); |
||
382 | } |
||
383 | frame.setSize(sz); |
||
384 | // restore frame location
|
||
385 | Point pos = new Point(10,10); |
||
386 | if (xml.contains("MDIFramePos")) { |
||
387 | int [] xy = xml.getIntArrayProperty("MDIFramePos"); |
||
388 | pos = new Point(xy[0], xy[1]); |
||
389 | } |
||
390 | frame.setLocation(pos); |
||
391 | 6101 | jaume | |
392 | 4299 | luisw2 | // restore frame status (Maximized, minimized, etc);
|
393 | int state = java.awt.Frame.MAXIMIZED_BOTH;
|
||
394 | if (xml.contains("MDIFrameState")) { |
||
395 | state = xml.getIntProperty("MDIFrameState");
|
||
396 | } |
||
397 | frame.setExtendedState(state); |
||
398 | 1067 | fernando | } |
399 | 6101 | jaume | |
400 | 4299 | luisw2 | private static XMLEntity saveMDIStatus() { |
401 | XMLEntity xml = new XMLEntity();
|
||
402 | // save frame size
|
||
403 | int [] wh = new int[2]; |
||
404 | wh[0] = frame.getWidth();
|
||
405 | wh[1] = frame.getHeight();
|
||
406 | xml.putProperty("MDIFrameSize", wh);
|
||
407 | // save frame location
|
||
408 | int [] xy = new int[2]; |
||
409 | xy[0] = frame.getX();
|
||
410 | xy[1] = frame.getY();
|
||
411 | xml.putProperty("MDIFramePos", xy);
|
||
412 | // save frame status
|
||
413 | xml.putProperty("MDIFrameState", frame.getExtendedState());
|
||
414 | return xml;
|
||
415 | } |
||
416 | 1067 | fernando | |
417 | /**
|
||
418 | 2142 | fernando | * @return
|
419 | */
|
||
420 | private static boolean validJVM() { |
||
421 | char thirdCharacter = System.getProperty("java.version").charAt(2); |
||
422 | if (thirdCharacter < '4'){ |
||
423 | return false; |
||
424 | }else{
|
||
425 | return true; |
||
426 | } |
||
427 | } |
||
428 | |||
429 | /**
|
||
430 | 1067 | fernando | * DOCUMENT ME!
|
431 | *
|
||
432 | * @throws ConfigurationException
|
||
433 | */
|
||
434 | private static void loadPluginsPersistence() throws ConfigurationException { |
||
435 | XMLEntity entity = persistenceFromXML(); |
||
436 | |||
437 | 4299 | luisw2 | //System.err.println("loadPluginPersistence()");
|
438 | 6861 | jaume | for (int i = 0; i < entity.getChildrenCount(); i++) { |
439 | 1067 | fernando | XMLEntity plugin = entity.getChild(i); |
440 | String pName = plugin.getStringProperty(
|
||
441 | "com.iver.andami.pluginName");
|
||
442 | 4299 | luisw2 | //System.err.println("--> "+pName);
|
443 | 1381 | vcaballero | if (pluginsServices.get(pName)!= null){ |
444 | ((PluginServices) pluginsServices.get(pName)).setPersistentXML(plugin); |
||
445 | 4299 | luisw2 | } else {
|
446 | if (pName.startsWith("Andami.Launcher")) |
||
447 | restoreMDIStatus(plugin); |
||
448 | 1381 | vcaballero | } |
449 | 1067 | fernando | } |
450 | } |
||
451 | 6101 | jaume | |
452 | 4299 | luisw2 | /**
|
453 | * Salva la persistencia de los plugins.
|
||
454 | * @author LWS
|
||
455 | */
|
||
456 | private static void savePluginPersistence() { |
||
457 | Iterator i = pluginsConfig.keySet().iterator();
|
||
458 | 1067 | fernando | |
459 | 4299 | luisw2 | XMLEntity entity = new XMLEntity();
|
460 | |||
461 | while (i.hasNext()) {
|
||
462 | String pName = (String) i.next(); |
||
463 | PluginServices ps = (PluginServices) pluginsServices.get(pName); |
||
464 | XMLEntity ent = ps.getPersistentXML(); |
||
465 | |||
466 | if (ent != null) { |
||
467 | ent.putProperty("com.iver.andami.pluginName", pName);
|
||
468 | entity.addChild(ent); |
||
469 | } |
||
470 | } |
||
471 | XMLEntity ent = saveMDIStatus(); |
||
472 | if (ent != null) { |
||
473 | ent.putProperty("com.iver.andami.pluginName", "Andami.Launcher"); |
||
474 | entity.addChild(ent); |
||
475 | } |
||
476 | try {
|
||
477 | persistenceToXML(entity); |
||
478 | } catch (ConfigurationException e1) { |
||
479 | logger.error(Messages.getString( |
||
480 | "Launcher.Se_produjo_un_error_guardando_la_configuracion_de_los_plugins"),
|
||
481 | e1); |
||
482 | } |
||
483 | } |
||
484 | |||
485 | 1067 | fernando | /**
|
486 | * DOCUMENT ME!
|
||
487 | */
|
||
488 | private static void installPluginsLabels() { |
||
489 | Iterator i = pluginsConfig.keySet().iterator();
|
||
490 | |||
491 | while (i.hasNext()) {
|
||
492 | String name = (String) i.next(); |
||
493 | PluginConfig pc = (PluginConfig) pluginsConfig.get(name); |
||
494 | PluginServices ps = (PluginServices) pluginsServices.get(name); |
||
495 | |||
496 | LabelSet[] ls = pc.getLabelSet();
|
||
497 | |||
498 | for (int j = 0; j < ls.length; j++) { |
||
499 | PluginClassLoader loader = ps.getClassLoader(); |
||
500 | |||
501 | try {
|
||
502 | Class clase = loader.loadClass(ls[j].getClassName());
|
||
503 | frame.setLabels(clase, ls[j].getLabel()); |
||
504 | } catch (ClassNotFoundException e) { |
||
505 | 1173 | fernando | logger.error(Messages.getString("Launcher.labelset_class"),
|
506 | 1067 | fernando | e); |
507 | } |
||
508 | 598 | fernando | } |
509 | 1067 | fernando | } |
510 | } |
||
511 | 598 | fernando | |
512 | 1067 | fernando | /**
|
513 | * DOCUMENT ME!
|
||
514 | *
|
||
515 | * @throws MDIManagerLoadException
|
||
516 | */
|
||
517 | private static void skinPlugin() throws MDIManagerLoadException { |
||
518 | Iterator i = pluginsConfig.keySet().iterator();
|
||
519 | 598 | fernando | |
520 | 1067 | fernando | while (i.hasNext()) {
|
521 | String name = (String) i.next(); |
||
522 | PluginConfig pc = (PluginConfig) pluginsConfig.get(name); |
||
523 | PluginServices ps = (PluginServices) pluginsServices.get(name); |
||
524 | |||
525 | if (pc.getExtensions().getSkinExtension() != null) { |
||
526 | if (MDIManagerFactory.getSkinExtension() != null) { |
||
527 | 1236 | fernando | logger.warn(Messages.getString( |
528 | "Launcher.Dos_skin_extension"));
|
||
529 | 1067 | fernando | } |
530 | |||
531 | SkinExtension se = pc.getExtensions().getSkinExtension(); |
||
532 | |||
533 | MDIManagerFactory.setSkinExtension(se, ps.getClassLoader()); |
||
534 | |||
535 | Class skinClass;
|
||
536 | |||
537 | try {
|
||
538 | skinClass = ps.getClassLoader().loadClass(se.getClassName()); |
||
539 | |||
540 | 5005 | jorpiell | com.iver.andami.plugins.IExtension skinInstance = (com.iver.andami.plugins.IExtension) skinClass.newInstance(); |
541 | 2862 | jaume | // classesExtensions.put(skinClass, skinInstance);
|
542 | // jaume
|
||
543 | ExtensionDecorator newExtensionDecorator = new ExtensionDecorator(skinInstance, ExtensionDecorator.INACTIVE);
|
||
544 | classesExtensions.put(skinClass, newExtensionDecorator); |
||
545 | 1067 | fernando | } catch (ClassNotFoundException e) { |
546 | 1236 | fernando | logger.error(Messages.getString( |
547 | "Launcher.No_se_encontro_la_clase_mdi_manager"), e);
|
||
548 | 1067 | fernando | throw new MDIManagerLoadException(e); |
549 | } catch (InstantiationException e) { |
||
550 | 1236 | fernando | logger.error(Messages.getString( |
551 | "Launcher.No_se_pudo_instanciar_la_clase_mdi_manager"),
|
||
552 | e); |
||
553 | 1067 | fernando | throw new MDIManagerLoadException(e); |
554 | } catch (IllegalAccessException e) { |
||
555 | 1236 | fernando | logger.error(Messages.getString( |
556 | "Launcher.No_se_pudo_acceder_a_la_clase_mdi_manager"),
|
||
557 | e); |
||
558 | 1067 | fernando | throw new MDIManagerLoadException(e); |
559 | } |
||
560 | 598 | fernando | } |
561 | 1067 | fernando | } |
562 | } |
||
563 | 598 | fernando | |
564 | 1067 | fernando | /**
|
565 | *
|
||
566 | */
|
||
567 | private static void frameIcon() { |
||
568 | Iterator i = pluginsConfig.keySet().iterator();
|
||
569 | 598 | fernando | |
570 | 1067 | fernando | while (i.hasNext()) {
|
571 | String pName = (String) i.next(); |
||
572 | PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
||
573 | PluginServices ps = (PluginServices) pluginsServices.get(pName); |
||
574 | 598 | fernando | |
575 | 1067 | fernando | if (pc.getIcon() != null) { |
576 | ImageIcon icon = new ImageIcon(ps.getClassLoader().getResource(pc.getIcon() |
||
577 | .getSrc())); |
||
578 | frame.setIconImage(icon.getImage()); |
||
579 | 1409 | fernando | frame.setTitlePrefix(pc.getIcon().getText()); |
580 | 1067 | fernando | } |
581 | } |
||
582 | } |
||
583 | 598 | fernando | |
584 | 1067 | fernando | /**
|
585 | *
|
||
586 | */
|
||
587 | private static void initializeExtensions() { |
||
588 | 2828 | fjp | Iterator i = pluginsOrdered.iterator();
|
589 | 598 | fernando | |
590 | 1067 | fernando | while (i.hasNext()) {
|
591 | String pName = (String) i.next(); |
||
592 | 2862 | jaume | logger.debug("Initializing extensions from " + pName);
|
593 | 1067 | fernando | PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
594 | PluginServices ps = (PluginServices) pluginsServices.get(pName); |
||
595 | 598 | fernando | |
596 | 1067 | fernando | Extension[] exts = pc.getExtensions().getExtension();
|
597 | 598 | fernando | |
598 | 1067 | fernando | TreeMap orderedExtensions = new TreeMap(new ExtensionComparator()); |
599 | 598 | fernando | |
600 | 1067 | fernando | for (int j = 0; j < exts.length; j++) { |
601 | if (!exts[j].getActive()) {
|
||
602 | continue;
|
||
603 | } |
||
604 | 598 | fernando | |
605 | 1067 | fernando | if (orderedExtensions.containsKey(exts[j])) {
|
606 | 1236 | fernando | logger.warn(Messages.getString( |
607 | "Launcher.Two_extensions_with_the_same_priority") +
|
||
608 | 1067 | fernando | exts[j].getClassName()); |
609 | } |
||
610 | 598 | fernando | |
611 | 1067 | fernando | orderedExtensions.put(exts[j], null);
|
612 | } |
||
613 | 598 | fernando | |
614 | 1067 | fernando | Iterator e = orderedExtensions.keySet().iterator();
|
615 | 598 | fernando | |
616 | 1067 | fernando | while (e.hasNext()) {
|
617 | Extension extension = (Extension) e.next(); |
||
618 | 5005 | jorpiell | com.iver.andami.plugins.IExtension extensionInstance; |
619 | 598 | fernando | |
620 | 1067 | fernando | try {
|
621 | Class extensionClass = ps.getClassLoader().loadClass(extension.getClassName());
|
||
622 | 5005 | jorpiell | extensionInstance = (com.iver.andami.plugins.IExtension) extensionClass.newInstance(); |
623 | 6101 | jaume | |
624 | // CON DECORATOR
|
||
625 | 2862 | jaume | // ANTES: classesExtensions.put(extensionClass, extensionInstance);
|
626 | // AHORA: CREAMOS UNA ExtensionDecorator y asignamos esta instancia para
|
||
627 | // poder ampliar con nuevas propiedades (AlwaysVisible, por ejemplo)
|
||
628 | // Para crear la nueva clase ExtensionDecorator, le pasamos como par?metro
|
||
629 | // la extensi?n original que acabamos de crear
|
||
630 | // 0-> Inactivo, controla la extension
|
||
631 | // 1-> Siempre visible
|
||
632 | // 2-> Invisible
|
||
633 | ExtensionDecorator newExtensionDecorator = new ExtensionDecorator(extensionInstance, ExtensionDecorator.INACTIVE);
|
||
634 | classesExtensions.put(extensionClass, newExtensionDecorator); |
||
635 | System.err.println("Loading "+extension.getClassName()+"..."); |
||
636 | 2828 | fjp | // logger.debug("Initializing " + extension.getClassName());
|
637 | 5005 | jorpiell | extensionInstance.initialize(); |
638 | 7303 | caballero | extensions.add(extensionInstance); |
639 | 2828 | fjp | // logger.debug(extension.getClassName() + " initialized.");
|
640 | 598 | fernando | |
641 | 1067 | fernando | } catch (InstantiationException e1) { |
642 | 1236 | fernando | logger.error(Messages.getString( |
643 | "Launcher.Error_instanciando_la_extension") +
|
||
644 | 1067 | fernando | extension.getClassName(), e1); |
645 | } catch (IllegalAccessException e1) { |
||
646 | 1236 | fernando | logger.error(Messages.getString( |
647 | "Launcher.Error_instanciando_la_extension") +
|
||
648 | 1067 | fernando | extension.getClassName(), e1); |
649 | } catch (ClassNotFoundException e1) { |
||
650 | 1236 | fernando | logger.error(Messages.getString( |
651 | "Launcher.No_se_encontro_la_clase_de_la_extension") +
|
||
652 | 1067 | fernando | extension.getClassName(), e1); |
653 | } catch (NoClassDefFoundError e1) { |
||
654 | 1236 | fernando | logger.error(Messages.getString( |
655 | "Launcher.Error_localizando_la_clase_de_la_extension") +
|
||
656 | 1067 | fernando | extension.getClassName(), e1); |
657 | } |
||
658 | } |
||
659 | } |
||
660 | } |
||
661 | 598 | fernando | |
662 | 7303 | caballero | private static void postInitializeExtensions() { |
663 | for (int i=0;i<extensions.size();i++) { |
||
664 | com.iver.andami.plugins.IExtension extensionInstance=(com.iver.andami.plugins.IExtension)extensions.get(i); |
||
665 | extensionInstance.postInitialize(); |
||
666 | } |
||
667 | } |
||
668 | 1067 | fernando | /**
|
669 | * DOCUMENT ME!
|
||
670 | */
|
||
671 | private static void installPluginsMenus() { |
||
672 | TreeMap orderedMenus = new TreeMap(new MenuComparator()); |
||
673 | 598 | fernando | |
674 | 1067 | fernando | Iterator i = pluginsConfig.keySet().iterator();
|
675 | 598 | fernando | |
676 | 1067 | fernando | while (i.hasNext()) {
|
677 | String pName = (String) i.next(); |
||
678 | PluginServices ps = (PluginServices) pluginsServices.get(pName); |
||
679 | PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
||
680 | 598 | fernando | |
681 | 1067 | fernando | Extension[] exts = pc.getExtensions().getExtension();
|
682 | 598 | fernando | |
683 | 1067 | fernando | for (int j = 0; j < exts.length; j++) { |
684 | if (!exts[j].getActive()) {
|
||
685 | continue;
|
||
686 | } |
||
687 | 598 | fernando | |
688 | 3298 | caballero | Menu[] menus = exts[j].getMenu(); |
689 | 598 | fernando | |
690 | 3298 | caballero | for (int k = 0; k < menus.length; k++) { |
691 | 1067 | fernando | SortableMenu sm = new SortableMenu(ps.getClassLoader(),
|
692 | 3298 | caballero | exts[j], menus[k]); |
693 | 598 | fernando | |
694 | 1067 | fernando | if (orderedMenus.containsKey(sm)) {
|
695 | 1236 | fernando | logger.error(Messages.getString( |
696 | 6589 | cesar | "Launcher.Two_menus_with_the_same_position") + " - " + |
697 | menus[k].getText()+ " - " + exts[j].getClassName());
|
||
698 | 1067 | fernando | } |
699 | 598 | fernando | |
700 | 1067 | fernando | orderedMenus.put(sm, null);
|
701 | } |
||
702 | } |
||
703 | 598 | fernando | |
704 | 1067 | fernando | // Se instalan las extensiones de MDI
|
705 | SkinExtension skinExt = pc.getExtensions().getSkinExtension(); |
||
706 | 598 | fernando | |
707 | 1067 | fernando | if (skinExt != null) { |
708 | Menu[] menu = skinExt.getMenu(); |
||
709 | 598 | fernando | |
710 | 1067 | fernando | for (int k = 0; k < menu.length; k++) { |
711 | SortableMenu sm = new SortableMenu(ps.getClassLoader(),
|
||
712 | skinExt, menu[k]); |
||
713 | 598 | fernando | |
714 | 1067 | fernando | if (orderedMenus.containsKey(sm)) {
|
715 | 1236 | fernando | logger.error(Messages.getString( |
716 | "Launcher.Two_menus_with_the_same_position") +
|
||
717 | 1067 | fernando | skinExt.getClassName()); |
718 | } |
||
719 | 598 | fernando | |
720 | 1067 | fernando | orderedMenus.put(sm, null);
|
721 | } |
||
722 | } |
||
723 | } |
||
724 | 598 | fernando | |
725 | 1067 | fernando | //Se itera por los menus ordenados
|
726 | Iterator e = orderedMenus.keySet().iterator();
|
||
727 | 598 | fernando | |
728 | 1067 | fernando | // Se ordenan los menues
|
729 | while (e.hasNext()) {
|
||
730 | try {
|
||
731 | SortableMenu sm = (SortableMenu) e.next(); |
||
732 | 598 | fernando | |
733 | 1067 | fernando | frame.addMenu(sm.loader, sm.extension, sm.menu); |
734 | } catch (ClassNotFoundException ex) { |
||
735 | 1236 | fernando | logger.error(Messages.getString( |
736 | "Launcher.No_se_encontro_la_clase_de_la_extension"), ex);
|
||
737 | 1067 | fernando | } |
738 | } |
||
739 | } |
||
740 | 598 | fernando | |
741 | 1067 | fernando | /**
|
742 | 6589 | cesar | * Installs the menus, toolbars, actiontools, selectable toolbars and combos.
|
743 | 6101 | jaume | * The order in which they are shown is determined here.
|
744 | 1067 | fernando | */
|
745 | private static void installPluginsControls() { |
||
746 | Iterator i = pluginsConfig.keySet().iterator();
|
||
747 | 598 | fernando | |
748 | 2112 | fernando | HashMap extensionPluginServices = new HashMap(); |
749 | HashMap extensionPluginConfig = new HashMap(); |
||
750 | TreeMap orderedExtensions = new TreeMap(new ExtensionComparator()); |
||
751 | 6101 | jaume | |
752 | 5421 | cesar | // First of all, sort the extensions.
|
753 | // We need to iterate on the plugins, and iterate on each plugin's extensions
|
||
754 | 6101 | jaume | // (each plugin may contain one or more extensions)
|
755 | 5421 | cesar | while (i.hasNext()) { // iterate on the plugins |
756 | String pName = (String) i.next(); |
||
757 | PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
||
758 | PluginServices ps = (PluginServices) pluginsServices.get(pName); |
||
759 | 6101 | jaume | |
760 | 5421 | cesar | Extension[] exts = pc.getExtensions().getExtension();
|
761 | 6101 | jaume | |
762 | 5421 | cesar | for (int j = 0; j < exts.length; j++) { // iterate on the extensions |
763 | if (exts[j].getActive()) {
|
||
764 | if (orderedExtensions.containsKey(exts[j])) {
|
||
765 | logger.error(Messages.getString( |
||
766 | "Launcher.Two_extensions_with_the_same_priority") +
|
||
767 | exts[j].getClassName()); |
||
768 | 1067 | fernando | } |
769 | 6101 | jaume | |
770 | 5421 | cesar | orderedExtensions.put(exts[j], null);
|
771 | extensionPluginServices.put(exts[j], ps); |
||
772 | extensionPluginConfig.put(exts[j], pc); |
||
773 | 1067 | fernando | } |
774 | 5421 | cesar | } |
775 | 2112 | fernando | } |
776 | 598 | fernando | |
777 | 5421 | cesar | TreeMap orderedTools = new TreeMap(new ToolComparator()); |
778 | Iterator e = orderedExtensions.keySet().iterator();
|
||
779 | 6101 | jaume | |
780 | 6614 | cesar | // sort the toolbars and tools from 'normal' extensions (actiontools, selectabletools)
|
781 | // and load the combo-scales and combo-buttons for the status bar
|
||
782 | 5421 | cesar | while (e.hasNext()) {
|
783 | Extension ext = (Extension) e.next(); |
||
784 | 6101 | jaume | |
785 | 5421 | cesar | ToolBar[] toolbars = ext.getToolBar();
|
786 | 6101 | jaume | |
787 | 6589 | cesar | // get tools from toolbars
|
788 | 5421 | cesar | for (int k = 0; k < toolbars.length; k++) { |
789 | ActionTool[] tools = toolbars[k].getActionTool();
|
||
790 | 6101 | jaume | |
791 | 5421 | cesar | for (int t = 0; t < tools.length; t++) { |
792 | 6589 | cesar | SortableTool sm = new SortableTool(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
|
793 | 5421 | cesar | toolbars[k], tools[t]); |
794 | 6589 | cesar | orderedTools.put(sm, null);
|
795 | 5421 | cesar | } |
796 | 6101 | jaume | |
797 | 5421 | cesar | SelectableTool[] sTools = toolbars[k].getSelectableTool();
|
798 | 6101 | jaume | |
799 | 5421 | cesar | for (int t = 0; t < sTools.length; t++) { |
800 | 6589 | cesar | SortableTool sm=new SortableTool(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
|
801 | 5421 | cesar | toolbars[k], sTools[t]); |
802 | 6589 | cesar | orderedTools.put(sm, null);
|
803 | 5421 | cesar | } |
804 | } |
||
805 | 6861 | jaume | |
806 | 6589 | cesar | // get controls for statusBar
|
807 | PluginServices ps = (PluginServices) extensionPluginServices.get(ext); |
||
808 | PluginClassLoader loader = ps.getClassLoader(); |
||
809 | 6861 | jaume | |
810 | 6589 | cesar | //ArrayList componentList = new ArrayList();
|
811 | ComboScale[] comboScaleArray = ext.getComboScale();
|
||
812 | for (int k=0; k < comboScaleArray.length; k++) { |
||
813 | org.gvsig.gui.beans.controls.comboscale.ComboScale combo = new org.gvsig.gui.beans.controls.comboscale.ComboScale();
|
||
814 | 6619 | cesar | String label = comboScaleArray[k].getLabel();
|
815 | if (label!=null) |
||
816 | combo.setLabel(label); |
||
817 | 6623 | cesar | String name = comboScaleArray[k].getName();
|
818 | if (name!=null) |
||
819 | combo.setName(name); |
||
820 | 6589 | cesar | String[] elementsString = ((String)comboScaleArray[k].getElements()).split(";"); |
821 | long[] elements = new long[elementsString.length]; |
||
822 | for (int currentElem=0; currentElem<elementsString.length; currentElem++) { |
||
823 | try {
|
||
824 | elements[currentElem] = Long.parseLong(elementsString[currentElem]);
|
||
825 | } |
||
826 | catch (NumberFormatException nfex1) { |
||
827 | 6918 | cesar | logger.error(ext.getClassName()+" -- "+Messages.getString( "error_parsing_comboscale_elements")); |
828 | 6589 | cesar | elements[currentElem] = 0;
|
829 | } |
||
830 | } |
||
831 | combo.setItems(elements); |
||
832 | try {
|
||
833 | long value = Long.parseLong((String)comboScaleArray[k].getValue()); |
||
834 | combo.setScale(value); |
||
835 | } |
||
836 | catch (NumberFormatException nfex2) { |
||
837 | 6918 | cesar | logger.error(ext.getClassName()+" -- "+Messages.getString( "error_parsing_comboscale_value")); |
838 | 6589 | cesar | } |
839 | try {
|
||
840 | 6614 | cesar | frame.addStatusBarControl(loader.loadClass(ext.getClassName()),combo); |
841 | 6589 | cesar | } catch (ClassNotFoundException e1) { |
842 | logger.error(Messages.getString("Launcher.error_getting_class_loader_for_status_bar_control"), e1);
|
||
843 | } |
||
844 | } |
||
845 | |||
846 | ComboButton[] comboButtonArray = ext.getComboButton();
|
||
847 | for (int k=0; k < comboButtonArray.length; k++) { |
||
848 | ComboButtonElement[] elementList = comboButtonArray[k].getComboButtonElement();
|
||
849 | org.gvsig.gui.beans.controls.combobutton.ComboButton combo = new org.gvsig.gui.beans.controls.combobutton.ComboButton();
|
||
850 | 6623 | cesar | String name = comboButtonArray[k].getName();
|
851 | if (name!=null) |
||
852 | combo.setName(name); |
||
853 | 6589 | cesar | for (int currentElement=0; currentElement<elementList.length; currentElement++) { |
854 | ComboButtonElement element = elementList[currentElement]; |
||
855 | ImageIcon icon;
|
||
856 | URL iconLocation = loader.getResource(element.getIcon());
|
||
857 | if (iconLocation==null) |
||
858 | logger.error(Messages.getString("Icon_not_found_")+element.getIcon());
|
||
859 | else {
|
||
860 | icon = new ImageIcon(iconLocation); |
||
861 | JButton button = new JButton(icon); |
||
862 | combo.addButton(button); |
||
863 | button.setActionCommand(element.getActionCommand()); |
||
864 | } |
||
865 | } |
||
866 | try {
|
||
867 | 6614 | cesar | frame.addStatusBarControl(loader.loadClass(ext.getClassName()), combo); |
868 | 6589 | cesar | } catch (ClassNotFoundException e1) { |
869 | logger.error(Messages.getString("Launcher.error_getting_class_loader_for_status_bar_control"), e1);
|
||
870 | } |
||
871 | } |
||
872 | 5421 | cesar | } |
873 | 598 | fernando | |
874 | 6589 | cesar | // Add the tools from MDI extensions to the ordered tool-list, so that we get a sorted list containing all the tools
|
875 | 5421 | cesar | i = pluginsConfig.keySet().iterator(); |
876 | while (i.hasNext()) {
|
||
877 | String pName = (String) i.next(); |
||
878 | PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
||
879 | PluginServices ps = (PluginServices) pluginsServices.get(pName); |
||
880 | 6101 | jaume | |
881 | 5421 | cesar | SkinExtension skinExt = pc.getExtensions().getSkinExtension(); |
882 | 6101 | jaume | |
883 | 5421 | cesar | if (skinExt != null) { |
884 | ToolBar[] toolbars = skinExt.getToolBar();
|
||
885 | 6101 | jaume | |
886 | 2112 | fernando | for (int k = 0; k < toolbars.length; k++) { |
887 | ActionTool[] tools = toolbars[k].getActionTool();
|
||
888 | 6101 | jaume | |
889 | 2112 | fernando | for (int t = 0; t < tools.length; t++) { |
890 | 6589 | cesar | SortableTool stb=new SortableTool(ps.getClassLoader(), skinExt,
|
891 | 3298 | caballero | toolbars[k], tools[t]); |
892 | 6589 | cesar | orderedTools.put(stb,null);
|
893 | 2112 | fernando | } |
894 | 6101 | jaume | |
895 | 2112 | fernando | SelectableTool[] sTools = toolbars[k].getSelectableTool();
|
896 | 6101 | jaume | |
897 | 2112 | fernando | for (int t = 0; t < sTools.length; t++) { |
898 | 6589 | cesar | SortableTool stb=new SortableTool(ps.getClassLoader(), skinExt,
|
899 | 3298 | caballero | toolbars[k], sTools[t]); |
900 | 6589 | cesar | orderedTools.put(stb,null);
|
901 | 1067 | fernando | } |
902 | } |
||
903 | 2112 | fernando | } |
904 | 6589 | cesar | // Install popup menus
|
905 | 5421 | cesar | PopupMenus pus = pc.getPopupMenus(); |
906 | 6101 | jaume | |
907 | 5421 | cesar | if (pus != null) { |
908 | PopupMenu[] menus = pus.getPopupMenu(); |
||
909 | 6101 | jaume | |
910 | 5421 | cesar | for (int j = 0; j < menus.length; j++) { |
911 | frame.addPopupMenu(ps.getClassLoader(), menus[j]); |
||
912 | 1067 | fernando | } |
913 | } |
||
914 | 5421 | cesar | } |
915 | 3298 | caballero | |
916 | 6589 | cesar | // loop on the ordered extension list, to add them to the interface in an ordered way
|
917 | 6101 | jaume | Iterator t = orderedTools.keySet().iterator();
|
918 | 5421 | cesar | while (t.hasNext()) {
|
919 | try {
|
||
920 | 6589 | cesar | SortableTool stb = (SortableTool) t.next(); |
921 | 5421 | cesar | if (stb.actiontool!=null) |
922 | frame.addTool(stb.loader, stb.extension,stb.toolbar, stb.actiontool); |
||
923 | else
|
||
924 | frame.addTool(stb.loader, stb.extension,stb.toolbar, stb.selectabletool); |
||
925 | } catch (ClassNotFoundException ex) { |
||
926 | logger.error(Messages.getString( |
||
927 | "Launcher.No_se_encontro_la_clase_de_la_extension"), ex);
|
||
928 | 3298 | caballero | } |
929 | 5421 | cesar | } |
930 | 1067 | fernando | } |
931 | 598 | fernando | |
932 | 1067 | fernando | /**
|
933 | 6861 | jaume | * Adds new plugins to the the andami-config file.
|
934 | 1067 | fernando | */
|
935 | private static void updateAndamiConfig() { |
||
936 | HashSet olds = new HashSet(); |
||
937 | 598 | fernando | |
938 | 1067 | fernando | Plugin[] plugins = andamiConfig.getPlugin();
|
939 | 598 | fernando | |
940 | 1067 | fernando | for (int i = 0; i < plugins.length; i++) { |
941 | olds.add(plugins[i].getName()); |
||
942 | } |
||
943 | 598 | fernando | |
944 | 1067 | fernando | Iterator i = pluginsServices.values().iterator();
|
945 | 598 | fernando | |
946 | 1067 | fernando | while (i.hasNext()) {
|
947 | PluginServices ps = (PluginServices) i.next(); |
||
948 | 598 | fernando | |
949 | 1067 | fernando | if (!olds.contains(ps.getPluginName())) {
|
950 | Plugin p = new Plugin();
|
||
951 | p.setName(ps.getPluginName()); |
||
952 | p.setUpdate(false);
|
||
953 | 598 | fernando | |
954 | 1067 | fernando | andamiConfig.addPlugin(p); |
955 | } |
||
956 | } |
||
957 | } |
||
958 | 598 | fernando | |
959 | 1067 | fernando | /**
|
960 | * DOCUMENT ME!
|
||
961 | */
|
||
962 | private static void pluginsClassLoaders() { |
||
963 | HashSet instalados = new HashSet(); |
||
964 | 598 | fernando | |
965 | 1067 | fernando | // Se itera hasta que est?n todos instalados
|
966 | while (instalados.size() != pluginsConfig.size()) {
|
||
967 | boolean circle = true; |
||
968 | 598 | fernando | |
969 | 1067 | fernando | //Hacemos una pasada por todos los plugins
|
970 | Iterator i = pluginsConfig.keySet().iterator();
|
||
971 | 598 | fernando | |
972 | 1067 | fernando | while (i.hasNext()) {
|
973 | String pluginName = (String) i.next(); |
||
974 | PluginConfig config = (PluginConfig) pluginsConfig.get(pluginName); |
||
975 | 598 | fernando | |
976 | 1067 | fernando | if (instalados.contains(pluginName)) {
|
977 | continue;
|
||
978 | } |
||
979 | 598 | fernando | |
980 | 1067 | fernando | //Se obtienen las dependencias y sus class loaders
|
981 | boolean ready = true; |
||
982 | Depends[] dependencies = config.getDepends();
|
||
983 | PluginClassLoader[] loaders = new PluginClassLoader[dependencies.length]; |
||
984 | 598 | fernando | |
985 | 1067 | fernando | for (int j = 0; j < dependencies.length; j++) { |
986 | if (pluginsConfig.get(dependencies[j].getPluginName()) == null) { |
||
987 | 1236 | fernando | logger.error(Messages.getString( |
988 | "Launcher.Dependencia_no_resuelta_en_plugin") +
|
||
989 | 1067 | fernando | pluginName + ": " +
|
990 | 1153 | fernando | dependencies[j].getPluginName()); |
991 | 598 | fernando | |
992 | 1067 | fernando | continue;
|
993 | } |
||
994 | 598 | fernando | |
995 | 1067 | fernando | if (!instalados.contains(dependencies[j].getPluginName())) {
|
996 | ready = false;
|
||
997 | } else {
|
||
998 | loaders[j] = ((PluginServices) pluginsServices.get(dependencies[j].getPluginName())).getClassLoader(); |
||
999 | } |
||
1000 | } |
||
1001 | 598 | fernando | |
1002 | 1067 | fernando | //Si no est?n sus dependencias satisfechas se aborta la instalaci?n
|
1003 | if (!ready) {
|
||
1004 | continue;
|
||
1005 | } |
||
1006 | 598 | fernando | |
1007 | 1067 | fernando | //Se genera el class loader
|
1008 | 1110 | fernando | String jardir = config.getLibraries().getLibraryDir();
|
1009 | File jarDir = new File(andamiConfig.getPluginsDirectory() + |
||
1010 | File.separator + pluginName + File.separator + jardir); |
||
1011 | File[] jarFiles = jarDir.listFiles(new FileFilter() { |
||
1012 | 1236 | fernando | public boolean accept(File pathname) { |
1013 | return (pathname.getName().toUpperCase()
|
||
1014 | .endsWith(".JAR")) ||
|
||
1015 | (pathname.getName().toUpperCase().endsWith(".ZIP"));
|
||
1016 | } |
||
1017 | }); |
||
1018 | |||
1019 | 1110 | fernando | URL[] urls = new URL[jarFiles.length]; |
1020 | 1236 | fernando | |
1021 | 1110 | fernando | for (int j = 0; j < jarFiles.length; j++) { |
1022 | 1067 | fernando | try {
|
1023 | 1110 | fernando | urls[j] = new URL("file:" + jarFiles[j]); |
1024 | 1067 | fernando | } catch (MalformedURLException e) { |
1025 | 1236 | fernando | logger.error(Messages.getString( |
1026 | "Launcher.No_se_puede_acceder_a") +
|
||
1027 | 1110 | fernando | jarFiles[j]); |
1028 | 1067 | fernando | } |
1029 | } |
||
1030 | 598 | fernando | |
1031 | 1067 | fernando | PluginClassLoader loader; |
1032 | 598 | fernando | |
1033 | 1067 | fernando | try {
|
1034 | loader = new PluginClassLoader(urls,
|
||
1035 | andamiConfig.getPluginsDirectory() + |
||
1036 | File.separator + pluginName,
|
||
1037 | Launcher.class.getClassLoader(), loaders); |
||
1038 | 598 | fernando | |
1039 | 1067 | fernando | PluginServices ps = new PluginServices(loader);
|
1040 | 598 | fernando | |
1041 | 1067 | fernando | pluginsServices.put(ps.getPluginName(), ps); |
1042 | 598 | fernando | |
1043 | 1067 | fernando | instalados.add(pluginName); |
1044 | 6101 | jaume | // FJP: Los metemos ordenados para luego no cargar uno que necesita de otro antes de tiempo. Esto lo usaremos al
|
1045 | 2828 | fjp | // inicializar los plugins
|
1046 | pluginsOrdered.add(pluginName); |
||
1047 | 598 | fernando | |
1048 | 1067 | fernando | circle = false;
|
1049 | } catch (IOException e) { |
||
1050 | 1236 | fernando | logger.error(Messages.getString( |
1051 | "Launcher.Error_con_las_librerias_del_plugin"), e);
|
||
1052 | 1067 | fernando | pluginsConfig.remove(pluginName); |
1053 | i = pluginsConfig.keySet().iterator(); |
||
1054 | } |
||
1055 | } |
||
1056 | 598 | fernando | |
1057 | 1067 | fernando | if (circle) {
|
1058 | 1236 | fernando | logger.error(Messages.getString( |
1059 | "Launcher.Hay_dependencias_circulares"));
|
||
1060 | 598 | fernando | |
1061 | 1067 | fernando | break;
|
1062 | } |
||
1063 | } |
||
1064 | 598 | fernando | |
1065 | 1067 | fernando | //Se eliminan los plugins que no fueron instalados
|
1066 | Iterator i = pluginsConfig.keySet().iterator();
|
||
1067 | 598 | fernando | |
1068 | 1067 | fernando | while (i.hasNext()) {
|
1069 | String pluginName = (String) i.next(); |
||
1070 | PluginConfig config = (PluginConfig) pluginsConfig.get(pluginName); |
||
1071 | PluginServices ps = (PluginServices) pluginsServices.get(pluginName); |
||
1072 | 598 | fernando | |
1073 | 1067 | fernando | if (ps == null) { |
1074 | pluginsConfig.remove(pluginName); |
||
1075 | i = pluginsConfig.keySet().iterator(); |
||
1076 | } |
||
1077 | 6101 | jaume | } |
1078 | 1067 | fernando | } |
1079 | 598 | fernando | |
1080 | 1067 | fernando | /**
|
1081 | * DOCUMENT ME!
|
||
1082 | */
|
||
1083 | private static void pluginsMessages() { |
||
1084 | 6101 | jaume | /* add gvsig translations first. This should be done using a generic "appPlugin" variable, instead
|
1085 | 4909 | cesar | * of using "com.iver.cit.gvsig" directly, but I'll do it when we use the new appgvSIG launcher.
|
1086 | 6101 | jaume | * I keep this workaround for the moment.
|
1087 | 4909 | cesar | */
|
1088 | PluginConfig config = (PluginConfig) pluginsConfig.get("com.iver.cit.gvsig");
|
||
1089 | PluginServices ps = (PluginServices) pluginsServices.get("com.iver.cit.gvsig");
|
||
1090 | if (config.getResourceBundle() != null) { |
||
1091 | org.gvsig.i18n.Messages.addResourceFamily(config.getResourceBundle().getName(), ps.getClassLoader(), "com.iver.cit.gvsig");
|
||
1092 | } |
||
1093 | |||
1094 | 1067 | fernando | //Iteramos por todos los plugins
|
1095 | Iterator i = pluginsConfig.keySet().iterator();
|
||
1096 | 6101 | jaume | |
1097 | 1067 | fernando | while (i.hasNext()) {
|
1098 | String pluginName = (String) i.next(); |
||
1099 | 4909 | cesar | if (!pluginName.equals("com.iver.cit.gvsig")) { // we've already loaded com.iver.cit.gvsig |
1100 | config = (PluginConfig) pluginsConfig.get(pluginName); |
||
1101 | ps = (PluginServices) pluginsServices.get(pluginName); |
||
1102 | 6101 | jaume | |
1103 | 4909 | cesar | if (config.getResourceBundle() != null && !config.getResourceBundle().getName().equals("")) { |
1104 | // add the locale files associated with the plugin
|
||
1105 | org.gvsig.i18n.Messages.addResourceFamily(config.getResourceBundle().getName(), ps.getClassLoader(), pluginName); |
||
1106 | } |
||
1107 | 1067 | fernando | } |
1108 | } |
||
1109 | } |
||
1110 | 598 | fernando | |
1111 | 1067 | fernando | /**
|
1112 | * DOCUMENT ME!
|
||
1113 | *
|
||
1114 | * @param name DOCUMENT ME!
|
||
1115 | *
|
||
1116 | * @return DOCUMENT ME!
|
||
1117 | */
|
||
1118 | static PluginServices getPluginServices(String name) { |
||
1119 | return (PluginServices) pluginsServices.get(name);
|
||
1120 | } |
||
1121 | 598 | fernando | |
1122 | 1067 | fernando | /**
|
1123 | * DOCUMENT ME!
|
||
1124 | *
|
||
1125 | * @return DOCUMENT ME!
|
||
1126 | */
|
||
1127 | static String getPluginsDir() { |
||
1128 | return andamiConfig.getPluginsDirectory();
|
||
1129 | } |
||
1130 | 598 | fernando | |
1131 | 1067 | fernando | /**
|
1132 | * DOCUMENT ME!
|
||
1133 | *
|
||
1134 | * @param s DOCUMENT ME!
|
||
1135 | */
|
||
1136 | static void setPluginsDir(String s) { |
||
1137 | andamiConfig.setPluginsDirectory(s); |
||
1138 | } |
||
1139 | 598 | fernando | |
1140 | 1067 | fernando | /**
|
1141 | * DOCUMENT ME!
|
||
1142 | *
|
||
1143 | * @return DOCUMENT ME!
|
||
1144 | */
|
||
1145 | static MDIFrame getMDIFrame() {
|
||
1146 | return frame;
|
||
1147 | } |
||
1148 | 598 | fernando | |
1149 | 1067 | fernando | /**
|
1150 | * DOCUMENT ME!
|
||
1151 | *
|
||
1152 | * @param pluginsDirectory
|
||
1153 | */
|
||
1154 | private static void loadPlugins(String pluginsDirectory) { |
||
1155 | File pDir = new File(pluginsDirectory); |
||
1156 | 598 | fernando | |
1157 | 1067 | fernando | if (!pDir.exists()) {
|
1158 | return;
|
||
1159 | } |
||
1160 | 598 | fernando | |
1161 | 1067 | fernando | File[] pluginDirs = pDir.listFiles(); |
1162 | 598 | fernando | |
1163 | 1067 | fernando | for (int i = 0; i < pluginDirs.length; i++) { |
1164 | if (pluginDirs[i].isDirectory()) {
|
||
1165 | File configXml = new File(pluginDirs[i].getAbsolutePath() + |
||
1166 | File.separator + "config.xml"); |
||
1167 | 598 | fernando | |
1168 | 1067 | fernando | try {
|
1169 | 8752 | cesar | FileInputStream is = new FileInputStream(configXml); |
1170 | Reader xml = com.iver.utiles.xml.XMLEncodingUtils.getReader(is);
|
||
1171 | if (xml==null) { |
||
1172 | // the encoding was not correctly detected, use system default
|
||
1173 | xml = new FileReader(configXml); |
||
1174 | } |
||
1175 | else {
|
||
1176 | // use a buffered reader to improve performance
|
||
1177 | xml = new BufferedReader(xml); |
||
1178 | } |
||
1179 | 1067 | fernando | PluginConfig pConfig = (PluginConfig) PluginConfig.unmarshal(xml); |
1180 | pluginsConfig.put(pluginDirs[i].getName(), pConfig); |
||
1181 | } catch (FileNotFoundException e) { |
||
1182 | 1236 | fernando | logger.info(Messages.getString( |
1183 | "Launcher.Ignorando_el_directorio") +
|
||
1184 | 1067 | fernando | pluginDirs[i].getAbsolutePath() + |
1185 | 1173 | fernando | Messages.getString("Launcher.config_no_encontrado"));
|
1186 | 1067 | fernando | } catch (MarshalException e) { |
1187 | 1236 | fernando | logger.info(Messages.getString( |
1188 | "Launcher.Ignorando_el_directorio") +
|
||
1189 | 1067 | fernando | pluginDirs[i].getAbsolutePath() + |
1190 | 1173 | fernando | Messages.getString("Launcher.config_mal_formado"), e);
|
1191 | 1067 | fernando | } catch (ValidationException e) {
|
1192 | 1236 | fernando | logger.info(Messages.getString( |
1193 | "Launcher.Ignorando_el_directorio") +
|
||
1194 | 1067 | fernando | pluginDirs[i].getAbsolutePath() + |
1195 | 1173 | fernando | Messages.getString("Launcher.config_mal_formado"), e);
|
1196 | 1067 | fernando | } |
1197 | } |
||
1198 | } |
||
1199 | } |
||
1200 | 598 | fernando | |
1201 | 1067 | fernando | /**
|
1202 | * DOCUMENT ME!
|
||
1203 | *
|
||
1204 | * @param language
|
||
1205 | * @param country
|
||
1206 | * @param variant
|
||
1207 | *
|
||
1208 | * @return DOCUMENT ME!
|
||
1209 | */
|
||
1210 | private static Locale getLocale(String language, String country, |
||
1211 | String variant) {
|
||
1212 | if (variant != null) { |
||
1213 | return new Locale(language, country, variant); |
||
1214 | } else if (country != null) { |
||
1215 | return new Locale(language, country); |
||
1216 | } else if (language != null) { |
||
1217 | return new Locale(language); |
||
1218 | } else {
|
||
1219 | return new Locale("es"); |
||
1220 | } |
||
1221 | } |
||
1222 | 598 | fernando | |
1223 | 1067 | fernando | /**
|
1224 | * DOCUMENT ME!
|
||
1225 | *
|
||
1226 | * @param file DOCUMENT ME!
|
||
1227 | *
|
||
1228 | * @throws IOException DOCUMENT ME!
|
||
1229 | * @throws MarshalException DOCUMENT ME!
|
||
1230 | * @throws ValidationException DOCUMENT ME!
|
||
1231 | */
|
||
1232 | private static void andamiConfigToXML(String file) |
||
1233 | throws IOException, MarshalException, ValidationException { |
||
1234 | File xml = new File(file); |
||
1235 | File parent = xml.getParentFile();
|
||
1236 | parent.mkdirs(); |
||
1237 | 598 | fernando | |
1238 | 1067 | fernando | FileWriter writer = new FileWriter(xml); |
1239 | andamiConfig.marshal(writer); |
||
1240 | } |
||
1241 | 598 | fernando | |
1242 | 1067 | fernando | /**
|
1243 | * DOCUMENT ME!
|
||
1244 | *
|
||
1245 | * @param file DOCUMENT ME!
|
||
1246 | *
|
||
1247 | * @throws ConfigurationException DOCUMENT ME!
|
||
1248 | */
|
||
1249 | private static void andamiConfigFromXML(String file) |
||
1250 | throws ConfigurationException { |
||
1251 | File xml = new File(file); |
||
1252 | 598 | fernando | |
1253 | 1067 | fernando | //Si no existe se ponen los valores por defecto
|
1254 | if (!xml.exists()) {
|
||
1255 | andamiConfig = new AndamiConfig();
|
||
1256 | 598 | fernando | |
1257 | 1067 | fernando | Andami andami = new Andami();
|
1258 | andami.setUpdate(true);
|
||
1259 | andamiConfig.setAndami(andami); |
||
1260 | andamiConfig.setLocaleCountry(Locale.getDefault().getCountry());
|
||
1261 | andamiConfig.setLocaleLanguage(Locale.getDefault().getLanguage());
|
||
1262 | andamiConfig.setLocaleVariant(Locale.getDefault().getVariant());
|
||
1263 | 598 | fernando | |
1264 | 1067 | fernando | if (System.getProperty("javawebstart.version") != null) // Es java web start) |
1265 | { |
||
1266 | 8120 | jmvivo | andamiConfig.setPluginsDirectory(new File(appHomeDir |
1267 | + "extensiones").getAbsolutePath());
|
||
1268 | 1067 | fernando | } else {
|
1269 | andamiConfig.setPluginsDirectory(new File(appName + |
||
1270 | File.separator + "extensiones").getAbsolutePath()); |
||
1271 | } |
||
1272 | 598 | fernando | |
1273 | 1067 | fernando | andamiConfig.setPlugin(new Plugin[0]); |
1274 | } else {
|
||
1275 | //Se lee la configuraci?n
|
||
1276 | FileReader reader;
|
||
1277 | 598 | fernando | |
1278 | 1067 | fernando | try {
|
1279 | reader = new FileReader(xml); |
||
1280 | andamiConfig = (AndamiConfig) AndamiConfig.unmarshal(reader); |
||
1281 | } catch (FileNotFoundException e) { |
||
1282 | throw new ConfigurationException(e); |
||
1283 | } catch (MarshalException e) { |
||
1284 | throw new ConfigurationException(e); |
||
1285 | } catch (ValidationException e) {
|
||
1286 | throw new ConfigurationException(e); |
||
1287 | } |
||
1288 | } |
||
1289 | } |
||
1290 | 598 | fernando | |
1291 | 1067 | fernando | /**
|
1292 | * DOCUMENT ME!
|
||
1293 | *
|
||
1294 | * @return DOCUMENT ME!
|
||
1295 | *
|
||
1296 | * @throws ConfigurationException DOCUMENT ME!
|
||
1297 | */
|
||
1298 | private static XMLEntity persistenceFromXML() throws ConfigurationException { |
||
1299 | File xml = new File(pluginsPersistencePath); |
||
1300 | 598 | fernando | |
1301 | 1067 | fernando | if (xml.exists()) {
|
1302 | FileReader reader;
|
||
1303 | 598 | fernando | |
1304 | 1067 | fernando | try {
|
1305 | reader = new FileReader(xml); |
||
1306 | 598 | fernando | |
1307 | 1067 | fernando | XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
1308 | 598 | fernando | |
1309 | 1067 | fernando | return new XMLEntity(tag); |
1310 | } catch (FileNotFoundException e) { |
||
1311 | throw new ConfigurationException(e); |
||
1312 | } catch (MarshalException e) { |
||
1313 | throw new ConfigurationException(e); |
||
1314 | } catch (ValidationException e) {
|
||
1315 | throw new ConfigurationException(e); |
||
1316 | } |
||
1317 | } else {
|
||
1318 | return new XMLEntity(); |
||
1319 | } |
||
1320 | } |
||
1321 | 598 | fernando | |
1322 | 1067 | fernando | /**
|
1323 | * DOCUMENT ME!
|
||
1324 | *
|
||
1325 | * @param entity DOCUMENT ME!
|
||
1326 | *
|
||
1327 | * @throws ConfigurationException DOCUMENT ME!
|
||
1328 | */
|
||
1329 | private static void persistenceToXML(XMLEntity entity) |
||
1330 | throws ConfigurationException { |
||
1331 | File xml = new File(pluginsPersistencePath); |
||
1332 | 598 | fernando | |
1333 | 1067 | fernando | FileWriter writer;
|
1334 | 598 | fernando | |
1335 | 1067 | fernando | try {
|
1336 | writer = new FileWriter(xml); |
||
1337 | entity.getXmlTag().marshal(writer); |
||
1338 | } catch (FileNotFoundException e) { |
||
1339 | throw new ConfigurationException(e); |
||
1340 | } catch (MarshalException e) { |
||
1341 | throw new ConfigurationException(e); |
||
1342 | } catch (ValidationException e) {
|
||
1343 | throw new ConfigurationException(e); |
||
1344 | } catch (IOException e) { |
||
1345 | throw new ConfigurationException(e); |
||
1346 | } |
||
1347 | } |
||
1348 | 598 | fernando | |
1349 | 1067 | fernando | /**
|
1350 | * Devuelve un array con los directorios de los plugins
|
||
1351 | *
|
||
1352 | * @param dirExt Directorio de las extensiones a partir del cual cuelgan
|
||
1353 | * todos los directorios de los plugins
|
||
1354 | *
|
||
1355 | * @return ArrayList con los directorios
|
||
1356 | */
|
||
1357 | private String[] getLocales(File dirExt) { |
||
1358 | ArrayList types = new ArrayList(); |
||
1359 | File[] files = dirExt.listFiles(); |
||
1360 | 598 | fernando | |
1361 | 1067 | fernando | for (int i = 0; i < files.length; i++) { |
1362 | if (files[i].isDirectory()) {
|
||
1363 | File[] textFile = files[i].listFiles(new FilenameFilter() { |
||
1364 | public boolean accept(File dir, String fileName) { |
||
1365 | return fileName.toLowerCase().startsWith("text_"); //$NON-NLS-1$ |
||
1366 | } |
||
1367 | }); |
||
1368 | 598 | fernando | |
1369 | 1067 | fernando | for (int j = 0; j < textFile.length; j++) { |
1370 | String s = (textFile[j]).getName().replaceAll("text_", ""); |
||
1371 | s = s.replaceAll(".properties", ""); |
||
1372 | s = s.trim(); |
||
1373 | 598 | fernando | |
1374 | 1067 | fernando | if (!types.contains(s)) {
|
1375 | types.add(s); |
||
1376 | } |
||
1377 | } |
||
1378 | } |
||
1379 | } |
||
1380 | 598 | fernando | |
1381 | 1067 | fernando | return (String[]) types.toArray(new String[0]); |
1382 | } |
||
1383 | 598 | fernando | |
1384 | 1067 | fernando | /**
|
1385 | * DOCUMENT ME!
|
||
1386 | *
|
||
1387 | * @return Returns the frame.
|
||
1388 | */
|
||
1389 | static MDIFrame getFrame() {
|
||
1390 | return frame;
|
||
1391 | } |
||
1392 | 598 | fernando | |
1393 | 1067 | fernando | /**
|
1394 | * Secuencia de cerrado de Andami
|
||
1395 | */
|
||
1396 | public static void closeApplication() { |
||
1397 | //Configuraci?n de Andami
|
||
1398 | try {
|
||
1399 | andamiConfigToXML(andamiConfigPath); |
||
1400 | } catch (MarshalException e) { |
||
1401 | 1236 | fernando | logger.error(Messages.getString( |
1402 | "Launcher.No_se_pudo_guardar_la_configuracion_de_andami"), e);
|
||
1403 | 1067 | fernando | } catch (ValidationException e) {
|
1404 | 1236 | fernando | logger.error(Messages.getString( |
1405 | "Launcher.No_se_pudo_guardar_la_configuracion_de_andami"), e);
|
||
1406 | 1067 | fernando | } catch (IOException e) { |
1407 | 1236 | fernando | logger.error(Messages.getString( |
1408 | "Launcher.No_se_pudo_guardar_la_configuracion_de_andami"), e);
|
||
1409 | 1067 | fernando | } |
1410 | 598 | fernando | |
1411 | 1067 | fernando | //Persistencia de los plugins
|
1412 | 4299 | luisw2 | savePluginPersistence(); |
1413 | 6101 | jaume | |
1414 | 5005 | jorpiell | //Finalize all the extensions
|
1415 | finalizeExtensions(); |
||
1416 | 6101 | jaume | |
1417 | 3707 | jaume | // Clean any temp data created
|
1418 | Utilities.cleanUpTempFiles();
|
||
1419 | 6101 | jaume | |
1420 | 1236 | fernando | //Para la depuraci?n de memory leaks
|
1421 | System.gc();
|
||
1422 | |||
1423 | System.exit(0); |
||
1424 | 1067 | fernando | } |
1425 | 6101 | jaume | |
1426 | 5005 | jorpiell | /**
|
1427 | 8761 | cesar | * Exectutes the terminate method for all the extensions, in the reverse
|
1428 | * order they were initialized
|
||
1429 | 5005 | jorpiell | *
|
1430 | */
|
||
1431 | private static void finalizeExtensions() { |
||
1432 | 8761 | cesar | for (int i=extensions.size()-1; i>=0; i--) { |
1433 | com.iver.andami.plugins.IExtension extensionInstance=(com.iver.andami.plugins.IExtension)extensions.get(i); |
||
1434 | extensionInstance.terminate(); |
||
1435 | 6101 | jaume | } |
1436 | 5005 | jorpiell | } |
1437 | 598 | fernando | |
1438 | 5005 | jorpiell | |
1439 | 1067 | fernando | /**
|
1440 | * DOCUMENT ME!
|
||
1441 | *
|
||
1442 | * @return DOCUMENT ME!
|
||
1443 | */
|
||
1444 | static HashMap getClassesExtensions() { |
||
1445 | return classesExtensions;
|
||
1446 | } |
||
1447 | 598 | fernando | |
1448 | 1067 | fernando | /**
|
1449 | * DOCUMENT ME!
|
||
1450 | *
|
||
1451 | 2332 | fjp | * @param extDir DOCUMENT ME!
|
1452 | */
|
||
1453 | private static void downloadExtensions(String extDir) { |
||
1454 | java.util.Date fechaActual = null;
|
||
1455 | |||
1456 | try {
|
||
1457 | if (System.getProperty("javawebstart.version") != null) { |
||
1458 | //Obtenemos la URL del servidor
|
||
1459 | BasicService bs = (BasicService) ServiceManager.lookup( |
||
1460 | "javax.jnlp.BasicService");
|
||
1461 | URL baseURL = bs.getCodeBase();
|
||
1462 | |||
1463 | //Se descargan las extensiones
|
||
1464 | 7303 | caballero | MultiSplashWindow.process(5,
|
1465 | 2332 | fjp | "Descargando las extensiones desde " + baseURL + " a " + |
1466 | extDir); |
||
1467 | |||
1468 | URL url = new URL(baseURL + "extensiones.zip"); |
||
1469 | URLConnection connection = url.openConnection();
|
||
1470 | |||
1471 | System.out.println(url.toExternalForm() + ":"); |
||
1472 | System.out.println(" Content Type: " + |
||
1473 | connection.getContentType()); |
||
1474 | System.out.println(" Content Length: " + |
||
1475 | connection.getContentLength()); |
||
1476 | System.out.println(" Last Modified: " + |
||
1477 | new Date(connection.getLastModified())); |
||
1478 | System.out.println(" Expiration: " + |
||
1479 | connection.getExpiration()); |
||
1480 | System.out.println(" Content Encoding: " + |
||
1481 | connection.getContentEncoding()); |
||
1482 | |||
1483 | // Guardamos la fecha del fichero de extensiones que nos hemos bajado, y
|
||
1484 | // comprobamos el ?ltimo que se ha bajado. Si no son
|
||
1485 | // iguales, nos bajamos el nuevo. Si son iguales, no
|
||
1486 | // nos bajamos nada.
|
||
1487 | Long miliSecondsInWeb = new Long(connection.getLastModified()); |
||
1488 | |||
1489 | // PluginServices ps = PluginServices.getPluginServices("com.iver.core");
|
||
1490 | // if (ps.getPersistentXML().getStringProperty("timestamp") != null)
|
||
1491 | File destDir = new File(extDir); |
||
1492 | |||
1493 | if (!destDir.exists()) {
|
||
1494 | // Creamos gvSIG
|
||
1495 | destDir.getParentFile().mkdir(); |
||
1496 | |||
1497 | if (!destDir.mkdir()) {
|
||
1498 | System.err.println("Imposible crear el directorio " + |
||
1499 | destDir.getAbsolutePath()); |
||
1500 | } |
||
1501 | } |
||
1502 | |||
1503 | File timeFile = new File(destDir.getParent() + File.separator + |
||
1504 | "timeStamp.properties");
|
||
1505 | |||
1506 | if (!timeFile.exists()) {
|
||
1507 | timeFile.createNewFile(); |
||
1508 | } |
||
1509 | |||
1510 | FileInputStream inAux = new FileInputStream(timeFile); |
||
1511 | Properties prop = new Properties(); |
||
1512 | prop.load(inAux); |
||
1513 | inAux.close(); |
||
1514 | |||
1515 | if (prop.getProperty("timestamp") != null) { |
||
1516 | Long lastMiliSeconds = (Long) new Long(prop.getProperty( |
||
1517 | "timestamp"));
|
||
1518 | |||
1519 | if (lastMiliSeconds.longValue() == miliSecondsInWeb.longValue()) {
|
||
1520 | System.out.println("No hay nueva actualizaci?n"); |
||
1521 | 7514 | caballero | logger.debug("No hay nueva actualizaci?n -> Return");
|
1522 | logger.debug("timeStampWeb= " + miliSecondsInWeb);
|
||
1523 | logger.debug("timeStampLocal= " + lastMiliSeconds);
|
||
1524 | 2332 | fjp | |
1525 | return;
|
||
1526 | } |
||
1527 | |||
1528 | System.out.println("timeStampWeb= " + miliSecondsInWeb); |
||
1529 | System.out.println("timeStampLocal= " + lastMiliSeconds); |
||
1530 | } else {
|
||
1531 | System.out.println("El timeStamp no est? escrito en " + |
||
1532 | timeFile.getAbsolutePath()); |
||
1533 | } |
||
1534 | |||
1535 | 7514 | caballero | InputStream stream = url.openStream();
|
1536 | File temp = File.createTempFile("gvsig", ".zip"); |
||
1537 | 2332 | fjp | |
1538 | 7514 | caballero | logger.debug(temp.getAbsolutePath()); |
1539 | 2332 | fjp | |
1540 | 7514 | caballero | temp.deleteOnExit(); |
1541 | FileOutputStream file = new FileOutputStream(temp); |
||
1542 | 2332 | fjp | |
1543 | 7514 | caballero | byte[] lt_read = new byte[1]; |
1544 | 2332 | fjp | |
1545 | 7514 | caballero | while (stream.read(lt_read) > 0) |
1546 | file.write(lt_read); |
||
1547 | 2332 | fjp | |
1548 | 7514 | caballero | stream.close(); |
1549 | stream = null;
|
||
1550 | file.close(); |
||
1551 | file = null;
|
||
1552 | 2332 | fjp | |
1553 | 7514 | caballero | System.gc();
|
1554 | 2332 | fjp | |
1555 | 7514 | caballero | logger.debug("Ha creado el fichero ZIP");
|
1556 | 2332 | fjp | //Se extrae el zip
|
1557 | 7303 | caballero | MultiSplashWindow.process(5, "Extensiones descargadas."); |
1558 | 2332 | fjp | |
1559 | System.out.println("Extrayendo a " + destDir.getAbsolutePath()); |
||
1560 | |||
1561 | Date fechaDir = new Date(destDir.lastModified()); |
||
1562 | System.out.println("Fecha del directorio " + extDir + " = " + |
||
1563 | fechaDir.toString()); |
||
1564 | Utilities.extractTo(temp, new File(extDir), splashWindow); |
||
1565 | |||
1566 | // Si todo ha ido bien, guardamos el timestamp.
|
||
1567 | /// App.instance.getPc().addProperties("timestamp", miliSecondsInWeb);
|
||
1568 | // XMLEntity xml=ps.getPersistentXML();
|
||
1569 | fechaActual = new java.util.Date();
|
||
1570 | |||
1571 | FileOutputStream outAux = new FileOutputStream(timeFile); |
||
1572 | prop.setProperty("timestamp", miliSecondsInWeb.toString());
|
||
1573 | prop.store(outAux, "last download");
|
||
1574 | outAux.close(); |
||
1575 | System.out.println("Fecha actual guardada: " + |
||
1576 | fechaActual.toGMTString()); |
||
1577 | |||
1578 | /* xml.putProperty("timestamp",fechaActual.toGMTString());
|
||
1579 | ps.setPresistentXML(xml); */
|
||
1580 | } |
||
1581 | } catch (IOException e) { |
||
1582 | NotificationManager.addError("", e);
|
||
1583 | } catch (UnavailableServiceException e) {
|
||
1584 | NotificationManager.addError("", e);
|
||
1585 | } catch (SecurityException e) { |
||
1586 | System.err.println("No se puede escribir el timeStamp " + |
||
1587 | fechaActual.toGMTString()); |
||
1588 | NotificationManager.addError("", e);
|
||
1589 | } |
||
1590 | } |
||
1591 | |||
1592 | /**
|
||
1593 | * DOCUMENT ME!
|
||
1594 | *
|
||
1595 | 1067 | fernando | * @return DOCUMENT ME!
|
1596 | */
|
||
1597 | private static Extensions[] getExtensions() { |
||
1598 | ArrayList array = new ArrayList(); |
||
1599 | Iterator iter = pluginsConfig.values().iterator();
|
||
1600 | |||
1601 | while (iter.hasNext()) {
|
||
1602 | array.add(((PluginConfig) iter.next()).getExtensions()); |
||
1603 | 735 | vcaballero | } |
1604 | 1067 | fernando | |
1605 | return (Extensions[]) array.toArray(new Extensions[0]); |
||
1606 | 735 | vcaballero | } |
1607 | 1067 | fernando | |
1608 | /**
|
||
1609 | * DOCUMENT ME!
|
||
1610 | *
|
||
1611 | * @return DOCUMENT ME!
|
||
1612 | */
|
||
1613 | public static HashMap getPluginConfig() { |
||
1614 | 735 | vcaballero | return pluginsConfig;
|
1615 | } |
||
1616 | 1067 | fernando | |
1617 | /**
|
||
1618 | * DOCUMENT ME!
|
||
1619 | *
|
||
1620 | * @param s DOCUMENT ME!
|
||
1621 | *
|
||
1622 | * @return DOCUMENT ME!
|
||
1623 | */
|
||
1624 | public static Extension getExtension(String s) { |
||
1625 | Extensions[] exts = getExtensions();
|
||
1626 | |||
1627 | for (int i = 0; i < exts.length; i++) { |
||
1628 | for (int j = 0; j < exts[i].getExtensionCount(); j++) { |
||
1629 | if (exts[i].getExtension(j).getClassName().equals(s)) {
|
||
1630 | 735 | vcaballero | return exts[i].getExtension(j);
|
1631 | } |
||
1632 | 1067 | fernando | } |
1633 | 735 | vcaballero | } |
1634 | 1067 | fernando | |
1635 | 735 | vcaballero | return null; |
1636 | } |
||
1637 | 1067 | fernando | |
1638 | /**
|
||
1639 | * DOCUMENT ME!
|
||
1640 | *
|
||
1641 | * @return DOCUMENT ME!
|
||
1642 | */
|
||
1643 | public static AndamiConfig getAndamiConfig() { |
||
1644 | 794 | vcaballero | return andamiConfig;
|
1645 | } |
||
1646 | 1236 | fernando | |
1647 | 1067 | fernando | /**
|
1648 | * DOCUMENT ME!
|
||
1649 | *
|
||
1650 | * @author $author$
|
||
1651 | * @version $Revision$
|
||
1652 | */
|
||
1653 | 1153 | fernando | private static class ExtensionComparator implements Comparator { |
1654 | 1067 | fernando | /**
|
1655 | * DOCUMENT ME!
|
||
1656 | *
|
||
1657 | * @param o1 DOCUMENT ME!
|
||
1658 | * @param o2 DOCUMENT ME!
|
||
1659 | *
|
||
1660 | * @return DOCUMENT ME!
|
||
1661 | */
|
||
1662 | public int compare(Object o1, Object o2) { |
||
1663 | Extension e1 = (Extension) o1; |
||
1664 | Extension e2 = (Extension) o2; |
||
1665 | |||
1666 | if (!e1.hasPriority() && !e2.hasPriority()) {
|
||
1667 | return -1; |
||
1668 | 735 | vcaballero | } |
1669 | 1067 | fernando | |
1670 | if (e1.hasPriority() && !e2.hasPriority()) {
|
||
1671 | 6696 | cesar | return Integer.MIN_VALUE; |
1672 | 1067 | fernando | } |
1673 | |||
1674 | if (e2.hasPriority() && !e1.hasPriority()) {
|
||
1675 | return Integer.MAX_VALUE; |
||
1676 | } |
||
1677 | |||
1678 | 2112 | fernando | if (e1.getPriority() != e2.getPriority()){
|
1679 | return e2.getPriority() - e1.getPriority();
|
||
1680 | }else{
|
||
1681 | return (e2.toString().compareTo(e1.toString()));
|
||
1682 | } |
||
1683 | 735 | vcaballero | } |
1684 | 1067 | fernando | } |
1685 | |||
1686 | /**
|
||
1687 | * DOCUMENT ME!
|
||
1688 | */
|
||
1689 | 1153 | fernando | private static class MenuComparator implements Comparator { |
1690 | 1067 | fernando | private static ExtensionComparator extComp = new ExtensionComparator(); |
1691 | |||
1692 | /**
|
||
1693 | * DOCUMENT ME!
|
||
1694 | *
|
||
1695 | * @param o1 DOCUMENT ME!
|
||
1696 | * @param o2 DOCUMENT ME!
|
||
1697 | *
|
||
1698 | * @return DOCUMENT ME!
|
||
1699 | */
|
||
1700 | public int compare(Object o1, Object o2) { |
||
1701 | SortableMenu e1 = (SortableMenu) o1; |
||
1702 | SortableMenu e2 = (SortableMenu) o2; |
||
1703 | |||
1704 | if (!e1.menu.hasPosition() && !e2.menu.hasPosition()) {
|
||
1705 | if (e1.extension instanceof SkinExtensionType) { |
||
1706 | return 1; |
||
1707 | } else if (e2.extension instanceof SkinExtensionType) { |
||
1708 | return -1; |
||
1709 | } else {
|
||
1710 | return extComp.compare(e1.extension, e2.extension);
|
||
1711 | } |
||
1712 | } |
||
1713 | |||
1714 | if (e1.menu.hasPosition() && !e2.menu.hasPosition()) {
|
||
1715 | 6696 | cesar | return Integer.MIN_VALUE; |
1716 | 1067 | fernando | } |
1717 | |||
1718 | if (e2.menu.hasPosition() && !e1.menu.hasPosition()) {
|
||
1719 | return Integer.MAX_VALUE; |
||
1720 | } |
||
1721 | 6696 | cesar | if (e1.menu.getPosition() != e2.menu.getPosition()){
|
1722 | //we don't return 0 unless both objects are the same, otherwise the objects get overwritten in the treemap
|
||
1723 | return e1.menu.getPosition() - e2.menu.getPosition();
|
||
1724 | }else{
|
||
1725 | return (e1.toString().compareTo(e2.toString()));
|
||
1726 | } |
||
1727 | 735 | vcaballero | } |
1728 | } |
||
1729 | 1067 | fernando | |
1730 | /**
|
||
1731 | * DOCUMENT ME!
|
||
1732 | *
|
||
1733 | * @author $author$
|
||
1734 | * @version $Revision$
|
||
1735 | */
|
||
1736 | 1153 | fernando | private static class SortableMenu { |
1737 | 1067 | fernando | public PluginClassLoader loader;
|
1738 | public Menu menu; |
||
1739 | public SkinExtensionType extension;
|
||
1740 | |||
1741 | /**
|
||
1742 | * DOCUMENT ME!
|
||
1743 | *
|
||
1744 | * @param loader DOCUMENT ME!
|
||
1745 | * @param skinExt
|
||
1746 | * @param menu2
|
||
1747 | */
|
||
1748 | public SortableMenu(PluginClassLoader loader,
|
||
1749 | SkinExtensionType skinExt, Menu menu2) {
|
||
1750 | extension = skinExt; |
||
1751 | menu = menu2; |
||
1752 | this.loader = loader;
|
||
1753 | } |
||
1754 | } |
||
1755 | 3298 | caballero | /**
|
1756 | * DOCUMENT ME!
|
||
1757 | */
|
||
1758 | 6589 | cesar | private static class SortableTool { |
1759 | 5421 | cesar | public PluginClassLoader loader;
|
1760 | public ToolBar toolbar;
|
||
1761 | public ActionTool actiontool;
|
||
1762 | public SelectableTool selectabletool;
|
||
1763 | public SkinExtensionType extension;
|
||
1764 | |||
1765 | /**
|
||
1766 | * DOCUMENT ME!
|
||
1767 | *
|
||
1768 | * @param loader DOCUMENT ME!
|
||
1769 | * @param skinExt
|
||
1770 | * @param menu2
|
||
1771 | */
|
||
1772 | 6589 | cesar | public SortableTool(PluginClassLoader loader,
|
1773 | 5421 | cesar | SkinExtensionType skinExt, ToolBar toolbar2,ActionTool actiontool2) { |
1774 | extension = skinExt; |
||
1775 | toolbar = toolbar2; |
||
1776 | actiontool=actiontool2; |
||
1777 | this.loader = loader;
|
||
1778 | } |
||
1779 | 6589 | cesar | public SortableTool(PluginClassLoader loader,
|
1780 | 5421 | cesar | SkinExtensionType skinExt, ToolBar toolbar2,SelectableTool selectabletool2) { |
1781 | extension = skinExt; |
||
1782 | toolbar = toolbar2; |
||
1783 | selectabletool=selectabletool2; |
||
1784 | this.loader = loader;
|
||
1785 | } |
||
1786 | } |
||
1787 | /**
|
||
1788 | * DOCUMENT ME!
|
||
1789 | */
|
||
1790 | 3298 | caballero | private static class ToolBarComparator implements Comparator { |
1791 | private static ExtensionComparator extComp = new ExtensionComparator(); |
||
1792 | |||
1793 | /**
|
||
1794 | * DOCUMENT ME!
|
||
1795 | *
|
||
1796 | * @param o1 DOCUMENT ME!
|
||
1797 | * @param o2 DOCUMENT ME!
|
||
1798 | *
|
||
1799 | * @return DOCUMENT ME!
|
||
1800 | */
|
||
1801 | public int compare(Object o1, Object o2) { |
||
1802 | 6589 | cesar | SortableTool e1 = (SortableTool) o1; |
1803 | SortableTool e2 = (SortableTool) o2; |
||
1804 | 6101 | jaume | |
1805 | 5421 | cesar | // if the toolbars have the same name, they are considered to be
|
1806 | // the same toolbar, so we don't need to do further comparing
|
||
1807 | if (e1.toolbar.getName().equals(e2.toolbar.getName()))
|
||
1808 | return 0; |
||
1809 | 6101 | jaume | |
1810 | 3298 | caballero | if (!e1.toolbar.hasPosition() && !e2.toolbar.hasPosition()) {
|
1811 | if (e1.extension instanceof SkinExtensionType) { |
||
1812 | return 1; |
||
1813 | } else if (e2.extension instanceof SkinExtensionType) { |
||
1814 | return -1; |
||
1815 | } else {
|
||
1816 | return extComp.compare(e1.extension, e2.extension);
|
||
1817 | } |
||
1818 | } |
||
1819 | |||
1820 | if (e1.toolbar.hasPosition() && !e2.toolbar.hasPosition()) {
|
||
1821 | 6696 | cesar | return Integer.MIN_VALUE; |
1822 | 3298 | caballero | } |
1823 | |||
1824 | if (e2.toolbar.hasPosition() && !e1.toolbar.hasPosition()) {
|
||
1825 | return Integer.MAX_VALUE; |
||
1826 | } |
||
1827 | 3310 | caballero | if (e1.toolbar.getPosition() != e2.toolbar.getPosition())
|
1828 | 5421 | cesar | return e1.toolbar.getPosition() - e2.toolbar.getPosition();
|
1829 | 6101 | jaume | |
1830 | 3310 | caballero | if (e1.toolbar.getActionTool().equals(e2.toolbar.getActionTool()) && e1.toolbar.getSelectableTool().equals(e2.toolbar.getSelectableTool())){
|
1831 | return 0; |
||
1832 | } |
||
1833 | 5421 | cesar | return (e1.toolbar.toString().compareTo(e2.toolbar.toString()));
|
1834 | 3298 | caballero | } |
1835 | } |
||
1836 | 6101 | jaume | |
1837 | 3298 | caballero | /**
|
1838 | 5421 | cesar | * <p>This class is used to compare tools (selectabletool and actiontool),
|
1839 | * using the "position"
|
||
1840 | * attribute.</p>
|
||
1841 | * <p>The ordering criteria are:</p>
|
||
1842 | * <ul><li>If the tools are placed in different toolbars, they use the toolbars'
|
||
1843 | * order.
|
||
1844 | * (using the ToolBarComparator).</li>
|
||
1845 | * <li></li>
|
||
1846 | * <li>If any of the tools has not 'position' attribute, the tool which
|
||
1847 | * <strong>has</strong> the attribute will be placed first.</li>
|
||
1848 | * <li>If both tools have the same position (or they don't have a
|
||
1849 | * 'position' attribute), the priority of the extensions where the tool is defined.</li></ul>
|
||
1850 | 3298 | caballero | *
|
1851 | 5421 | cesar | * @author cesar
|
1852 | 3298 | caballero | * @version $Revision$
|
1853 | */
|
||
1854 | 5421 | cesar | private static class ToolComparator implements Comparator { |
1855 | private static ToolBarComparator toolBarComp = new ToolBarComparator(); |
||
1856 | 3298 | caballero | /**
|
1857 | * DOCUMENT ME!
|
||
1858 | *
|
||
1859 | 5421 | cesar | * @param o1 DOCUMENT ME!
|
1860 | * @param o2 DOCUMENT ME!
|
||
1861 | *
|
||
1862 | * @return DOCUMENT ME!
|
||
1863 | 3298 | caballero | */
|
1864 | 5421 | cesar | public int compare(Object o1, Object o2) { |
1865 | // compare the toolbars which contain the tools
|
||
1866 | int result = toolBarComp.compare(o1, o2);
|
||
1867 | if (result != 0) { // if the toolbars are different, use their order |
||
1868 | return result;
|
||
1869 | } |
||
1870 | // otherwise, compare the tools
|
||
1871 | 6589 | cesar | SortableTool e1 = (SortableTool) o1; |
1872 | SortableTool e2 = (SortableTool) o2; |
||
1873 | 5421 | cesar | int e1Position=-1, e2Position=-1; |
1874 | |||
1875 | if (e1.actiontool!=null) { |
||
1876 | if (e1.actiontool.hasPosition())
|
||
1877 | e1Position = e1.actiontool.getPosition(); |
||
1878 | } |
||
1879 | else if (e1.selectabletool!=null) { |
||
1880 | if (e1.selectabletool.hasPosition())
|
||
1881 | e1Position = e1.selectabletool.getPosition(); |
||
1882 | } |
||
1883 | 6101 | jaume | |
1884 | 5421 | cesar | if (e2.actiontool!=null) { |
1885 | if (e2.actiontool.hasPosition())
|
||
1886 | e2Position = e2.actiontool.getPosition(); |
||
1887 | } |
||
1888 | else if (e2.selectabletool!=null){ |
||
1889 | if (e2.selectabletool.hasPosition())
|
||
1890 | e2Position = e2.selectabletool.getPosition(); |
||
1891 | } |
||
1892 | 6101 | jaume | |
1893 | 5421 | cesar | if (e1Position==-1 && e2Position!=-1) { |
1894 | return 1; |
||
1895 | } |
||
1896 | if (e1Position!=-1 && e2Position==-1) { |
||
1897 | return -1; |
||
1898 | } |
||
1899 | if (e1Position!=-1 && e2Position!=-1) { |
||
1900 | result = e1Position - e2Position; |
||
1901 | // we don't return 0 unless both objects are the same, otherwise the objects get overwritten in the treemap
|
||
1902 | if (result!=0) return result; |
||
1903 | } |
||
1904 | return e1.toString().compareTo(e2.toString());
|
||
1905 | 3298 | caballero | } |
1906 | } |
||
1907 | 6101 | jaume | |
1908 | |||
1909 | 4306 | ldiaz | /**
|
1910 | * validates the user before starting gvsig
|
||
1911 | *
|
||
1912 | */
|
||
1913 | private static void validate(){ |
||
1914 | 6101 | jaume | |
1915 | 4306 | ldiaz | IAuthentication session = null;
|
1916 | try {
|
||
1917 | session = (IAuthentication)Class.forName("com.iver.andami.authentication.Session").newInstance(); |
||
1918 | |||
1919 | } catch (ClassNotFoundException e) { |
||
1920 | // TODO Auto-generated catch block
|
||
1921 | 4308 | ldiaz | //e.printStackTrace();
|
1922 | 4306 | ldiaz | return;
|
1923 | } catch (InstantiationException e) { |
||
1924 | // TODO Auto-generated catch block
|
||
1925 | 4308 | ldiaz | //e.printStackTrace();
|
1926 | return;
|
||
1927 | 4306 | ldiaz | } catch (IllegalAccessException e) { |
1928 | // TODO Auto-generated catch block
|
||
1929 | 4308 | ldiaz | //e.printStackTrace();
|
1930 | return;
|
||
1931 | 4306 | ldiaz | } |
1932 | 6101 | jaume | |
1933 | 4306 | ldiaz | session.setPluginDirectory( andamiConfig.getPluginsDirectory() ); |
1934 | if (session.validationRequired()){
|
||
1935 | 7584 | ldiaz | if(session.Login()){
|
1936 | 4306 | ldiaz | System.out.println("You are logged in"); |
1937 | } |
||
1938 | else{
|
||
1939 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
1940 | 6101 | jaume | "You are not logged in");
|
1941 | 7584 | ldiaz | //System.exit(0);
|
1942 | 4358 | ldiaz | } |
1943 | PluginServices.setAuthentication(session); |
||
1944 | 6101 | jaume | } |
1945 | 4306 | ldiaz | } |
1946 | 6101 | jaume | |
1947 | public static String getDefaultLookAndFeel() { |
||
1948 | String osName = (String) System.getProperty("os.name"); |
||
1949 | |||
1950 | if (osName.substring(0,3).toLowerCase().equals("win")) |
||
1951 | return UIManager.getSystemLookAndFeelClassName(); |
||
1952 | else
|
||
1953 | return nonWinDefaultLookAndFeel;
|
||
1954 | } |
||
1955 | 6951 | cesar | |
1956 | /**
|
||
1957 | * Gets the ISO 839 two-characters-long language code matching the
|
||
1958 | * provided language code (which may be an ISO 839-2/T
|
||
1959 | * three-characters-long code or an ISO 839-1 two-characters-long
|
||
1960 | * code).
|
||
1961 | 7303 | caballero | *
|
1962 | 6951 | cesar | * If the provided parameter is already two characters long, it
|
1963 | * returns the parameter without any modification.
|
||
1964 | 7303 | caballero | *
|
1965 | 6951 | cesar | * @param langCode A language code representing either
|
1966 | * an ISO 839-2/T language code or an ISO 839-1 code.
|
||
1967 | * @return A two-characters-long code specifying
|
||
1968 | * an ISO 839 language code.
|
||
1969 | */
|
||
1970 | private static String normalizeLanguageCode(String langCode) { |
||
1971 | final String fileName = "iso_639.tab"; |
||
1972 | if (langCode.length()==2) |
||
1973 | return langCode;
|
||
1974 | else if (langCode.length()==3) { |
||
1975 | if (langCode.equals("va") || langCode.equals("val")) { // special case for Valencian |
||
1976 | return "ca"; |
||
1977 | } |
||
1978 | URL isoCodes = Launcher.class.getClassLoader().getResource(fileName);
|
||
1979 | if (isoCodes!=null) { |
||
1980 | try {
|
||
1981 | BufferedReader reader =
|
||
1982 | new BufferedReader(new InputStreamReader(isoCodes.openStream(), "ISO-8859-1")); |
||
1983 | String line;
|
||
1984 | |||
1985 | while ((line = reader.readLine()) != null) { |
||
1986 | String[] language = line.split("\t"); |
||
1987 | if (language[0].equals(langCode)) // first column is the three characters code |
||
1988 | return language[2]; // third column i the two characters code |
||
1989 | } |
||
1990 | } |
||
1991 | catch (IOException ex) { |
||
1992 | logger.error(Messages.getString("Error_reading_isocodes_file"), ex);
|
||
1993 | return "es"; |
||
1994 | } |
||
1995 | } |
||
1996 | else {
|
||
1997 | logger.error(Messages.getString("Error_reading_isocodes_file"));
|
||
1998 | return "es"; |
||
1999 | } |
||
2000 | } |
||
2001 | return "es"; |
||
2002 | } |
||
2003 | 7303 | caballero | |
2004 | 6951 | cesar | /**
|
2005 | * Configures the locales (languages and local resources) to be used
|
||
2006 | * by the application.
|
||
2007 | 7303 | caballero | *
|
2008 | 6951 | cesar | * First it tries to get the locale from the command line parameters,
|
2009 | * then the andami-config file is checked.
|
||
2010 | 7303 | caballero | *
|
2011 | 6951 | cesar | * The locale name is normalized to get a two characters language code
|
2012 | * as defined by ISO-639-1 (although ISO-639-2/T three characters codes
|
||
2013 | * are also accepted from the command line or the configuration file).
|
||
2014 | 7303 | caballero | *
|
2015 | 6951 | cesar | * Finally, the gvsig-i18n library and the default locales for Java and
|
2016 | * Swing are configured.
|
||
2017 | *
|
||
2018 | */
|
||
2019 | private static void configureLocales(String[] args) { |
||
2020 | // Configurar el locale
|
||
2021 | String localeStr = null; |
||
2022 | for (int i=2; i < args.length; i++) |
||
2023 | { |
||
2024 | int index = args[i].indexOf("language="); |
||
2025 | if (index != -1) |
||
2026 | localeStr = args[i].substring(index+9);
|
||
2027 | } |
||
2028 | if (localeStr == null) |
||
2029 | { |
||
2030 | localeStr = andamiConfig.getLocaleLanguage(); |
||
2031 | } |
||
2032 | localeStr = normalizeLanguageCode(localeStr); |
||
2033 | locale = getLocale(localeStr, |
||
2034 | andamiConfig.getLocaleCountry(), |
||
2035 | andamiConfig.getLocaleVariant()); |
||
2036 | Locale.setDefault(locale);
|
||
2037 | JComponent.setDefaultLocale(locale);
|
||
2038 | org.gvsig.i18n.Messages.addLocale(locale); |
||
2039 | // add english and spanish as fallback languages
|
||
2040 | org.gvsig.i18n.Messages.addLocale(new Locale("en")); |
||
2041 | org.gvsig.i18n.Messages.addLocale(new Locale("es")); |
||
2042 | org.gvsig.i18n.Messages.addResourceFamily("com.iver.andami.text", "com.iver.andami.text"); |
||
2043 | |||
2044 | } |
||
2045 | 8120 | jmvivo | |
2046 | /**
|
||
2047 | * Gets Home Directory location of the application.
|
||
2048 | * May be set from outside the aplication by means of
|
||
2049 | * -DgvSIG.home=C:/data/gvSIG, where gvSIG its the name
|
||
2050 | * of the application
|
||
2051 | * @return
|
||
2052 | */
|
||
2053 | public static String getAppHomeDir() { |
||
2054 | return appHomeDir;
|
||
2055 | } |
||
2056 | |||
2057 | /**
|
||
2058 | * Sets Home Directory location of the application.
|
||
2059 | * May be set from outside the aplication by means of
|
||
2060 | * -DgvSIG.home=C:/data/gvSIG, where gvSIG its the name
|
||
2061 | * of the application
|
||
2062 | * @param appHomeDir
|
||
2063 | */
|
||
2064 | public static void setAppHomeDir(String appHomeDir) { |
||
2065 | Launcher.appHomeDir = appHomeDir; |
||
2066 | } |
||
2067 | 598 | fernando | } |