1 17 package org.eclipse.emf.edit.ui.dnd; 18 19 20 import org.eclipse.swt.dnd.ByteArrayTransfer; 21 import org.eclipse.swt.dnd.TransferData; 22 23 24 35 public class LocalTransfer extends ByteArrayTransfer 36 { 37 40 protected static final String TYPE_NAME = "local-transfer-format"; 41 42 45 protected static final int TYPE_ID = registerType(TYPE_NAME); 46 47 50 protected static LocalTransfer instance; 51 52 55 public static LocalTransfer getInstance() 56 { 57 if (instance == null) 58 { 59 instance = new LocalTransfer(); 60 } 61 62 return instance; 63 } 64 65 68 protected long startTime; 69 70 73 protected Object object; 74 75 78 protected LocalTransfer() 79 { 80 } 81 82 85 protected int[] getTypeIds() 86 { 87 return new int[] { TYPE_ID }; 88 } 89 90 93 public String [] getTypeNames() 94 { 95 return new String [] { TYPE_NAME }; 96 } 97 98 101 public void javaToNative(Object object, TransferData transferData) 102 { 103 startTime = System.currentTimeMillis(); 104 this.object = object; 105 if (transferData != null) 106 { 107 super.javaToNative(String.valueOf(startTime).getBytes(), transferData); 108 } 109 } 110 111 114 public Object nativeToJava(TransferData transferData) 115 { 116 byte[] bytes = (byte[])super.nativeToJava(transferData); 117 if (bytes == null) return null; 118 119 try 120 { 121 long startTime = Long.valueOf(new String (bytes)).longValue(); 122 return this.startTime == startTime ? object : null; 123 } 124 catch (NumberFormatException exception) 125 { 126 return null; 127 } 128 } 129 } 130 | Popular Tags |