Coverage Report - org.argouml.uml.ui.behavior.common_behavior.ActionNewAction
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionNewAction
6%
2/31
0%
0/24
5.5
ActionNewAction$Roles
N/A
N/A
5.5
 
 1  
 /* $Id: ActionNewAction.java 17890 2010-01-12 21:21:00Z 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-2006 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.ui.behavior.common_behavior;
 40  
 
 41  
 import java.awt.event.ActionEvent;
 42  
 
 43  
 import org.argouml.model.Model;
 44  
 import org.argouml.ui.targetmanager.TargetManager;
 45  
 import org.argouml.uml.ui.AbstractActionNewModelElement;
 46  
 import org.tigris.toolbar.toolbutton.ModalAction;
 47  
 
 48  
 /**
 49  
  * @since Dec 15, 2002
 50  
  * @author jaap.branderhorst@xs4all.nl
 51  
  */
 52  
 public abstract class ActionNewAction extends AbstractActionNewModelElement 
 53  
     implements ModalAction {
 54  
 
 55  
     /**
 56  
      * The constant defining the role the action
 57  
      * to be created plays for its parent.
 58  
      * For example, if one wishes to create
 59  
      * an entry action for a state, this is
 60  
      * filled with "entry". The values are defined
 61  
      * in the interface Roles
 62  
      */
 63  
     public static final String ROLE = "role";
 64  
 
 65  
     /**
 66  
      * Contains the roles definitions for UML actions.
 67  
      *
 68  
      */
 69  
     public static interface Roles {
 70  
         /**
 71  
          * The entry activity for some state.
 72  
          */
 73  
         String ENTRY = "entry";
 74  
 
 75  
         /**
 76  
          * The exit activity for some state.
 77  
          */
 78  
         String EXIT = "exit";
 79  
 
 80  
         /**
 81  
          * The doactivity with some state.
 82  
          */
 83  
         String DO = "do";
 84  
 
 85  
         /**
 86  
          * The action with some message.
 87  
          */
 88  
         String ACTION = "action";
 89  
 
 90  
         /**
 91  
          * The effect of some transition.
 92  
          */
 93  
         String EFFECT = "effect";
 94  
 
 95  
         /**
 96  
          * The effect of some transition.
 97  
          */
 98  
         String MEMBER = "member";
 99  
     }
 100  
 
 101  
     /**
 102  
      * Constructor for ActionNewAction.
 103  
      */
 104  
     protected ActionNewAction() {
 105  912
         super();
 106  912
     }
 107  
 
 108  
     /**
 109  
      * Implementors should create a concrete action like
 110  
      * a CallAction in this method.
 111  
      * @return Object
 112  
      */
 113  
     protected abstract Object createAction();
 114  
 
 115  
     /*
 116  
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 117  
      */
 118  
     public void actionPerformed(ActionEvent e) {
 119  0
         super.actionPerformed(e);
 120  0
         Object action = createAction();
 121  0
         if (getValue(ROLE).equals(Roles.EXIT)) {
 122  0
             Model.getStateMachinesHelper().setExit(getTarget(), action);
 123  0
         } else if (getValue(ROLE).equals(Roles.ENTRY)) {
 124  0
             Model.getStateMachinesHelper().setEntry(getTarget(), action);
 125  0
         } else if (getValue(ROLE).equals(Roles.DO)) {
 126  0
             Model.getStateMachinesHelper().setDoActivity(
 127  
                     getTarget(), action);
 128  0
         } else if (getValue(ROLE).equals(Roles.ACTION)) {
 129  0
             Model.getCollaborationsHelper().setAction(getTarget(), action);
 130  0
         } else if (getValue(ROLE).equals(Roles.EFFECT)) {
 131  0
             Model.getStateMachinesHelper().setEffect(getTarget(), action);
 132  0
         } else if (getValue(ROLE).equals(Roles.MEMBER)) {
 133  0
             Model.getCommonBehaviorHelper().addAction(getTarget(), action);
 134  
         }
 135  0
         TargetManager.getInstance().setTarget(action);
 136  0
     }
 137  
 
 138  
     /**
 139  
      * @param role
 140  
      *            the role the action plays
 141  
      * @param t
 142  
      *            the transition or state to get the action for
 143  
      * @return the action
 144  
      */
 145  
     public static Object getAction(String role, Object t) {
 146  0
         if (role.equals(Roles.EXIT)) {
 147  0
             return Model.getFacade().getExit(t);
 148  0
         } else if (role.equals(Roles.ENTRY)) {
 149  0
             return Model.getFacade().getEntry(t);
 150  0
         } else if (role.equals(Roles.DO)) {
 151  0
             return Model.getFacade().getDoActivity(t);
 152  0
         } else if (role.equals(Roles.ACTION)) {
 153  0
             return Model.getFacade().getAction(t);
 154  0
         } else if (role.equals(Roles.EFFECT)) {
 155  0
             return Model.getFacade().getEffect(t);
 156  0
         } else if (role.equals(Roles.MEMBER)) {
 157  0
             return Model.getFacade().getActions(t);
 158  
         }
 159  0
         return null;
 160  
     }
 161  
 }