1 package eu
.etaxonomy
.taxeditor
.controller
;
3 import org
.eclipse
.swt
.dnd
.ByteArrayTransfer
;
4 import org
.eclipse
.swt
.dnd
.TransferData
;
6 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
9 * For drag and drop - a drag widget with this transfer type can only be dropped onto
10 * a drop widget with the same type.
15 public class TaxonTransfer
extends ByteArrayTransfer
{
17 private static final String TAXONTYPENAME
= "taxon_type";
18 private static final int TAXONTYPEID
= registerType (TAXONTYPENAME
);
19 private static final TaxonTransfer INSTANCE
= new TaxonTransfer();
22 * The object associated with this transfer event
24 private TaxonBase taxonBase
;
27 * Returns the singleton
29 public static TaxonTransfer
getInstance() {
33 * Set transfer data for local use
35 public void setTaxon(TaxonBase taxon
) {
36 this.taxonBase
= taxon
;
39 * Returns the local transfer data
41 public TaxonBase
getTaxon() {
46 * The type ID is used to identify this transfer
49 protected int[] getTypeIds() {
50 return new int[] { TAXONTYPEID
};
54 protected String
[] getTypeNames() {
55 return new String
[] { TAXONTYPENAME
} ;
59 protected void javaToNative(Object object
, TransferData transferData
) {
60 // No encoding needed since this is a hardcoded string read and written
61 // in the same process.
62 // See nativeToJava below
63 byte[] check
= TAXONTYPENAME
.getBytes();
64 super.javaToNative(check
, transferData
);
68 protected Object
nativeToJava(TransferData transferData
) {
69 Object result
= super.nativeToJava(transferData
);
70 if (isInvalidNativeType(result
)) {
71 throw new RuntimeException(); //$NON-NLS-1$
76 private boolean isInvalidNativeType(Object result
) {
77 // No encoding needed since this is a hardcoded string read and written
78 // in the same process.
79 // See javaToNative above
80 return !(result
instanceof byte[])
81 || !TAXONTYPENAME
.equals(new String((byte[]) result
));