1 package eu
.etaxonomy
.taxeditor
.editor
;
3 import org
.eclipse
.swt
.dnd
.ByteArrayTransfer
;
4 import org
.eclipse
.swt
.dnd
.TransferData
;
5 import org
.eclipse
.swt
.widgets
.Widget
;
8 * For drag and drop - a drag widget with this transfer type can only be dropped onto
9 * a drop widget with the same type.
14 public class WidgetTransfer
extends ByteArrayTransfer
{
16 private static final String WIDGETTYPENAME
= "widget_type";
17 private static final int WIDGETTYPEID
= registerType (WIDGETTYPENAME
);
18 private static final WidgetTransfer INSTANCE
= new WidgetTransfer();
21 * The object associated with this transfer event
23 private Widget widget
;
26 * Returns the singleton
28 public static WidgetTransfer
getInstance() {
32 * Set transfer data for local use
34 public void setWidget(Widget widget
) {
38 * Returns the local transfer data
40 public Widget
getWidget() {
45 * The type ID is used to identify this transfer
48 protected int[] getTypeIds() {
49 return new int[] { WIDGETTYPEID
};
53 protected String
[] getTypeNames() {
54 return new String
[] { WIDGETTYPENAME
} ;
58 protected void javaToNative(Object object
, TransferData transferData
) {
59 // No encoding needed since this is a hardcoded string read and written
60 // in the same process.
61 // See nativeToJava below
62 byte[] check
= WIDGETTYPENAME
.getBytes();
63 super.javaToNative(check
, transferData
);
67 protected Object
nativeToJava(TransferData transferData
) {
68 Object result
= super.nativeToJava(transferData
);
69 if (isInvalidNativeType(result
)) {
70 throw new RuntimeException(); //$NON-NLS-1$
75 private boolean isInvalidNativeType(Object result
) {
76 // No encoding needed since this is a hardcoded string read and written
77 // in the same process.
78 // See javaToNative above
79 return !(result
instanceof byte[])
80 || !WIDGETTYPENAME
.equals(new String((byte[]) result
));