svn commit: r15151 - branches/gsoc2008/feature1_5138_bszanto: argouml-app/src/org/argouml/ui/explorer 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-03 05:07:55-0700
New Revision: 15151

Modified:
   branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java
   branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddExistingNode.java
   branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/AddExistingNodeCommand.java
   branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/UMLDiagram.java
   branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/SequenceDiagramRenderer.java
   branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/UMLSequenceDiagram.java

Log:
The "Add to diagram" right click menu of a Class in model explorer adds a new Classifier Role if the current diagram is a seq 2 diagram.

Modified: branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java?view=diff&rev=15151&p1=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java&p2=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java&r1=15150&r2=15151
==============================================================================
--- branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java	(original)
+++ branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java	2008-07-03 05:07:55-0700
@@ -248,8 +248,6 @@
                     
             if (!multiSelect) {
                 
-                //I should do the test here
-                
                 if ((classifierSelected && !relationshipSelected)
                         || (packageSelected && selectedItem != projectModel)
                         || (stateVertexSelected

Modified: branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddExistingNode.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddExistingNode.java?view=diff&rev=15151&p1=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddExistingNode.java&p2=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddExistingNode.java&r1=15150&r2=15151
==============================================================================
--- branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddExistingNode.java	(original)
+++ branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/ActionAddExistingNode.java	2008-07-03 05:07:55-0700
@@ -27,6 +27,8 @@
 
 import java.awt.event.ActionEvent;
 
+import javax.swing.Action;
+
 import org.argouml.kernel.ProjectManager;
 import org.argouml.ui.targetmanager.TargetManager;
 import org.argouml.uml.diagram.ArgoDiagram;
@@ -67,6 +69,12 @@
         if (dia == null) {
             return false;
         }
+        
+        if (dia instanceof UMLDiagram && 
+                ((UMLDiagram) dia).doesAccept(object)) {
+            return true;
+        }
+        
         MutableGraphModel gm = (MutableGraphModel) dia.getGraphModel();
         return gm.canAddNode(target);
     }

Modified: branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/AddExistingNodeCommand.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/AddExistingNodeCommand.java?view=diff&rev=15151&p1=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/AddExistingNodeCommand.java&p2=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/AddExistingNodeCommand.java&r1=15150&r2=15151
==============================================================================
--- branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/AddExistingNodeCommand.java	(original)
+++ branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/AddExistingNodeCommand.java	2008-07-03 05:07:55-0700
@@ -114,16 +114,26 @@
         }
 
         String instructions = null;
+        ModePlace placeMode = null;
         if (object != null) {
-            instructions =
-                Translator.localize(
-                    "misc.message.click-on-diagram-to-add",
-                    new Object[] {
-                            Model.getFacade().toString(object),
-                    });
+            ArgoDiagram activeDiagram = ProjectManager.getManager().
+                getCurrentProject().getActiveDiagram();
+            
+            if (activeDiagram instanceof UMLDiagram &&
+                    ((UMLDiagram) activeDiagram).doesAccept(object)) {
+                //TODO: i18n
+                instructions = "Click on diagram to add as a new Classifier Role";
+            } else {
+                instructions =
+                    Translator.localize(
+                            "misc.message.click-on-diagram-to-add",
+                            new Object[] {Model.getFacade().toString(object),});
+                
+            }
             Globals.showStatus(instructions);
         }
-        ModePlace placeMode = new ModePlace(this, instructions);
+        
+        placeMode = new ModePlace(this, instructions);       
         placeMode.setAddRelatedEdges(true);
 
         if (location == null) {

Modified: branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/UMLDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/UMLDiagram.java?view=diff&rev=15151&p1=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/UMLDiagram.java&p2=branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/UMLDiagram.java&r1=15150&r2=15151
==============================================================================
--- branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/UMLDiagram.java	(original)
+++ branches/gsoc2008/feature1_5138_bszanto/argouml-app/src/org/argouml/uml/diagram/ui/UMLDiagram.java	2008-07-03 05:07:55-0700
@@ -51,7 +51,9 @@
 import org.argouml.util.ToolBarUtility;
 import org.tigris.gef.base.ModeBroom;
 import org.tigris.gef.base.ModeCreatePolyEdge;
+import org.tigris.gef.base.ModePlace;
 import org.tigris.gef.base.ModeSelect;
+import org.tigris.gef.graph.GraphFactory;
 import org.tigris.toolbar.ToolBarFactory;
 import org.tigris.toolbar.ToolBarManager;
 import org.tigris.toolbar.toolbutton.ToolButton;
@@ -561,7 +563,31 @@
     }
 
     /**
-     * The UID.
+     * Method to test it the diagram can accept a certain object.
+     * This should be overriden by any diagram that wants to accept a certain
+     * type of object. All other diagrams should not bother since the default
+     * answer is false, ie. don't accept the object.
+     * @param objectToAccept
+     * @return True if it can accept it, false otherwise.
      */
-    static final long serialVersionUID = -401219134410459387L;
+    public boolean doesAccept(Object objectToAccept) {
+        return false;
+    }
+    
+//    /**
+//     * Creates a diagram specific @see org.tigris.gef.base.ModePlace that 
+//     * alowes the diagram to place an accepted type of object 
+//     * [ @see #doesAccept(Object) ] as it should. This is required 1. since a 
+//     * diagram may receive an object that can't be placed as is, but needs some
+//     * tranformation and 2. diagrams in modules should be independent from the
+//     * main app, and should use their own implementation of ModePlace if it's
+//     * required.
+//     * @param gf
+//     * @param instructions
+//     * @return The created ModePlace.
+//     */
+//    public ModePlace getModePlace(GraphFactory gf, String instructions) {
+//        return new ModePlace(gf, instructions);
+//    }
+    
 }

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=15151&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=15150&r2=15151
==============================================================================
--- 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-03 05:07:55-0700
@@ -30,8 +30,11 @@
 import org.argouml.model.Model;
 import org.argouml.uml.CommentEdge;
 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.tigris.gef.base.Editor;
+import org.tigris.gef.base.Globals;
 import org.tigris.gef.base.Layer;
 import org.tigris.gef.graph.GraphModel;
 import org.tigris.gef.presentation.FigEdge;
@@ -48,6 +51,21 @@
      */
     private static final Logger LOG =
         Logger.getLogger(SequenceDiagramRenderer.class);
+    
+    private Object makeNode(Object base) {
+        Object node = null;
+        Editor ce = Globals.curEditor();
+        GraphModel gm = ce.getGraphModel();
+        if (gm instanceof SequenceDiagramGraphModel) {
+            Object collaboration =
+                ((SequenceDiagramGraphModel) gm).getCollaboration();
+            node =
+                Model.getCollaborationsFactory().buildClassifierRole(
+                        collaboration);
+        }
+        //TODO: add the base
+        return node;
+    }
 
     /*
      * @see org.tigris.gef.graph.GraphNodeRenderer#getFigNodeFor(
@@ -61,6 +79,13 @@
             result = new FigClassifierRole(node);
         } else if (Model.getFacade().isAComment(node)) {
             result = new FigComment(gm, node);
+        } else if (Model.getFacade().isAClass(node) 
+                || Model.getFacade().isAActor(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.
+             */
+            result = new FigClassifierRole(makeNode(node));
         }
         LOG.debug("SequenceDiagramRenderer getFigNodeFor " + result);
         lay.add(result);

Modified: branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/UMLSequenceDiagram.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/UMLSequenceDiagram.java?view=diff&rev=15151&p1=branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/UMLSequenceDiagram.java&p2=branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/UMLSequenceDiagram.java&r1=15150&r2=15151
==============================================================================
--- branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/UMLSequenceDiagram.java	(original)
+++ branches/gsoc2008/feature1_5138_bszanto/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/UMLSequenceDiagram.java	2008-07-03 05:07:55-0700
@@ -38,6 +38,8 @@
 import org.argouml.uml.diagram.ui.UMLDiagram;
 import org.tigris.gef.base.LayerPerspective;
 import org.tigris.gef.base.LayerPerspectiveMutable;
+import org.tigris.gef.base.ModePlace;
+import org.tigris.gef.graph.GraphFactory;
 import org.tigris.gef.graph.MutableGraphModel;
 import org.tigris.gef.presentation.FigNode;
 
@@ -172,4 +174,12 @@
         damage();
         return true;
     }
+    
+    @Override
+    public boolean doesAccept(Object objectToAccept) {
+        if (Model.getFacade().isAClass(objectToAccept)) {
+            return true;
+        }
+        return false;
+    }
 }
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.