1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 public class ElementNode extends ResultNode {
41 private static final long serialVersionUID = -4697678300417972206L;
42
43 private Element element = null;
44 private static final ImageIcon ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/obj16/element.gif");;
45
46 private static ElementDetailsDialog dialog = null;
47
48 private String value = null;
49 private URI uri = null;
50
51 public ElementNode(URI uri, Element value) {
52 this.element = value;
53 this.uri = uri;
54 }
55
56 public String getName() {
57 return element.getNodeName();
58 }
59
60 public String getValue() {
61 if ( value == null) {
62 StringBuffer buffer = new StringBuffer( element.getNodeName());
63
64 if ( element.getText() != null && element.getText().length() > 0) {
65 buffer.append( " - ");
66 buffer.append( getFirstLine(element.getText()));
67 }
68
69 value = buffer.toString();
70 }
71
72 return value;
73 }
74
75 public String getDescription() {
76 return "["+element.getType().getName()+"] "+getValue();
77 }
78
79 public ImageIcon getIcon() {
80 return ICON;
81 }
82
83 @Override
84 public JPopupMenu getPopupMenu(JFrame parent) {
85 JPopupMenu popup = new JPopupMenu();
86 popup.add(getOpenURIAction(uri, 0, 0));
87 popup.add(getEditURIAction(uri, 0, 0));
88 popup.addSeparator();
89 popup.add(getCopyAction());
90 popup.addSeparator();
91 popup.add(getPropertiesAction(getDialog(parent)));
92
93 MenuUtilities.alignMenu(popup);
94
95 return popup;
96 }
97
98 @Override
99 public RunnableAction getDefaultAction(JFrame parent) {
100 return getPropertiesAction(getDialog(parent));
101 }
102
103 private ElementDetailsDialog getDialog(JFrame parent) {
104 if (dialog == null) {
105 dialog = new ElementDetailsDialog(parent);
106 }
107
108 dialog.setElement(element);
109
110 return dialog;
111 }
112
113 public String getCopyValue() {
114 return element.getContext();
115 }
116 }