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
;
67 public CdmErrorDialog(Shell parentShell
,
72 Object
[] updatedObjects
) {
73 this(parentShell
, dialogTitle
, message
, status
, stackTrace
);
74 this.message
= message
== null ? status
.getMessage()
75 : message
+ "\n " + status
.getMessage(); //$NON-NLS-1$
84 public CdmErrorDialog(Shell parentShell
,
88 this(parentShell
, dialogTitle
, message
, status
, "");
92 * @see org.eclipse.jface.dialogs.ErrorDialog#buttonPressed(int)
95 protected void buttonPressed(int id
) {
96 super.buttonPressed(id
);
97 if (id
== IDialogConstants
.DETAILS_ID
) {
98 Point oldSize
= getShell().computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
);
99 // set height to max allowed
100 if(getShell().getSize().y
> DIALOG_MAX_HEIGHT
) {
101 getShell().setSize(getShell().getSize().x
, 500);
103 getShell().setSize(getShell().getSize().x
, oldSize
.y
);
110 * @see org.eclipse.jface.dialogs.ErrorDialog#createDropDownList(org.eclipse.swt.widgets.Composite)
113 protected List
createDropDownList(Composite parent
) {
114 List list
= super.createDropDownList(parent
);
115 list
.getMenu().getItem(0).setText(JFaceResources
.getString("copy all"));
120 * @see org.eclipse.jface.dialogs.ErrorDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
123 protected void createButtonsForButtonBar(Composite parent
) {
124 copyButton
= createButton(parent
, 2000,"Copy Error", false);
125 copyButton
.addSelectionListener(new SelectionListener() {
127 * @see SelectionListener.widgetSelected (SelectionEvent)
130 public void widgetSelected(SelectionEvent e
) {
131 copyStackTraceToClipboard();
134 * @see SelectionListener.widgetDefaultSelected(SelectionEvent)
137 public void widgetDefaultSelected(SelectionEvent e
) {
138 copyStackTraceToClipboard();
141 super.createButtonsForButtonBar(parent
);
146 * Copies the stack trace to the clipboard
149 private void copyStackTraceToClipboard() {
150 if(stackTrace
!= null && !stackTrace
.isEmpty()) {
151 if (clipboard
!= null) {
154 clipboard
= new Clipboard(copyButton
.getDisplay());
155 clipboard
.setContents(new Object
[] { stackTrace
},
156 new Transfer
[] { TextTransfer
.getInstance() });