Coverage Report - org.xmlhammer.gui.output.ElementNode
 
Classes in this File Line Coverage Branch Coverage Complexity
ElementNode
26% 
0% 
0
 
 1  
 /*
 2  
  * $Id: ElementNode.java,v 1.9 2007/07/04 19:42:48 edankert Exp $
 3  
  *
 4  
  * The contents of this file are subject to the Mozilla Public License 
 5  
  * Version 1.1 (the "License"); you may not use this file except in 
 6  
  * compliance with the License. You may obtain a copy of the License at 
 7  
  * http://www.mozilla.org/MPL/ 
 8  
  *
 9  
  * Software distributed under the License is distributed on an "AS IS" basis, 
 10  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
 11  
  * for the specific language governing rights and limitations under the License.
 12  
  *
 13  
  * The Original Code is XML Hammer code. (org.xmlhammer.*)
 14  
  *
 15  
  * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
 16  
  * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
 17  
  * All Rights Reserved.
 18  
  *
 19  
  * Contributor(s): Edwin Dankert <edankert@gmail.com>
 20  
  */
 21  
 package org.xmlhammer.gui.output;
 22  
 
 23  
 import java.net.URI;
 24  
 
 25  
 import javax.swing.ImageIcon;
 26  
 import javax.swing.JFrame;
 27  
 import javax.swing.JPopupMenu;
 28  
 
 29  
 import org.bounce.RunnableAction;
 30  
 import org.bounce.MenuUtilities;
 31  
 import org.bounce.image.ImageLoader;
 32  
 import org.xmlhammer.model.project.Element;
 33  
 
 34  
 /**
 35  
  * The node for an XML Element.
 36  
  *
 37  
  * @version        $Revision: 1.9 $, $Date: 2007/07/04 19:42:48 $
 38  
  * @author Edwin Dankert <edankert@gmail.com>
 39  
  */
 40  0
 public class ElementNode extends ResultNode {
 41  
         private static final long serialVersionUID = -4697678300417972206L;
 42  
 
 43  132
     private Element element = null;
 44  22
         private static final ImageIcon ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/obj16/element.gif");;
 45  
 
 46  22
     private static ElementDetailsDialog dialog = null;
 47  
 
 48  132
     private String value = null;
 49  132
     private URI uri = null;
 50  
         
 51  132
         public ElementNode(URI uri, Element value) {
 52  132
                 this.element = value;
 53  132
         this.uri = uri;
 54  132
         }
 55  
         
 56  
         public String getName() {
 57  0
                 return element.getNodeName();
 58  
         }
 59  
         
 60  
         public String getValue() {
 61  0
                 if ( value == null) {
 62  0
                         StringBuffer buffer = new StringBuffer( element.getNodeName());
 63  
                         
 64  0
                         if ( element.getText() != null && element.getText().length() > 0) {
 65  0
                                 buffer.append( " - ");
 66  0
                                 buffer.append( getFirstLine(element.getText()));
 67  
                         }
 68  
                         
 69  0
                         value = buffer.toString();
 70  
                 }
 71  
                 
 72  0
                 return value;
 73  
         }
 74  
         
 75  
         public String getDescription() {
 76  0
                 return "["+element.getType().getName()+"] "+getValue();
 77  
         }
 78  
         
 79  
         public ImageIcon getIcon() {
 80  0
                 return ICON;
 81  
         }
 82  
     
 83  
     @Override
 84  
     public JPopupMenu getPopupMenu(JFrame parent) {
 85  0
         JPopupMenu popup = new JPopupMenu();
 86  0
         popup.add(getOpenURIAction(uri, 0, 0));
 87  0
         popup.add(getEditURIAction(uri, 0, 0));
 88  0
         popup.addSeparator();
 89  0
         popup.add(getCopyAction());
 90  0
         popup.addSeparator();
 91  0
         popup.add(getPropertiesAction(getDialog(parent)));
 92  
         
 93  0
         MenuUtilities.alignMenu(popup);
 94  
 
 95  0
         return popup;
 96  
     }
 97  
     
 98  
     @Override
 99  
     public RunnableAction getDefaultAction(JFrame parent) {
 100  0
         return getPropertiesAction(getDialog(parent));
 101  
     }
 102  
     
 103  
     private ElementDetailsDialog getDialog(JFrame parent) {
 104  0
         if (dialog == null) {
 105  0
             dialog = new ElementDetailsDialog(parent);
 106  
         }
 107  
         
 108  0
         dialog.setElement(element);
 109  
 
 110  0
         return dialog;
 111  
     }
 112  
     
 113  
     public String getCopyValue() {
 114  0
         return element.getContext();
 115  
     }
 116  
 }