Coverage Report - org.argouml.uml.ui.foundation.extension_mechanisms.ActionNewTagDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionNewTagDefinition
12%
3/24
0%
0/10
3.5
 
 1  
 /* $Id: ActionNewTagDefinition.java 19070 2011-02-24 09:12:08Z thn $
 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  
  *    bobtarling
 11  
  *    Thomas Neustupny
 12  
  *****************************************************************************
 13  
  *
 14  
  * Some portions of this file was previously release using the BSD License:
 15  
  */
 16  
 
 17  
 // Copyright (c) 2004-2009 The Regents of the University of California. All
 18  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 19  
 // software and its documentation without fee, and without a written
 20  
 // agreement is hereby granted, provided that the above copyright notice
 21  
 // and this paragraph appear in all copies.  This software program and
 22  
 // documentation are copyrighted by The Regents of the University of
 23  
 // California. The software program and documentation are supplied "AS
 24  
 // IS", without any accompanying services from The Regents. The Regents
 25  
 // does not warrant that the operation of the program will be
 26  
 // uninterrupted or error-free. The end-user understands that the program
 27  
 // was developed for research purposes and is advised not to rely
 28  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 29  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 30  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 31  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 32  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 33  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 34  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 35  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 36  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 37  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 38  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 39  
 
 40  
 package org.argouml.uml.ui.foundation.extension_mechanisms;
 41  
 
 42  
 import java.awt.event.ActionEvent;
 43  
 
 44  
 import javax.swing.Action;
 45  
 
 46  
 import org.argouml.application.helpers.ResourceLoaderWrapper;
 47  
 import org.argouml.i18n.Translator;
 48  
 import org.argouml.kernel.UmlModelMutator;
 49  
 import org.argouml.model.Model;
 50  
 import org.argouml.ui.targetmanager.TargetManager;
 51  
 import org.argouml.ui.UndoableAction;
 52  
 
 53  
 
 54  
 /**
 55  
  * This action creates a new TagDefinition in the current Model or Stereotype or
 56  
  * Package.
 57  
  *
 58  
  * @author rastaman@tigris.org
 59  
  */
 60  
 @UmlModelMutator
 61  
 public class ActionNewTagDefinition extends UndoableAction {
 62  
 
 63  
     /**
 64  
      * The constructor.
 65  
      */
 66  
     public ActionNewTagDefinition() {
 67  900
         super(Translator.localize("button.new-tagdefinition"),
 68  
                 ResourceLoaderWrapper.lookupIcon("button.new-tagdefinition"));
 69  
         // Set the tooltip string:
 70  900
         putValue(Action.SHORT_DESCRIPTION, 
 71  
                 Translator.localize("button.new-tagdefinition"));
 72  900
     }
 73  
 
 74  
     /*
 75  
      * @see java.awt.event.ActionListener#actionPerformed(
 76  
      *      java.awt.event.ActionEvent)
 77  
      */
 78  
     public void actionPerformed(ActionEvent e) {
 79  0
         super.actionPerformed(e);
 80  0
         Object t = TargetManager.getInstance().getModelTarget();
 81  0
         Object owner = null;
 82  0
         Object namespace = null;
 83  0
         if (Model.getFacade().isAStereotype(t)) {
 84  0
             owner = t;
 85  0
         } else if (Model.getFacade().isAPackage(t)) {
 86  0
             namespace = t;
 87  
         } else {
 88  0
             namespace = Model.getFacade().getInnerContainingModel(t);
 89  
         }
 90  0
         Object newTagDefinition = null;
 91  0
         if (Model.getFacade().getUmlVersion().charAt(0) == '1') {
 92  0
             newTagDefinition = Model.getExtensionMechanismsFactory()
 93  
                 .buildTagDefinition((String) null, owner, namespace);
 94  
         } else {
 95  0
             Object type = null;
 96  0
             for (Object aType : Model.getExtensionMechanismsHelper()
 97  
                     .getCommonTaggedValueTypes()) {
 98  0
                 if ("String".equals(Model.getFacade().getName(aType))) {
 99  0
                     type = aType;
 100  0
                     break;
 101  
                 }
 102  
             }
 103  0
             newTagDefinition = Model.getCoreFactory().buildAttribute2(t, type);
 104  
         }
 105  0
         TargetManager.getInstance().setTarget(newTagDefinition);
 106  0
         super.actionPerformed(e);
 107  0
     }
 108  
 
 109  
 }