1 package eu
.etaxonomy
.taxeditor
.model
;
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.
14 public class TaxonTransfer
extends ByteArrayTransfer
{
16 private static final String TAXONTYPENAME
= "taxon_type";
17 private static final int TAXONTYPEID
= registerType (TAXONTYPENAME
);
18 private static final TaxonTransfer INSTANCE
= new TaxonTransfer();
21 * The object associated with this transfer event
23 private TaxonBase
<?
> taxonBase
;
26 * Returns the singleton
31 * @return a {@link eu.etaxonomy.taxeditor.model.TaxonTransfer} object.
33 public static TaxonTransfer
getInstance() {
37 * Set transfer data for local use
42 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
44 public void setTaxon(TaxonBase
<?
> taxon
) {
45 this.taxonBase
= taxon
;
48 * Returns the local transfer data
53 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
55 public TaxonBase
<?
> getTaxon() {
60 * The type ID is used to identify this transfer
63 protected int[] getTypeIds() {
64 return new int[] { TAXONTYPEID
};
68 protected String
[] getTypeNames() {
69 return new String
[] { TAXONTYPENAME
} ;
73 protected void javaToNative(Object object
, TransferData transferData
) {
74 // No encoding needed since this is a hardcoded string read and written
75 // in the same process.
76 // See nativeToJava below
77 byte[] check
= TAXONTYPENAME
.getBytes();
78 super.javaToNative(check
, transferData
);
82 protected Object
nativeToJava(TransferData transferData
) {
83 Object result
= super.nativeToJava(transferData
);
84 if (isInvalidNativeType(result
)) {
85 throw new RuntimeException(); //$NON-NLS-1$
90 private boolean isInvalidNativeType(Object result
) {
91 // No encoding needed since this is a hardcoded string read and written
92 // in the same process.
93 // See javaToNative above
94 return !(result
instanceof byte[])
95 || !TAXONTYPENAME
.equals(new String((byte[]) result
));