svn commit: r17253 - trunk/src/argouml-app/src/org/argouml/uml/diagram: static_structure/ui ui

Michiel van der Wulp <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2009-08-10 01:12:27-0700
New Revision: 17253

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java

Log:
Patch from issue 1853: Make click on composition toolbelt button of a class work.
It works when you shift-hoover, but do not shift-click or the broom appears!

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java?view=diff&pathrev=17253&r1=17252&r2=17253
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/SelectionClass.java	2009-08-10 01:12:27-0700
@@ -25,6 +25,7 @@
 package org.argouml.uml.diagram.static_structure.ui;
 
 import java.awt.event.MouseEvent;
+import java.util.Collection;
 
 import javax.swing.Icon;
 
@@ -32,7 +33,9 @@
 import org.argouml.model.Model;
 import org.argouml.uml.diagram.deployment.DeploymentDiagramGraphModel;
 import org.argouml.uml.diagram.ui.SelectionNodeClarifiers2;
+import org.tigris.gef.base.Editor;
 import org.tigris.gef.base.Globals;
+import org.tigris.gef.base.ModeCreateEdgeAndNode;
 import org.tigris.gef.presentation.Fig;
 
 /**
@@ -153,6 +156,24 @@
     }
 
     @Override
+    protected ModeCreateEdgeAndNode getNewModeCreateEdgeAndNode(Editor ce,
+            Object theEdgeType, boolean postProcess,
+            SelectionNodeClarifiers2 nodeCreator) {
+        return  new ModeCreateEdgeAndNodeWithComposition(ce,
+                theEdgeType, postProcess, nodeCreator);
+    }
+
+    @Override
+    protected void postProcessEdge2(Object newEdge) {
+        if (Model.getFacade().isAAssociation(newEdge)) {
+            Collection assocEnds = Model.getFacade().getConnections(newEdge);
+            Object firstAE = assocEnds.iterator().next();
+            Object aggregationKind = Model.getAggregationKind().getComposite();
+            Model.getCoreHelper().setAggregation(firstAE, aggregationKind);
+        }
+    }
+
+    @Override
     public void mouseEntered(MouseEvent me) {
         super.mouseEntered(me);
         useComposite = me.isShiftDown();
@@ -163,4 +184,22 @@
         return Model.getCoreFactory().buildClass();
     }
 
+    /**
+     * My derived version that handles the creation of composition associations.
+     *
+     * @author Michiel
+     */
+    class ModeCreateEdgeAndNodeWithComposition extends ModeCreateEdgeAndNode {
+
+        public ModeCreateEdgeAndNodeWithComposition(Editor ce, Object edgeType,
+                boolean postProcess, SelectionNodeClarifiers2 nodeCreator) {
+            super(ce, edgeType, postProcess, nodeCreator);
+        }
+
+        @Override
+        protected void postProcessEdge(Object newEdge) {
+            postProcessEdge2(newEdge);
+        }
+    }
+
 }

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java?view=diff&pathrev=17253&r1=17252&r2=17253
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/SelectionNodeClarifiers2.java	2009-08-10 01:12:27-0700
@@ -79,6 +79,8 @@
     
     private static final int OFFSET = 2; 
     
+    private Object newEdge = null;
+
     private int button;
     
     /**
@@ -299,17 +301,36 @@
         if (edgeType != null && nodeType != null) {
             Editor ce = Globals.curEditor();
             ModeCreateEdgeAndNode m =
-                new ModeCreateEdgeAndNode(ce,
-                      edgeType, isEdgePostProcessRequested(), this);
+                getNewModeCreateEdgeAndNode(ce,
+                        edgeType, isEdgePostProcessRequested(), this);
             m.setup((FigNode) getContent(), getContent().getOwner(),
                     bx, by, reverse);
             ce.pushMode(m);
         }
     }
     
+    /**
+     * Override this to implement post-processing.
+     * 
+     * @param ce the current Editor
+     * @param edgeType the new edge type
+     * @param postProcess true if post-processing is wanted
+     * @param nodeCreator this class will create the node
+     * @return the ModeCreate
+     */
+    protected ModeCreateEdgeAndNode getNewModeCreateEdgeAndNode(
+            Editor ce, Object edgeType, boolean postProcess, 
+            SelectionNodeClarifiers2 nodeCreator) {
+        return  new ModeCreateEdgeAndNode(ce,
+              edgeType, postProcess, nodeCreator);
+    }
+    
     @Override
     public void buttonClicked(int buttonCode) {
         super.buttonClicked(buttonCode);
+        if (isEdgePostProcessRequested()) {
+            postProcessEdge2(newEdge);
+        }
     }
 
     protected Object createEdgeAbove(MutableGraphModel gm, Object newNode) {
@@ -329,15 +350,14 @@
     }
 
     private Object createEdge(MutableGraphModel gm, Object newNode, int index) {
-        Object edge;
         if (isReverseEdge(index)) {
-            edge = gm.connect(
+            newEdge = gm.connect(
                     newNode, getContent().getOwner(), getNewEdgeType(index));
         } else {
-            edge = gm.connect(
+            newEdge = gm.connect(
                     getContent().getOwner(), newNode, getNewEdgeType(index));
         }
-        return edge;
+        return newEdge;
     }
     
     protected Object createEdgeToSelf(MutableGraphModel gm) {
@@ -415,7 +435,14 @@
     protected boolean isEdgePostProcessRequested() {
         return false;
     }
-    
+
+    /**
+     * @param newEdge the new edge to post-process
+     */
+    protected void postProcessEdge2(Object newEdge) {
+        // do nothing by default
+    }
+
     /**
      * @return index of last button/handle that was clicked
      */

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

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.