1 package eu
.etaxonomy
.taxeditor
.model
;
3 import org
.eclipse
.core
.runtime
.IStatus
;
4 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
5 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
6 import org
.eclipse
.jface
.resource
.JFaceResources
;
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
;
13 import org
.eclipse
.swt
.graphics
.Point
;
14 import org
.eclipse
.swt
.widgets
.Button
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.swt
.widgets
.List
;
17 import org
.eclipse
.swt
.widgets
.Shell
;
20 * Error dialog class specifically implemented for the editor.
21 * The main difference with {@link org.eclipse.jface.dialogs.ErrorDialog} is that
22 * this dialog has a fixed max height.
27 public class CdmErrorDialog
extends ErrorDialog
{
29 private static final int DIALOG_MAX_HEIGHT
= 500;
31 private Button copyButton
;
32 private final String stackTrace
;
35 * The current clipboard. To be disposed when closing the dialog.
37 private Clipboard clipboard
;
46 public CdmErrorDialog(Shell parentShell
,
54 IStatus
.OK
| IStatus
.INFO
| IStatus
.WARNING
| IStatus
.ERROR
);
55 this.stackTrace
= stackTrace
;
64 public CdmErrorDialog(Shell parentShell
,
68 this(parentShell
, dialogTitle
, message
, status
, "");
72 * @see org.eclipse.jface.dialogs.ErrorDialog#buttonPressed(int)
75 protected void buttonPressed(int id
) {
76 super.buttonPressed(id
);
77 if (id
== IDialogConstants
.DETAILS_ID
) {
78 Point oldSize
= getShell().computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
79 // set height to max allowed
80 if(getShell().getSize().y
> DIALOG_MAX_HEIGHT
) {
81 getShell().setSize(getShell().getSize().x
, 500);
83 getShell().setSize(getShell().getSize().x
, oldSize
.y
);
90 * @see org.eclipse.jface.dialogs.ErrorDialog#createDropDownList(org.eclipse.swt.widgets.Composite)
93 protected List
createDropDownList(Composite parent
) {
94 List list
= super.createDropDownList(parent
);
95 list
.getMenu().getItem(0).setText(JFaceResources
.getString("copy all"));
100 * @see org.eclipse.jface.dialogs.ErrorDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
103 protected void createButtonsForButtonBar(Composite parent
) {
104 copyButton
= createButton(parent
, 2000,"Copy Error", false);
105 copyButton
.addSelectionListener(new SelectionListener() {
107 * @see SelectionListener.widgetSelected (SelectionEvent)
110 public void widgetSelected(SelectionEvent e
) {
111 copyStackTraceToClipboard();
114 * @see SelectionListener.widgetDefaultSelected(SelectionEvent)
117 public void widgetDefaultSelected(SelectionEvent e
) {
118 copyStackTraceToClipboard();
121 super.createButtonsForButtonBar(parent
);
126 * Copies the stack trace to the clipboard
129 private void copyStackTraceToClipboard() {
130 if(stackTrace
!= null && !stackTrace
.isEmpty()) {
131 if (clipboard
!= null) {
134 clipboard
= new Clipboard(copyButton
.getDisplay());
135 clipboard
.setContents(new Object
[] { stackTrace
},
136 new Transfer
[] { TextTransfer
.getInstance() });