svn commit: r17164 - branches/BRANCH_0_28_x/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/UMLSequenceDiagram.java

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-07-06 13:08:02-0700
New Revision: 17164

Modified:
   branches/BRANCH_0_28_x/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/UMLSequenceDiagram.java

Log:
Add to branch the sequence diagram fixes

Modified: branches/BRANCH_0_28_x/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/UMLSequenceDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/BRANCH_0_28_x/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/UMLSequenceDiagram.java?view=diff&pathrev=17164&r1=17163&r2=17164
==============================================================================
--- branches/BRANCH_0_28_x/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/UMLSequenceDiagram.java	(original)
+++ branches/BRANCH_0_28_x/src/argouml-core-diagrams-sequence2/src/org/argouml/sequence2/diagram/UMLSequenceDiagram.java	2009-07-06 13:08:02-0700
@@ -32,6 +32,8 @@
 
 import org.apache.log4j.Logger;
 import org.argouml.i18n.Translator;
+import org.argouml.model.CollaborationsHelper;
+import org.argouml.model.Facade;
 import org.argouml.model.Model;
 import org.argouml.uml.diagram.DiagramSettings;
 import org.argouml.uml.diagram.static_structure.ui.FigComment;
@@ -313,4 +315,97 @@
     public ModePlace getModePlace(GraphFactory gf, String instructions) {
         return new ModePlaceClassifierRole(gf, instructions);
     }
+
+    public Object getCollaboration() {
+        return ((SequenceDiagramGraphModel) getGraphModel()).getCollaboration();
+    }
+
+    /**
+     * Ensure that all elements represented in this diagram are part of this
+     * diagrams collaboration
+     */
+    public void postLoad() {
+        super.postLoad();
+        
+        final Facade facade = Model.getFacade();                   
+        
+        // See issue 5811. We have collaborationroles, associationroles
+        // and messages and actions saved to the incorrect interaction and
+        // and collaboration. If we detect this circumstance at load then
+        // move the model elements and delete the empty collaborations
+        // and interactions.
+        final Object collaboration = getCollaboration();
+        Object correctInteraction = null;
+        for (final Fig f : getLayer().getContents()) {
+            final Object modelElement = f.getOwner();
+            if (f instanceof FigMessage) {
+                final Object interaction = facade.getInteraction(modelElement);
+                final Object context = facade.getContext(interaction);
+                if (context == collaboration) {
+                    correctInteraction = interaction;
+                }
+            }
+        }
+        if (correctInteraction != null) {
+            final CollaborationsHelper collabHelper =
+                Model.getCollaborationsHelper();
+            for (final Fig f : getLayer().getContents()) {
+                if (f instanceof FigMessage) {
+                    final Object message = f.getOwner();
+                    final Object interaction = facade.getInteraction(message);
+                    final Object context = facade.getContext(interaction);
+                    final Object action = facade.getAction(message);
+                    if (context != collaboration) {
+                        LOG.warn("namespace of interaction does not match "
+                                + "collaboration - moving "
+                                + message + " to " + correctInteraction);
+                        collabHelper.addMessage(correctInteraction, message);
+                        Model.getCoreHelper().setNamespace(
+                                action, collaboration);
+                        // If this leaves the interaction empty then
+                        // delete it.
+                        if (facade.getMessages(interaction).isEmpty()) {
+                            LOG.warn("Deleting empty interaction "
+                                    + interaction);
+                            Model.getUmlFactory().delete(interaction);
+                            // If that in turn leaves the collaboration empty
+                            // then delete that also.
+                            if (facade.getOwnedElements(context).isEmpty()) {
+                                LOG.warn("Deleting empty collaboration "
+                                        + context);
+                                Model.getUmlFactory().delete(context);
+                            }
+                        }
+                    }
+                } else if (f instanceof FigClassifierRole) {
+                    final Object cr = f.getOwner();
+                    final Object namespace = facade.getNamespace(cr);
+                    if (namespace != collaboration) {
+                        LOG.warn("namespace of classifierrole does not match "
+                                + "collaboration - moving "
+                                + cr + " to " + collaboration);
+                        
+                        Model.getCoreHelper().setNamespace(
+                                cr, collaboration);
+                        
+                        Collection associationEndRoles =
+                            facade.getAssociationEnds(cr);
+                        for (Object assEndRole : associationEndRoles) {
+                            Object assRole = facade.getAssociation(assEndRole);
+                            if (facade.getNamespace(assRole) != collaboration) {
+                                Model.getCoreHelper().setNamespace(
+                                        assRole, collaboration);
+                            }
+                        }
+                        
+                        if (facade.getOwnedElements(namespace).isEmpty()) {
+                            LOG.warn("Deleting empty collaboration "
+                                    + collaboration);
+                            Model.getUmlFactory().delete(collaboration);
+                        }
+                    }
+                }
+            }
+        }
+    }
 }

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

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.