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

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2008-02-20 10:36:34-0800
New Revision: 14139

Modified:
   trunk/src/app/src/org/argouml/uml/diagram/ui/ActionSetPath.java
   trunk/src/app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java

Log:
Improvement on the changes done for issue 4832: Show the correct pop-up menu entries.

Modified: trunk/src/app/src/org/argouml/uml/diagram/ui/ActionSetPath.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/ui/ActionSetPath.java?view=diff&rev=14139&p1=trunk/src/app/src/org/argouml/uml/diagram/ui/ActionSetPath.java&p2=trunk/src/app/src/org/argouml/uml/diagram/ui/ActionSetPath.java&r1=14138&r2=14139
==============================================================================
--- trunk/src/app/src/org/argouml/uml/diagram/ui/ActionSetPath.java	(original)
+++ trunk/src/app/src/org/argouml/uml/diagram/ui/ActionSetPath.java	2008-02-20 10:36:34-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2007 The Regents of the University of California. All
+// Copyright (c) 2007-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
@@ -24,17 +24,22 @@
 
 package org.argouml.uml.diagram.ui;
 
-import java.util.Iterator;
 import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.swing.Action;
 
 import org.argouml.i18n.Translator;
+import org.argouml.model.Model;
+import org.argouml.ui.UndoableAction;
 import org.argouml.uml.diagram.PathContainer;
+import org.tigris.gef.base.Editor;
 import org.tigris.gef.base.Globals;
 import org.tigris.gef.base.Selection;
 import org.tigris.gef.presentation.Fig;
-import org.tigris.gef.undo.UndoableAction;
 
 
 /**
@@ -44,6 +49,11 @@
  */
 class ActionSetPath extends UndoableAction {
 
+    private static final UndoableAction SHOW_PATH =
+        new ActionSetPath(false);
+    private static final UndoableAction HIDE_PATH =
+        new ActionSetPath(true);
+
     private boolean isPathVisible;
 
     /**
@@ -62,6 +72,52 @@
         }
         putValue(Action.NAME, name);
     }
+    
+    /**
+     * Static function to return the path show and/or hide actions 
+     * needed for the selected Figs.
+     * 
+     * @return Only returns the actions for the menu-items that make sense for
+     *         the current selection.
+     */
+    public static Collection<UndoableAction> getActions() {
+        Collection<UndoableAction> actions = new ArrayList<UndoableAction>();
+        Editor ce = Globals.curEditor();
+        List<Fig> figs = ce.getSelectionManager().getFigs();
+        for (Fig f : figs) {
+            if (f instanceof PathContainer) {
+                Object owner = f.getOwner();
+                if (Model.getFacade().isAModelElement(owner)) {
+                    Object ns = Model.getFacade().getNamespace(owner);
+                    if (ns != null) {
+                        /* Only show the path item when there is 
+                         * an owning namespace. */
+                        if (((PathContainer) f).isPathVisible()) {
+                            actions.add(HIDE_PATH);
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+        for (Fig f : figs) {
+            if (f instanceof PathContainer) {
+                Object owner = f.getOwner();
+                if (Model.getFacade().isAModelElement(owner)) {
+                    Object ns = Model.getFacade().getNamespace(owner);
+                    if (ns != null) {
+                        /* Only show the path item when there is 
+                         * an owning namespace. */
+                        if (!((PathContainer) f).isPathVisible()) {
+                            actions.add(SHOW_PATH);
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+        return actions;
+    }
 
     /**
      * @see org.tigris.gef.undo.UndoableAction#actionPerformed(java.awt.event.ActionEvent)
@@ -75,10 +131,10 @@
             Globals.curEditor().getSelectionManager().selections().iterator();
         while (i.hasNext()) {
             Selection sel = (Selection) i.next();
-            Fig       f   = sel.getContent();
+            Fig f = sel.getContent();
 		        
             if (f instanceof PathContainer) {
-        	((PathContainer) f).setPathVisible(!isPathVisible);
+                ((PathContainer) f).setPathVisible(!isPathVisible);
             }
         }
     }

Modified: trunk/src/app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java?view=diff&rev=14139&p1=trunk/src/app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java&p2=trunk/src/app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java&r1=14138&r2=14139
==============================================================================
--- trunk/src/app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	(original)
+++ trunk/src/app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	2008-02-20 10:36:34-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-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
@@ -83,6 +83,7 @@
 import org.argouml.ui.ArgoJMenu;
 import org.argouml.ui.Clarifier;
 import org.argouml.ui.ProjectActions;
+import org.argouml.ui.UndoableAction;
 import org.argouml.ui.targetmanager.TargetManager;
 import org.argouml.uml.StereotypeUtility;
 import org.argouml.uml.diagram.ArgoDiagram;
@@ -550,13 +551,8 @@
     protected ArgoJMenu buildShowPopUp() {
         ArgoJMenu showMenu = new ArgoJMenu("menu.popup.show");
 
-        Object owner = getOwner();
-        if (Model.getFacade().isAModelElement(owner)) {
-            Object ns = Model.getFacade().getNamespace(owner);
-            if (ns != null) {
-                /* Only show the path item when there is an owning namespace. */
-                showMenu.add(new ActionSetPath(isPathVisible()));
-            }
+        for (UndoableAction ua : ActionSetPath.getActions()) {
+            showMenu.add(ua);
         }
         return showMenu;
     }
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.