svn commit: r15443 - trunk/src/argouml-app/src/org/argouml/uml/ui: . foundation/core

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2008-08-01 17:00:41-0700
New Revision: 15443

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/ui/PropPanel.java
   trunk/src/argouml-app/src/org/argouml/uml/ui/TabProps.java
   trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/PropPanelModelElement.java

Log:
Issue 5271: Remove actions to edit a readonly model element

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/PropPanel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/PropPanel.java?view=diff&rev=15443&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/PropPanel.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/PropPanel.java&r1=15442&r2=15443
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/PropPanel.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/PropPanel.java	2008-08-01 17:00:41-0700
@@ -57,6 +57,7 @@
 import org.argouml.i18n.Translator;
 import org.argouml.kernel.ProfileConfiguration;
 import org.argouml.kernel.ProjectManager;
+import org.argouml.kernel.UmlModelMutator;
 import org.argouml.model.Model;
 import org.argouml.ui.ActionCreateContainedModelElement;
 import org.argouml.ui.LookAndFeelMgr;
@@ -235,7 +236,9 @@
     }
     
     public void buildToolbar() {
-        ToolBarFactory factory = new ToolBarFactory(actions);
+        LOG.debug("Building toolbar");
+
+        ToolBarFactory factory = new ToolBarFactory(getActions());
         factory.setRollover(true);
         factory.setFloatable(false);
         JToolBar toolBar = factory.createToolBar();
@@ -248,6 +251,14 @@
                 Translator.localize("action.select"));
     }
 
+    /**
+     * Get the actions that will make up the toolbar on this panel.
+     * @return The list of actions to show for this panel.
+     */
+    protected List getActions() {
+        return actions;
+    }
+
     private static class TargettableButton extends JButton
         implements TargettableModelView {
 
@@ -595,6 +606,7 @@
         if (isVisible()) {
             fireTargetSet(e);
         }
+        buildToolbar();
     }
 
     private void fireTargetSet(TargetEvent targetEvent) {

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/TabProps.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/TabProps.java?view=diff&rev=15443&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/TabProps.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/TabProps.java&r1=15442&r2=15443
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/TabProps.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/TabProps.java	2008-08-01 17:00:41-0700
@@ -245,9 +245,6 @@
             LOG.debug("Factory created " + panel.getClass().getName()
                     + " for " + trgt.getClass().getName());
             panels.put(trgt.getClass(), panel);
-            if (panel instanceof PropPanel) {
-        	((PropPanel) panel).buildToolbar();
-            }
             return panel;
         }
 
@@ -281,9 +278,9 @@
             ((Orientable) propPanel).setOrientation(getOrientation());
         }
         
+        // TODO: We shouldn't need this as well as the above.
         if (propPanel instanceof PropPanel) {
             ((PropPanel) propPanel).setOrientation(getOrientation());
-            ((PropPanel) propPanel).buildToolbar();
         }
 
         return propPanel;

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/PropPanelModelElement.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/PropPanelModelElement.java?view=diff&rev=15443&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/PropPanelModelElement.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/PropPanelModelElement.java&r1=15442&r2=15443
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/PropPanelModelElement.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/PropPanelModelElement.java	2008-08-01 17:00:41-0700
@@ -24,6 +24,10 @@
 
 package org.argouml.uml.ui.foundation.core;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.Action;
 import javax.swing.ImageIcon;
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
@@ -33,6 +37,7 @@
 import javax.swing.JTextField;
 
 import org.argouml.i18n.Translator;
+import org.argouml.kernel.UmlModelMutator;
 import org.argouml.model.Model;
 import org.argouml.ui.targetmanager.TargetManager;
 import org.argouml.uml.ui.PropPanel;
@@ -170,6 +175,29 @@
                 new UMLDerivedCheckBox());
 
     }
+    
+    /**
+     * This overrides the behaviour of the base class to filter out any
+     * actions that could be used to attempt to modify the UML model on
+     * a readonly element.
+     * @return The list of actions to show for this panel.
+     */
+    protected final List getActions() {
+        List actions = super.getActions();
+        if (Model.getFacade().isAUMLElement(getTarget())
+                && Model.getModelManagementHelper().isReadOnly(getTarget())) {
+            final List filteredActions = new ArrayList(2);
+            for (Object o : actions) {
+                if (o instanceof Action && !o.getClass().isAnnotationPresent(
+                        UmlModelMutator.class)) {
+                    filteredActions.add(o);
+                }
+            }
+            return filteredActions;
+        } else {
+            return actions;
+        }
+    }
 
     /**
      * Calling this method navigates the target one level up, to the owner of
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.