View Javadoc

1   /*
2    * $Id: AttributeNode.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  
22  package org.xmlhammer.gui.output;
23  
24  import java.awt.Dimension;
25  import java.net.URI;
26  
27  import javax.swing.ImageIcon;
28  import javax.swing.JFrame;
29  import javax.swing.JPopupMenu;
30  
31  import org.bounce.RunnableAction;
32  import org.bounce.MenuUtilities;
33  import org.bounce.image.ImageLoader;
34  import org.xmlhammer.model.project.Attribute;
35  
36  /***
37   * The node for an XML attribute.
38   *
39   * @version	$Revision: 1.9 $, $Date: 2007/07/04 19:42:48 $
40   * @author Edwin Dankert <edankert@gmail.com>
41   */
42  public class AttributeNode extends ResultNode {
43      static final Dimension EDITORPANE_SIZE = new Dimension( 100, 60);        
44  
45      private static final long serialVersionUID = -1312728718437717912L;
46  
47      private static final ImageIcon ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/obj16/att_URI_obj.gif");;
48      private static AttributeDetailsDialog dialog = null;
49  
50      private Attribute value = null;
51      private URI uri = null;
52  
53  	public AttributeNode(URI uri, Attribute value) {
54  		this.value = value;
55          this.uri = uri;
56  	}
57  	
58  	public String getName() {
59  		return value.getName();
60  	}
61  	
62  	public String getValue() {
63  		return value.getNodeName()+" - "+value.getNodeValue();
64  	}
65  	
66  	public String getDescription() {
67  		return "{"+value.getNamespaceURI()+"}"+value.getName()+" - "+value.getValue();
68  	}
69  	
70  	public ImageIcon getIcon() {
71  		return ICON;
72  	}
73  
74      @Override
75      public JPopupMenu getPopupMenu(JFrame parent) {
76          JPopupMenu popup = new JPopupMenu();
77          popup.add(getOpenURIAction(uri, 0, 0));
78          popup.add(getEditURIAction(uri, 0, 0));
79          popup.addSeparator();
80          popup.add(getCopyAction());
81          popup.addSeparator();
82          popup.add(getPropertiesAction(getDialog(parent)));
83          
84          MenuUtilities.alignMenu(popup);
85  
86          return popup;
87      }
88      
89      @Override
90      public RunnableAction getDefaultAction(JFrame parent) {
91          return getPropertiesAction(getDialog(parent));
92      }
93      
94      private AttributeDetailsDialog getDialog(JFrame parent) {
95          if (dialog == null) {
96              dialog = new AttributeDetailsDialog(parent);
97          }
98          
99          dialog.setAttribute(value);
100 
101         return dialog;
102     }
103     
104     public String getCopyValue() {
105         return value.getNodeName()+"=\""+value.getNodeValue()+"\"";
106     }
107 }