Coverage Report - org.argouml.uml.ui.AbstractActionRemoveElement
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractActionRemoveElement
0%
0/14
0%
0/8
1.429
 
 1  
 /* $Id: AbstractActionRemoveElement.java 17881 2010-01-12 21:09:28Z 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  
  *    bobtarling
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2007 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;
 40  
 
 41  
 import javax.swing.Action;
 42  
 
 43  
 import org.argouml.i18n.Translator;
 44  
 import org.argouml.kernel.UmlModelMutator;
 45  
 import org.argouml.model.Model;
 46  
 import org.argouml.ui.UndoableAction;
 47  
 
 48  
 /**
 49  
  * Base class for remove actions. Remove actions can remove an element
 50  
  * from the model. This can either be a total remove ('erase from
 51  
  * model') or just a remove from a list of bases as in the case of
 52  
  * classifierrole bases.<p>
 53  
  *
 54  
  * @author jaap.branderhorst@xs4all.nl
 55  
  * @since Jan 25, 2003
 56  
  */
 57  
 @UmlModelMutator
 58  
 public class AbstractActionRemoveElement extends UndoableAction {
 59  
 
 60  
     /**
 61  
      * The object that owns the object that must be removed (the
 62  
      * object that is the target of the projectbrowser in most cases).
 63  
      */
 64  
     private Object target;
 65  
 
 66  
     private Object objectToRemove;
 67  
 
 68  
     /**
 69  
      * Constructor for AbstractActionRemoveElement.
 70  
      */
 71  
     protected AbstractActionRemoveElement() {
 72  0
         this(Translator.localize("menu.popup.remove"));
 73  0
     }
 74  
 
 75  
     /**
 76  
      *  The constructor.
 77  
      * @param name the name for this action
 78  
      */
 79  
     protected AbstractActionRemoveElement(String name) {
 80  0
         super(Translator.localize(name),
 81  
                 null);
 82  
         // Set the tooltip string:
 83  0
         putValue(Action.SHORT_DESCRIPTION, 
 84  
                 Translator.localize(name));
 85  0
     }
 86  
 
 87  
      /**
 88  
      * Returns the target.
 89  
      *
 90  
      * @return MModelElement
 91  
      */
 92  
     public Object getTarget() {
 93  0
         return target;
 94  
     }
 95  
 
 96  
     /**
 97  
      * Sets the target.
 98  
      *
 99  
      * @param theTarget The target to set
 100  
      */
 101  
     public void setTarget(Object theTarget) {
 102  0
         target = theTarget;
 103  0
         setEnabled(isEnabled());
 104  0
     }
 105  
 
 106  
     /**
 107  
      * Returns the objectToRemove.
 108  
      *
 109  
      * @return Object
 110  
      */
 111  
     public Object getObjectToRemove() {
 112  0
         return objectToRemove;
 113  
     }
 114  
 
 115  
     /**
 116  
      * Sets the objectToRemove.
 117  
      *
 118  
      * @param theObjectToRemove The objectToRemove to set
 119  
      */
 120  
     public void setObjectToRemove(Object theObjectToRemove) {
 121  0
         objectToRemove = theObjectToRemove;
 122  0
         setEnabled(isEnabled());
 123  0
     }
 124  
 
 125  
     /*
 126  
      * @see javax.swing.Action#isEnabled()
 127  
      */
 128  
     @Override
 129  
     public boolean isEnabled() {
 130  0
         return getObjectToRemove() != null
 131  
                 && !Model.getModelManagementHelper().isReadOnly(
 132  
                         getObjectToRemove()) && getTarget() != null
 133  
                 && !Model.getModelManagementHelper().isReadOnly(getTarget());
 134  
     }
 135  
 
 136  
 }