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