Revision 38564 branches/v2_0_0_prep/frameworks/_fwAndami/src/org/gvsig/andami/Launcher.java

View differences:

Launcher.java
76 76
import java.text.MessageFormat;
77 77
import java.util.ArrayList;
78 78
import java.util.Comparator;
79
import java.util.Enumeration;
79 80
import java.util.HashMap;
80 81
import java.util.HashSet;
81 82
import java.util.Iterator;
......
108 109
import org.apache.log4j.spi.LoggingEvent;
109 110
import org.exolab.castor.xml.MarshalException;
110 111
import org.exolab.castor.xml.ValidationException;
111
import org.slf4j.Logger;
112
import org.slf4j.LoggerFactory;
113

  
112
import org.gvsig.andami.actioninfo.ActionInfo;
113
import org.gvsig.andami.actioninfo.ActionInfoManager;
114 114
import org.gvsig.andami.authentication.IAuthentication;
115
import org.gvsig.andami.authentication.LoginUI;
116 115
import org.gvsig.andami.config.generate.Andami;
117 116
import org.gvsig.andami.config.generate.AndamiConfig;
118 117
import org.gvsig.andami.config.generate.Plugin;
119
import org.gvsig.andami.iconthemes.IIconTheme;
120
import org.gvsig.andami.iconthemes.IconThemeManager;
121 118
import org.gvsig.andami.messages.Messages;
122 119
import org.gvsig.andami.messages.NotificationManager;
123 120
import org.gvsig.andami.plugins.ExclusiveUIExtension;
124 121
import org.gvsig.andami.plugins.ExtensionDecorator;
125 122
import org.gvsig.andami.plugins.IExtension;
126 123
import org.gvsig.andami.plugins.PluginClassLoader;
124
import org.gvsig.andami.plugins.config.generate.Action;
127 125
import org.gvsig.andami.plugins.config.generate.ActionTool;
128 126
import org.gvsig.andami.plugins.config.generate.ComboButton;
129 127
import org.gvsig.andami.plugins.config.generate.ComboButtonElement;
......
147 145
import org.gvsig.andami.ui.ToolsWindowManager;
148 146
import org.gvsig.andami.ui.fonts.FontUtils;
149 147
import org.gvsig.andami.ui.mdiFrame.MDIFrame;
150
import org.gvsig.andami.ui.mdiFrame.NewStatusBar;
151 148
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory;
152 149
import org.gvsig.andami.ui.splash.MultiSplashWindow;
153 150
import org.gvsig.andami.ui.theme.Theme;
......
162 159
import org.gvsig.tools.exception.ListBaseException;
163 160
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
164 161
import org.gvsig.tools.swing.api.ToolsSwingLocator;
162
import org.gvsig.tools.swing.icontheme.IconTheme;
163
import org.gvsig.tools.swing.icontheme.IconThemeManager;
164
import org.gvsig.tools.util.FolderSet;
165
import org.gvsig.tools.util.FolderSet.FolderEntry;
165 166
import org.gvsig.utils.DateTime;
166 167
import org.gvsig.utils.XMLEntity;
167 168
import org.gvsig.utils.xml.XMLEncodingUtils;
168 169
import org.gvsig.utils.xmlEntity.generate.XmlTag;
170
import org.slf4j.Logger;
171
import org.slf4j.LoggerFactory;
169 172

  
170 173
/**
171 174
 * <p>
......
226 229
		}
227 230
	}
228 231

  
232
	private static Launcher launcherInstance;
233

  
234
	public static Launcher getInstance() {
235
		if( launcherInstance == null ) {
236
			launcherInstance = new Launcher();
237
		}
238
		return launcherInstance;
239
	}
240
	
229 241
	public static void main(String[] args) throws Exception {
230
		Launcher launcher = new Launcher();
242
		Launcher launcher = getInstance();
231 243
		boolean install = false;
232 244
		for (int i = 0; i < args.length; i++) {
233 245
			if (args[i].equalsIgnoreCase("--install")) {
......
301 313
			public void refresh() {
302 314
			}
303 315
		});
316
		
317
		new PluginsLibrary().initialize();
304 318

  
305 319
		try {
306 320
			initIconThemes();
......
335 349
		configureProxy();
336 350

  
337 351
		// 2. TODO Buscar actualizaciones de los plugins
338
		splashWindow.process(20, PluginServices.getText(Launcher.class,
339
				"SplashWindow.looking_for_updates"));
340
		try {
341
			this.downloadExtensions(andamiConfig.getPluginsDirectory());
342
		} catch (Exception ex) {
343
			this.addError("Can't downloads plugins", ex);
344
		}
352
//		splashWindow.process(20, PluginServices.getText(Launcher.class,
353
//				"SplashWindow.looking_for_updates"));
354
//		try {
355
//			this.downloadExtensions(andamiConfig.getPluginsDirectory());
356
//		} catch (Exception ex) {
357
//			this.addError("Can't downloads plugins", ex);
358
//		}
345 359

  
346 360
		// 2.5. Initialize andami libraries
347 361
		splashWindow.process(25, PluginServices.getText(Launcher.class,
......
496 510
				"creating_main_window"));
497 511
		frame.setVisible(true);
498 512

  
499
		// 20. Se ejecuta el postInitialize
513
		/* 
514
		 * Initialize installer local repository folders 
515
		 */
516
		initializeLocalAddOnRepositoryFolders();
517

  
518
		// 19. Se ejecuta el postInitialize
500 519
		splashWindow.process(190, PluginServices.getText(Launcher.class,
501 520
				"SplashWindow.post_initializing_extensions"));
502 521
		SwingUtilities.invokeAndWait(new Runnable() {
......
509 528

  
510 529
		// Definimos un KeyEventDispatcher global para que las extensiones
511 530
		// puedan registrar sus "teclas r?pidas".
512
		GlobalKeyEventDispatcher keyDispatcher = GlobalKeyEventDispatcher
513
				.getInstance();
514
		KeyboardFocusManager.getCurrentKeyboardFocusManager()
515
				.addKeyEventDispatcher(keyDispatcher);
531
		GlobalKeyEventDispatcher keyDispatcher = GlobalKeyEventDispatcher.getInstance();
532
		KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);
516 533

  
517 534
		SwingUtilities.invokeAndWait(new Runnable() {
518 535

  
......
520 537
				frame.enableControls();
521 538
			}
522 539
		});
540

  
541
		createDefaultIconTheme();
542

  
523 543
		splashWindow.close();
524 544
		if (launcherrors != null) {
525 545
			NotificationManager.addError(launcherrors);
......
530 550

  
531 551
	}
532 552

  
553
	private void initializeLocalAddOnRepositoryFolders() {
554
		InstallerManager installerManager = InstallerLocator.getInstallerManager();
555

  
556
		File defaultAddonsRepository = PluginsLocator.getManager().getPluginsFolder();
557

  
558
		installerManager.addLocalAddonRepository(defaultAddonsRepository);
559
		installerManager.setDefaultLocalAddonRepository(defaultAddonsRepository);
560
		
561
		IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
562
		FolderSet fset = iconManager.getRepository();
563
		Iterator<FolderSet.FolderEntry> it = fset.iterator();
564
		while( it.hasNext() ) {
565
			FolderEntry entry = it.next();
566
			installerManager.addLocalAddonRepository(entry.getFolder());
567
		}
568
	}
569
	
570
	private void createDefaultIconTheme() {
571
		PluginsManager pluginsManager = PluginsLocator.getManager();
572
		IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
573
		
574
		File f = new File(pluginsManager.getApplicationHomeFolder(),"icon-theme");
575
		if( !f.exists() ) {
576
			f.mkdir();
577
		}
578
		IconTheme theme = iconManager.getDefault();
579
		File f2 = new File(f,theme.getID()) ;
580
		if( !f2.exists() ) {
581
			logger.info("Creating default icon theme in "+f.getAbsolutePath());
582
			theme.export(f);
583
		}
584
	}
585
	
533 586
	/**
534 587
     * 
535 588
     */
......
697 750
	 * Return the directory applicaction is installed.
698 751
	 */
699 752
	public static String getApplicationDirectory() {
700
		return new File("").getAbsolutePath();
753
		return getApplicationFolder().getAbsolutePath();
701 754
	}
755
	
756
    public static File getApplicationFolder() {
757
        // TODO: check if there is a better way to handle this
758
        return new File(System.getProperty("user.dir"));
759
    }
702 760

  
703 761
	private void registerIcons() {
704
		PluginServices.getIconTheme().registerDefault(
705
				"login-gvsig",
706
				LoginUI.class.getClassLoader().getResource(
707
						"images/login_gvsig.png"));
708
		PluginServices.getIconTheme().registerDefault(
709
				"splash-gvsig",
710
				MultiSplashWindow.class.getClassLoader().getResource(
711
						"images/splash.png"));
712
		PluginServices.getIconTheme().registerDefault(
713
				"info-icon",
714
				NewStatusBar.class.getClassLoader().getResource(
715
						"images/info.gif"));
716
		PluginServices.getIconTheme().registerDefault(
717
				"error-icon",
718
				NewStatusBar.class.getClassLoader().getResource(
719
						"images/error.gif"));
720
		PluginServices.getIconTheme().registerDefault(
721
				"warning-icon",
722
				NewStatusBar.class.getClassLoader().getResource(
723
						"images/warning.gif"));
724
		PluginServices.getIconTheme().registerDefault(
725
				"no-icon",
726
				NewStatusBar.class.getClassLoader().getResource(
727
						"images/no_icon.png"));
762
		IconTheme theme = PluginServices.getIconTheme();
763
		ClassLoader loader = Launcher.class.getClassLoader();	
764
		
765
		String[][] icons = {
766
				// MultiSplashWindow
767
				{ "main", "splash-default" },
768
				// NewStatusBar
769
				{ "main", "statusbar-info" },
770
				{ "main", "statusbar-warning" },
771
				{ "main", "statusbar-error" }
772
		};
773
		for( int i=0; i<icons.length; i++) {
774
			try {
775
				IconThemeHelper.registerIcon(icons[i][0], icons[i][1], Launcher.class);
776
			} catch(Exception e) {
777
				logger.info("Can't register icon '"+icons[i][0]+"' ("+icons[i][1]+").");
778
			}
779
		}		
780
		theme.setDefaultIcon(loader.getResource("images/main/default-icon.png" ));
728 781
	}
729 782

  
730 783
	/**
......
1242 1295
		}
1243 1296
	}
1244 1297

  
1245
	private void installPluginsMenus() {
1298
	private void registerActionOfExtensions(ActionInfoManager actionManager,
1299
			Enumeration<SkinExtensionType> extensiones, ClassLoader loader) {
1300
		ActionInfo actionInfo;
1301
		while (extensiones.hasMoreElements()) {
1302
			SkinExtensionType extension = extensiones.nextElement();
1303
			Class<? extends IExtension> classExtension;
1304
			try {
1305
				classExtension = (Class<? extends IExtension>) loader
1306
						.loadClass(extension.getClassName());
1307

  
1308
				Enumeration<Action> actions = extension.enumerateAction();
1309
				while (actions.hasMoreElements()) {
1310
					Action action = actions.nextElement();
1311
					if (action.getName() == null) {
1312
						logger.info("invalid action name (null) in "+ extension.getClassName()+" of "+ loader.toString());
1313
					} else {
1314
						actionInfo = actionManager.createAction(
1315
								classExtension, action.getName(),
1316
								action.getLabel(), action.getActionCommand(),
1317
								action.getIcon(), null, action.getPosition(),
1318
								action.getTooltip());
1319
						actionManager.registerAction(actionInfo);
1320
						if( action.getPosition() < 100000000 ) {
1321
							logger.info("Invalid position in action ("+ actionInfo.toString()+ ").");
1322
							action.setPosition( action.getPosition() + 1000000000);
1323
						}
1324
					}
1325
				}
1326

  
1327
				Enumeration<Menu> menus = extension.enumerateMenu();
1328
				while (menus.hasMoreElements()) {
1329
					Menu menu = menus.nextElement();
1330
					if (!menu.getIs_separator() ) {
1331
						actionInfo = actionManager.createAction(
1332
							classExtension, menu.getName(), menu.getText(),
1333
							menu.getActionCommand(), menu.getIcon(),
1334
							menu.getKey(), menu.getPosition(),
1335
							menu.getTooltip());
1336
						actionInfo = actionManager.registerAction(actionInfo);
1337
						if (actionInfo != null) {
1338
							menu.setActionCommand(actionInfo.getCommand());
1339
							menu.setTooltip(actionInfo.getTooltip());
1340
							menu.setIcon(actionInfo.getIconName());
1341
							menu.setPosition(actionInfo.getPosition());
1342
							menu.setKey(actionInfo.getAccelerator());
1343
							menu.setName(actionInfo.getName());
1344
						}
1345
					} 
1346
					if( menu.getPosition() < 100000000 ) {
1347
						logger.info("Invalid position in menu ("+ menu.getText() + ").");
1348
						menu.setPosition( menu.getPosition() + 1000000000);
1349
					}
1350

  
1351
				}
1352
				Enumeration<ToolBar> toolBars = extension.enumerateToolBar();
1353
				while (toolBars.hasMoreElements()) {
1354
					ToolBar toolBar = toolBars.nextElement();
1355

  
1356
					Enumeration<ActionTool> actionTools = toolBar
1357
							.enumerateActionTool();
1358
					while (actionTools.hasMoreElements()) {
1359
						ActionTool actionTool = actionTools.nextElement();
1360
						actionInfo = actionManager.createAction(
1361
								classExtension, actionTool.getName(),
1362
								actionTool.getText(),
1363
								actionTool.getActionCommand(),
1364
								actionTool.getIcon(),
1365
								null,
1366
								actionTool.getPosition(),
1367
								actionTool.getTooltip());
1368
						actionInfo = actionManager.registerAction(actionInfo);
1369
						if (actionInfo != null) {
1370
							actionTool.setActionCommand(actionInfo.getCommand());
1371
							actionTool.setTooltip(actionInfo.getTooltip());
1372
							actionTool.setIcon(actionInfo.getIconName());
1373
							actionTool.setPosition(actionInfo.getPosition());
1374
							actionTool.setName(actionInfo.getName());
1375
						}
1376
					}
1377

  
1378
					Enumeration<SelectableTool> selectableTool = toolBar
1379
							.enumerateSelectableTool();
1380
					while (selectableTool.hasMoreElements()) {
1381
						SelectableTool actionTool = selectableTool
1382
								.nextElement();
1383
						actionInfo = actionManager.createAction(
1384
								classExtension, actionTool.getName(),
1385
								actionTool.getText(),
1386
								actionTool.getActionCommand(),
1387
								actionTool.getIcon(),
1388
								actionTool.getEnableText(),
1389
								actionTool.getPosition(),
1390
								actionTool.getTooltip());
1391
						actionInfo = actionManager.registerAction(actionInfo);
1392
						if (actionInfo != null) {
1393
							actionTool.setActionCommand(actionInfo.getCommand());
1394
							actionTool.setTooltip(actionInfo.getTooltip());
1395
							actionTool.setIcon(actionInfo.getIconName());
1396
							actionTool.setPosition(actionInfo.getPosition());
1397
							actionTool.setName(actionInfo.getName());
1398
						}
1399
					}
1400
				}
1401
			} catch (ClassNotFoundException e) {
1402
				logger.warn(
1403
						"Can't register actions of extension '"
1404
								+ extension.getClassName() + "'", e);
1405
			}
1406
		}
1407
	}
1408
	
1409
	@SuppressWarnings("unchecked")
1410
	private void registerActions() {
1411
		logger.info("registerActions");
1412

  
1413
		ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1414
		Iterator<String> it = pluginsConfig.keySet().iterator();
1415

  
1416
		while (it.hasNext()) {
1417
			String pluginName = it.next();
1418
			PluginConfig pluginConfig = pluginsConfig.get(pluginName);
1419
			PluginServices pluginService = pluginsServices.get(pluginName);
1420
			PluginClassLoader loader =  pluginService.getClassLoader();
1421

  
1422
			logger.info("registerActions of plugin '"+pluginName+"'.");
1423

  
1424
			Extensions extensionConfig = pluginConfig.getExtensions();
1425
			
1426
			
1427
			Enumeration<SkinExtensionType> extensiones = extensionConfig.enumerateExtension();
1428
			registerActionOfExtensions(actionManager, extensiones, loader);
1429

  
1430
			Enumeration<SkinExtensionType> skinSxtensiones = extensionConfig.enumerateSkinExtension();
1431
			registerActionOfExtensions(actionManager, skinSxtensiones, loader);
1432

  
1433
			PopupMenus pluginPopupMenus = pluginConfig.getPopupMenus();
1434
			if (pluginPopupMenus != null) {
1435
				PopupMenu[] menus1 = pluginPopupMenus.getPopupMenu();
1436
				for (int j = 0; j < menus1.length; j++) {
1437
					PopupMenu popupMenu = menus1[j];
1438
					Enumeration<Menu> menus2 = popupMenu.enumerateMenu();
1439
					while (menus2.hasMoreElements()) {
1440
						Menu menu = menus2.nextElement();
1441
						if (!menu.getIs_separator() ) {
1442
							if( menu.getName() == null) {   
1443
								logger.info("Null name for popmenu '"+menu.getText()+"' in plugin "+ pluginService.getPluginName() );
1444
							} else {
1445
								ActionInfo actionInfo = actionManager.getAction(menu.getName());
1446
								if( actionInfo!=null ) {
1447
									menu.setActionCommand(actionInfo.getCommand());
1448
									menu.setTooltip(actionInfo.getTooltip());
1449
									menu.setIcon(actionInfo.getIconName());
1450
									menu.setPosition(actionInfo.getPosition());
1451
									menu.setText( actionInfo.getLabel());
1452
									menu.setKey(actionInfo.getAccelerator());
1453
								}
1454
							}
1455
						}
1456
					}
1457
				}
1458
			}
1459
			
1460

  
1461
		}
1462
	}
1463
	
1464

  
1465
	private TreeSet<SortableMenu> getOrderedMenus() { 
1466

  
1246 1467
		TreeSet<SortableMenu> orderedMenus = new TreeSet<SortableMenu>(
1247 1468
				new MenuComparator());
1248 1469

  
......
1311 1532

  
1312 1533
		}
1313 1534

  
1535
		return orderedMenus;
1536
	}
1537

  
1538
	private void installPluginsMenus() {
1539
		logger.info("installPluginsMenus");
1540

  
1541
		TreeSet<SortableMenu> orderedMenus = getOrderedMenus();
1542

  
1314 1543
		// Se itera por los menus ordenados
1315 1544
		Iterator<SortableMenu> e = orderedMenus.iterator();
1316 1545

  
......
1319 1548
			try {
1320 1549
				SortableMenu sm = e.next();
1321 1550

  
1551
				logger.info(sm.menu.getPosition()+":"+sm.menu.getText()+":"+sm.loader.getPluginName()+":"+sm.extension.getClassName());
1552
				
1322 1553
				frame.addMenu(sm.loader, sm.extension, sm.menu);
1323 1554

  
1324 1555
			} catch (ClassNotFoundException ex) {
......
1343 1574
		}
1344 1575
	}
1345 1576

  
1577
	public class PluginMenuItem {
1578
		private Menu menu;
1579
		private PluginClassLoader loader;
1580
		private SkinExtensionType extension;
1581

  
1582
		PluginMenuItem(PluginClassLoader loader,
1583
				SkinExtensionType extension, Menu menu) {
1584
			this.menu = menu;
1585
			this.loader = loader;
1586
			this.extension = extension;
1587
		}
1588
		
1589
		public PluginServices getPlugin() {
1590
			String pluginName = loader.getPluginName();
1591
			return PluginServices.getPluginServices(pluginName);
1592
		}
1593
		
1594
		public String getExtensionName() {
1595
			return this.extension.getClassName();
1596
		}
1597
		
1598
		public IExtension getExtension() {
1599
			Class<?> extensionClass;
1600
			try {
1601
				extensionClass = loader.loadClass(this.extension.getClassName());
1602
			} catch (ClassNotFoundException e) {
1603
				return null;
1604
			}
1605
			return PluginServices.getExtension(extensionClass);
1606
		}
1607
		
1608
		public String getText() {
1609
			return this.menu.getText();
1610
		}
1611

  
1612
		public long getPosition() {
1613
			return this.menu.getPosition();
1614
		}
1615
		
1616
		public String getName() {
1617
			return this.menu.getName();
1618
		}
1619
		
1620
		public boolean isParent() {
1621
			return menu.getIs_separator();
1622
		}
1623
		
1624
		public String getPluginName() {
1625
			return this.loader.getPluginName();
1626
		}
1627
		
1628
		public ActionInfo getAction() {
1629
			ActionInfoManager manager = PluginsLocator.getActionInfoManager();
1630
			return manager.getAction(this.menu.getName());
1631
		}
1632
	}
1633
	
1634
	public List<PluginMenuItem> getPluginMenuItems() {
1635
		List<PluginMenuItem> menuItems = new ArrayList<Launcher.PluginMenuItem>();
1636

  
1637
		TreeSet<SortableMenu> orderedMenus = getOrderedMenus();
1638
		Iterator<SortableMenu> e = orderedMenus.iterator();
1639
		while (e.hasNext()) {
1640
				SortableMenu sm = e.next();
1641
				PluginMenuItem item = new PluginMenuItem(sm.loader, sm.extension, sm.menu);
1642
				menuItems.add(item);
1643
		}
1644
		return menuItems;
1645
	}
1646

  
1647
	
1346 1648
	/**
1347 1649
	 * Installs the menus, toolbars, actiontools, selectable toolbars and
1348 1650
	 * combos. The order in which they are shown is determined here.
1349 1651
	 */
1350 1652
	private void installPluginsControls() {
1653
		logger.info("installPluginsControls (toolbars)");
1654

  
1351 1655
		Iterator<String> i = pluginsConfig.keySet().iterator();
1352 1656

  
1353 1657
		Map<Extension, PluginServices> extensionPluginServices = new HashMap<Extension, PluginServices>();
......
1572 1876
				}
1573 1877
				// Install popup menus
1574 1878
				PopupMenus pus = pc.getPopupMenus();
1575

  
1576 1879
				if (pus != null) {
1577 1880
					PopupMenu[] menus = pus.getPopupMenu();
1578

  
1579 1881
					for (int j = 0; j < menus.length; j++) {
1580
						frame.addPopupMenu(ps.getClassLoader(), menus[j]);
1882
						String menuName = "(unknow)";
1883
						try  {
1884
							menuName = menus[j].getName();
1885
							frame.addPopupMenu(ps.getClassLoader(), menus[j]);
1886
						} catch(Throwable ex) {
1887
							addError("Error adding popup menu' "+ menuName +"' in plugin '"+pName+"'.");
1888
						}
1581 1889
					}
1582 1890
				}
1583 1891
			} catch (Throwable e3) {
......
1767 2075
				i = pluginsConfig.keySet().iterator();
1768 2076
			}
1769 2077
		}
2078
		registerActions();
1770 2079
	}
1771 2080

  
1772 2081
	private void pluginsMessages() {
......
1829 2138

  
1830 2139
		for (int i = 0; i < pluginDirs.length; i++) {
1831 2140
			if (pluginDirs[i].isDirectory()) {
2141
				String pluginName =  pluginDirs[i].getName();
1832 2142
				File configXml = new File(pluginDirs[i].getAbsolutePath(),
1833 2143
						"config.xml");
1834 2144

  
1835 2145
				try {
1836 2146
					FileInputStream is = new FileInputStream(configXml);
1837
					Reader xml = org.gvsig.utils.xml.XMLEncodingUtils
1838
							.getReader(is);
2147
					Reader xml = org.gvsig.utils.xml.XMLEncodingUtils.getReader(is);
1839 2148
					if (xml == null) {
1840 2149
						// the encoding was not correctly detected, use system
1841 2150
						// default
......
1844 2153
						// use a buffered reader to improve performance
1845 2154
						xml = new BufferedReader(xml);
1846 2155
					}
1847
					PluginConfig pConfig = (PluginConfig) PluginConfig
1848
							.unmarshal(xml);
2156
					PluginConfig pConfig = (PluginConfig) PluginConfig.unmarshal(xml);
1849 2157
					pluginsConfig.put(pluginDirs[i].getName(), pConfig);
1850 2158
				} catch (FileNotFoundException e) {
1851
					logger
1852
							.info("Plugin folder without config.xml. Skip plugin '"
1853
									+ pluginDirs[i].getAbsolutePath() + "'.");
2159
					logger.info("Plugin '"+pluginName+"' without config.xml ("
2160
									+ pluginDirs[i].getAbsolutePath() + ").");
1854 2161
				} catch (MarshalException e) {
1855
					this.addError("Can't load plugin '"
1856
							+ pluginDirs[i].getAbsolutePath() + "'.", e);
2162
					this.addError("Can't load plugin '"+pluginName+"', incorrect config.xml." + e.getMessage() +" ("
2163
							+ pluginDirs[i].getAbsolutePath() + ").", e);
1857 2164
				} catch (ValidationException e) {
1858
					this.addError("Can't load plugin '"
1859
							+ pluginDirs[i].getAbsolutePath() + "'.", e);
2165
					this.addError("Can't load plugin '"+pluginName+"', invalid config.xml." + e.getMessage() +" ("
2166
							+ pluginDirs[i].getAbsolutePath() + ").", e);
1860 2167
				}
1861 2168
			}
1862 2169
		}
1863 2170

  
1864 2171
		if (pluginsConfig.size() == 0) {
1865
			logger
1866
					.error("No valid plugin was found. The plugins directory currently is: "
2172
			logger.error("No valid plugin was found. The plugins directory currently is: "
1867 2173
							+ pDir.getAbsolutePath()
1868 2174
							+ "\n\tDid you specify the correct directory in the Launch Configuration parameters?\n\tExiting now...");
1869 2175
			System.exit(-1);
......
2201 2507
			if (e2.menu.hasPosition() && !e1.menu.hasPosition()) {
2202 2508
				return Integer.MAX_VALUE;
2203 2509
			}
2204
			if (e1.menu.getPosition() != e2.menu.getPosition()) {
2510
			
2511
			if( e1.menu.getPosition() == e2.menu.getPosition() ) {
2205 2512
				// we don't return 0 unless both objects are the same, otherwise
2206 2513
				// the objects get overwritten in the treemap
2207
				return e1.menu.getPosition() - e2.menu.getPosition();
2208
			} else {
2209 2514
				return (e1.toString().compareTo(e2.toString()));
2210 2515
			}
2516
    		if( e1.menu.getPosition() > e2.menu.getPosition() ) {
2517
				return Integer.MAX_VALUE;
2518
			}
2519
    		return Integer.MIN_VALUE;
2520
    		
2211 2521
		}
2212 2522
	}
2213 2523

  
......
2223 2533
			menu = menu2;
2224 2534
			this.loader = loader;
2225 2535
		}
2536
		
2226 2537
	}
2227 2538

  
2228 2539
	private static class SortableTool {
......
2321 2632

  
2322 2633
		public int compare(SortableTool e1, SortableTool e2) {
2323 2634
			// compare the toolbars which contain the tools
2324
			int result = toolBarComp.compare(e1, e2);
2635
			long result = toolBarComp.compare(e1, e2);
2325 2636
			if (result != 0) { // if the toolbars are different, use their order
2326
				return result;
2637
				return result>0? 1:-1;
2327 2638
			}
2328 2639
			// otherwise, compare the tools
2329
			int e1Position = -1, e2Position = -1;
2640
			long e1Position = -1, e2Position = -1;
2330 2641

  
2331 2642
			if (e1.actiontool != null) {
2332 2643
				if (e1.actiontool.hasPosition()) {
......
2359 2670
				// we don't return 0 unless both objects are the same, otherwise
2360 2671
				// the objects get overwritten in the treemap
2361 2672
				if (result != 0) {
2362
					return result;
2673
					return  result>0? 1:-1;
2363 2674
				}
2364 2675
			}
2365 2676
			return e1.toString().compareTo(e2.toString());
......
2552 2863
	public static String getAppHomeDir() {
2553 2864
		return appHomeDir;
2554 2865
	}
2866
	
2867
    public static File getApplicationHomeFolder() {
2868
        return new File(getAppHomeDir());
2869
    }
2555 2870

  
2556 2871
	/**
2557 2872
	 * Sets Home Directory location of the application. May be set from outside
......
2648 2963
	// }
2649 2964

  
2650 2965
	public static void initIconThemes() {
2651
		IconThemeManager iconManager = IconThemeManager.getIconThemeManager();
2652
		IIconTheme icontheme = iconManager.getIconThemeFromConfig();
2653
		if (icontheme != null) {
2654
			iconManager.setCurrent(icontheme);
2966
		PluginsManager pluginsManager = PluginsLocator.getManager();
2967
		IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
2968
		
2969
		File f = new File(pluginsManager.getApplicationFolder(),"icon-theme");
2970
		if( !f.exists() ) { 
2971
			f.mkdir();
2655 2972
		}
2973
		iconManager.getRepository().add(f,"_Global");
2974
		
2975
		f = new File(pluginsManager.getApplicationHomeFolder(),"icon-theme");
2976
		if( !f.exists() ) {
2977
			f.mkdir();
2978
		}
2979
		iconManager.getRepository().add(f,"_User");
2980
		
2981
		// TODO: falta por cargar de algun fichero de config el nombre del tema 
2982
		//		  por deecto a usar y seleccionarlo aqui como tema corriente.
2983
		//
2656 2984
	}
2657 2985

  
2658 2986
	/**

Also available in: Unified diff