svn commit: r15424 - branches/gsoc2008/feature1_5138_bszanto: argouml-app/src/org/argouml/uml/diagram/collaboration/ui argouml-app/src/org/argouml/uml/diagram/ui argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bszanto
Date: 2008-07-31 07:50:13-0700
New Revision: 15424

Modified:
   branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/CollabDiagramRenderer.java
   branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java
   branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/DnDJGraph.java
   branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/SequenceDiagramRenderer.java

Log:
[1] Collaboration diagrams now have the same utilities like Seq2 diagrams (a classifier "Added to diagram" or DnD creates a new CR with that classifier as base); [2] removed some unused imports; [3] updated some comments

Modified: branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/CollabDiagramRenderer.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/CollabDiagramRenderer.java?view=diff&rev=15424&p1=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/CollabDiagramRenderer.java&p2=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/CollabDiagramRenderer.java&r1=15423&r2=15424
==============================================================================
--- branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/CollabDiagramRenderer.java	(original)
+++ branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/CollabDiagramRenderer.java	2008-07-31 07:50:13-0700
@@ -27,14 +27,17 @@
 import java.util.Map;
 
 import org.apache.log4j.Logger;
+import org.argouml.kernel.ProjectManager;
 import org.argouml.model.Model;
 import org.argouml.uml.CommentEdge;
+import org.argouml.uml.diagram.ArgoDiagram;
 import org.argouml.uml.diagram.UmlDiagramRenderer;
 import org.argouml.uml.diagram.static_structure.ui.FigComment;
 import org.argouml.uml.diagram.static_structure.ui.FigEdgeNote;
 import org.argouml.uml.diagram.ui.FigDependency;
 import org.argouml.uml.diagram.ui.FigGeneralization;
 import org.argouml.uml.diagram.ui.FigMessage;
+import org.argouml.uml.diagram.ui.UMLDiagram;
 import org.tigris.gef.base.Layer;
 import org.tigris.gef.graph.GraphModel;
 import org.tigris.gef.presentation.FigEdge;
@@ -82,14 +85,18 @@
 				 Object node, Map styleAttributes) {
 
         FigNode figNode = null;
-
+        ArgoDiagram diag = ProjectManager.getManager().getCurrentProject()
+                .getActiveDiagram();
         if (Model.getFacade().isAClassifierRole(node)) {
             figNode = new FigClassifierRole(gm, lay, node);
         } else if (Model.getFacade().isAMessage(node)) {
             figNode = new FigMessage(gm, lay, node);
         } else if (Model.getFacade().isAComment(node)) {
             figNode = new FigComment(gm, node);
-        } else {
+        } else if (diag instanceof UMLDiagram
+                && ((UMLDiagram) diag).doesAccept(node)) {
+            figNode = ((UMLDiagram) diag).drop(node, null);
+        } else { 
             LOG.debug("TODO: CollabDiagramRenderer getFigNodeFor");
             return null;
         }

Modified: branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java?view=diff&rev=15424&p1=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java&p2=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java&r1=15423&r2=15424
==============================================================================
--- branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java	(original)
+++ branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java	2008-07-31 07:50:13-0700
@@ -24,10 +24,13 @@
 
 package org.argouml.uml.diagram.collaboration.ui;
 
+import java.awt.Point;
+import java.awt.event.MouseEvent;
 import java.beans.PropertyVetoException;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 
 import javax.swing.Action;
 
@@ -42,10 +45,15 @@
 import org.argouml.uml.diagram.ui.RadioAction;
 import org.argouml.uml.diagram.ui.UMLDiagram;
 import org.argouml.util.ToolBarUtility;
+import org.tigris.gef.base.Editor;
+import org.tigris.gef.base.Globals;
 import org.tigris.gef.base.Layer;
 import org.tigris.gef.base.LayerPerspective;
 import org.tigris.gef.base.LayerPerspectiveMutable;
 import org.tigris.gef.base.ModeCreatePolyEdge;
+import org.tigris.gef.base.ModePlace;
+import org.tigris.gef.graph.GraphFactory;
+import org.tigris.gef.graph.GraphModel;
 import org.tigris.gef.presentation.Fig;
 import org.tigris.gef.presentation.FigNode;
 
@@ -424,6 +432,115 @@
             FigNode oldEncloser, FigNode newEncloser) {
         // Do nothing.        
     }
+    
+    /**
+     * A sequence diagram can accept all classifiers. It will add them as a new 
+     * Classifier Role with that classifier as a base.
+     * @param objectToAccept
+     * @return
+     * @see org.argouml.uml.diagram.ui.UMLDiagram#doesAccept(java.lang.Object)
+     */
+    @Override
+    public boolean doesAccept(Object objectToAccept) {
+        if (Model.getFacade().isAClassifier(objectToAccept)) {
+            return true;
+        }
+        return false;
+    }
+    
+    /**
+     * Creates a new Classifier Role with a specified base.
+     * @param base
+     * @return The new CR
+     */
+    private Object makeNewCR(Object base) {
+        Object node = null;
+        Editor ce = Globals.curEditor();
+        GraphModel gm = ce.getGraphModel();
+        if (gm instanceof CollabDiagramGraphModel) {
+            Object collaboration =
+                ((CollabDiagramGraphModel) gm).getHomeModel();
+            node =
+                Model.getCollaborationsFactory().buildClassifierRole(
+                        collaboration);
+          }
+        Model.getCollaborationsHelper().addBase(node, base);
+        
+        return node;
+    }
+    
+    /**
+     * Creates the Fig for the CR. Y position will be adjusted to match other 
+     * the other CRs.
+     * @param classifierRole
+     * @param location The position where to put the new fig.
+     * @return
+     */
+    private FigClassifierRole makeNewFigCR(Object classifierRole, 
+            Point location) {
+        
+        FigClassifierRole newCR = new FigClassifierRole(getGraphModel(),
+                getLayer(), classifierRole);
+        
+        getGraphModel().getNodes().add(newCR.getOwner());
+        
+        // Y position of the new CR should match existing CRs Y position
+        List nodes = getLayer().getContentsNoEdges();
+        int i = 0;
+        boolean figClassifierRoleFound = false;
+        Fig fig = null;
+        while (i < nodes.size() && !figClassifierRoleFound) {
+            fig = (Fig) nodes.get(i);
+            if (nodes.get(i) instanceof Fig) {
+                if (fig != newCR && fig instanceof FigClassifierRole) {
+                    newCR.setY(fig.getY());
+                    newCR.setHeight(fig.getHeight());
+                    figClassifierRoleFound = true;
+                }
+            }
+            i++;
+        }
+        if (location != null) {
+            if (newCR.getY() == 0) {
+                newCR.setY(location.y);
+            }
+            newCR.setX(location.x);
+        }
+        return newCR;
+    }
+    
+    @Override
+    public FigNode drop(Object droppedObject, Point location) {
+        FigClassifierRole newCR = null;
+        if (Model.getFacade().isAClassifierRole(droppedObject)) {
+            newCR = makeNewFigCR(droppedObject, location);           
+        } else if (Model.getFacade().isAClassifier(droppedObject)){
+            newCR = makeNewFigCR(makeNewCR(droppedObject), location);
+        }
+        if (newCR != null) {
+            add(newCR);
+            LOG.debug("Dropped object " + droppedObject + " converted to " 
+                    + newCR);
+        } else {
+            LOG.debug("Dropped object NOT added " + droppedObject);
+        }
+        return newCR;
+    }
+    
+    @Override
+    public String getInstructions(Object droppedObject) {
+        if (Model.getFacade().isAClassifier(droppedObject)) {
+            //TODO: i18n
+            return "Click on diagram to add as a new Classifier Role";
+        }
+        return super.getInstructions(droppedObject);
+    }
+    
+    
+    @Override
+    public ModePlace getModePlace(GraphFactory gf, String instructions) {
+        return new ModePlace(gf, instructions);
+    }
 
     /**
      * The UID.

Modified: branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/DnDJGraph.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/DnDJGraph.java?view=diff&rev=15424&p1=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/DnDJGraph.java&p2=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/DnDJGraph.java&r1=15423&r2=15424
==============================================================================
--- branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/DnDJGraph.java	(original)
+++ branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/DnDJGraph.java	2008-07-31 07:50:13-0700
@@ -38,7 +38,6 @@
 
 import org.apache.log4j.Logger;
 import org.argouml.kernel.ProjectManager;
-import org.argouml.model.Model;
 import org.argouml.ui.TransferableModelElements;
 import org.argouml.uml.diagram.ArgoDiagram;
 import org.tigris.gef.base.Diagram;

Modified: branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/SequenceDiagramRenderer.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/SequenceDiagramRenderer.java?view=diff&rev=15424&p1=branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/SequenceDiagramRenderer.java&p2=branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/SequenceDiagramRenderer.java&r1=15423&r2=15424
==============================================================================
--- branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/SequenceDiagramRenderer.java	(original)
+++ branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/SequenceDiagramRenderer.java	2008-07-31 07:50:13-0700
@@ -24,8 +24,6 @@
 
 package org.argouml.uml.diagram.sequence2.ui;
 
-import java.awt.Point;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
@@ -34,19 +32,13 @@
 import org.argouml.uml.CommentEdge;
 import org.argouml.uml.diagram.ArgoDiagram;
 import org.argouml.uml.diagram.UmlDiagramRenderer;
-import org.argouml.uml.diagram.sequence2.SequenceDiagramGraphModel;
 import org.argouml.uml.diagram.static_structure.ui.FigComment;
 import org.argouml.uml.diagram.static_structure.ui.FigEdgeNote;
 import org.argouml.uml.diagram.ui.UMLDiagram;
-import org.tigris.gef.base.Editor;
-import org.tigris.gef.base.Globals;
 import org.tigris.gef.base.Layer;
-import org.tigris.gef.base.Mode;
 import org.tigris.gef.graph.GraphModel;
-import org.tigris.gef.presentation.Fig;
 import org.tigris.gef.presentation.FigEdge;
 import org.tigris.gef.presentation.FigNode;
-import org.tigris.swidgets.DropDownIcon;
 
 /**
  *
@@ -72,8 +64,8 @@
             .getActiveDiagram();
         if (diag instanceof UMLDiagram
                 && ((UMLDiagram) diag).doesAccept(node)) {
-            // if the user tries to add a Class or an Actor, a new CR should be
-            // created with the Class or the Actor as a Base. This is done by
+            // if the user tries to add a classifier, a new CR should be created
+        	// with the classifier as a Base. This is done by
             // the diagram via the drop method.
             result = ((UMLDiagram) diag).drop(node, null);
         } else {
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.