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.bounce.util.URIUtils;
33 import org.xmlhammer.model.project.Warning;
34
35 /***
36 * The node for a warning.
37 *
38 * @version $Revision: 1.14 $, $Date: 2007/07/04 19:42:48 $
39 * @author Edwin Dankert <edankert@gmail.com>
40 */
41 public class WarningNode extends ResultNode {
42 private static final long serialVersionUID = 926492815637254913L;
43
44 private static final ImageIcon ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/obj16/warning.gif");
45 private static ExceptionDetailsDialog dialog = null;
46
47 private Warning warning = null;
48 private URI uri = null;
49
50 public WarningNode(URI uri, Warning warning) {
51 this.warning = warning;
52 this.uri = uri;
53 }
54
55 public String getName() {
56 return getValue();
57 }
58
59 public String getValue() {
60 StringBuilder builder = new StringBuilder();
61
62 if (warning.getSystemId() != null) {
63 URI systemId = URIUtils.createURI(warning.getSystemId());
64
65 if (uri.compareTo(systemId) != 0) {
66 builder.append(URIUtils.getName(systemId));
67 builder.append(" - ");
68 }
69 }
70
71 builder.append("[");
72 builder.append(getNumber(warning.getLine()));
73 builder.append(":");
74 builder.append(getNumber(warning.getColumn()));
75 builder.append("] ");
76 builder.append(warning.getLocalizedMessage());
77
78 return builder.toString();
79 }
80
81 public String getDescription() {
82 return getValue();
83 }
84
85 public ImageIcon getIcon() {
86 return ICON;
87 }
88
89 public String getContext() {
90 return "";
91 }
92
93 @Override
94 public JPopupMenu getPopupMenu(JFrame parent) {
95 JPopupMenu popup = new JPopupMenu();
96 popup.add(getOpenURIAction(getOpenableURI(), getNumber(warning.getLine()), getNumber(warning.getColumn())));
97 popup.add(getEditURIAction(getOpenableURI(), getNumber(warning.getLine()), getNumber(warning.getColumn())));
98 popup.addSeparator();
99 popup.add(getCopyAction());
100 popup.addSeparator();
101 popup.add(getPropertiesAction(getDialog(parent)));
102
103 MenuUtilities.alignMenu(popup);
104
105 return popup;
106 }
107
108 @Override
109 public RunnableAction getDefaultAction(JFrame parent) {
110 return getPropertiesAction(getDialog(parent));
111 }
112
113 private ExceptionDetailsDialog getDialog(JFrame parent) {
114 if (dialog == null) {
115 dialog = new ExceptionDetailsDialog(parent, "Warning Details");
116 }
117
118 dialog.setException(warning, uri, ICON);
119
120 return dialog;
121 }
122
123 private static int getNumber(Integer integer) {
124 if (integer != null) {
125 return integer;
126 }
127
128 return -1;
129 }
130
131 public String getCopyValue() {
132 return "[warning] "+getValue();
133 }
134
135 private URI getOpenableURI() {
136 if (warning.getSystemId() != null) {
137 return URIUtils.createURI(warning.getSystemId());
138 }
139
140 return uri;
141 }
142 }