1 11 package org.eclipse.jface.util; 12 13 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.jface.resource.JFaceResources; 17 import org.eclipse.jface.viewers.ISelection; 18 import org.eclipse.swt.dnd.ByteArrayTransfer; 19 import org.eclipse.swt.dnd.TransferData; 20 21 33 public class LocalSelectionTransfer extends ByteArrayTransfer { 34 35 private static final String TYPE_NAME = "local-selection-transfer-format" + (new Long (System.currentTimeMillis())).toString(); 40 private static final int TYPEID = registerType(TYPE_NAME); 41 42 private static final LocalSelectionTransfer INSTANCE = new LocalSelectionTransfer(); 43 44 private ISelection selection; 45 46 private long selectionSetTime; 47 48 51 protected LocalSelectionTransfer() { 52 } 54 55 60 public static LocalSelectionTransfer getTransfer() { 61 return INSTANCE; 62 } 63 64 69 public ISelection getSelection() { 70 return selection; 71 } 72 73 80 private boolean isInvalidNativeType(Object result) { 81 return !(result instanceof byte[]) 82 || !TYPE_NAME.equals(new String ((byte[]) result)); 83 } 84 85 90 protected int[] getTypeIds() { 91 return new int[] { TYPEID }; 92 } 93 94 99 protected String [] getTypeNames() { 100 return new String [] { TYPE_NAME }; 101 } 102 103 111 public void javaToNative(Object object, TransferData transferData) { 112 byte[] check = TYPE_NAME.getBytes(); 113 super.javaToNative(check, transferData); 114 } 115 116 122 public Object nativeToJava(TransferData transferData) { 123 Object result = super.nativeToJava(transferData); 124 if (isInvalidNativeType(result)) { 125 Policy.getLog().log(new Status( 126 IStatus.ERROR, 127 Policy.JFACE, 128 IStatus.ERROR, 129 JFaceResources.getString("LocalSelectionTransfer.errorMessage"), null)); } 131 return selection; 132 } 133 134 139 public void setSelection(ISelection s) { 140 selection = s; 141 } 142 143 151 public long getSelectionSetTime() { 152 return selectionSetTime; 153 } 154 155 165 public void setSelectionSetTime(long time) { 166 selectionSetTime = time; 167 } 168 } 169 | Popular Tags |