1 package eu
.etaxonomy
.taxeditor
.controller
;
3 import org
.eclipse
.swt
.dnd
.ByteArrayTransfer
;
4 import org
.eclipse
.swt
.dnd
.TransferData
;
5 import org
.eclipse
.swt
.widgets
.Widget
;
7 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
10 * For drag and drop - a drag widget with this transfer type can only be dropped onto
11 * a drop widget with the same type.
16 public class WidgetTransfer
extends ByteArrayTransfer
{
18 private static final String WIDGETTYPENAME
= "widget_type";
19 private static final int WIDGETTYPEID
= registerType (WIDGETTYPENAME
);
20 private static final WidgetTransfer INSTANCE
= new WidgetTransfer();
23 * The object associated with this transfer event
25 private Widget widget
;
28 * Returns the singleton
30 public static WidgetTransfer
getInstance() {
34 * Set transfer data for local use
36 public void setWidget(Widget widget
) {
40 * Returns the local transfer data
42 public Widget
getWidget() {
47 * The type ID is used to identify this transfer
50 protected int[] getTypeIds() {
51 return new int[] { WIDGETTYPEID
};
55 protected String
[] getTypeNames() {
56 return new String
[] { WIDGETTYPENAME
} ;
60 protected void javaToNative(Object object
, TransferData transferData
) {
61 // No encoding needed since this is a hardcoded string read and written
62 // in the same process.
63 // See nativeToJava below
64 byte[] check
= WIDGETTYPENAME
.getBytes();
65 super.javaToNative(check
, transferData
);
69 protected Object
nativeToJava(TransferData transferData
) {
70 Object result
= super.nativeToJava(transferData
);
71 if (isInvalidNativeType(result
)) {
72 throw new RuntimeException(); //$NON-NLS-1$
77 private boolean isInvalidNativeType(Object result
) {
78 // No encoding needed since this is a hardcoded string read and written
79 // in the same process.
80 // See javaToNative above
81 return !(result
instanceof byte[])
82 || !WIDGETTYPENAME
.equals(new String((byte[]) result
));