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

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-02-08 16:46:31-0800
New Revision: 16775

Modified:
   trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigActivation.java
   trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigLifeLine.java

Log:
Issue 5691: Only end activation when return message found pointing to same classifier role as message that created the activation.

Modified: trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigActivation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigActivation.java?view=diff&pathrev=16775&r1=16774&r2=16775
==============================================================================
--- trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigActivation.java	(original)
+++ trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigActivation.java	2009-02-08 16:46:31-0800
@@ -42,7 +42,9 @@
     
     private FigRect rectFig;
     private FigDestroy destroyFig;
-
+    
+    // The FigMessage that triggered this FigActivation into existence
+    private FigMessage activatingMessage;
     
     /**
      * TODO: Document
@@ -78,11 +80,16 @@
      * @param owner owning UML element or null
      * @param bounds position (top center) and size. If the width or height is
      *            0, the default will be used.
+     * @param activatingMessage The FigMessage that triggered this activation
+     *            to exist
      * @param settings rendering settings
      */
-    public FigActivation(Object owner, Rectangle bounds,
-            DiagramSettings settings) {
-        this(owner, bounds, settings, false);
+    public FigActivation(
+            final Object owner,
+            final Rectangle bounds,
+            final DiagramSettings settings,
+            final FigMessage activatingMessage) {
+        this(owner, bounds, settings, activatingMessage, false);
     }
 
     /**
@@ -92,11 +99,18 @@
      * @param bounds position (top center) and size.  If the width or height is
      *            0, the default will be used.
      * @param settings rendering settings
+     * @param activatingMessage The FigMessage that triggered this activation
+     *            to exist
      * @param destroy true if activation should end with a destroy fig.
      */
-    public FigActivation(Object owner, Rectangle bounds,
-            DiagramSettings settings, boolean destroy) {
+    public FigActivation(
+            final Object owner,
+            final Rectangle bounds,
+            final DiagramSettings settings,
+            final FigMessage activatingMessage,
+            final boolean destroy) {
         super(owner, settings);
+        this.activatingMessage = activatingMessage;
         initialize(bounds, destroy);
     }
     
@@ -127,5 +141,18 @@
     public boolean isDestroy () {
         return destroyFig != null;
     }
-
-}
+    
+    public boolean isActivatorEnd(FigMessage messageFig) {
+        if (messageFig == null) {
+            throw new IllegalArgumentException(
+                    "An instance of FigMessage is required");
+        }
+        if (!messageFig.isReturnAction()) {
+            return false;
+        }
+        if (activatingMessage == null) {
+            return true;
+        }
+        return messageFig.getDestFigNode() == activatingMessage.getSourceFigNode();
+    }
+}
\ No newline at end of file

Modified: trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigLifeLine.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigLifeLine.java?view=diff&pathrev=16775&r1=16774&r2=16775
==============================================================================
--- trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigLifeLine.java	(original)
+++ trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/FigLifeLine.java	2009-02-08 16:46:31-0800
@@ -29,7 +29,6 @@
 import java.util.LinkedList;
 import java.util.List;
 
-import org.argouml.model.Model;
 import org.argouml.uml.diagram.DiagramSettings;
 import org.argouml.uml.diagram.ui.ArgoFigGroup;
 import org.tigris.gef.presentation.FigLine;
@@ -102,37 +101,36 @@
         for (FigActivation figAct : stackedActivations) {
             addFig(figAct);
         }       
-	// TODO: Do we need this?
+        // TODO: Do we need this?
         calcBounds();
     }
 
     private List<FigActivation> createStandardActivations(
-    		final List<FigMessage> figMessages) {        
-	
+                final List<FigMessage> figMessages) {        
+        
         final List<FigActivation> newActivations =
             new LinkedList<FigActivation>();
-	
+        
         // Check here if there are no incoming call actions
         // if not then create an activation at the top of the lifeline
+        FigActivation currentActivation = null;
         if (!hasIncomingCallActionFirst(figMessages)) {
-            newActivations.add(createActivationFig(
+            currentActivation = createActivationFig(
                     getOwner(),
                     lineFig.getX(),
                     lineFig.getY(), 
                     lineFig.getWidth(), 
-                    lineFig.getHeight(), 
-                    getSettings()));
-        } else {
-            final FigClassifierRole cr =
-                (FigClassifierRole) getGroup();                
-            
-            FigActivation currentActivation = null;
+                    lineFig.getHeight(),
+                    getSettings(),
+                    null);
+        }
+        
+        for (FigMessage figMessage : figMessages) {
+            int ySender = 0;
             
-            for (FigMessage figMessage : figMessages) {
-                int ySender = 0;
+            if (!figMessage.isSelfMessage()) {
                 if (currentActivation == null
-                        && cr.equals(figMessage.getDestFigNode())
-                        && !cr.equals(figMessage.getSourceFigNode())
+                        && isIncoming(figMessage)
                         && figMessage.isCallAction()) {
                     // if we are the dest and is a call action, create the 
                     // activation, but don't add it until the height is set.
@@ -142,25 +140,26 @@
                             lineFig.getX(), 
                             ySender, 
                             0, 
-                            0, 
-                            getSettings()); 
+                            0,
+                            getSettings(),
+                            figMessage);
                 } else if (currentActivation == null
-                        && cr.equals(figMessage.getDestFigNode())
-                        && !cr.equals(figMessage.getSourceFigNode())
+                        && isIncoming(figMessage)
                         && figMessage.isCreateAction()) {
-                    // if we are the dest of a create action, create the
-                    // entire activation, because we should need the destroy X
+                    // if we are the destination of a create action,
+                    // create the entire activation, because we should
+                    // need the destroy X
                     currentActivation = createActivationFig(
                             getOwner(),
                             lineFig.getX(),
                             lineFig.getY(),
                             0,
                             0,
-                            getSettings());
+                            getSettings(),
+                            figMessage);
                 } else if (currentActivation != null
-                        && cr.equals(figMessage.getSourceFigNode()) 
-                        && !cr.equals(figMessage.getDestFigNode())
-                        && figMessage.isReturnAction()) {
+                        && isOutgoing(figMessage)
+                        && currentActivation.isActivatorEnd(figMessage)) {
                     // if we are the source of a return action
                     // the activation ends here.
                     ySender = figMessage.getStartY();
@@ -169,8 +168,7 @@
                     newActivations.add(currentActivation);
                     currentActivation = null;
                 } else if (currentActivation != null
-                        && cr.equals(figMessage.getDestFigNode())
-                        && !cr.equals(figMessage.getSourceFigNode())
+                        && isOutgoing(figMessage)
                         && figMessage.isDestroyAction()) {
                     // if we are the target of a destroy action
                     // the figlifeline ends here and we add the activation
@@ -183,41 +181,62 @@
                     currentActivation = null;
                 }
             }
-            
-            // If we have a currentAct object that means have reached the end
-            // of the lifeline with a call or a create not returned.
-            // Add the activation to the list after setting its height to end
-            // at the end of the lifeline.
-            if (currentActivation != null) {
-                currentActivation.setHeight(getHeight() - (currentActivation.getY() - getY()));
-                newActivations.add(currentActivation);
-            }
+        }
+        
+        // If we have a currentAct object that means have reached the end
+        // of the lifeline with a call or a create not returned.
+        // Add the activation to the list after setting its height to end
+        // at the end of the lifeline.
+        if (currentActivation != null) {
+            currentActivation.setHeight(
+                    getHeight() - (currentActivation.getY() - getY()));
+            newActivations.add(currentActivation);
         }
         
         return newActivations;
     }
     
-    FigActivation createActivationFig(
+    /**
+     * Return true if the given message fig is pointing in to this lifeline.
+     * @param messageFig
+     * @return true if the message is incoming
+     */
+    private boolean isIncoming(FigMessage messageFig) {
+        return (messageFig.getDestFigNode().getOwner() == getOwner());
+    }
+    
+    /**
+     * Return true if the given message fig is pointing out from this lifeline.
+     * @param messageFig
+     * @return true if the message is outgoing
+     */
+    private boolean isOutgoing(FigMessage messageFig) {
+        return (messageFig.getSourceFigNode().getOwner() == getOwner());
+    }
+    
+    private FigActivation createActivationFig(
             final Object owner, 
             final int x, 
             final int y, 
             final int w, 
-            final int h, 
-            final DiagramSettings settings) {
+            final int h,
+            final DiagramSettings settings,
+            final FigMessage messageFig) {
         return new FigActivation(
                 owner,
                 new Rectangle(x, y, w, h),
-                settings);
+                settings,
+                messageFig);
     }
     
     private List<FigActivation> createStackedActivations(
-	    final List<FigMessage> figMessages) {
-	
-	final List<FigActivation> newActivations =
-	    new LinkedList<FigActivation>();
-	
-	FigActivation currentAct = null;
-	
+            final List<FigMessage> figMessages) {
+        
+        final List<FigActivation> newActivations =
+            new LinkedList<FigActivation>();
+        
+        FigActivation currentAct = null;
+        
         for (FigMessage figMessage : figMessages) {
             int ySender = 0;
             // if we are the dest and is a call action, create the 
@@ -228,7 +247,7 @@
                     currentAct = new FigActivation(figMessage.getOwner(),
                             new Rectangle(lineFig.getX()
                                     + FigActivation.DEFAULT_WIDTH / 2, ySender,
-                                    0, 0), getSettings(), false);
+                                    0, 0), getSettings(), figMessage, false);
                 } else if (currentAct != null
                         && figMessage.isReturnAction()) {
                     ySender = figMessage.getStartY();
@@ -243,7 +262,7 @@
 
 
     private boolean hasIncomingCallActionFirst(
-    		final List<FigMessage> figMessages) {
+                final List<FigMessage> figMessages) {
         final FigClassifierRole cr =
             (FigClassifierRole) getGroup();
         if (figMessages.isEmpty()) {
@@ -258,22 +277,6 @@
         return false;
     }
     
-    private boolean hasOutgoingDestroyActions(List<FigMessage> messages) {
-        boolean found = false;
-        final FigClassifierRole cr =
-            (FigClassifierRole) getGroup();                
-        for (FigMessage message : messages) {
-            Object action = message.getAction();
-            if (cr.equals(message.getSourceFigNode())                    
-                    && !cr.equals(message.getDestFigNode())
-                    && Model.getFacade().isADestroyAction(action)) {
-                found = true;
-                break;
-            }
-        }
-        return found;
-    }
-    
     private void clearActivations() {
         for (FigActivation oldActivation : activations) {
             removeFig(oldActivation);    
@@ -320,10 +323,6 @@
         firePropChange("bounds", oldBounds, getBounds());
     }
     
-//    public int getLineWidth() {
-//        return lineFig.getLineWidth();
-//    }
-    
     public void setLineWidth(int w) {
         lineFig.setLineWidth(w);
     }

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

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.