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