Coverage Report - org.argouml.uml.diagram.ui.ActionEdgesDisplay
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionEdgesDisplay
0%
0/32
0%
0/10
2
 
 1  
 /* $Id: ActionEdgesDisplay.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  
  *    bobtarling
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-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.Enumeration;
 43  
 import java.util.Iterator;
 44  
 import java.util.List;
 45  
 
 46  
 import javax.swing.Action;
 47  
 
 48  
 import org.argouml.i18n.Translator;
 49  
 import org.argouml.model.Model;
 50  
 import org.argouml.uml.diagram.ArgoDiagram;
 51  
 import org.argouml.uml.diagram.DiagramUtils;
 52  
 import org.tigris.gef.base.Editor;
 53  
 import org.tigris.gef.base.Globals;
 54  
 import org.tigris.gef.base.Selection;
 55  
 import org.tigris.gef.graph.MutableGraphModel;
 56  
 import org.tigris.gef.presentation.Fig;
 57  
 import org.argouml.ui.UndoableAction;
 58  
 
 59  
 /**
 60  
  * An action that makes all edges on the selected node visible/not visible
 61  
  * on the diagram.
 62  
  *
 63  
  * @author David Manura
 64  
  * @since 0.13.5
 65  
  */
 66  
 public class ActionEdgesDisplay extends UndoableAction {
 67  
 
 68  
     // compartments
 69  0
     private static UndoableAction showEdges = new ActionEdgesDisplay(true,
 70  
                 Translator.localize("menu.popup.add.all-relations"));
 71  0
     private static UndoableAction hideEdges = new ActionEdgesDisplay(false,
 72  
                 Translator.localize("menu.popup.remove.all-relations"));
 73  
 
 74  
     private boolean show;
 75  
 
 76  
     /**
 77  
      * The constructor.
 78  
      *
 79  
      * @param showEdge to show or not to show
 80  
      * @param desc the name
 81  
      */
 82  
     protected ActionEdgesDisplay(boolean showEdge, String desc) {
 83  0
         super(desc, null);
 84  
                 // Set the tooltip string:
 85  0
         putValue(Action.SHORT_DESCRIPTION, desc);
 86  0
         show = showEdge;
 87  0
     }
 88  
 
 89  
     /*
 90  
      * TODO: Support commentEdges.
 91  
      * TODO: Support associations to self.
 92  
      *
 93  
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 94  
      */
 95  
     @Override
 96  
     public void actionPerformed(ActionEvent ae) {
 97  0
             super.actionPerformed(ae);
 98  0
         ArgoDiagram d = DiagramUtils.getActiveDiagram();
 99  0
         Editor ce = Globals.curEditor();
 100  0
         MutableGraphModel mgm = (MutableGraphModel) ce.getGraphModel();
 101  
 
 102  0
         Enumeration e = ce.getSelectionManager().selections().elements();
 103  0
         while (e.hasMoreElements()) {
 104  0
             Selection sel = (Selection) e.nextElement();
 105  0
             Object owner = sel.getContent().getOwner();
 106  
 
 107  0
             if (show) { // add
 108  0
                 mgm.addNodeRelatedEdges(owner);
 109  
 //                Collection c = Model.getFacade().getComments(owner);
 110  
 //                Iterator i = c.iterator();
 111  
 //                while (i.hasNext()) {
 112  
 //                    Object annotatedElement = i.next();
 113  
 //                    Fig f = d.presentationFor(annotatedElement);
 114  
 //                    // and now what? How do I add it to the diagram?
 115  
 //                }
 116  
             } else { // remove
 117  0
                 List edges = mgm.getInEdges(owner);
 118  0
                 edges.addAll(mgm.getOutEdges(owner));
 119  0
                 Iterator e2 = edges.iterator();
 120  0
                 while (e2.hasNext()) {
 121  0
                     Object edge = e2.next();
 122  0
                     if (Model.getFacade().isAAssociationEnd(edge)) {
 123  0
                         edge = Model.getFacade().getAssociation(edge);
 124  
                     }
 125  0
                     Fig fig = d.presentationFor(edge);
 126  0
                     if (fig != null) {
 127  0
                         fig.removeFromDiagram();
 128  
                     }
 129  0
                 }
 130  
                 //The next does not yet work for comment edges:
 131  
 //                Collection c = Model.getFacade().getComments(owner);
 132  
 //                Iterator i = c.iterator();
 133  
 //                while (i.hasNext()) {
 134  
 //                    Object annotatedElement = i.next();
 135  
 //                    Fig f = d.presentationFor(annotatedElement);
 136  
 //                    if (f != null) f.removeFromDiagram();
 137  
 //                }
 138  
             }
 139  0
         }
 140  0
     }
 141  
 
 142  
     /**
 143  
      * @return true if the action is enabled
 144  
      * @see org.tigris.gef.undo.UndoableAction#isEnabled()
 145  
      */
 146  
     @Override
 147  
     public boolean isEnabled() {
 148  0
         return true;
 149  
     }
 150  
 
 151  
 
 152  
     /**
 153  
      * @return Returns the showEdges.
 154  
      */
 155  
     public static UndoableAction getShowEdges() {
 156  0
         return showEdges;
 157  
     }
 158  
 
 159  
 
 160  
     /**
 161  
      * @return Returns the hideEdges.
 162  
      */
 163  
     public static UndoableAction getHideEdges() {
 164  0
         return hideEdges;
 165  
     }
 166  
 
 167  
 }
 168  
 
 169  
 
 170