Debian Codegraph @

org.eclipse.jdt.core.tests.model/workspace/Converter/src/test0332/LocalSelectionTransfer.java

raw
1 /*
2 * (c) Copyright IBM Corp. 2000, 2001.
3 * All Rights Reserved.
4 */
5 package test0332;
6
7 import org.eclipse.swt.dnd.ByteArrayTransfer;
8 import org.eclipse.swt.dnd.TransferData;
9 import org.eclipse.swt.widgets.Widget;
10
11 import org.eclipse.jdt.internal.ui.JavaPlugin;
12 import org.eclipse.jface.viewers.ISelection;
13 import org.eclipse.jdt.internal.ui.JavaUIMessages;
14
15 public class LocalSelectionTransfer extends ByteArrayTransfer {
16
17 // First attempt to create a UUID for the type name to make sure that
18 // different Eclipse applications use different "types" of
19 // <code>LocalSelectionTransfer</code>
20 private static final String TYPE_NAME= "local-selection-transfer-format" + (new Long(System.currentTimeMillis())).toString(); //$NON-NLS-1$;
21 private static final int TYPEID= registerType(TYPE_NAME);
22
23 private static final LocalSelectionTransfer INSTANCE= new LocalSelectionTransfer();
24
25 private ISelection fSelection;
26 private int fTime;
27
28 private LocalSelectionTransfer() {
29 }
30
31 /**
32 * Returns the singleton.
33 */
34 public static LocalSelectionTransfer getInstance() {
35 return INSTANCE;
36 }
37
38 /**
39 * Sets the transfer data for local use.
40 */
41 public void setSelection(ISelection s) {
42 fSelection= s;
43 }
44
45 /**
46 * Returns the local transfer data.
47 */
48 public ISelection getSelection() {
49 return fSelection;
50 }
51
52 public void javaToNative(Object object, TransferData transferData) {
53 byte[] check= TYPE_NAME.getBytes();
54 super.javaToNative(check, transferData);
55 }
56
57 public Object nativeToJava(TransferData transferData) {
58 Object result= super.nativeToJava(transferData);
59 if (isInvalidNativeType(result)) {
60 JavaPlugin.logErrorMessage(JavaUIMessages.getString("LocalSelectionTransfer.errorMessage")); //$NON-NLS-1$
61 }
62 return fSelection;
63 }
64
65 private boolean isInvalidNativeType(Object result) {
66 return !(result instanceof byte[]) || !TYPE_NAME.equals(new String((byte[])result));
67 }
68
69 /**
70 * The type id used to identify this transfer.
71 */
72 protected int[] getTypeIds() {
73 return new int[] {TYPEID};
74 }
75
76 protected String[] getTypeNames(){
77 return new String[] {TYPE_NAME};
78 }
79
80 public int getTime() {
81 return fTime;
82 }
83
84 public void setTime(int time) {
85 fTime= time;
86 }
87
88 }