svn commit: r16826 - trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram

Thomas Neustupny <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: thn
Date: 2009-02-22 04:33:04-0800
New Revision: 16826

Added:
   trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/ActionSetOperation.java   (contents, props changed)
Modified:
   trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigMessage.java

Log:
fix for issue 5665: quickly choose a valid operation for a message

Added: trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/ActionSetOperation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/ActionSetOperation.java?view=markup&pathrev=16826
==============================================================================
--- (empty file)
+++ trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/ActionSetOperation.java	2009-02-22 04:33:04-0800
@@ -0,0 +1,67 @@
+// $Id$
+// Copyright (c) 1996-2009 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.sequence2.diagram;
+
+import java.awt.event.ActionEvent;
+
+import org.argouml.model.Model;
+import org.tigris.gef.undo.UndoableAction;
+
+/**
+ * Action to set the operation of an action.
+ * 
+ * @author Thomas Neustupny ([email protected])
+ */
+public class ActionSetOperation extends UndoableAction {
+
+    private Object action;
+    private Object operation;
+	
+    /**
+     * The constructor.
+     * 
+     * @param ac The action
+     * @param op The operation
+     * @param label The menu item label for the operation
+     */
+    public ActionSetOperation(Object ac, Object op, String label) {
+        super(label, null);
+        //super(Model.getFacade().getName(op), null);
+        action = ac;
+        operation = op;
+    }
+
+    /*
+     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        //TODO: What can we do with other kind of actions?
+        if (Model.getFacade().isACallAction(action)) {
+            Model.getCommonBehaviorHelper().setOperation(action, operation);
+        }
+        super.actionPerformed(e);
+    }
+}

Modified: trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigMessage.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigMessage.java?view=diff&pathrev=16826&r1=16825&r2=16826
==============================================================================
--- trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigMessage.java	(original)
+++ trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigMessage.java	2009-02-22 04:33:04-0800
@@ -26,16 +26,25 @@
 
 import java.awt.Color;
 import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.Vector;
+
+import javax.swing.JSeparator;
 
 import org.apache.log4j.Logger;
 import org.argouml.model.Model;
 import org.argouml.model.UmlChangeEvent;
+import org.argouml.notation.Notation;
+import org.argouml.notation.NotationProvider;
 import org.argouml.notation.NotationProviderFactory2;
 import org.argouml.notation.SDNotationSettings;
+import org.argouml.ui.ArgoJMenu;
 import org.argouml.uml.diagram.DiagramSettings;
 import org.argouml.uml.diagram.ui.FigEdgeModelElement;
 import org.argouml.uml.diagram.ui.FigTextGroup;
@@ -200,7 +209,56 @@
     public Object getAction() {
         return action;
     }
- 
+
+    /**
+     * @param me the MouseEvent that triggered the popup menu request
+     * @return a Vector containing a combination of these 4 types: Action,
+     *         JMenu, JMenuItem, JSeparator.
+     */
+    @Override
+    public Vector getPopUpActions(MouseEvent me) {
+        Vector popUpActions = super.getPopUpActions(me);
+        
+        // Operations ...
+        if (Model.getFacade().isACallAction(getAction())) {
+            ArgoJMenu opMenu = buildOperationMenu();
+            int index = popUpActions.size() - getPopupAddOffset() - 1;
+            if (index < 0) {
+                index = 0;
+            }
+            popUpActions.add(index, new JSeparator());
+            popUpActions.add(index, opMenu);
+        }
+
+        return popUpActions;
+    }
+
+    protected ArgoJMenu buildOperationMenu() {
+        ArgoJMenu opMenu = new ArgoJMenu("Operation");
+        Iterator<Object> iter = getReceiverOperations().iterator();
+        opMenu.setEnabled(iter.hasNext());
+        while (iter.hasNext()) {
+            Object op = iter.next();
+            NotationProvider np = null;
+            try {
+                String s = getNotationSettings().getNotationLanguage();
+                np = NotationProviderFactory2.getInstance()
+                    .getNotationProvider(
+                        NotationProviderFactory2.TYPE_OPERATION,
+                        op,
+                        Notation.findNotation(s));
+            } catch (Exception e) {
+                //TODO: add logging, but this will never happen and is handled
+                np = null;
+            }
+            String label = (np != null)
+                ? np.toString(op, getNotationSettings())
+                : Model.getFacade().getName(op);
+            opMenu.add(new ActionSetOperation(getAction(), op, label));
+        }
+        return opMenu;
+    }
+
     @Override
     public Selection makeSelection() {
         return new SelectionMessage(this);
@@ -352,7 +410,24 @@
             LOG.error("Exception caught", e);
         }
     }
-    
+
+    private Collection<Object> getReceiverOperations() {
+        ArrayList<Object> opList = new ArrayList<Object>();
+        Object action = getAction();
+	    Object receiver = Model.getFacade().getReceiver(getOwner());
+        if (action != null && receiver != null) {
+            //TODO: What can we do with other kind of actions?
+            if (Model.getFacade().isACallAction(action)) {
+                Iterator bases =
+                    Model.getFacade().getBases(receiver).iterator();
+                while (bases.hasNext()) {
+                    Object base = bases.next();
+                    opList.addAll(Model.getFacade().getOperations(base));
+                }
+            }
+        }
+        return opList;
+    }
     /**
      * Determines the activator of this message based on the message position
      * in relation to other messages.

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=1208567

To unsubscribe from this discussion, e-mail: [[email protected]].
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.