Coverage Report - org.argouml.uml.diagram.static_structure.ui.FigInterface
 
Classes in this File Line Coverage Branch Coverage Complexity
FigInterface
0%
0/62
0%
0/40
4.833
 
 1  
 /* $Id: FigInterface.java 17735 2010-01-04 14:49:32Z bobtarling $
 2  
  *******************************************************************************
 3  
  * Copyright (c) 2010 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  
  *    Bob Tarling
 11  
  *******************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 // $Id: FigInterface.java 17735 2010-01-04 14:49:32Z bobtarling $
 16  
 // Copyright (c) 1996-2009 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.static_structure.ui;
 40  
 
 41  
 import java.awt.Rectangle;
 42  
 import java.util.HashSet;
 43  
 import java.util.Set;
 44  
 
 45  
 import org.apache.log4j.Logger;
 46  
 import org.argouml.model.Model;
 47  
 import org.argouml.ui.targetmanager.TargetManager;
 48  
 import org.argouml.uml.diagram.ArgoDiagram;
 49  
 import org.argouml.uml.diagram.DiagramSettings;
 50  
 import org.argouml.uml.diagram.ui.FigAttributesCompartment;
 51  
 import org.tigris.gef.base.Selection;
 52  
 import org.tigris.gef.presentation.Fig;
 53  
 
 54  
 /**
 55  
  * Class to display graphics for a UML Interface in a diagram.
 56  
  * <p>
 57  
  * An Interface may show stereotypes and a compartment for
 58  
  * operations. Attributes are not supported in ArgoUML.
 59  
  */
 60  
 public class FigInterface extends FigClassifierBox {
 61  
 
 62  0
     private static final Logger LOG = Logger.getLogger(FigInterface.class);
 63  
 
 64  
     /**
 65  
      * Initialization common to multiple constructors.
 66  
      */
 67  
     private void initialize(Rectangle bounds) {
 68  
         // Put all the bits together, suppressing bounds calculations until
 69  
         // we're all done for efficiency.
 70  0
         enableSizeChecking(false);
 71  0
         setSuppressCalcBounds(true);
 72  
 
 73  0
         getStereotypeFig().setKeyword("interface");
 74  0
         getStereotypeFig().setVisible(true);
 75  
         /* The next line is needed so that we have the right dimension 
 76  
          * when drawing this Fig on the diagram by pressing down 
 77  
          * the mouse button, even before releasing the mouse button: */
 78  0
         getNameFig().setTopMargin(
 79  
                 getStereotypeFig().getMinimumSize().height);
 80  
         
 81  0
         addFig(getBigPort());
 82  0
         addFig(getNameFig());
 83  
         // stereotype fig covers the name fig:
 84  0
         addFig(getStereotypeFig());
 85  
         // Only add an attribute compartment if its valid for this
 86  
         // container
 87  0
         if (Model.getUmlFactory().isContainmentValid(
 88  
                 Model.getMetaTypes().getAttribute(),
 89  
                 getOwner())) {
 90  0
             addFig(new FigAttributesCompartment(
 91  
                     getOwner(),
 92  
                     DEFAULT_COMPARTMENT_BOUNDS, 
 93  
                     getSettings()));
 94  
         }
 95  0
         addFig(getOperationsFig());
 96  
 
 97  
         // Make all the parts match the main fig
 98  0
         setFilled(true);
 99  0
         setFillColor(FILL_COLOR);
 100  0
         setLineColor(LINE_COLOR);
 101  0
         setLineWidth(LINE_WIDTH);
 102  
 
 103  
         /* Set the drop location in the case of D&D: */
 104  0
         if (bounds != null) {
 105  0
             setLocation(bounds.x, bounds.y);
 106  
         }
 107  
 
 108  0
         setSuppressCalcBounds(false);
 109  
 
 110  
         // Set the bounds of the figure to the total of the above 
 111  0
         setBounds(getBounds());
 112  0
         enableSizeChecking(true);
 113  0
     }
 114  
 
 115  
     /**
 116  
      * Construct an Interface fig
 117  
      * 
 118  
      * @param owner owning UML element
 119  
      * @param bounds position and size
 120  
      * @param settings rendering settings
 121  
      */
 122  
     public FigInterface(Object owner, Rectangle bounds, 
 123  
             DiagramSettings settings) {
 124  0
         super(owner, bounds, settings);
 125  0
         initialize(bounds);
 126  0
     }
 127  
     
 128  
     @Override
 129  
     public Selection makeSelection() {
 130  0
         return new SelectionInterface(this);
 131  
     }
 132  
 
 133  
     @Override
 134  
     public void setEnclosingFig(Fig encloser) {
 135  0
         Fig oldEncloser = getEnclosingFig();
 136  
 
 137  0
         if (encloser == null
 138  
                 || (encloser != null
 139  
                 && !Model.getFacade().isAInstance(encloser.getOwner()))) {
 140  0
             super.setEnclosingFig(encloser);
 141  
         }
 142  0
         if (!(Model.getFacade().isAModelElement(getOwner()))) {
 143  0
             return;
 144  
         }
 145  
         /* If this fig is not visible, do not adapt the UML model!
 146  
          * This is used for deleting. See issue 3042.
 147  
          */
 148  0
         if  (!isVisible()) {
 149  0
             return;
 150  
         }
 151  0
         Object me = getOwner();
 152  0
         Object m = null;
 153  
 
 154  
         try {
 155  
             // If moved into an Package
 156  0
             if (encloser != null
 157  
                     && oldEncloser != encloser
 158  
                     && Model.getFacade().isAPackage(encloser.getOwner())) {
 159  0
                 Model.getCoreHelper().setNamespace(me, encloser.getOwner());
 160  
             }
 161  
 
 162  
             // If default Namespace is not already set
 163  0
             if (Model.getFacade().getNamespace(me) == null
 164  
                     && (TargetManager.getInstance().getTarget()
 165  
                     instanceof ArgoDiagram)) {
 166  0
                 m =
 167  
                     ((ArgoDiagram) TargetManager.getInstance().getTarget())
 168  
                         .getNamespace();
 169  0
                 Model.getCoreHelper().setNamespace(me, m);
 170  
             }
 171  0
         } catch (Exception e) {
 172  0
             LOG.error("could not set package due to:" + e
 173  
                     + "' at " + encloser, e);
 174  0
         }
 175  
 
 176  
         // The next if-clause is important for the Deployment-diagram
 177  
         // it detects if the enclosing fig is a component, in this case
 178  
         // the container will be set for the owning Interface
 179  0
         if (encloser != null
 180  
                 && (Model.getFacade().isAComponent(encloser.getOwner()))) {
 181  0
             moveIntoComponent(encloser);
 182  0
             super.setEnclosingFig(encloser);
 183  
         }
 184  0
     }
 185  
 
 186  
     /**
 187  
      * USED BY PGML.tee.
 188  
      * @return the class name and bounds together with compartment
 189  
      * visibility.
 190  
      * TODO: Is this not duplicate with the parent?
 191  
      */
 192  
     @Override
 193  
     public String classNameAndBounds() {
 194  0
         return super.classNameAndBounds()
 195  
                 + "operationsVisible=" + isOperationsVisible();
 196  
     }
 197  
 
 198  
     @Override
 199  
     protected void updateListeners(Object oldOwner, Object newOwner) {
 200  0
         Set<Object[]> listeners = new HashSet<Object[]>();
 201  
 
 202  
         // Collect the set of model elements that we want to listen to
 203  0
         if (newOwner != null) {
 204  
             // TODO: Because we get called on each and every change event, when
 205  
             // the model is in a state of flux, we'll often get an
 206  
             // InvalidElementException before we finish this collection. The
 207  
             // only saving grace is that we're called SO many times that on the
 208  
             // last time, things should be stable again and we'll get a good set
 209  
             // of elements for the final update.  We need a better mechanism.
 210  
             
 211  
             // add the listeners to the newOwner
 212  0
             listeners.add(new Object[] {newOwner, null});
 213  
             
 214  
             // and its stereotypes
 215  
             // TODO: Aren't stereotypes handled elsewhere?
 216  
             for (Object stereotype 
 217  0
                     : Model.getFacade().getStereotypes(newOwner)) {
 218  0
                 listeners.add(new Object[] {stereotype, null});
 219  
             }
 220  
 
 221  
             // and its features
 222  0
             for (Object feat : Model.getFacade().getFeatures(newOwner)) {
 223  0
                 listeners.add(new Object[] {feat, null});
 224  
                 // and the stereotypes of its features
 225  
                 for (Object stereotype 
 226  0
                         : Model.getFacade().getStereotypes(feat)) {
 227  0
                     listeners.add(new Object[] {stereotype, null});
 228  
                 }
 229  
                 // and the parameter of its operations
 230  0
                 if (Model.getFacade().isAOperation(feat)) {
 231  0
                     for (Object param : Model.getFacade().getParameters(feat)) {
 232  0
                         listeners.add(new Object[] {param, null});
 233  
                         /* Testing: Add a parameter to an operation on an Interface.
 234  
                          * Does the Interface Fig adapt its width? */
 235  
                     }
 236  
                 }
 237  
             }
 238  
         }
 239  
         
 240  
         // Update the listeners to match the desired set using the minimal
 241  
         // update facility
 242  0
         updateElementListeners(listeners);
 243  0
     }
 244  
 
 245  
 }