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.
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
32 * @return a {@link eu.etaxonomy.taxeditor.model.TaxonTransfer} object.
34 public static TaxonTransfer
getInstance() {
38 * Set transfer data for local use
43 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
45 public void setTaxon(TaxonBase
<?
> taxon
) {
46 this.taxonBase
= taxon
;
49 * Returns the local transfer data
54 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
56 public TaxonBase
<?
> getTaxon() {
61 * The type ID is used to identify this transfer
65 protected int[] getTypeIds() {
66 return new int[] { TAXONTYPEID
};
71 protected String
[] getTypeNames() {
72 return new String
[] { TAXONTYPENAME
} ;
77 protected void javaToNative(Object object
, TransferData transferData
) {
78 // No encoding needed since this is a hardcoded string read and written
79 // in the same process.
80 // See nativeToJava below
81 byte[] check
= TAXONTYPENAME
.getBytes();
82 super.javaToNative(check
, transferData
);
87 protected Object
nativeToJava(TransferData transferData
) {
88 Object result
= super.nativeToJava(transferData
);
89 if (isInvalidNativeType(result
)) {
90 throw new RuntimeException(); //$NON-NLS-1$
95 private boolean isInvalidNativeType(Object result
) {
96 // No encoding needed since this is a hardcoded string read and written
97 // in the same process.
98 // See javaToNative above
99 return !(result
instanceof byte[])
100 || !TAXONTYPENAME
.equals(new String((byte[]) result
));