svn commit: r14735 - trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeAssociation.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2008-05-14 11:37:52-0700
New Revision: 14735

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeAssociation.java

Log:
Use thread safe updateLayout instead of modelChanged to simplify.

We don't need to set owner to null as the Fig will be garbage collected.

Other refactoring.

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeAssociation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeAssociation.java?view=diff&rev=14735&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeAssociation.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeAssociation.java&r1=14734&r2=14735
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeAssociation.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeAssociation.java	2008-05-14 11:37:52-0700
@@ -35,6 +35,7 @@
 
 import org.argouml.model.Model;
 import org.argouml.model.RemoveAssociationEvent;
+import org.argouml.model.UmlChangeEvent;
 import org.tigris.gef.base.Editor;
 import org.tigris.gef.base.Globals;
 import org.tigris.gef.base.Layer;
@@ -124,21 +125,18 @@
 
 
     /**
-     * Used when a n-ary association becomes a binary association.
+     * Called when a model event is received from model subsystem.
+     * handles when a n-ary association becomes a binary association.
      *
      * @param mee the event
      */
-    protected void modelChanged(PropertyChangeEvent mee) {
-        super.modelChanged(mee);
-        if ("connection".equals(mee.getPropertyName())) {
-            if (mee instanceof RemoveAssociationEvent) {
-                Object association =
-                    ((RemoveAssociationEvent) mee).getSource();
-                if (Model.getFacade().getConnections(association).size()
-                        == 2) {
-                    reduceToBinary();
-                }
-            }
+    protected void updateLayout(UmlChangeEvent mee) {
+        super.updateLayout(mee);
+        if (mee instanceof RemoveAssociationEvent
+                && "connection".equals(mee.getPropertyName())
+                && Model.getFacade().getConnections(mee.getSource()).size() 
+                == 2) {
+            reduceToBinary();
         }
     }
 
@@ -147,32 +145,23 @@
      * from the model (OR from the diagram?), 
      * reduce this to a binary association.
      */
-    void reduceToBinary() {
+    private void reduceToBinary() {
         final Object association = getOwner();
-        final Fig oldNodeFig = this;
-        SwingUtilities.invokeLater(new Runnable() {
-            public void run() {
-                oldNodeFig.setOwner(null);
-                FigEdge figEdge = null;
-                Editor editor = Globals.curEditor();
-                GraphModel gm = editor.getGraphModel();
-                GraphEdgeRenderer renderer =
-                    editor.getGraphEdgeRenderer();
-                Layer lay = editor.getLayerManager().getActiveLayer();
-                figEdge =
-                    renderer.getFigEdgeFor(gm, lay, association, null);
-                editor.add(figEdge);
-                if (gm instanceof MutableGraphModel) {
-                    MutableGraphModel mutableGraphModel =
-                        (MutableGraphModel) gm;
-                    mutableGraphModel.removeNode(association);
-                    mutableGraphModel.addEdge(association);
-                }
-                oldNodeFig.removeFromDiagram();
-                editor.getSelectionManager().deselectAll();
-                editor.damageAll();
-            }
-        });
+        final Editor editor = Globals.curEditor();
+        final MutableGraphModel gm = 
+            (MutableGraphModel) editor.getGraphModel();
+        final GraphEdgeRenderer renderer =
+            editor.getGraphEdgeRenderer();
+        gm.removeNode(association);
+        removeFromDiagram();
+        final Layer lay = editor.getLayerManager().getActiveLayer();
+        final FigAssociation figEdge = (FigAssociation) renderer.getFigEdgeFor(
+                gm, lay, association, null);
+        editor.add(figEdge);
+        gm.addEdge(association);
+        figEdge.computeRoute();
+        editor.getSelectionManager().deselectAll();
+        editor.damageAll();
     }
     
     /*
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.