svn commit: r15595 - trunk/src/argouml-app/src/org/argouml/uml/diagram/ui

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2008-08-20 11:21:50-0700
New Revision: 15595

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionList.java   (contents, props changed)
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java

Log:
RESOLVED - task 5332: DeleteFromModel enabled for read-only elements on diagrams 
http://argouml.tigris.org/issues/show_bug.cgi?id=5332

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionList.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionList.java?view=diff&rev=15595&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionList.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionList.java&r1=15594&r2=15595
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionList.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/ActionList.java	2008-08-20 11:21:50-0700
@@ -1,140 +1,152 @@
-// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $

-// Copyright (c) 2008 The Regents of the University of California. All

-// Rights Reserved. Permission to use, copy, modify, and distribute this

-// software and its documentation without fee, and without a written

-// agreement is hereby granted, provided that the above copyright notice

-// and this paragraph appear in all copies. This software program and

-// documentation are copyrighted by The Regents of the University of

-// California. The software program and documentation are supplied "AS

-// IS", without any accompanying services from The Regents. The Regents

-// does not warrant that the operation of the program will be

-// uninterrupted or error-free. The end-user understands that the program

-// was developed for research purposes and is advised not to rely

-// exclusively on the program for any reason. IN NO EVENT SHALL THE

-// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,

-// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,

-// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF

-// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF

-// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY

-// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE

-// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF

-// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,

-// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

-

-package org.argouml.uml.diagram.ui;

-

-import java.util.List;

-import java.util.Vector;

-

-import javax.swing.Action;

-import javax.swing.JMenu;

-import javax.swing.JMenuItem;

-

-import org.argouml.kernel.UmlModelMutator;

-

-/**

- * A specialist collection used for filtering the return from getPopUpActions

- * in FigNodeModelElement and FigEdgeModelElement.

- * This class should remain package scope as I imagine its lifetime to be

- * short (we need a better way of registering Actions with Figs)

- *

- * @author Bob Tarling

- */

-class ActionList extends Vector {

-    

-    final private boolean readonly;

-    

-    ActionList(List list, boolean readonly) {

-        super(list);

-        this.readonly = readonly;

-    }

-    

-    public boolean add(Object o) {

-        if (readonly) {

-            if (o instanceof UmlModelMutator) {

-                return false;

-            } else if (o instanceof JMenu) {

-                o = trimMenu(o);

-            }

-        }

-        if (o != null) {

-            return super.add(o);

-        } else {

-            return false;

-        }

-    }

-    

-    public void addElement(Object o) {

-        if (readonly) {

-            if (o instanceof UmlModelMutator) {

-                return;

-            } else if (o instanceof JMenu) {

-                o = trimMenu(o);

-            }

-        }

-        if (o != null) {

-            super.addElement(o);

-        }

-    }

-    

-    public void add(int index, Object o) {

-        if (readonly) {

-            if (o instanceof UmlModelMutator) {

-                return;

-            } else if (o instanceof JMenu) {

-                o = trimMenu(o);

-            }

-        }

-        if (o != null) {

-            super.add(index, o);

-        }

-    }

-    

-    public void insertElementAt(Object o, int index) {

-        if (readonly) {

-            if (o instanceof UmlModelMutator) {

-                return;

-            } else if (o instanceof JMenu) {

-                o = trimMenu(o);

-            }

-        }

-        if (o != null) {

-            super.insertElementAt(o, index);

-        }

-    }

-    

-    /**

-     * Trim out any menu items that have a UML model mutating action

-     * @param o

-     * @return The trimmed menu or null if all contents trimmed out.

-     */

-    private JMenu trimMenu(Object o) {

-        JMenu menu = (JMenu) o;

-        for (int i = menu.getItemCount() - 1; i >= 0; --i) {

-            JMenuItem menuItem = menu.getItem(i);

-            Action action = menuItem.getAction();

-            if (action == null

-                    && menuItem.getActionListeners().length > 0

-                    && menuItem.getActionListeners()[0] instanceof Action) {

-                action = (Action) menuItem.getActionListeners()[0];

-            }

-            if (isUmlMutator(action)) {

-                menu.remove(i);

-            }

-        }

-        if (menu.getItemCount() == 0) {

-            return null;

-        }

-        return menu;

-    }

-    

-    /**

-     * @param a An object (typically an Action) to test if its a UML model

-     * mutator

-     * @return true if the given action mutates the UML model.

-     */

-    private boolean isUmlMutator(Object a) {

-        return a.getClass().isAnnotationPresent(UmlModelMutator.class);

-    }

-}

+// $Id$
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.uml.diagram.ui;
+
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.Action;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+import org.argouml.kernel.UmlModelMutator;
+
+/**
+ * A specialist collection used for filtering the return from getPopUpActions
+ * in FigNodeModelElement and FigEdgeModelElement.
+ * This class should remain package scope as I imagine its lifetime to be
+ * short (we need a better way of registering Actions with Figs)
+ *
+ * @author Bob Tarling
+ */
+class ActionList<E> extends Vector<E> {
+    
+    private final boolean readonly;
+    
+    /**
+     * Construct an ActionList which filters modifying actions when
+     * the readonly flag is set using initialList as the initial
+     * content.
+     * 
+     * @param initialList initial contents to use for list.
+     * @param readOnly true if mutating actions should be filtered
+     */
+    ActionList(List<? extends E> initialList, boolean readOnly) {
+        super(initialList);
+        this.readonly = readOnly;
+    }
+    
+    @Override
+    public boolean add(E o) {
+        if (readonly) {
+            if (isUmlMutator(o) ) {
+                return false;
+            } else if (o instanceof JMenu) {
+                o = (E) trimMenu((JMenu) o);
+            }
+        }
+        if (o != null) {
+            return super.add(o);
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public void addElement(E o) {
+        if (readonly) {
+            if (isUmlMutator(o)) {
+                return;
+            } else if (o instanceof JMenu) {
+                o = (E) trimMenu((JMenu) o);
+            }
+        }
+        if (o != null) {
+            super.addElement(o);
+        }
+    }
+    
+    @Override
+    public void add(int index, E o) {
+        if (readonly) {
+            if (isUmlMutator(o)) {
+                return;
+            } else if (o instanceof JMenu) {
+                o = (E) trimMenu((JMenu) o);
+            }
+        }
+        if (o != null) {
+            super.add(index, o);
+        }
+    }
+    
+    @Override
+    public void insertElementAt(E o, int index) {
+        if (readonly) {
+            if (isUmlMutator(o)) {
+                return;
+            } else if (o instanceof JMenu) {
+                o = (E) trimMenu((JMenu) o);
+            }
+        }
+        if (o != null) {
+            super.insertElementAt(o, index);
+        }
+    }
+    
+    /**
+     * Trim out any menu items that have a UML model mutating action
+     * @param menu the menu to be filtered
+     * @return The trimmed menu or null if all contents trimmed out.
+     */
+    private JMenu trimMenu(JMenu menu) {
+        for (int i = menu.getItemCount() - 1; i >= 0; --i) {
+            JMenuItem menuItem = menu.getItem(i);
+            Action action = menuItem.getAction();
+            if (action == null
+                    && menuItem.getActionListeners().length > 0
+                    && menuItem.getActionListeners()[0] instanceof Action) {
+                action = (Action) menuItem.getActionListeners()[0];
+            }
+            if (isUmlMutator(action)) {
+                menu.remove(i);
+            }
+        }
+        if (menu.getItemCount() == 0) {
+            return null;
+        }
+        return menu;
+    }
+    
+    /**
+     * @param a An object (typically an Action) to test if its a UML model
+     * mutator
+     * @return true if the given action mutates the UML model.
+     */
+    private boolean isUmlMutator(Object a) {
+        return a instanceof UmlModelMutator 
+            || a.getClass().isAnnotationPresent(UmlModelMutator.class);
+    }
+}

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java?view=diff&rev=15595&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java&r1=15594&r2=15595
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	2008-08-20 11:21:50-0700
@@ -166,7 +166,7 @@
     /**
      * Offset from the end of the set of popup actions at which new items
      * should be inserted by concrete figures.
-     * See #getPopUpActions()
+     * @See {@link #getPopUpActions(MouseEvent)}
      */
     private static int popupAddOffset;
 
@@ -475,8 +475,9 @@
     }
 
     /**
-     * This method shall return a Vector of one of these 4 types:
+     * This method returns a Vector of one of these 4 types:
      * AbstractAction, JMenu, JMenuItem, JSeparator.
+     * {@inheritDoc}
      */
     @Override
     public Vector getPopUpActions(MouseEvent me) {
@@ -497,8 +498,11 @@
                     ProjectActions.getInstance().getRemoveFromDiagramAction());
             popupAddOffset++;
         }
-        popUpActions.add(new ActionDeleteModelElements());
-        popupAddOffset++;
+        
+        if (!isReadOnly()) {
+            popUpActions.add(new ActionDeleteModelElements());
+            popupAddOffset++;
+        }
 
         /* Check if multiple items are selected: */
         if (TargetManager.getInstance().getTargets().size() == 1) {
@@ -550,7 +554,8 @@
             // we don't what they are. - tfm
             stereotypesView.addRadioItem(new ActionStereotypeViewTextual(this));
             stereotypesView.addRadioItem(new ActionStereotypeViewBigIcon(this));
-            stereotypesView.addRadioItem(new ActionStereotypeViewSmallIcon(this));
+            stereotypesView.addRadioItem(
+                    new ActionStereotypeViewSmallIcon(this));
             
             popUpActions.add(0, stereotypesView);
         }
@@ -758,6 +763,7 @@
     /*
      * @see org.tigris.gef.presentation.Fig#makeSelection()
      */
+    @Override
     public Selection makeSelection() {
         return new SelectionNodeClarifiers(this);
     }
@@ -1227,7 +1233,8 @@
      * of a change to a model element. Do not call this method directly
      * yourself.
      * <p>Override this in any subclasses in order to change what model
-     * elements the FigNode is listening to as a result of change to the model.</p>
+     * elements the FigNode is listening to as a result of change to the model.
+     * </p>
      * <p>This method is guaranteed by the framework to be running on the same
      * thread as the model subsystem.</p>
      * TODO: Lets refactor this at some time to take UmlChangeEvent argument
@@ -1536,6 +1543,8 @@
     /*
      * @see org.tigris.gef.presentation.Fig#classNameAndBounds()
      */
+    @Deprecated
+    @Override
     public String classNameAndBounds() {
         return getClass().getName()
             + "[" + getX() + ", " + getY() + ", "
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.