Index: MDIFrame.java
===================================================================
--- MDIFrame.java	(revision 38563)
+++ MDIFrame.java	(revision 38564)
@@ -45,7 +45,6 @@
 import java.awt.Dimension;
 import java.awt.FlowLayout;
 import java.awt.Insets;
-import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ComponentEvent;
@@ -73,20 +72,24 @@
 import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JSeparator;
-import javax.swing.KeyStroke;
 import javax.swing.MenuElement;
 import javax.swing.SwingUtilities;
 import javax.swing.Timer;
 import javax.swing.WindowConstants;
 
+import org.gvsig.andami.IconThemeHelper;
 import org.gvsig.andami.Launcher;
 import org.gvsig.andami.LibraryExtension;
 import org.gvsig.andami.PluginServices;
+import org.gvsig.andami.PluginsLocator;
+import org.gvsig.andami.actioninfo.ActionInfo;
+import org.gvsig.andami.actioninfo.ActionInfoManager;
+import org.gvsig.andami.actioninfo.ActionInfoStatusCache;
 import org.gvsig.andami.messages.Messages;
-import org.gvsig.andami.messages.NotificationManager;
 import org.gvsig.andami.plugins.ExtensionDecorator;
 import org.gvsig.andami.plugins.IExtension;
 import org.gvsig.andami.plugins.PluginClassLoader;
@@ -100,6 +103,8 @@
 import org.gvsig.andami.ui.mdiManager.MDIManager;
 import org.gvsig.andami.ui.mdiManager.MDIManagerFactory;
 import org.gvsig.gui.beans.controls.IControl;
+import org.gvsig.tools.swing.api.ToolsSwingLocator;
+import org.gvsig.tools.swing.icontheme.IconTheme;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -269,7 +274,9 @@
         if (!SwingUtilities.isEventDispatchThread()) {
             throw new RuntimeException("No Event Dispatch Thread");
         }
-
+        
+        Class<? extends IExtension> classExtension = (Class<? extends IExtension>) loader.loadClass(ext.getClassName());
+        
         // Para traducir
         PluginServices ps =
             PluginServices.getPluginServices(loader.getPluginName());
@@ -301,8 +308,6 @@
         btn.setVisible(false);
         String name = toolBar.getName();
 
-        MDIManagerFactory.createManager().registerAction(ext.getClassName(), selectableTool);
-        
         SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name);
 
         if (jtb == null) {
@@ -330,7 +335,7 @@
                 btn.getActionCommand());
         }
 
-        controlClass.put(btn, loader.loadClass(ext.getClassName()));
+        controlClass.put(btn, classExtension);
 
         if (selectableTool.getName() != null) {
             btn.setName(selectableTool.getName());
@@ -370,15 +375,14 @@
         if (!SwingUtilities.isEventDispatchThread()) {
             throw new RuntimeException("No Event Dispatch Thread");
         }
-
+        Class<? extends IExtension> classExtension = (Class<? extends IExtension>) loader.loadClass(ext.getClassName());
+        
         // Para traducir los textos que vengan
         PluginServices ps =
             PluginServices.getPluginServices(loader.getPluginName());
 
         JToolBarButton btn;
-        ImageIcon image =
-            PluginServices.getIconTheme().get(actionTool.getIcon(),
-                ps.getClassLoader());
+        ImageIcon image = IconThemeHelper.getImageIcon(actionTool.getIcon());
 
         if (image != null) {
             btn = new JToolBarButton(actionTool.getText(), image);
@@ -398,8 +402,6 @@
         btn.setEnabled(false);
         btn.setVisible(false);
 
-        MDIManagerFactory.createManager().registerAction(ext.getClassName(), actionTool);
-        
         String name = toolBar.getName();
 
         SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name);
@@ -414,7 +416,7 @@
 
         jtb.add(btn);
 
-        controlClass.put(btn, loader.loadClass(ext.getClassName()));
+        controlClass.put(btn, classExtension);
 
         if (actionTool.getName() != null) {
             btn.setName(actionTool.getName());
@@ -511,20 +513,8 @@
         if (!SwingUtilities.isEventDispatchThread()) {
             throw new RuntimeException("No Event Dispatch Thread");
         }
+		JMenu menuPadre = createMenuAncestors(menu, loader);
 
-        JMenu menuPadre = createMenuAncestors(menu, loader);
-
-        // Se registra y a�ade el menu
-        /*
-         * String[] aux = menu.getText().split("/");
-         * 
-         * if (aux.length == 2)
-         * if (aux[1].equals("----"))
-         * {
-         * menuPadre.addSeparator();
-         * return;
-         * }
-         */
         if (menu.getIs_separator()) {
             menuPadre.addSeparator();
             return;
@@ -532,13 +522,10 @@
 
         JMenuItem nuevoMenu = createJMenuItem(loader, menu);
         nuevoMenu.addMouseListener(tooltipListener);
-        nuevoMenu.addActionListener(this);
+        //nuevoMenu.addActionListener(this);
         menuPadre.add(nuevoMenu);
-        controlClass.put(nuevoMenu, loader.loadClass(ext.getClassName()));
-
-        MDIManagerFactory.createManager().registerAction(ext.getClassName(), menu);
-
-        
+        Class<? extends IExtension> classExtension = (Class<? extends IExtension>) loader.loadClass(ext.getClassName());
+        controlClass.put(nuevoMenu, classExtension);
     }
 
     /**
@@ -743,15 +730,31 @@
      *            Evento producido
      */
     public void actionPerformed(ActionEvent e) {
-        Object control = e.getSource();
-        org.gvsig.andami.plugins.IExtension ext =
-            (org.gvsig.andami.plugins.IExtension) classesExtensions
-                .get(controlClass.get(control));
-        String actionCommand = e.getActionCommand();
+        
+//        org.gvsig.andami.plugins.IExtension ext =
+//            (org.gvsig.andami.plugins.IExtension) classesExtensions
+//                .get(controlClass.get(control));
+    	String actionName = "(unknow)";
         try {
-            logger.info("{}.execute('{}')", ext.getClass().getSimpleName(), actionCommand);
-            ext.execute(actionCommand);
+            JComponent control = (JComponent) e.getSource();
+            actionName = control.getName();
+            
+        	ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
+        	ActionInfo action = actionManager.getAction(control.getName());
+        	Object args = null;
+            if( control instanceof IControl ) {
+            	args = ((IControl) control).getValue();
+            }
+            if( args == null ) {
+            	action.execute();
+            } else {
+            	action.execute(args);            	
+            }
+        	
+//            logger.info("{}.execute('{}')", ext.getClass().getSimpleName(), actionCommand);
+//            ext.execute(actionCommand);
 
+        	String actionCommand = e.getActionCommand();
             try {
                 JToolBarToggleButton toggle = (JToolBarToggleButton) control;
                 ToggleButtonModel model = (ToggleButtonModel) toggle.getModel();
@@ -760,14 +763,15 @@
             } catch (NullPointerException ex) {
             }
 
-        } catch (RuntimeException t) {
-            if (ext == null) {
-                logger.error(Messages
-                    .getString("No_extension_associated_with_this_event_")
-                    + e.getActionCommand());
-            }
-            NotificationManager.addError(Messages
-                .getString("MDIFrame.Error_no_capturado_por_el_usuario"), t);
+        } catch (Throwable ex) {
+        	logger.error("Can't perform action '"+actionName+"'.",ex);
+//            if (ext == null) {
+//                logger.error(Messages
+//                    .getString("No_extension_associated_with_this_event_")
+//                    + e.getActionCommand());
+//            }
+//            NotificationManager.addError(Messages
+//                .getString("MDIFrame.Error_no_capturado_por_el_usuario"), t);
         }
 
         enableControls();
@@ -818,13 +822,9 @@
             popupMap.put(name, popupMenu);
         }
 
-        // Se a�aden las entradas
         Menu[] menues = menu.getMenu();
-
         for (int i = 0; i < menues.length; i++) {
-            // Se registra y a�ade el menu
             JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
-
             popupMenu.add(nuevoMenu);
         }
     }
@@ -845,53 +845,38 @@
 
         PluginServices ps =
             PluginServices.getPluginServices(loader.getPluginName());
+        
         String text = menu.getText();
-        text = text.substring(text.lastIndexOf('/') + 1);
+        int n = text.lastIndexOf('/');
+        if( n>=0  ) {
+        	text = text.substring(n + 1);
+        }
         String translatedText = ps.getText(text);
 
+        IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
         if (menu.getIcon() != null) {
-            ImageIcon image =
-                PluginServices.getIconTheme().get(menu.getIcon(),
-                    ps.getClassLoader());
-            if (image != null) {
+        	if( iconTheme.exists(menu.getIcon()) ) {
+        		ImageIcon image = iconTheme.get(menu.getIcon());
                 nuevoMenu = new JMenuItem(translatedText, image);
             } else {
-                nuevoMenu =
-                    new JMenuItem(translatedText, PluginServices.getIconTheme()
-                        .get(noIcon));
-                logger.error(PluginServices
-                    .getText(this, "Unable_to_find_icon")
-                    + ": "
-                    + menu.getIcon());
+                nuevoMenu = new JMenuItem(translatedText);
+                logger.info("menu icon '"+ menu.getIcon()+ "' not exists.");
             }
         } else {
             nuevoMenu = new JMenuItem(translatedText);
         }
-        nuevoMenu.setName(text);
-        if (menu.getMnemonic() != null) {
-            if (menu.getMnemonic().length() != 1) {
-                throw new RuntimeException(
-                    "Mnemonic must be 1 character length");
-            }
+        nuevoMenu.setName(menu.getName());
+//		if (menu.getMnemonic() != null) {
+//			if (menu.getMnemonic().length() != 1) {
+//				throw new RuntimeException(
+//						"Mnemonic must be 1 character length");
+//			}
+//			nuevoMenu.setMnemonic(KeyMapping.getKey(menu.getMnemonic()
+//					.charAt(0)));
+//		}
 
-            nuevoMenu.setMnemonic(KeyMapping.getKey(menu.getMnemonic()
-                .charAt(0)));
-        }
-
         if (menu.getKey() != null) {
-            String osName = System.getProperty("os.name");
-            boolean MAC_OS_X = osName.toLowerCase().startsWith("mac os x");
-            if (MAC_OS_X) {
-                // en OS X, en vez de hardwiring la ShortcutKey, usamos el
-                // default sugerido por el OS
-                nuevoMenu.setAccelerator(KeyStroke.getKeyStroke(KeyMapping
-                    .getKey(menu.getKey().charAt(0)), Toolkit
-                    .getDefaultToolkit().getMenuShortcutKeyMask()));
-            } else {
-                nuevoMenu.setAccelerator(KeyStroke.getKeyStroke(
-                    KeyMapping.getKey(menu.getKey().charAt(0)),
-                    ActionEvent.ALT_MASK));
-            }
+            nuevoMenu.setAccelerator(KeyMapping.getKeyStroke(menu.getKey()));
         }
 
         nuevoMenu.setActionCommand(menu.getActionCommand());
@@ -907,6 +892,13 @@
         nuevoMenu.setEnabled(true);
         nuevoMenu.setVisible(true);
 
+        if( menu.getName() != null ) {
+    		ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
+    		final ActionInfo actionInfo = actionManager.getAction(menu.getName());
+    		if( actionInfo != null ) {
+    			nuevoMenu.addActionListener(actionInfo);
+    		}
+        }
         return nuevoMenu;
     }
 
@@ -1004,76 +996,96 @@
      */
     public void enableControls() {
         if (!SwingUtilities.isEventDispatchThread()) {
-            throw new RuntimeException("No Event Dispatch Thread");
+        	SwingUtilities.invokeLater(new Runnable() {
+				public void run() {
+					enableControls();
+				}
+			});
+			return;
         }
 
+        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
+        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
+        
         Iterator e = classesExtensions.values().iterator();
-        HashMap estadoExtensiones = new HashMap();
-        HashMap visibilidadExtensiones = new HashMap();
 
-        while (e.hasNext()) {
-            ExtensionDecorator ext = (ExtensionDecorator) e.next();
+//        HashMap estadoExtensiones = new HashMap();
+//        HashMap visibilidadExtensiones = new HashMap();
+//
+//        while (e.hasNext()) {
+//            ExtensionDecorator ext = (ExtensionDecorator) e.next();
+//
+//            try {
+//                if (estadoExtensiones.get(ext) == null) {
+//                    boolean b;
+//                    if (ext.getVisibility() == ExtensionDecorator.ALWAYS_VISIBLE) {
+//                        b = true;
+//                    } else
+//                        if (ext.getVisibility() == ExtensionDecorator.ALWAYS_INVISIBLE) {
+//                            b = false;
+//                        } else {
+//                            if (PluginServices.getExclusiveUIExtension() == null) {
+//                                b = ext.isVisible();
+//                            } else {
+//                                b =
+//                                    PluginServices.getExclusiveUIExtension()
+//                                        .isVisible(ext.getExtension());
+//                            }
+//                        }
+//                    Boolean visible = new Boolean(b);
+//                    Boolean enabled = new Boolean(false);
+//
+//                    if (visible.booleanValue()) {
+//                        if (PluginServices.getExclusiveUIExtension() == null) {
+//                            enabled = new Boolean(ext.isEnabled());
+//                        } else {
+//                            enabled =
+//                                new Boolean(PluginServices
+//                                    .getExclusiveUIExtension().isEnabled(
+//                                        ext.getExtension()));
+//                        }
+//
+//                    }
+//
+//                    estadoExtensiones.put(ext, enabled);
+//                    visibilidadExtensiones.put(ext, visible);
+//                }
+//            } catch (Throwable e1) {
+//                NotificationManager.addError(Messages
+//                    .getString("MDIFrame.Error_no_capturado_por_el_usuario"),
+//                    e1);
+//                estadoExtensiones.put(ext, Boolean.FALSE);
+//            }
+//        }
 
-            try {
-                if (estadoExtensiones.get(ext) == null) {
-                    boolean b;
-                    if (ext.getVisibility() == ExtensionDecorator.ALWAYS_VISIBLE) {
-                        b = true;
-                    } else
-                        if (ext.getVisibility() == ExtensionDecorator.ALWAYS_INVISIBLE) {
-                            b = false;
-                        } else {
-                            if (PluginServices.getExclusiveUIExtension() == null) {
-                                b = ext.isVisible();
-                            } else {
-                                b =
-                                    PluginServices.getExclusiveUIExtension()
-                                        .isVisible(ext.getExtension());
-                            }
-                        }
-                    Boolean visible = new Boolean(b);
-                    Boolean enabled = new Boolean(false);
-
-                    if (visible.booleanValue()) {
-                        if (PluginServices.getExclusiveUIExtension() == null) {
-                            enabled = new Boolean(ext.isEnabled());
-                        } else {
-                            enabled =
-                                new Boolean(PluginServices
-                                    .getExclusiveUIExtension().isEnabled(
-                                        ext.getExtension()));
-                        }
-
-                    }
-
-                    estadoExtensiones.put(ext, enabled);
-                    visibilidadExtensiones.put(ext, visible);
-                }
-            } catch (Throwable e1) {
-                NotificationManager.addError(Messages
-                    .getString("MDIFrame.Error_no_capturado_por_el_usuario"),
-                    e1);
-                estadoExtensiones.put(ext, Boolean.FALSE);
-            }
-        }
-
         // Enable or disable controls, according to its associated extensions
         e = controlClass.keySet().iterator();
 
         while (e.hasNext()) {
             JComponent control = (JComponent) e.next();
+            String actionlName = control.getName();
+            ActionInfo action = actionManager.getAction(actionlName);
+            try {
+//            	
+//                org.gvsig.andami.plugins.IExtension ext =
+//                    (org.gvsig.andami.plugins.IExtension) classesExtensions
+//                        .get(controlClass.get(control));
+//                boolean enabled =
+//                    ((Boolean) estadoExtensiones.get(ext)).booleanValue();
+//                boolean visible =
+//                    ((Boolean) visibilidadExtensiones.get(ext)).booleanValue();
 
-            try {
-                org.gvsig.andami.plugins.IExtension ext =
-                    (org.gvsig.andami.plugins.IExtension) classesExtensions
-                        .get(controlClass.get(control));
-                boolean enabled =
-                    ((Boolean) estadoExtensiones.get(ext)).booleanValue();
-                boolean visible =
-                    ((Boolean) visibilidadExtensiones.get(ext)).booleanValue();
+                boolean enabled = false;
+                boolean visible = cache.isVisible(action);
+                if( visible ) {
+                	enabled = cache.isEnabled(action);
+                }
+                    
                 control.setEnabled(enabled);
                 control.setVisible(visible);
             } catch (Exception ex) {
+            	logger.info("Can't enable/show control '"+actionlName +"'.",ex);
+            	this.message("Can't enable/show control '"+actionlName +"'.", JOptionPane.ERROR_MESSAGE);
                 control.setEnabled(false);
                 control.setVisible(false);
             }
@@ -1146,8 +1158,41 @@
 
         showMemory();
     }
+    
+    public void refreshControls() {
+        if (!SwingUtilities.isEventDispatchThread()) {
+        	SwingUtilities.invokeLater(new Runnable() {
+				public void run() {
+					enableControls();
+				}
+			});
+			return;
+        }
 
-    /**
+        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
+        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
+        
+        Iterator e = controlClass.keySet().iterator();
+
+        while (e.hasNext()) {
+            JComponent control = (JComponent) e.next();
+            String actionlName = control.getName();
+            ActionInfo action = actionManager.getAction(actionlName);
+            if( action!=null ) {
+	            if( control instanceof AbstractButton ) {
+	            	AbstractButton button = (AbstractButton) control;
+	            	button.setIcon(action.getIcon());
+	            }
+            }
+        }
+        enableControls();
+    }
+
+    public void message(String msg, int messageTyoe) {
+    	this.getStatusBar().message(msg, messageTyoe);
+	}
+
+	/**
      * Establece la visibilidad de un menu y todos sus descendientes en la
      * jerarquia teniendo en cuenta la visibilidad de todos los submenus.
      * 
@@ -1479,7 +1524,14 @@
         // Se registra y a�ade el menu
         JMenuItem nuevoMenu = createJMenuItem(loader, menu);
         nuevoMenu.addMouseListener(tooltipListener);
-        nuevoMenu.addActionListener(listener);
+        if( listener != null ) {
+    		ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
+    		final ActionInfo actionInfo = actionManager.getAction(menu.getName());
+    		if( actionInfo != null ) {
+    			nuevoMenu.removeActionListener(actionInfo);
+    		}
+        	nuevoMenu.addActionListener(listener);
+        }
         menuPadre.add(nuevoMenu);
 
         infoCodedMenus.put(menu, nuevoMenu);
