Revision 5361

View differences:

trunk/frameworks/_fwAndami/src/com/iver/andami/Launcher.java
690 690
	}
691 691

  
692 692
	/**
693
	 * Installs the menus, toolbars, actiontools and selectable toolbars.
694
	 * The order in which they are shown is determined here. 
693
	 *
695 694
	 */
696 695
	private static void installPluginsControls() {
697 696
		Iterator i = pluginsConfig.keySet().iterator();
......
699 698
		HashMap extensionPluginServices = new HashMap();
700 699
		HashMap extensionPluginConfig = new HashMap();
701 700
		TreeMap orderedExtensions = new TreeMap(new ExtensionComparator());
702
		
703
		// First of all, sort the extensions.
704
		// We need to iterate on the plugins, and iterate on each plugin's extensions
705
		// (each plugin may contain one or more extensions) 
706
		while (i.hasNext()) { // iterate on the plugins
707
			String pName = (String) i.next();
708
			PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
709
			PluginServices ps = (PluginServices) pluginsServices.get(pName);
710
			
711
			Extension[] exts = pc.getExtensions().getExtension();
712
			
713
			for (int j = 0; j < exts.length; j++) { // iterate on the extensions
714
				if (exts[j].getActive()) {
715
					if (orderedExtensions.containsKey(exts[j])) {
716
						logger.error(Messages.getString(
717
						"Launcher.Two_extensions_with_the_same_priority") +
718
						exts[j].getClassName());
701
		while (i.hasNext()) {
702
				String pName = (String) i.next();
703
				PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
704
				PluginServices ps = (PluginServices) pluginsServices.get(pName);
705

  
706
				Extension[] exts = pc.getExtensions().getExtension();
707

  
708
				for (int j = 0; j < exts.length; j++) {
709
					if (exts[j].getActive()) {
710
						if (orderedExtensions.containsKey(exts[j])) {
711
							logger.error(Messages.getString(
712
									"Launcher.Two_extensions_with_the_same_priority") +
713
								exts[j].getClassName());
714
						}
715

  
716
						orderedExtensions.put(exts[j], null);
717
						extensionPluginServices.put(exts[j], ps);
718
						extensionPluginConfig.put(exts[j], pc);
719 719
					}
720
					
721
					orderedExtensions.put(exts[j], null);
722
					extensionPluginServices.put(exts[j], ps);
723
					extensionPluginConfig.put(exts[j], pc);
724 720
				}
725
			}
726 721
		}
727 722

  
728 723
		///try {
729
		TreeMap orderedTools = new TreeMap(new ToolComparator());
730
		Iterator e = orderedExtensions.keySet().iterator();
731
		
732
		// Ahora se ordenan las herramientas (actiontools y selectabletools) de las extensiones
733
		while (e.hasNext()) {
734
			Extension ext = (Extension) e.next();
735
			
736
			ToolBar[] toolbars = ext.getToolBar();
737
			
738
			for (int k = 0; k < toolbars.length; k++) {
739
				ActionTool[] tools = toolbars[k].getActionTool();
740
				
741
				for (int t = 0; t < tools.length; t++) {
742
					SortableToolBar sm = new SortableToolBar(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
743
							toolbars[k], tools[t]);
744
					orderedTools.put(sm, null);
745
					///frame.addTool(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
746
					///	toolbars[k], tools[t]);
747
				}
748
				
749
				SelectableTool[] sTools = toolbars[k].getSelectableTool();
750
				
751
				for (int t = 0; t < sTools.length; t++) {
752
					SortableToolBar sm=new SortableToolBar(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
753
							toolbars[k], sTools[t]);
754
					orderedTools.put(sm, null);
755
					///frame.addTool(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
756
					///	toolbars[k], sTools[t]);
757
				}
758
			}
759
		}
724
			TreeMap orderedToolBars = new TreeMap(new ToolBarComparator());
725
			Iterator e = orderedExtensions.keySet().iterator();
760 726

  
761
		// Ahora se ordenan las herramientas (actiontools y selectabletools) de las extensiones de MDI
762
		i = pluginsConfig.keySet().iterator();
763
		while (i.hasNext()) {
764
			String pName = (String) i.next();
765
			PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
766
			PluginServices ps = (PluginServices) pluginsServices.get(pName);
767
			 
768
			SkinExtension skinExt = pc.getExtensions().getSkinExtension();
769
			
770
			if (skinExt != null) {
771
				ToolBar[] toolbars = skinExt.getToolBar();
772
				
727
			// Se instalan las extensiones
728
			while (e.hasNext()) {
729
				Extension ext = (Extension) e.next();
730

  
731
				ToolBar[] toolbars = ext.getToolBar();
732

  
773 733
				for (int k = 0; k < toolbars.length; k++) {
774 734
					ActionTool[] tools = toolbars[k].getActionTool();
775
					
735

  
776 736
					for (int t = 0; t < tools.length; t++) {
777
						SortableToolBar stb=new SortableToolBar(ps.getClassLoader(), skinExt,
737
						SortableToolBar sm = new SortableToolBar(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
778 738
								toolbars[k], tools[t]);
779
						orderedTools.put(stb,null);
780
						///frame.addTool(ps.getClassLoader(), skinExt,
739
						orderedToolBars.put(sm, null);
740
						///frame.addTool(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
781 741
						///	toolbars[k], tools[t]);
782 742
					}
783
					
743

  
784 744
					SelectableTool[] sTools = toolbars[k].getSelectableTool();
785
					
745

  
786 746
					for (int t = 0; t < sTools.length; t++) {
787
						SortableToolBar stb=new SortableToolBar(ps.getClassLoader(), skinExt,
747
						SortableToolBar sm=new SortableToolBar(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
788 748
								toolbars[k], sTools[t]);
789
						orderedTools.put(stb,null);
790
						///frame.addTool(ps.getClassLoader(), skinExt,
749
						orderedToolBars.put(sm, null);
750
						///frame.addTool(((PluginServices)extensionPluginServices.get(ext)).getClassLoader(), ext,
791 751
						///	toolbars[k], sTools[t]);
792 752
					}
793 753
				}
794 754
			}
795
			//Se instalan los popup menus
796
			PopupMenus pus = pc.getPopupMenus();
797
			
798
			if (pus != null) {
799
				PopupMenu[] menus = pus.getPopupMenu();
800
				
801
				for (int j = 0; j < menus.length; j++) {
802
					frame.addPopupMenu(ps.getClassLoader(), menus[j]);
755

  
756
			i = pluginsConfig.keySet().iterator();
757
			while (i.hasNext()) {
758
				String pName = (String) i.next();
759
				PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
760
				PluginServices ps = (PluginServices) pluginsServices.get(pName);
761
				// Se instalan las extensiones de MDI
762
				SkinExtension skinExt = pc.getExtensions().getSkinExtension();
763
	
764
				if (skinExt != null) {
765
					ToolBar[] toolbars = skinExt.getToolBar();
766
	
767
					for (int k = 0; k < toolbars.length; k++) {
768
						ActionTool[] tools = toolbars[k].getActionTool();
769
	
770
						for (int t = 0; t < tools.length; t++) {
771
							SortableToolBar stb=new SortableToolBar(ps.getClassLoader(), skinExt,
772
									toolbars[k], tools[t]);
773
							orderedToolBars.put(stb,null);
774
							///frame.addTool(ps.getClassLoader(), skinExt,
775
							///	toolbars[k], tools[t]);
776
						}
777
	
778
						SelectableTool[] sTools = toolbars[k].getSelectableTool();
779
	
780
						for (int t = 0; t < sTools.length; t++) {
781
							SortableToolBar stb=new SortableToolBar(ps.getClassLoader(), skinExt,
782
									toolbars[k], sTools[t]);
783
							orderedToolBars.put(stb,null);
784
							///frame.addTool(ps.getClassLoader(), skinExt,
785
							///	toolbars[k], sTools[t]);
786
						}
787
					}
788
	
789
					/*
790
					   Menu[] menu = skinExt.getMenu();
791
					   for (int k = 0; k < menu.length; k++) {
792
					       frame.addMenu(ps.getClassLoader(), skinExt, menu[k]);
793
					   }
794
					 */
803 795
				}
796
				//Se instalan los popup menus
797
				PopupMenus pus = pc.getPopupMenus();
798

  
799
				if (pus != null) {
800
					PopupMenu[] menus = pus.getPopupMenu();
801

  
802
					for (int j = 0; j < menus.length; j++) {
803
						frame.addPopupMenu(ps.getClassLoader(), menus[j]);
804
					}
805
				}
804 806
			}
805
		}
807
//			Se itera por los menus ordenados
808
			Iterator t = orderedToolBars.keySet().iterator();
806 809

  
807
		// Se itera por las herramientas ordenadas, para
808
		// a?adirlas a la interfaz de forma ordenada
809
		Iterator t = orderedTools.keySet().iterator();		
810
		while (t.hasNext()) {
811
			try {
812
				SortableToolBar stb = (SortableToolBar) t.next();
813
				if (stb.actiontool!=null)
814
					frame.addTool(stb.loader, stb.extension,stb.toolbar, stb.actiontool);
815
				else
816
					frame.addTool(stb.loader, stb.extension,stb.toolbar, stb.selectabletool);
817
			} catch (ClassNotFoundException ex) {
818
				logger.error(Messages.getString(
819
				"Launcher.No_se_encontro_la_clase_de_la_extension"), ex);
810
			// Se ordenan los menues
811
			while (t.hasNext()) {
812
				try {
813
					SortableToolBar stb = (SortableToolBar) t.next();
814
					if (stb.actiontool!=null)
815
						frame.addTool(stb.loader, stb.extension,stb.toolbar, stb.actiontool);
816
					else
817
						frame.addTool(stb.loader, stb.extension,stb.toolbar, stb.selectabletool);
818
				} catch (ClassNotFoundException ex) {
819
					logger.error(Messages.getString(
820
							"Launcher.No_se_encontro_la_clase_de_la_extension"), ex);
821
				}
820 822
			}
821
		}
822 823
		///} catch (ClassNotFoundException e) {
823 824
		///	logger.error(Messages.getString(
824 825
		///			"Launcher.No_se_encontro_la_clase_de_la_extension"), e);
......
1652 1653
	/**
1653 1654
	 * DOCUMENT ME!
1654 1655
	 */
1655
	private static class SortableToolBar {
1656
		public PluginClassLoader loader;
1657
		public ToolBar toolbar;
1658
		public ActionTool actiontool;
1659
		public SelectableTool selectabletool;
1660
		public SkinExtensionType extension;
1661

  
1662
		/**
1663
		 * DOCUMENT ME!
1664
		 *
1665
		 * @param loader DOCUMENT ME!
1666
		 * @param skinExt
1667
		 * @param menu2
1668
		 */
1669
		public SortableToolBar(PluginClassLoader loader,
1670
			SkinExtensionType skinExt, ToolBar toolbar2,ActionTool actiontool2) {
1671
			extension = skinExt;
1672
			toolbar = toolbar2;
1673
			actiontool=actiontool2;
1674
			this.loader = loader;
1675
		}
1676
		public SortableToolBar(PluginClassLoader loader,
1677
				SkinExtensionType skinExt, ToolBar toolbar2,SelectableTool selectabletool2) {
1678
			extension = skinExt;
1679
			toolbar = toolbar2;
1680
			selectabletool=selectabletool2;
1681
			this.loader = loader;
1682
		}
1683
	}
1684
	/**
1685
	 * DOCUMENT ME!
1686
	 */
1687 1656
	private static class ToolBarComparator implements Comparator {
1688 1657
		private static ExtensionComparator extComp = new ExtensionComparator();
1689 1658

  
......
1698 1667
		public int compare(Object o1, Object o2) {
1699 1668
			SortableToolBar e1 = (SortableToolBar) o1;
1700 1669
			SortableToolBar e2 = (SortableToolBar) o2;
1701
			
1702
			// if the toolbars have the same name, they are considered to be
1703
			// the same toolbar, so we don't need to do further comparing
1704
			if (e1.toolbar.getName().equals(e2.toolbar.getName()))
1705
				return 0;
1706
			
1670

  
1707 1671
			if (!e1.toolbar.hasPosition() && !e2.toolbar.hasPosition()) {
1708 1672
				if (e1.extension instanceof SkinExtensionType) {
1709 1673
					return 1;
......
1722 1686
				return Integer.MAX_VALUE;
1723 1687
			}
1724 1688
			if (e1.toolbar.getPosition() != e2.toolbar.getPosition())
1725
				return e1.toolbar.getPosition() - e2.toolbar.getPosition();
1689
			return e1.toolbar.getPosition() - e2.toolbar.getPosition();
1726 1690
			
1727 1691
			if (e1.toolbar.getActionTool().equals(e2.toolbar.getActionTool()) && e1.toolbar.getSelectableTool().equals(e2.toolbar.getSelectableTool())){
1728 1692
				return 0;
1729 1693
			}
1730
			return (e1.toolbar.toString().compareTo(e2.toolbar.toString())); 
1694
			return 1; 
1731 1695
		}
1732 1696
	}
1733
	
1734 1697
	/**
1735
	 * <p>This class is used to compare tools (selectabletool and actiontool),
1736
	 * using the "position"
1737
	 * attribute.</p>
1738
	 * <p>The ordering criteria are:</p>
1739
	 * <ul><li>If the tools are placed in different toolbars, they use the toolbars'
1740
	 * order.
1741
	 * (using the ToolBarComparator).</li>
1742
	 * <li></li>
1743
	 * <li>If any of the tools has not 'position' attribute, the tool which
1744
	 * <strong>has</strong> the attribute will be placed first.</li>
1745
	 * <li>If both tools have the same position (or they don't have a
1746
	 * 'position' attribute), the priority of the extensions where the tool is defined.</li></ul>
1698
	 * DOCUMENT ME!
1747 1699
	 *
1748
	 * @author cesar
1700
	 * @author $author$
1749 1701
	 * @version $Revision$
1750 1702
	 */
1751
	private static class ToolComparator implements Comparator {
1752
		private static ToolBarComparator toolBarComp = new ToolBarComparator();
1703
	private static class SortableToolBar {
1704
		public PluginClassLoader loader;
1705
		public ToolBar toolbar;
1706
		public ActionTool actiontool;
1707
		public SelectableTool selectabletool;
1708
		public SkinExtensionType extension;
1709

  
1753 1710
		/**
1754 1711
		 * DOCUMENT ME!
1755 1712
		 *
1756
		 * @param o1 DOCUMENT ME!
1757
		 * @param o2 DOCUMENT ME!
1758
		 *
1759
		 * @return DOCUMENT ME!
1713
		 * @param loader DOCUMENT ME!
1714
		 * @param skinExt
1715
		 * @param menu2
1760 1716
		 */
1761
		public int compare(Object o1, Object o2) {
1762
			// compare the toolbars which contain the tools
1763
			int result = toolBarComp.compare(o1, o2);
1764
			if (result != 0) { // if the toolbars are different, use their order
1765
				return result;
1766
			}
1767
			// otherwise, compare the tools
1768
			SortableToolBar e1 = (SortableToolBar) o1;
1769
			SortableToolBar e2 = (SortableToolBar) o2;
1770
			int e1Position=Integer.MAX_VALUE, e2Position=Integer.MAX_VALUE;
1771

  
1772
			if (e1.actiontool!=null) {
1773
				if (e1.actiontool.hasPosition())
1774
					e1Position = e1.actiontool.getPosition();
1775
			}
1776
			else if (e1.selectabletool!=null) {
1777
				if (e1.selectabletool.hasPosition())
1778
					e1Position = e1.selectabletool.getPosition();
1779
			}
1780
			
1781
			if (e2.actiontool!=null) {
1782
				if (e2.actiontool.hasPosition())
1783
					e2Position = e2.actiontool.getPosition();
1784
			}
1785
			else if (e2.selectabletool!=null){
1786
				if (e2.selectabletool.hasPosition())
1787
					e2Position = e2.selectabletool.getPosition();
1788
			}
1789
			return e1Position - e2Position; 
1717
		public SortableToolBar(PluginClassLoader loader,
1718
			SkinExtensionType skinExt, ToolBar toolbar2,ActionTool actiontool2) {
1719
			extension = skinExt;
1720
			toolbar = toolbar2;
1721
			actiontool=actiontool2;
1722
			this.loader = loader;
1790 1723
		}
1724
			public SortableToolBar(PluginClassLoader loader,
1725
				SkinExtensionType skinExt, ToolBar toolbar2,SelectableTool selectabletool2) {
1726
				extension = skinExt;
1727
				toolbar = toolbar2;
1728
				selectabletool=selectabletool2;
1729
				this.loader = loader;
1730
			}
1791 1731
	}
1792 1732
	
1793 1733
	

Also available in: Unified diff