Coverage Report - org.argouml.model.euml.UmlHelperEUMLImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
UmlHelperEUMLImpl
0%
0/96
0%
0/48
5.375
 
 1  
 // $Id: UmlHelperEUMLImpl.java 18529 2010-07-18 13:50:09Z bobtarling $
 2  
 /*******************************************************************************
 3  
  * Copyright (c) 2007,2010 Tom Morris and other contributors
 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  
  *    Tom Morris - initial implementation 
 11  
  *******************************************************************************/
 12  
 package org.argouml.model.euml;
 13  
 
 14  
 import java.util.ArrayList;
 15  
 import java.util.Arrays;
 16  
 import java.util.Collection;
 17  
 import java.util.Iterator;
 18  
 import java.util.List;
 19  
 
 20  
 import org.argouml.model.Model;
 21  
 import org.argouml.model.UmlHelper;
 22  
 import org.eclipse.uml2.uml.Action;
 23  
 import org.eclipse.uml2.uml.ActivityEdge;
 24  
 import org.eclipse.uml2.uml.Behavior;
 25  
 import org.eclipse.uml2.uml.Element;
 26  
 import org.eclipse.uml2.uml.Enumeration;
 27  
 import org.eclipse.uml2.uml.EnumerationLiteral;
 28  
 import org.eclipse.uml2.uml.Extend;
 29  
 import org.eclipse.uml2.uml.ExtensionPoint;
 30  
 import org.eclipse.uml2.uml.Feature;
 31  
 import org.eclipse.uml2.uml.Operation;
 32  
 import org.eclipse.uml2.uml.Parameter;
 33  
 import org.eclipse.uml2.uml.ParameterSet;
 34  
 import org.eclipse.uml2.uml.Property;
 35  
 import org.eclipse.uml2.uml.Relationship;
 36  
 import org.eclipse.uml2.uml.Transition;
 37  
 import org.eclipse.uml2.uml.UseCase;
 38  
 
 39  
 /**
 40  
  * The implementation of the UmlHelper for EUML2.
 41  
  */
 42  
 class UmlHelperEUMLImpl implements UmlHelper {
 43  
 
 44  
     /**
 45  
      * The model implementation.
 46  
      */
 47  
     private EUMLModelImplementation modelImpl;
 48  
 
 49  
     /**
 50  
      * Constructor.
 51  
      * 
 52  
      * @param implementation
 53  
      *            The ModelImplementation.
 54  
      */
 55  0
     public UmlHelperEUMLImpl(EUMLModelImplementation implementation) {
 56  0
         modelImpl = implementation;
 57  0
     }
 58  
 
 59  
     public void addListenersToModel(Object model) {
 60  
         // Nothing to do
 61  
 
 62  0
     }
 63  
 
 64  
     // TODO: Model implementation independent
 65  
     public void deleteCollection(Collection col) {
 66  0
         Iterator it = col.iterator();
 67  0
         while (it.hasNext()) {
 68  0
             modelImpl.getUmlFactory().delete(it.next());
 69  
         }
 70  0
     }
 71  
 
 72  
     /*
 73  
      * @see org.argouml.model.UmlHelper#getSource(java.lang.Object)
 74  
      */
 75  
     public Object getSource(Object relationship) {
 76  0
         if (relationship instanceof Relationship) {
 77  
             // handles all children of relationship including extend and
 78  
             // include which are not members of core
 79  0
             return modelImpl.getCoreHelper().getSource(relationship);
 80  0
         } else if (relationship instanceof Transition) {
 81  0
             return modelImpl.getStateMachinesHelper().getSource(relationship);
 82  0
         } else if (relationship instanceof ActivityEdge) {
 83  0
             return ((ActivityEdge) relationship).getSource();
 84  0
         } else if (relationship instanceof Property) {
 85  
             // TODO: We expect an association end here - check more carefully? - tfm
 86  0
             return modelImpl.getCoreHelper().getSource(relationship);
 87  
         }
 88  0
         throw new IllegalArgumentException();
 89  
     }
 90  
 
 91  
     /*
 92  
      * @see org.argouml.model.UmlHelper#getDestination(java.lang.Object)
 93  
      */
 94  
     public Object getDestination(Object relationship) {
 95  0
         if (relationship instanceof Relationship) {
 96  
             // handles all children of relationship including extend and
 97  
             // include which are not members of core
 98  0
             return modelImpl.getCoreHelper().getDestination(relationship);
 99  0
         } else if (relationship instanceof ActivityEdge) {
 100  0
             return ((ActivityEdge) relationship).getTarget();
 101  0
         } else if (relationship instanceof Transition) {
 102  0
             return modelImpl.getStateMachinesHelper().
 103  
                     getDestination(relationship);
 104  0
         } else if (relationship instanceof Property) {
 105  
             // TODO: We expect an association end here - check more carefully? - tfm
 106  0
             return modelImpl.getCoreHelper().getDestination(relationship);
 107  
         }
 108  0
         throw new IllegalArgumentException();
 109  
     }
 110  
 
 111  
    /*
 112  
      * @see org.argouml.model.UmlHelper#move(java.lang.Object, org.argouml.model.UmlHelper.Direction)
 113  
      */
 114  
     public void move(Object parent, Object element, Direction direction) {
 115  
         if (false) {
 116  
             //TODO: More work require - code below is from MDR implementation
 117  
 //        if (element instanceof Argument) {
 118  
 //            final Argument arg = (Argument) element;
 119  
 //            final Action action = arg.getAction();
 120  
 //            final List<Argument> f = action.getActualArgument();
 121  
 //            final int oldIndex = f.indexOf(arg);
 122  
 //            final int newIndex = newPosition(oldIndex, f.size(), direction);
 123  
 //            f.remove(arg);
 124  
 //            f.add(newIndex, arg);
 125  
 //        } else if (element instanceof Action) {
 126  
 //            final Action act = (Action) element;
 127  
 //            final ActionSequence actionSequence = act.getInGroups();
 128  
 //            final List<Action> f = actionSequence.getAction();
 129  
 //            final int oldIndex = f.indexOf(act);
 130  
 //            final int newIndex = newPosition(oldIndex, f.size(), direction);
 131  
 //            f.remove(actionSequence);
 132  
 //            f.add(newIndex, actionSequence);
 133  
 //        } else if (element instanceof AssociationEnd) {
 134  
 //            final AssociationEnd assEnd = (AssociationEnd) element;
 135  
 //            final UmlAssociation assoc = assEnd.getAssociation();
 136  
 //            final List<AssociationEnd> f =  assoc.getConnection();
 137  
 //            final int oldIndex = f.indexOf(assEnd);
 138  
 //            final int newIndex = newPosition(oldIndex, f.size(), direction);
 139  
 //            f.remove(assEnd);
 140  
 //            f.add(newIndex, assEnd);
 141  
 //        } else if (element instanceof Property && parent instanceof AssociationEnd) {
 142  
 //            final Attribute attr = (Attribute) element;
 143  
 //            final AssociationEnd assocEnd = attr.getAssociationEnd();
 144  
 //            final List<Attribute> f = assocEnd.getQualifier();
 145  
 //            final int oldIndex = f.indexOf(assocEnd);
 146  
 //            final int newIndex = newPosition(oldIndex, f.size(), direction);
 147  
 //            f.remove(attr);
 148  
 //            f.add(newIndex, attr);
 149  0
         } else if (element instanceof Feature) {
 150  0
             final Feature att = (Feature) element;
 151  0
             final Element cls = att.getOwner();
 152  0
             final List f = Model.getFacade().getFeatures(cls);
 153  0
             final int oldIndex = f.indexOf(att);
 154  0
             final int newIndex = newPosition(oldIndex, f.size(), direction);
 155  0
             Model.getCoreHelper().removeFeature(cls, att);
 156  0
             Model.getCoreHelper().addFeature(cls, newIndex, att);
 157  
 
 158  0
         } else if (element instanceof Parameter && parent instanceof Behavior) {
 159  0
             final Parameter param = (Parameter) element;
 160  0
             final Behavior behavior = (Behavior) parent;
 161  0
             final List<Parameter> f = behavior.getOwnedParameters();
 162  0
             final int oldIndex = f.indexOf(param);
 163  0
             final int newIndex = newPosition(oldIndex, f.size(), direction);
 164  0
             f.remove(param);
 165  0
             f.add(newIndex, param);
 166  0
         } else if (element instanceof Parameter && parent instanceof ParameterSet) {
 167  0
             final Parameter param = (Parameter) element;
 168  0
             final ParameterSet set = (ParameterSet) parent;
 169  0
             final List<Parameter> f = set.getParameters();
 170  0
             final int oldIndex = f.indexOf(param);
 171  0
             final int newIndex = newPosition(oldIndex, f.size(), direction);
 172  0
             f.remove(param);
 173  0
             f.add(newIndex, param);
 174  
             // UML 1.4 case
 175  
 //        } else if (element instanceof Parameter && parent instanceof Event) {
 176  
 //            final Parameter param = (Parameter) element;
 177  
 //            final Event event = (Event) parent;
 178  
 //            final List<Parameter> f = event.getParameter();
 179  
 //            final int oldIndex = f.indexOf(param);
 180  
 //            final int newIndex = newPosition(oldIndex, f.size(), direction);
 181  
 //            f.remove(param);
 182  
 //            f.add(newIndex, param);
 183  0
         } else if (element instanceof Parameter) {
 184  0
             final Parameter param = (Parameter) element;
 185  0
             final Operation operation = param.getOperation();
 186  0
             final List<Parameter> f = operation.getOwnedParameters();
 187  0
             final int oldIndex = f.indexOf(param);
 188  0
             final int newIndex = newPosition(oldIndex, f.size(), direction);
 189  0
             f.remove(param);
 190  0
             f.add(newIndex, param);
 191  0
         } else if (element instanceof EnumerationLiteral) {
 192  0
             final EnumerationLiteral lit = (EnumerationLiteral) element;
 193  0
             final Enumeration enumeration = lit.getEnumeration();
 194  0
             final List<EnumerationLiteral> f = enumeration.getOwnedLiterals();
 195  0
             final int oldIndex = f.indexOf(lit);
 196  0
             final int newIndex = newPosition(oldIndex, f.size(), direction);
 197  0
             f.remove(lit);
 198  0
             f.add(newIndex, lit);
 199  0
         } else if (element instanceof ExtensionPoint && parent instanceof Extend) {
 200  0
             final ExtensionPoint ep = (ExtensionPoint) element;
 201  0
             final Extend extend = (Extend) parent;
 202  0
             final List<ExtensionPoint> f = extend.getExtensionLocations();
 203  0
             final int oldIndex = f.indexOf(ep);
 204  0
             final int newIndex = newPosition(oldIndex, f.size(), direction);
 205  0
             f.remove(ep);
 206  0
             f.add(newIndex, ep);
 207  
 //        } else if (element instanceof LinkEnd) {
 208  
 //            final LinkEnd le = (LinkEnd) element;
 209  
 //            final Link link = le.getLink();
 210  
 //            final List f = new ArrayList(Model.getFacade().getConnections(link));
 211  
 //            final int oldIndex = f.indexOf(le);
 212  
 //            final int newIndex = newPosition(oldIndex, f.size(), direction);
 213  
 //            f.remove(le);
 214  
 //            f.add(newIndex, le);
 215  
 //            Model.getCoreHelper().setConnections(link, f);
 216  0
         } else if (element instanceof ExtensionPoint && parent instanceof UseCase) {
 217  0
             final ExtensionPoint ep = (ExtensionPoint) element;
 218  0
             final UseCase extend = ep.getUseCase();
 219  0
             final List f = new ArrayList(Model.getFacade().getExtensionPoints(extend));
 220  0
             final int oldIndex = f.indexOf(ep);
 221  0
             final int newIndex = newPosition(oldIndex, f.size(), direction);
 222  0
             f.remove(ep);
 223  0
             f.add(newIndex, ep);
 224  0
             Model.getUseCasesHelper().setExtensionPoints(ep, f);
 225  
         }
 226  0
     }
 227  
     
 228  
     private int newPosition(int index, int size, Direction direction) {
 229  
         final int posn;
 230  0
         if (direction == Direction.DOWN) {
 231  0
             posn = index + 1;
 232  0
         } else if (direction == Direction.UP) {
 233  0
             posn = index - 1;
 234  0
         } else if (direction == Direction.TOP) {
 235  0
             posn = 0;
 236  0
         } else if (direction == Direction.BOTTOM) {
 237  0
             posn = size;
 238  
         } else {
 239  0
             posn = 0;
 240  
         }
 241  0
         return posn;
 242  
     }
 243  
 
 244  
     /*
 245  
      * @see org.argouml.model.UmlHelper#move(java.lang.Object, org.argouml.model.UmlHelper.Direction)
 246  
      */
 247  
     public boolean isMovable(Object metaType) {
 248  0
         final Class<?>[] movableMetaType = {
 249  
             Action.class, 
 250  
             EnumerationLiteral.class,
 251  
             Extend.class,
 252  
             ExtensionPoint.class,
 253  
             Operation.class,
 254  
             Parameter.class,
 255  
             Property.class};
 256  0
         return Arrays.asList(movableMetaType).contains(metaType);
 257  
     }
 258  
 
 259  
 
 260  
 }