Coverage Report - org.argouml.uml.diagram.ui.ActionSetPath
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionSetPath
0%
0/42
0%
0/28
5.333
 
 1  
 /* $Id: ActionSetPath.java 17865 2010-01-12 20:45:26Z 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  
  *    mvw
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2007-2008 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.diagram.ui;
 40  
 
 41  
 import java.awt.event.ActionEvent;
 42  
 import java.util.ArrayList;
 43  
 import java.util.Collection;
 44  
 import java.util.Iterator;
 45  
 import java.util.List;
 46  
 
 47  
 import javax.swing.Action;
 48  
 
 49  
 import org.argouml.i18n.Translator;
 50  
 import org.argouml.model.Model;
 51  
 import org.argouml.ui.UndoableAction;
 52  
 import org.argouml.uml.diagram.PathContainer;
 53  
 import org.tigris.gef.base.Editor;
 54  
 import org.tigris.gef.base.Globals;
 55  
 import org.tigris.gef.base.Selection;
 56  
 import org.tigris.gef.presentation.Fig;
 57  
 
 58  
 
 59  
 /**
 60  
  * This action shows or hides the path in the name.
 61  
  *
 62  
  * @author Michiel
 63  
  */
 64  
 class ActionSetPath extends UndoableAction {
 65  
 
 66  0
     private static final UndoableAction SHOW_PATH =
 67  
         new ActionSetPath(false);
 68  0
     private static final UndoableAction HIDE_PATH =
 69  
         new ActionSetPath(true);
 70  
 
 71  
     private boolean isPathVisible;
 72  
 
 73  
     /**
 74  
      * Constructor.
 75  
      *
 76  
      * @param isVisible <tt>true</tt> if the path is visible.
 77  
      */
 78  
     public ActionSetPath(boolean isVisible) {
 79  0
         super();
 80  0
         isPathVisible = isVisible;
 81  
         String name;
 82  0
         if (isVisible) {
 83  0
             name = Translator.localize("menu.popup.hide.path");
 84  
         } else {
 85  0
             name = Translator.localize("menu.popup.show.path");
 86  
         }
 87  0
         putValue(Action.NAME, name);
 88  0
     }
 89  
     
 90  
     /**
 91  
      * Static function to return the path show and/or hide actions 
 92  
      * needed for the selected Figs.
 93  
      * 
 94  
      * @return Only returns the actions for the menu-items that make sense for
 95  
      *         the current selection.
 96  
      */
 97  
     public static Collection<UndoableAction> getActions() {
 98  0
         Collection<UndoableAction> actions = new ArrayList<UndoableAction>();
 99  0
         Editor ce = Globals.curEditor();
 100  0
         List<Fig> figs = ce.getSelectionManager().getFigs();
 101  0
         for (Fig f : figs) {
 102  0
             if (f instanceof PathContainer) {
 103  0
                 Object owner = f.getOwner();
 104  0
                 if (Model.getFacade().isAModelElement(owner)) {
 105  0
                     Object ns = Model.getFacade().getNamespace(owner);
 106  0
                     if (ns != null) {
 107  
                         /* Only show the path item when there is 
 108  
                          * an owning namespace. */
 109  0
                         if (((PathContainer) f).isPathVisible()) {
 110  0
                             actions.add(HIDE_PATH);
 111  0
                             break;
 112  
                         }
 113  
                     }
 114  
                 }
 115  0
             }
 116  
         }
 117  0
         for (Fig f : figs) {
 118  0
             if (f instanceof PathContainer) {
 119  0
                 Object owner = f.getOwner();
 120  0
                 if (Model.getFacade().isAModelElement(owner)) {
 121  0
                     Object ns = Model.getFacade().getNamespace(owner);
 122  0
                     if (ns != null) {
 123  
                         /* Only show the path item when there is 
 124  
                          * an owning namespace. */
 125  0
                         if (!((PathContainer) f).isPathVisible()) {
 126  0
                             actions.add(SHOW_PATH);
 127  0
                             break;
 128  
                         }
 129  
                     }
 130  
                 }
 131  0
             }
 132  
         }
 133  0
         return actions;
 134  
     }
 135  
 
 136  
     /**
 137  
      * @see org.tigris.gef.undo.UndoableAction#actionPerformed(java.awt.event.ActionEvent)
 138  
      */
 139  
     @Override
 140  
     public void actionPerformed(ActionEvent e) {
 141  0
         super.actionPerformed(e);
 142  
 
 143  
         // enumerate all selected figures and update their path accordingly  
 144  0
         Iterator< ? > i =
 145  
             Globals.curEditor().getSelectionManager().selections().iterator();
 146  0
         while (i.hasNext()) {
 147  0
             Selection sel = (Selection) i.next();
 148  0
             Fig f = sel.getContent();
 149  
                         
 150  0
             if (f instanceof PathContainer) {
 151  0
                 ((PathContainer) f).setPathVisible(!isPathVisible);
 152  
             }
 153  0
         }
 154  0
     }
 155  
     
 156  
 }