Coverage Report - org.argouml.uml.ui.AbstractActionAddModelElement2
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractActionAddModelElement2
0%
0/25
0%
0/4
1.067
 
 1  
 /* $Id: AbstractActionAddModelElement2.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) 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 java.awt.event.ActionEvent;
 42  
 import java.util.Collection;
 43  
 import java.util.List;
 44  
 
 45  
 import javax.swing.Action;
 46  
 import javax.swing.Icon;
 47  
 import javax.swing.JOptionPane;
 48  
 
 49  
 import org.argouml.i18n.Translator;
 50  
 import org.argouml.kernel.UmlModelMutator;
 51  
 import org.argouml.util.ArgoFrame;
 52  
 import org.argouml.ui.UndoableAction;
 53  
 
 54  
 /**
 55  
  * Abstract action that is the parent to all add actions that add the
 56  
  * modelelements via the UMLAddDialog.
 57  
  * 
 58  
  * @since Oct 2, 2002
 59  
  * @author jaap.branderhorst@xs4all.nl
 60  
  */
 61  
 @UmlModelMutator
 62  
 public abstract class AbstractActionAddModelElement2 extends UndoableAction {
 63  
 
 64  
     private Object target;
 65  0
     private boolean multiSelect = true;
 66  0
     private boolean exclusive = true;
 67  
 
 68  
     /**
 69  
      * Construct an action to add a model element to some list.
 70  
      */
 71  
     protected AbstractActionAddModelElement2() {
 72  0
         super(Translator.localize("menu.popup.add-modelelement"), null);
 73  
         // Set the tooltip string:
 74  0
         putValue(Action.SHORT_DESCRIPTION, 
 75  
                 Translator.localize("menu.popup.add-modelelement"));
 76  0
     }
 77  
 
 78  
     /**
 79  
      * Construct a named action to add a model element to some list.
 80  
      * @param name name for action
 81  
      */
 82  
     public AbstractActionAddModelElement2(String name) {
 83  0
         super(name);
 84  0
     }
 85  
 
 86  
     /**
 87  
      * Construct an action to add a model element to some list with the
 88  
      * given name and icon.
 89  
      * @param name name for action
 90  
      * @param icon icon for action
 91  
      */
 92  
     public AbstractActionAddModelElement2(String name, Icon icon) {
 93  0
         super(name, icon);
 94  0
     }
 95  
     
 96  
 
 97  
     /*
 98  
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 99  
      */
 100  
     @Override
 101  
     public void actionPerformed(ActionEvent e) {
 102  0
         super.actionPerformed(e);
 103  0
         UMLAddDialog dialog =
 104  
             new UMLAddDialog(getChoices(), getSelected(), getDialogTitle(),
 105  
                              isMultiSelect(),
 106  
                              isExclusive());
 107  0
         int result = dialog.showDialog(ArgoFrame.getFrame());
 108  0
         if (result == JOptionPane.OK_OPTION) {
 109  0
             doIt(dialog.getSelected());
 110  
         }
 111  0
     }
 112  
     
 113  
     /**
 114  
      * Returns the choices the user has in the UMLAddDialog. The choices are
 115  
      * depicted on the left side of the UMLAddDialog (sorry Arabic users) and
 116  
      * can be moved via the buttons on the dialog to the right side. On the
 117  
      * right side are the selected modelelements.
 118  
      * @return List of choices
 119  
      */
 120  
     protected abstract List getChoices();
 121  
 
 122  
     
 123  
     /**
 124  
      * The modelelements already selected BEFORE the dialog is shown.
 125  
      * @return List of model elements
 126  
      */
 127  
     protected abstract List getSelected();
 128  
 
 129  
     /**
 130  
      * The action that has to be done by ArgoUml after the user clicks ok in the
 131  
      * UMLAddDialog.
 132  
      * @param selected The choices the user has selected in the UMLAddDialog
 133  
      */
 134  
     protected abstract void doIt(Collection selected);
 135  
 
 136  
     /*
 137  
      * @see javax.swing.Action#isEnabled()
 138  
      */
 139  
     @Override
 140  
     public boolean isEnabled() {
 141  0
         return !getChoices().isEmpty();
 142  
     }
 143  
     
 144  
     
 145  
     /**
 146  
      * Returns the UML model target.
 147  
      * @return UML ModelElement
 148  
      */
 149  
     protected Object getTarget() {
 150  0
         return target;
 151  
     }
 152  
 
 153  
     /**
 154  
      * Sets the UML model target.
 155  
      * @param theTarget The target to set
 156  
      */
 157  
     public void setTarget(Object theTarget) {
 158  0
         target = theTarget;
 159  0
     }
 160  
 
 161  
     /**
 162  
      * Returns the title of the dialog.
 163  
      * @return String
 164  
      */
 165  
     protected abstract String getDialogTitle();
 166  
 
 167  
     /**
 168  
      * Returns the exclusive.
 169  
      * @return boolean
 170  
      */
 171  
     public boolean isExclusive() {
 172  0
         return exclusive;
 173  
     }
 174  
 
 175  
     /**
 176  
      * Returns the multiSelect.
 177  
      * @return boolean
 178  
      */
 179  
     public boolean isMultiSelect() {
 180  0
         return multiSelect;
 181  
     }
 182  
 
 183  
     /**
 184  
      * Sets the exclusive.
 185  
      * @param theExclusive The exclusive to set
 186  
      */
 187  
     public void setExclusive(boolean theExclusive) {
 188  0
         exclusive = theExclusive;
 189  0
     }
 190  
 
 191  
     /**
 192  
      * Sets the multiSelect.
 193  
      * @param theMultiSelect The multiSelect to set
 194  
      */
 195  
     public void setMultiSelect(boolean theMultiSelect) {
 196  0
         multiSelect = theMultiSelect;
 197  0
     }
 198  
 
 199  
 }