Coverage Report - org.argouml.uml.diagram.ArgoDiagramImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ArgoDiagramImpl
27%
68/246
11%
18/152
3.316
 
 1  
 /* $Id: ArgoDiagramImpl.java 17850 2010-01-12 19:53:35Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    tfmorris
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2008 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.uml.diagram;
 40  
 
 41  
 import java.beans.PropertyChangeEvent;
 42  
 import java.beans.PropertyChangeListener;
 43  
 import java.beans.PropertyVetoException;
 44  
 import java.beans.VetoableChangeListener;
 45  
 import java.util.ArrayList;
 46  
 import java.util.Iterator;
 47  
 import java.util.List;
 48  
 
 49  
 import org.apache.log4j.Logger;
 50  
 import org.argouml.application.events.ArgoDiagramAppearanceEvent;
 51  
 import org.argouml.application.events.ArgoEventPump;
 52  
 import org.argouml.application.events.ArgoEventTypes;
 53  
 import org.argouml.application.events.ArgoNotationEvent;
 54  
 import org.argouml.kernel.Project;
 55  
 import org.argouml.kernel.ProjectManager;
 56  
 import org.argouml.model.CoreHelper;
 57  
 import org.argouml.model.DeleteInstanceEvent;
 58  
 import org.argouml.model.InvalidElementException;
 59  
 import org.argouml.model.Model;
 60  
 import org.argouml.model.ModelManagementHelper;
 61  
 import org.argouml.uml.diagram.activity.ui.FigPool;
 62  
 import org.argouml.uml.diagram.static_structure.ui.FigComment;
 63  
 import org.argouml.uml.diagram.ui.ArgoFig;
 64  
 import org.argouml.uml.diagram.ui.FigEdgeModelElement;
 65  
 import org.argouml.uml.diagram.ui.FigNodeModelElement;
 66  
 import org.argouml.util.EnumerationIterator;
 67  
 import org.argouml.util.IItemUID;
 68  
 import org.argouml.util.ItemUID;
 69  
 import org.tigris.gef.base.Diagram;
 70  
 import org.tigris.gef.base.Editor;
 71  
 import org.tigris.gef.base.LayerPerspective;
 72  
 import org.tigris.gef.graph.GraphModel;
 73  
 import org.tigris.gef.graph.MutableGraphSupport;
 74  
 import org.tigris.gef.presentation.Fig;
 75  
 import org.tigris.gef.presentation.FigEdge;
 76  
 import org.tigris.gef.presentation.FigGroup;
 77  
 import org.tigris.gef.presentation.FigNode;
 78  
 import org.tigris.gef.undo.UndoManager;
 79  
 
 80  
 /**
 81  
  * This class represents all Diagrams within ArgoUML.
 82  
  * It is based upon the GEF Diagram.<p>
 83  
  * 
 84  
  * It adds a namespace, and the capability 
 85  
  * to delete itself when its namespace is deleted. <p>
 86  
  * 
 87  
  * TODO: MVW: I am not sure of the following:<p>
 88  
  * The "namespace" of the diagram is e.g. used when creating new elements
 89  
  * that are shown on the diagram; they will have their namespace set
 90  
  * according this. It is NOT necessarily equal to the "owner". <p>
 91  
  *
 92  
  * MVW: I doubt all following:
 93  
  * The "namespace" of the diagram is e.g. used to register a listener
 94  
  * to the UML model, to be notified if this element is removed;
 95  
  * which will imply that this diagram has to be deleted, too. <p>
 96  
  * 
 97  
  * Hence the namespace of e.g. a collaboration diagram should be the
 98  
  * represented classifier or, in case of a represented operation, the
 99  
  * classifier that owns this operation.
 100  
  * And the namespace of the statechart diagram should be 
 101  
  * the namespace of its statemachine.
 102  
  */
 103  
 public abstract class ArgoDiagramImpl extends Diagram 
 104  
     implements PropertyChangeListener, VetoableChangeListener, ArgoDiagram, 
 105  
     IItemUID {
 106  
 
 107  
     private ItemUID id;
 108  
 
 109  
     /**
 110  
      * The project this diagram is contained in.
 111  
      */
 112  
     private Project project;
 113  
 
 114  
     protected Object namespace;
 115  
     
 116  
     private DiagramSettings settings;
 117  
 
 118  900
     private static final Logger LOG = Logger.getLogger(ArgoDiagramImpl.class);
 119  
 
 120  
     /**
 121  
      * Default constructor.  Used by PGML parser when diagram is first created.
 122  
      * @deprecated for 0.27.2 by tfmorris.  The 0-arg constructor of our sub
 123  
      * classes will get called by the PGML parser, but this should not get
 124  
      * propagated up the hierarchy.  The GEF Diagram constructor implementation
 125  
      * is going to provide defaults for all missing args anyway, so we should
 126  
      * always use the fully specified 3-arg constructor.
 127  
      */
 128  
     @Deprecated
 129  
     public ArgoDiagramImpl() {
 130  76
         super();
 131  
                 
 132  
         // TODO: What is this trying to do? It's never going to get called - tfm
 133  
         // really dirty hack to remove unwanted listeners
 134  76
         getLayer().getGraphModel().removeGraphEventListener(getLayer());
 135  
         
 136  76
         constructorInit();
 137  76
     }
 138  
 
 139  
 
 140  
     /**
 141  
      * The constructor.
 142  
      *
 143  
      * @param diagramName the name of the diagram
 144  
      * @deprecated for 0.27.2 by tfmorris. Use 
 145  
      * {@link #ArgoDiagramImpl(String, GraphModel, LayerPerspective)}.
 146  
      */
 147  
     @Deprecated
 148  
     public ArgoDiagramImpl(String diagramName) {
 149  
         // next line patch to issue 596 (hopefully)
 150  0
         super(diagramName);
 151  
         try {
 152  0
             setName(diagramName);
 153  0
         } catch (PropertyVetoException pve) { }
 154  0
         constructorInit();
 155  0
     }
 156  
 
 157  
     /**
 158  
      * Construct a new ArgoUML diagram.  This is the preferred form of the
 159  
      * constructor.  If you don't know the name yet, make one up (because that's
 160  
      * what the super classes constructors are going to do anyway).
 161  
      * 
 162  
      * @param name the name of the new diagram
 163  
      * @param graphModel graph model to associate with diagram
 164  
      * @param layer layer to associate with diagram 
 165  
      * (use new LayerPerspective(name, graphModel)) if you need a default
 166  
      */
 167  
     public ArgoDiagramImpl(String name, GraphModel graphModel,
 168  
             LayerPerspective layer) {
 169  2040
         super(name, graphModel, layer);
 170  
         // TODO: Do we really need to do this? Carried over from old behavior
 171  
         try {
 172  2040
             setName(name);
 173  0
         } catch (PropertyVetoException pve) {
 174  2040
         }
 175  2040
         constructorInit();
 176  2040
     }
 177  
 
 178  
     /**
 179  
      * Finish initialization which is common to multiple constructors which
 180  
      * don't invoke each other.
 181  
      */
 182  
     private void constructorInit() {
 183  
         // TODO: These should get replaced immediately by the creating
 184  
         // initialization code, but make sure we've got a default just in case.
 185  2116
         Project project = ProjectManager.getManager().getCurrentProject();
 186  2116
         if (project != null) {
 187  316
             settings = project.getProjectSettings().getDefaultDiagramSettings();
 188  
         }
 189  
         // TODO: we should be given an Undo manager to use rather than looking
 190  
         // for a global one
 191  2116
         if (!(UndoManager.getInstance() instanceof DiagramUndoManager)) {
 192  900
             UndoManager.setInstance(new DiagramUndoManager());
 193  900
             LOG.info("Setting Diagram undo manager");
 194  
         } else {
 195  1216
             LOG.info("Diagram undo manager already set");
 196  
         }
 197  
 
 198  
         // Register for notification of any global changes that would affect
 199  
         // our rendering
 200  2116
         ArgoEventPump.addListener(ArgoEventTypes.ANY_NOTATION_EVENT, this);
 201  2116
         ArgoEventPump.addListener(
 202  
                 ArgoEventTypes.ANY_DIAGRAM_APPEARANCE_EVENT, this);
 203  
 
 204  
         // Listen for name changes so we can veto them if we don't like them
 205  2116
         addVetoableChangeListener(this);
 206  2116
     }
 207  
     
 208  
 
 209  
     public void setName(String n) throws PropertyVetoException {
 210  4292
         super.setName(n);
 211  4292
         MutableGraphSupport.enableSaveAction();
 212  4292
     }
 213  
 
 214  
 
 215  
     public void setItemUID(ItemUID i) {
 216  0
         id = i;
 217  0
     }
 218  
 
 219  
 
 220  
     public ItemUID getItemUID() {
 221  0
         return id;
 222  
     }
 223  
 
 224  
 
 225  
     /**
 226  
      * The UID.
 227  
      */
 228  
     static final long serialVersionUID = -401219134410459387L;
 229  
 
 230  
 
 231  
     public String getVetoMessage(String propertyName) {
 232  0
             if (propertyName.equals("name")) {
 233  0
             return "Name of diagram may not exist already";
 234  
             }
 235  0
         return null;
 236  
     }
 237  
 
 238  
 
 239  
     public Fig getContainingFig(Object obj) {
 240  2598
         Fig fig = super.presentationFor(obj);
 241  2598
         if (fig == null && Model.getFacade().isAUMLElement(obj)) {
 242  
             // maybe we have a modelelement that is part of some other
 243  
             // fig
 244  0
             if (Model.getFacade().isAOperation(obj)
 245  
                     || Model.getFacade().isAReception(obj)
 246  
                     || Model.getFacade().isAAttribute(obj)) {
 247  
 
 248  
                 // get all the classes from the diagram
 249  0
                 return presentationFor(Model.getFacade().getOwner(obj));
 250  
             }
 251  
         }
 252  2598
         return fig;
 253  
     }
 254  
 
 255  
 
 256  
     public void damage() {
 257  26
         if (getLayer() != null && getLayer().getEditors() != null) {
 258  26
             Iterator it = getLayer().getEditors().iterator();
 259  39
             while (it.hasNext()) {
 260  13
                 ((Editor) it.next()).damageAll();
 261  
             }
 262  
         }
 263  26
     }
 264  
 
 265  
 
 266  
     public List getEdges() {
 267  148
         if (getGraphModel() != null) {
 268  148
             return getGraphModel().getEdges();
 269  
         }
 270  0
         return super.getEdges();
 271  
     }
 272  
 
 273  
 
 274  
     public List getNodes() {
 275  148
         if (getGraphModel() != null) {
 276  148
             return getGraphModel().getNodes();
 277  
         }
 278  0
         return super.getNodes();
 279  
     }
 280  
 
 281  
 
 282  
     public String toString() {
 283  9143
         return "Diagram: " + getName();
 284  
     }
 285  
 
 286  
 
 287  
     public String repair() {
 288  0
         StringBuffer report = new StringBuffer(500);
 289  
 
 290  
         boolean faultFixed;
 291  
         do {
 292  0
             faultFixed = false;
 293  0
             List<Fig> figs = new ArrayList<Fig>(getLayer().getContentsNoEdges());
 294  0
             for (Fig f : figs) {
 295  0
                 if (repairFig(f, report)) {
 296  0
                     faultFixed = true;
 297  
                 }
 298  
             }
 299  0
             figs = new ArrayList<Fig>(getLayer().getContentsEdgesOnly());
 300  0
             for (Fig f : figs) {
 301  0
                 if (repairFig(f, report)) {
 302  0
                     faultFixed = true;
 303  
                 }
 304  
             }
 305  0
         } while (faultFixed); // Repeat until no faults are fixed
 306  
 
 307  0
         return report.toString();
 308  
     }
 309  
     
 310  
     private boolean repairFig(Fig f, StringBuffer report) {
 311  0
         LOG.info("Checking " + figDescription(f) + f.getOwner());
 312  0
         boolean faultFixed = false;
 313  0
         String figDescription = null;
 314  
         
 315  
         // 1. Make sure all Figs in the Diagrams layer refer back to
 316  
         // that layer.
 317  0
         if (!getLayer().equals(f.getLayer())) {
 318  0
             if (figDescription == null) {
 319  0
                 figDescription = figDescription(f);
 320  0
                 report.append(figDescription);
 321  
             }
 322  
 
 323  
             // The report
 324  0
             if (f.getLayer() == null) {
 325  0
                 report.append("-- Fixed: layer was null\n");
 326  
             } else {
 327  0
                 report.append("-- Fixed: refered to wrong layer\n");
 328  
             }
 329  0
             faultFixed = true;
 330  
             // The fix
 331  0
             f.setLayer(getLayer());
 332  
         }
 333  
 
 334  
         // 2. Make sure that all Figs are visible
 335  0
         if (!f.isVisible()) {
 336  0
             if (figDescription == null) {
 337  0
                 figDescription = figDescription(f);
 338  0
                 report.append(figDescription);
 339  
             }
 340  
             // The report
 341  0
             report.append("-- Fixed: a Fig must be visible\n");
 342  0
             faultFixed = true;
 343  
             // The fix
 344  0
             f.setVisible(true);
 345  
         }
 346  
 
 347  0
         if (f instanceof FigEdge) {
 348  
             // 3. Make sure all FigEdges are attached to a valid FigNode
 349  
             // The report
 350  0
             FigEdge fe = (FigEdge) f;
 351  0
             FigNode destFig = fe.getDestFigNode();
 352  0
             FigNode sourceFig = fe.getSourceFigNode();
 353  
 
 354  0
             if (destFig == null) {
 355  0
                 if (figDescription == null) {
 356  0
                     figDescription = figDescription(f);
 357  0
                     report.append(figDescription);
 358  
                 }
 359  0
                 faultFixed = true;
 360  0
                 report.append("-- Removed: as it has no dest Fig\n");
 361  0
                 f.removeFromDiagram();
 362  0
             } else if (sourceFig == null) {
 363  0
                 if (figDescription == null) {
 364  0
                     figDescription = figDescription(f);
 365  0
                     report.append(figDescription);
 366  
                 }
 367  0
                 faultFixed = true;
 368  0
                 report.append("-- Removed: as it has no source Fig\n");
 369  0
                 f.removeFromDiagram();
 370  0
             } else if (sourceFig.getOwner() == null) {
 371  0
                 if (figDescription == null) {
 372  0
                     figDescription = figDescription(f);
 373  0
                     report.append(figDescription);
 374  
                 }
 375  0
                 faultFixed = true;
 376  0
                 report.append("-- Removed: as its source Fig has no owner\n");
 377  0
                 f.removeFromDiagram();
 378  0
             } else if (destFig.getOwner() == null) {
 379  0
                 if (figDescription == null) {
 380  0
                     figDescription = figDescription(f);
 381  0
                     report.append(figDescription);
 382  
                 }
 383  0
                 faultFixed = true;
 384  0
                 report.append(
 385  
                         "-- Removed: as its destination Fig has no owner\n");
 386  0
                 f.removeFromDiagram();
 387  0
             } else if (Model.getUmlFactory().isRemoved(
 388  
                     sourceFig.getOwner())) {
 389  0
                 if (figDescription == null) {
 390  0
                     figDescription = figDescription(f);
 391  0
                     report.append(figDescription);
 392  
                 }
 393  0
                 faultFixed = true;
 394  0
                 report.append("-- Removed: as its source Figs owner is no "
 395  
                     + "longer in the repository\n");
 396  0
                 f.removeFromDiagram();
 397  0
             } else if (Model.getUmlFactory().isRemoved(
 398  
                     destFig.getOwner())) {
 399  0
                 if (figDescription == null) {
 400  0
                     figDescription = figDescription(f);
 401  0
                     report.append(figDescription);
 402  
                 }
 403  0
                 faultFixed = true;
 404  0
                 report.append("-- Removed: as its destination Figs owner "
 405  
                     + "is no longer in the repository\n");
 406  0
                 f.removeFromDiagram();
 407  
             }
 408  0
         } else if ((f instanceof FigNode || f instanceof FigEdge)
 409  
                 && f.getOwner() == null && !(f instanceof FigPool)) {
 410  0
             if (figDescription == null) {
 411  0
                 figDescription = figDescription(f);
 412  0
                 report.append(figDescription);
 413  
             }
 414  
             // 4. Make sure all FigNodes and FigEdges have an owner
 415  
             // The report
 416  0
             faultFixed = true;
 417  0
             report.append("-- Removed: owner was null\n");
 418  
             // The fix
 419  0
             f.removeFromDiagram();
 420  0
         } else if ((f instanceof FigNode || f instanceof FigEdge)
 421  
                 &&  Model.getFacade().isAUMLElement(f.getOwner())
 422  
                 &&  Model.getUmlFactory().isRemoved(f.getOwner())) {
 423  0
             if (figDescription == null) {
 424  0
                 figDescription = figDescription(f);
 425  0
                 report.append(figDescription);
 426  
             }
 427  
             // 5. Make sure all FigNodes and FigEdges have a valid owner
 428  
             // The report
 429  0
             faultFixed = true;
 430  0
             report.append(
 431  
                     "-- Removed: model element no longer in the repository\n");
 432  
             // The fix
 433  0
             f.removeFromDiagram();
 434  0
         } else if (f instanceof FigGroup && !(f instanceof FigNode)) {
 435  0
             if (figDescription == null) {
 436  0
                 figDescription = figDescription(f);
 437  0
                 report.append(figDescription);
 438  
             }
 439  
             // 4. Make sure the only FigGroups on a diagram are also
 440  
             //    FigNodes
 441  
             // The report
 442  0
             faultFixed = true;
 443  0
             report.append(
 444  
                     "-- Removed: a FigGroup should not be on the diagram\n");
 445  
             // The fix
 446  0
             f.removeFromDiagram();
 447  
         }
 448  
         
 449  0
         return faultFixed;
 450  
     }
 451  
 
 452  
     /**
 453  
      * Generate a description of a Fig that would be most meaningful to a
 454  
      * developer and the user.
 455  
      * This is used by the repair routines to describe the Fig that was repaired
 456  
      * <ul>
 457  
      * <li>FigComment - the text within body compartment of the Fig
 458  
      * <li>FigNodeModelElement -
 459  
      *        the text within the name compartment of the FigNode
 460  
      * <li>FigEdgeModelElement -
 461  
      *        the text within name compartment of the FigEdge and the
 462  
      *        descriptions of the adjoining FigNodes
 463  
      * </ul>
 464  
      * @param f the Fig to describe
 465  
      * @return The description as a String.
 466  
      */
 467  
     private String figDescription(Fig f) {
 468  0
         String description = "\n" + f.getClass().getName();
 469  0
         if (f instanceof FigComment) {
 470  0
             description += " \"" + ((FigComment) f).getBody() + "\"";
 471  0
         } else if (f instanceof FigNodeModelElement) {
 472  0
             description += " \"" + ((FigNodeModelElement) f).getName() + "\"";
 473  0
         } else if (f instanceof FigEdgeModelElement) {
 474  0
             FigEdgeModelElement fe = (FigEdgeModelElement) f;
 475  0
             description += " \"" + fe.getName() + "\"";
 476  
             String source;
 477  0
             if (fe.getSourceFigNode() == null) {
 478  0
                 source = "(null)";
 479  
             } else {
 480  0
                 source =
 481  
                     ((FigNodeModelElement) fe.getSourceFigNode()).getName();
 482  
             }
 483  
             String dest;
 484  0
             if (fe.getDestFigNode() == null) {
 485  0
                 dest = "(null)";
 486  
             } else {
 487  0
                 dest = ((FigNodeModelElement) fe.getDestFigNode()).getName();
 488  
             }
 489  0
             description += " [" + source + "=>" + dest + "]";
 490  
         }
 491  0
         return description + "\n";
 492  
     }
 493  
 
 494  
 
 495  
     public List presentationsFor(Object obj) {
 496  0
         List<Fig> presentations = new ArrayList<Fig>();
 497  0
         int figCount = getLayer().getContents().size();
 498  0
         for (int figIndex = 0; figIndex < figCount; ++figIndex) {
 499  0
             Fig fig = (Fig) getLayer().getContents().get(figIndex);
 500  0
             if (fig.getOwner() == obj) {
 501  0
                 presentations.add(fig);
 502  
             }
 503  
         }
 504  
 
 505  0
         return presentations;
 506  
     }
 507  
 
 508  
     // TODO: Move to GEF
 509  
     public void remove() {
 510  174
         List<Fig> contents = new ArrayList<Fig>(getLayer().getContents());
 511  174
         int size = contents.size();
 512  174
         for (int i = 0; i < size; ++i) {
 513  0
             Fig f = contents.get(i);
 514  0
             f.removeFromDiagram();
 515  
         }
 516  174
         firePropertyChange("remove", null, null);
 517  174
         super.remove();
 518  174
     }
 519  
     
 520  
 
 521  
     public void setProject(Project p) {
 522  2116
         project = p;
 523  2116
     }
 524  
 
 525  
     public Project getProject() {
 526  2
         return project;
 527  
     }
 528  
     
 529  
     public abstract void encloserChanged(
 530  
             FigNode enclosed, FigNode oldEncloser, FigNode newEncloser); 
 531  
         // Do nothing, override in subclass.
 532  
 
 533  
 
 534  
     public Object getDependentElement() {
 535  37
         return null;
 536  
     }
 537  
 
 538  
 
 539  
     public Object getNamespace() {
 540  15788
         return namespace;
 541  
     }
 542  
 
 543  
 
 544  
     public void setNamespace(Object ns) {
 545  2116
         if (!Model.getFacade().isANamespace(ns)) {
 546  0
             LOG.error("Not a namespace");
 547  0
             LOG.error(ns);
 548  0
             throw new IllegalArgumentException("Given object not a namespace");
 549  
         }
 550  2116
         if ((namespace != null) && (namespace != ns)) {
 551  0
             Model.getPump().removeModelEventListener(this, namespace);
 552  
         }
 553  2116
         Object oldNs = namespace;
 554  2116
         namespace = ns;
 555  2116
         firePropertyChange(NAMESPACE_KEY, oldNs, ns);
 556  
     
 557  
         // Add the diagram as a listener to the namespace so
 558  
         // that when the namespace is removed the diagram is deleted also.
 559  
         /* Listening only to "remove" events does not work... 
 560  
          * TODO: Check if this works now with new event pump - tfm 
 561  
          */
 562  2116
         Model.getPump().addModelEventListener(this, namespace, "remove");
 563  2116
     }
 564  
 
 565  
 
 566  
     public void setModelElementNamespace(Object modelElement, Object ns) {
 567  0
         if (modelElement == null) {
 568  0
             return;
 569  
         }
 570  
         
 571  
         // If we're not provided a namespace then get it from the diagram or
 572  
         // the root
 573  0
         if (ns == null) {
 574  0
             if (getNamespace() != null) {
 575  0
                 ns = getNamespace();
 576  
             } else {
 577  0
                 ns = getProject().getRoot();
 578  
             }
 579  
         }
 580  
         
 581  
         // If we haven't succeeded in getting a namespace then abort
 582  0
         if (ns == null) {
 583  0
             return;
 584  
         }
 585  
         
 586  
         // If we're trying to set the namespace to the existing value
 587  
         // then don't do any more work.
 588  0
         if (Model.getFacade().getNamespace(modelElement) == ns) {
 589  0
             return;
 590  
         }
 591  
         
 592  0
         CoreHelper coreHelper = Model.getCoreHelper();
 593  0
         ModelManagementHelper modelHelper = Model.getModelManagementHelper();
 594  
         
 595  0
         if (!modelHelper.isCyclicOwnership(ns, modelElement)
 596  
                 && coreHelper.isValidNamespace(modelElement, ns)) {
 597  
             
 598  0
             coreHelper.setModelElementContainer(modelElement, ns);
 599  
             /* TODO: move the associations to the correct owner (namespace)
 600  
              * i.e. issue 2151
 601  
              */
 602  
         }
 603  0
     }
 604  
 
 605  
 
 606  
     public void propertyChange(PropertyChangeEvent evt) {
 607  0
         if ((evt.getSource() == namespace)
 608  
                 && (evt instanceof DeleteInstanceEvent)
 609  
                 && "remove".equals(evt.getPropertyName())) {
 610  
 
 611  0
             Model.getPump().removeModelEventListener(this, namespace, "remove");
 612  
             
 613  0
             if (getProject() != null) {
 614  0
                 getProject().moveToTrash(this);
 615  
             }
 616  
         }
 617  0
     }
 618  
 
 619  
 
 620  
     public Object getOwner() {
 621  5410
         return getNamespace();
 622  
     }
 623  
 
 624  
     public Iterator<Fig> getFigIterator() {
 625  0
         return new EnumerationIterator(elements());
 626  
     }
 627  
     
 628  
     public void setDiagramSettings(DiagramSettings newSettings) {
 629  2116
         settings = newSettings;
 630  2116
     }
 631  
     
 632  
     public DiagramSettings getDiagramSettings() {
 633  0
         return settings;
 634  
     }
 635  
     
 636  
     /**
 637  
      * Handles a global change to the diagram font.
 638  
      * @param e the event
 639  
      * @see org.argouml.application.events.ArgoDiagramAppearanceEventListener#diagramFontChanged(org.argouml.application.events.ArgoDiagramAppearanceEvent)
 640  
      */
 641  
     public void diagramFontChanged(ArgoDiagramAppearanceEvent e) {
 642  24
         renderingChanged();
 643  24
     }
 644  
     
 645  
     /**
 646  
      * Rerender the entire diagram based on new global rendering settings.
 647  
      * <p>
 648  
      * NOTE: Figs which define their own presentation listeners will get 
 649  
      * re-rendered twice
 650  
      */
 651  
     public void renderingChanged() {
 652  26
         for (Object fig : getLayer().getContents()) {
 653  
             try {
 654  
                 // This should always be true, but just in case...
 655  0
                 if (fig instanceof ArgoFig) {
 656  0
                     ((ArgoFig) fig).renderingChanged();
 657  
                 } else {
 658  0
                     LOG.warn("Diagram " + getName() + " contains non-ArgoFig "
 659  
                             + fig);
 660  
                 }
 661  0
             } catch (InvalidElementException e) {
 662  0
                 LOG.error("Tried to refresh deleted element ", e);
 663  0
             }
 664  
         }
 665  26
         damage();        
 666  26
     }
 667  
 
 668  
     public void notationChanged(ArgoNotationEvent e) {
 669  2
         renderingChanged();  
 670  2
     }
 671  
 
 672  
     public void notationAdded(ArgoNotationEvent e) {
 673  
         // Do nothing
 674  0
     }
 675  
 
 676  
     public void notationProviderAdded(ArgoNotationEvent e) {
 677  
         // Do nothing
 678  0
     }
 679  
 
 680  
     public void notationProviderRemoved(ArgoNotationEvent e) {
 681  
         // Do nothing
 682  0
     }
 683  
 
 684  
 
 685  
     public void notationRemoved(ArgoNotationEvent e) {
 686  
         // Do nothing
 687  0
     }
 688  
 
 689  
 
 690  
     /**
 691  
      * Receive vetoable change event. GEF will call this method with the 'name'
 692  
      * property when it attempts to set the name. If this will be a duplicate
 693  
      * for the project, we can veto the requested change.
 694  
      * 
 695  
      * @param evt the change event
 696  
      * @throws PropertyVetoException if the name is illegal. Usuallly this means
 697  
      *             a duplicate in the project.
 698  
      * @see java.beans.VetoableChangeListener#vetoableChange(java.beans.PropertyChangeEvent)
 699  
      */
 700  
     public void vetoableChange(PropertyChangeEvent evt)
 701  
         throws PropertyVetoException {
 702  
         
 703  2252
         if ("name".equals(evt.getPropertyName())) {
 704  2252
             if (project != null) {
 705  0
                 if (!project.isValidDiagramName((String) evt.getNewValue())) {
 706  0
                     throw new PropertyVetoException("Invalid name", evt);
 707  
                 }
 708  
             }
 709  
         }    
 710  2252
     }
 711  
     
 712  
 }