1 package eu
.etaxonomy
.taxeditor
.actions
;
3 import org
.eclipse
.swt
.dnd
.ByteArrayTransfer
;
4 import org
.eclipse
.swt
.dnd
.TransferData
;
6 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
7 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
10 * For drag and drop - a drag widget with this transfer type
11 * can only be dropped onto a drop widget with the same type.
16 public class SynonymRelationshipTransfer
extends ByteArrayTransfer
{
18 private static final String RELATIONTYPENAME
= "relation_type";
19 private static final int RELATIONTYPEID
= registerType (RELATIONTYPENAME
);
20 private static final SynonymRelationshipTransfer INSTANCE
= new SynonymRelationshipTransfer();
23 * The object associated with this transfer event
25 private SynonymRelationship synonymRelationship
;
28 * Returns the singleton
30 public static SynonymRelationshipTransfer
getInstance() {
34 * Set transfer data for local use
36 public void setSynonymRelationship(SynonymRelationship synonymRelationship
) {
37 this.synonymRelationship
= synonymRelationship
;
40 * Returns the local transfer data
42 public SynonymRelationship
getSynonymRelationship() {
43 return synonymRelationship
;
47 * The type ID is used to identify this transfer
50 protected int[] getTypeIds() {
51 return new int[] { RELATIONTYPEID
};
55 protected String
[] getTypeNames() {
56 return new String
[] { RELATIONTYPENAME
} ;
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
= RELATIONTYPENAME
.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$
74 return synonymRelationship
;
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 || !RELATIONTYPENAME
.equals(new String((byte[]) result
));