Coverage Report - org.argouml.uml.diagram.static_structure.ui.SelectionStereotype
 
Classes in this File Line Coverage Branch Coverage Complexity
SelectionStereotype
0%
0/42
0%
0/18
2.9
 
 1  
 /* $Id: SelectionStereotype.java 17864 2010-01-12 20:11:26Z 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  
  *    mvw
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2006-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.static_structure.ui;
 40  
 
 41  
 import java.awt.event.MouseEvent;
 42  
 
 43  
 import javax.swing.Icon;
 44  
 
 45  
 import org.argouml.application.helpers.ResourceLoaderWrapper;
 46  
 import org.argouml.model.Model;
 47  
 import org.argouml.uml.StereotypeUtility;
 48  
 import org.argouml.uml.diagram.deployment.DeploymentDiagramGraphModel;
 49  
 import org.argouml.uml.diagram.ui.SelectionNodeClarifiers2;
 50  
 import org.tigris.gef.base.Globals;
 51  
 import org.tigris.gef.graph.MutableGraphModel;
 52  
 import org.tigris.gef.presentation.Fig;
 53  
 
 54  
 /**
 55  
  * The buttons on selection for a Stereotype. <p>
 56  
  * 
 57  
  * TODO: Find a way to hide the OperationsCompartment 
 58  
  * on the FigClass of the created metaclass.
 59  
  * 
 60  
  * @author michiel
 61  
  */
 62  
 public class SelectionStereotype extends SelectionNodeClarifiers2 {
 63  
 
 64  0
     private static Icon inheritIcon =
 65  
         ResourceLoaderWrapper.lookupIconResource("Generalization");
 66  0
     private static Icon dependIcon =
 67  
         ResourceLoaderWrapper.lookupIconResource("Dependency");
 68  
 
 69  
     private boolean useComposite;
 70  
     
 71  0
     private static Icon icons[] = 
 72  
     {dependIcon,
 73  
      inheritIcon,
 74  
      null,
 75  
      null,
 76  
      null,
 77  
     };
 78  
 
 79  
     // TODO: I18N required
 80  0
     private static String instructions[] = 
 81  
     {"Add a baseClass",
 82  
      "Add a subStereotype",
 83  
      null,
 84  
      null,
 85  
      null,
 86  
      "Move object(s)",
 87  
     };
 88  
 
 89  
     /**
 90  
      * Construct a new  SelectionStereotype for the given Fig.
 91  
      *
 92  
      * @param f the given fig
 93  
      */
 94  
     public SelectionStereotype(Fig f) {
 95  0
         super(f);
 96  0
     }
 97  
 
 98  
     @Override
 99  
     public void mouseEntered(MouseEvent me) {
 100  0
         super.mouseEntered(me);
 101  0
         useComposite = me.isShiftDown();
 102  0
     }
 103  
 
 104  
     @Override
 105  
     protected Object getNewNode(int index) {
 106  0
         if (index == 0) {
 107  0
             index = getButton();
 108  
         }
 109  0
         Object ns = Model.getFacade().getNamespace(getContent().getOwner());
 110  0
         switch (index) {
 111  
         case 10:
 112  0
             Object clazz = Model.getCoreFactory().buildClass(ns);
 113  0
             StereotypeUtility.dealWithStereotypes(clazz, "metaclass", false);
 114  0
             return clazz;
 115  
         case 11:
 116  0
             Object st = 
 117  
                 Model.getExtensionMechanismsFactory().createStereotype();
 118  0
             Model.getCoreHelper().setNamespace(st, ns);
 119  0
             return st;
 120  
         }
 121  0
         return null;
 122  
     }
 123  
 
 124  
     @Override
 125  
     protected Object getNewNodeType(int index) {
 126  0
         switch (index) {
 127  
         case 10:
 128  0
             return Model.getMetaTypes().getClass();
 129  
         case 11:
 130  0
             return Model.getMetaTypes().getStereotype();
 131  
         }
 132  0
         return null;
 133  
     }
 134  
 
 135  
     @Override
 136  
     protected Object createEdgeAbove(MutableGraphModel mgm, Object newNode) {
 137  0
         Object dep = super.createEdgeAbove(mgm, newNode);
 138  0
         StereotypeUtility.dealWithStereotypes(dep, "stereotype", false);
 139  0
         return dep;
 140  
     }
 141  
 
 142  
     @Override
 143  
     protected Icon[] getIcons() {
 144  
         // In the DeploymentDiagram there are no Generalizations
 145  0
         if (Globals.curEditor().getGraphModel() 
 146  
                 instanceof DeploymentDiagramGraphModel) {
 147  0
             return null;
 148  
         }
 149  0
         if (Model.getModelManagementHelper().isReadOnly(
 150  
                 getContent().getOwner())) {
 151  0
             return new Icon[] {null, inheritIcon, null, null, null };
 152  
         }
 153  0
         return icons;
 154  
     }
 155  
 
 156  
     @Override
 157  
     protected String getInstructions(int index) {
 158  0
         return instructions[index - BASE];
 159  
     }
 160  
 
 161  
     @Override
 162  
     protected Object getNewEdgeType(int index) {
 163  0
         if (index == TOP) {
 164  0
             return Model.getMetaTypes().getDependency();
 165  0
         } else if (index == BOTTOM) {
 166  0
             return Model.getMetaTypes().getGeneralization();
 167  
         }
 168  0
         return null;
 169  
     }
 170  
 
 171  
     @Override
 172  
     protected boolean isReverseEdge(int index) {
 173  0
         if (index == BOTTOM) {
 174  0
             return true;
 175  
         }
 176  0
         return false;
 177  
     }
 178  
 
 179  
     @Override
 180  
     protected boolean isEdgePostProcessRequested() {
 181  0
         return useComposite;
 182  
     }
 183  
 
 184  
 }