Revision fa518bf8
Added by Cherian Mathew over 9 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/CdmErrorDialog.java | ||
---|---|---|
5 | 5 |
import org.eclipse.jface.dialogs.IDialogConstants; |
6 | 6 |
import org.eclipse.jface.resource.JFaceResources; |
7 | 7 |
import org.eclipse.swt.SWT; |
8 |
import org.eclipse.swt.dnd.Clipboard; |
|
9 |
import org.eclipse.swt.dnd.TextTransfer; |
|
10 |
import org.eclipse.swt.dnd.Transfer; |
|
11 |
import org.eclipse.swt.events.SelectionEvent; |
|
12 |
import org.eclipse.swt.events.SelectionListener; |
|
8 | 13 |
import org.eclipse.swt.graphics.Point; |
14 |
import org.eclipse.swt.widgets.Button; |
|
9 | 15 |
import org.eclipse.swt.widgets.Composite; |
10 | 16 |
import org.eclipse.swt.widgets.List; |
11 | 17 |
import org.eclipse.swt.widgets.Shell; |
... | ... | |
22 | 28 |
|
23 | 29 |
private static final int DIALOG_MAX_HEIGHT = 500; |
24 | 30 |
|
25 |
public CdmErrorDialog(Shell parentShell, String dialogTitle, |
|
26 |
String message, IStatus status) { |
|
27 |
super(parentShell, |
|
28 |
dialogTitle, |
|
29 |
message, status, |
|
30 |
IStatus.OK| IStatus.INFO | IStatus.WARNING | IStatus.ERROR); |
|
31 |
} |
|
31 |
private Button copyButton; |
|
32 |
private final String stackTrace; |
|
33 |
|
|
34 |
/** |
|
35 |
* The current clipboard. To be disposed when closing the dialog. |
|
36 |
*/ |
|
37 |
private Clipboard clipboard; |
|
38 |
|
|
39 |
/** |
|
40 |
* @param parentShell |
|
41 |
* @param dialogTitle |
|
42 |
* @param message |
|
43 |
* @param status |
|
44 |
* @param stackTrace |
|
45 |
*/ |
|
46 |
public CdmErrorDialog(Shell parentShell, |
|
47 |
String dialogTitle, |
|
48 |
String message, |
|
49 |
IStatus status, |
|
50 |
String stackTrace) { |
|
51 |
super(parentShell, |
|
52 |
dialogTitle, |
|
53 |
message, status, |
|
54 |
IStatus.OK| IStatus.INFO | IStatus.WARNING | IStatus.ERROR); |
|
55 |
this.stackTrace = stackTrace; |
|
56 |
} |
|
32 | 57 |
|
58 |
/** |
|
59 |
* @param parentShell |
|
60 |
* @param dialogTitle |
|
61 |
* @param message |
|
62 |
* @param status |
|
63 |
*/ |
|
64 |
public CdmErrorDialog(Shell parentShell, |
|
65 |
String dialogTitle, |
|
66 |
String message, |
|
67 |
IStatus status) { |
|
68 |
this(parentShell, dialogTitle, message, status, ""); |
|
69 |
} |
|
70 |
|
|
71 |
/* (non-Javadoc) |
|
72 |
* @see org.eclipse.jface.dialogs.ErrorDialog#buttonPressed(int) |
|
73 |
*/ |
|
33 | 74 |
@Override |
34 | 75 |
protected void buttonPressed(int id) { |
35 | 76 |
super.buttonPressed(id); |
... | ... | |
45 | 86 |
|
46 | 87 |
} |
47 | 88 |
|
89 |
/* (non-Javadoc) |
|
90 |
* @see org.eclipse.jface.dialogs.ErrorDialog#createDropDownList(org.eclipse.swt.widgets.Composite) |
|
91 |
*/ |
|
48 | 92 |
@Override |
49 | 93 |
protected List createDropDownList(Composite parent) { |
50 | 94 |
List list = super.createDropDownList(parent); |
51 | 95 |
list.getMenu().getItem(0).setText(JFaceResources.getString("copy all")); |
52 | 96 |
return list; |
53 | 97 |
} |
98 |
|
|
99 |
/* (non-Javadoc) |
|
100 |
* @see org.eclipse.jface.dialogs.ErrorDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) |
|
101 |
*/ |
|
102 |
@Override |
|
103 |
protected void createButtonsForButtonBar(Composite parent) { |
|
104 |
copyButton = createButton(parent, 2000,"Copy Error", false); |
|
105 |
copyButton.addSelectionListener(new SelectionListener() { |
|
106 |
/* |
|
107 |
* @see SelectionListener.widgetSelected (SelectionEvent) |
|
108 |
*/ |
|
109 |
@Override |
|
110 |
public void widgetSelected(SelectionEvent e) { |
|
111 |
copyStackTraceToClipboard(); |
|
112 |
} |
|
113 |
/* |
|
114 |
* @see SelectionListener.widgetDefaultSelected(SelectionEvent) |
|
115 |
*/ |
|
116 |
@Override |
|
117 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
118 |
copyStackTraceToClipboard(); |
|
119 |
} |
|
120 |
}); |
|
121 |
super.createButtonsForButtonBar(parent); |
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
/** |
|
126 |
* Copies the stack trace to the clipboard |
|
127 |
* |
|
128 |
*/ |
|
129 |
private void copyStackTraceToClipboard() { |
|
130 |
if(stackTrace != null && !stackTrace.isEmpty()) { |
|
131 |
if (clipboard != null) { |
|
132 |
clipboard.dispose(); |
|
133 |
} |
|
134 |
clipboard = new Clipboard(copyButton.getDisplay()); |
|
135 |
clipboard.setContents(new Object[] { stackTrace }, |
|
136 |
new Transfer[] { TextTransfer.getInstance() }); |
|
137 |
} |
|
138 |
} |
|
54 | 139 |
} |
Also available in: Unified diff
Added copy button to popup and context info to the error trace