Coverage Report - org.argouml.uml.diagram.static_structure.ui.SelectionClass
 
Classes in this File Line Coverage Branch Coverage Complexity
SelectionClass
0%
0/43
0%
0/16
1.786
SelectionClass$ModeCreateEdgeAndNodeWithComposition
0%
0/5
N/A
1.786
 
 1  
 /* $Id: SelectionClass.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) 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.static_structure.ui;
 40  
 
 41  
 import java.awt.event.MouseEvent;
 42  
 import java.util.Collection;
 43  
 
 44  
 import javax.swing.Icon;
 45  
 
 46  
 import org.argouml.application.helpers.ResourceLoaderWrapper;
 47  
 import org.argouml.model.Model;
 48  
 import org.argouml.uml.diagram.deployment.DeploymentDiagramGraphModel;
 49  
 import org.argouml.uml.diagram.ui.SelectionNodeClarifiers2;
 50  
 import org.tigris.gef.base.Editor;
 51  
 import org.tigris.gef.base.Globals;
 52  
 import org.tigris.gef.base.ModeCreateEdgeAndNode;
 53  
 import org.tigris.gef.presentation.Fig;
 54  
 
 55  
 /**
 56  
  * @author jrobbins@ics.uci.edu
 57  
  */
 58  
 public class SelectionClass extends SelectionNodeClarifiers2 {
 59  
 
 60  0
     private static Icon inherit =
 61  
         ResourceLoaderWrapper.lookupIconResource("Generalization");
 62  
 
 63  0
     private static Icon assoc =
 64  
         ResourceLoaderWrapper.lookupIconResource("Association");
 65  
 
 66  0
     private static Icon compos =
 67  
         ResourceLoaderWrapper.lookupIconResource("CompositeAggregation");
 68  
 
 69  0
     private static Icon selfassoc =
 70  
         ResourceLoaderWrapper.lookupIconResource("SelfAssociation");
 71  
 
 72  
     private boolean useComposite;
 73  
 
 74  0
     private static Icon icons[] = 
 75  
     {inherit,
 76  
      inherit,
 77  
      assoc,
 78  
      assoc,
 79  
      selfassoc,
 80  
     };
 81  
     
 82  
     // TODO: I18N required
 83  0
     private static String instructions[] = 
 84  
     {"Add a superclass",
 85  
      "Add a subclass",
 86  
      "Add an associated class",
 87  
      "Add an associated class",
 88  
      "Add a self association",
 89  
      "Move object(s)",
 90  
     };
 91  
 
 92  0
     private static Object edgeType[] = 
 93  
     {Model.getMetaTypes().getGeneralization(),
 94  
      Model.getMetaTypes().getGeneralization(),
 95  
      Model.getMetaTypes().getAssociation(),
 96  
      Model.getMetaTypes().getAssociation(),
 97  
      Model.getMetaTypes().getAssociation(),
 98  
     };
 99  
 
 100  
     /**
 101  
      * Construct a new SelectionClass for the given Fig.
 102  
      *
 103  
      * @param f The given Fig.
 104  
      */
 105  
     public SelectionClass(Fig f) { 
 106  0
         super(f);
 107  0
     }
 108  
 
 109  
     @Override
 110  
     protected Icon[] getIcons() {
 111  0
         Icon workingIcons[] = new Icon[icons.length];
 112  0
         System.arraycopy(icons, 0, workingIcons, 0, icons.length);
 113  
 
 114  
         // No Generalizations on Deployment Diagram
 115  0
         if (Globals.curEditor().getGraphModel() 
 116  
                 instanceof DeploymentDiagramGraphModel) {
 117  0
             workingIcons[TOP - BASE] = null;
 118  0
             workingIcons[BOTTOM - BASE] = null;
 119  
         }
 120  0
         if (useComposite) {
 121  0
             workingIcons[LEFT - BASE] = compos;
 122  0
             workingIcons[RIGHT - BASE] = compos;
 123  
         } 
 124  
         // Readonly class: no generalization, no association to self
 125  0
         if (Model.getModelManagementHelper().isReadOnly(
 126  
                 getContent().getOwner())) {
 127  0
             return new Icon[] {null, inherit, null, null, null };
 128  
         }
 129  0
         return workingIcons;
 130  
     }
 131  
     
 132  
     @Override
 133  
     protected String getInstructions(int index) {
 134  0
         return instructions[index - BASE];
 135  
     }
 136  
 
 137  
     @Override
 138  
     protected Object getNewNodeType(int i) {
 139  0
         return Model.getMetaTypes().getUMLClass();
 140  
     }
 141  
 
 142  
     @Override
 143  
     protected Object getNewEdgeType(int i) {
 144  0
         if (i == 0) {
 145  0
             i = getButton();
 146  
         }
 147  0
         return edgeType[i - 10];
 148  
     }
 149  
 
 150  
     @Override
 151  
     protected boolean isReverseEdge(int i) {
 152  0
         if (i == BOTTOM || i == LEFT) {
 153  0
             return true;
 154  
         } 
 155  0
         return false;
 156  
     }
 157  
     
 158  
     @Override
 159  
     protected boolean isDraggableHandle(int index) {
 160  
         // Self-association isn't draggable
 161  0
         if (index == LOWER_LEFT) {
 162  0
             return false;
 163  
         }
 164  0
         return true;
 165  
     }
 166  
 
 167  
     @Override
 168  
     protected boolean isEdgePostProcessRequested() {
 169  0
         return useComposite;
 170  
     }
 171  
 
 172  
     @Override
 173  
     protected ModeCreateEdgeAndNode getNewModeCreateEdgeAndNode(Editor ce,
 174  
             Object theEdgeType, boolean postProcess,
 175  
             SelectionNodeClarifiers2 nodeCreator) {
 176  0
         return  new ModeCreateEdgeAndNodeWithComposition(ce,
 177  
                 theEdgeType, postProcess, nodeCreator);
 178  
     }
 179  
 
 180  
     @Override
 181  
     protected void postProcessEdge2(Object newEdge) {
 182  0
         if (Model.getFacade().isAAssociation(newEdge)) {
 183  0
             Collection assocEnds = Model.getFacade().getConnections(newEdge);
 184  0
             Object firstAE = assocEnds.iterator().next();
 185  0
             Object aggregationKind = Model.getAggregationKind().getComposite();
 186  0
             Model.getCoreHelper().setAggregation(firstAE, aggregationKind);
 187  
         }
 188  0
     }
 189  
 
 190  
     @Override
 191  
     public void mouseEntered(MouseEvent me) {
 192  0
         super.mouseEntered(me);
 193  0
         useComposite = me.isShiftDown();
 194  0
     }
 195  
 
 196  
     @Override
 197  
     protected Object getNewNode(int index) {
 198  0
         return Model.getCoreFactory().buildClass();
 199  
     }
 200  
 
 201  
     /**
 202  
      * My derived version that handles the creation of composition associations.
 203  
      *
 204  
      * @author Michiel
 205  
      */
 206  
     class ModeCreateEdgeAndNodeWithComposition extends ModeCreateEdgeAndNode {
 207  
 
 208  
         public ModeCreateEdgeAndNodeWithComposition(Editor ce, Object edgeType,
 209  0
                 boolean postProcess, SelectionNodeClarifiers2 nodeCreator) {
 210  0
             super(ce, edgeType, postProcess, nodeCreator);
 211  0
         }
 212  
 
 213  
         @Override
 214  
         protected void postProcessEdge(Object newEdge) {
 215  0
             postProcessEdge2(newEdge);
 216  0
         }
 217  
     }
 218  
 
 219  
 }