Mercurial > projects > dwt-addons
annotate dwtx/jface/util/LocalSelectionTransfer.d @ 43:ea8ff534f622
Fix override and super aliases
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 11 Apr 2008 01:24:25 +0200 |
parents | 51d06982c550 |
children |
rev | line source |
---|---|
31 | 1 /******************************************************************************* |
2 * Copyright (c) 2005, 2006 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.util.LocalSelectionTransfer; | |
14 | |
15 import dwtx.jface.util.Policy; | |
16 | |
17 import dwt.dnd.ByteArrayTransfer; | |
18 import dwt.dnd.TransferData; | |
19 import dwtx.core.runtime.IStatus; | |
20 import dwtx.core.runtime.Status; | |
21 import dwtx.jface.resource.JFaceResources; | |
22 import dwtx.jface.viewers.ISelection; | |
23 | |
24 import dwt.dwthelper.utils; | |
25 import tango.text.convert.Format; | |
26 | |
27 /** | |
28 * A LocalSelectionTransfer may be used for drag and drop operations | |
29 * within the same instance of Eclipse. | |
30 * The selection is made available directly for use in the DropTargetListener. | |
31 * dropAccept method. The DropTargetEvent passed to dropAccept does not contain | |
32 * the drop data. The selection may be used for validation purposes so that the | |
33 * drop can be aborted if appropriate. | |
34 * | |
35 * This class is not intended to be subclassed. | |
36 * | |
37 * @since 3.2 | |
38 */ | |
39 public class LocalSelectionTransfer : ByteArrayTransfer { | |
40 | |
41 // First attempt to create a UUID for the type name to make sure that | |
42 // different Eclipse applications use different "types" of | |
43 // <code>LocalSelectionTransfer</code> | |
44 private static const String TYPE_NAME; | |
45 | |
46 private static const int TYPEID; | |
47 | |
48 private static const LocalSelectionTransfer INSTANCE; | |
49 | |
50 private ISelection selection; | |
51 | |
52 private long selectionSetTime; | |
53 | |
54 static this(){ | |
55 TYPE_NAME = Format("local-selection-transfer-format{}", System.currentTimeMillis()); //$NON-NLS-1$; | |
56 TYPEID = registerType(TYPE_NAME); | |
57 INSTANCE = new LocalSelectionTransfer(); | |
58 } | |
59 | |
60 /** | |
61 * Only the singleton instance of this class may be used. | |
62 */ | |
63 protected this() { | |
64 // do nothing | |
65 } | |
66 | |
67 /** | |
68 * Returns the singleton. | |
69 * | |
70 * @return the singleton | |
71 */ | |
72 public static LocalSelectionTransfer getTransfer() { | |
73 return INSTANCE; | |
74 } | |
75 | |
76 /** | |
77 * Returns the local transfer data. | |
78 * | |
79 * @return the local transfer data | |
80 */ | |
81 public ISelection getSelection() { | |
82 return selection; | |
83 } | |
84 | |
85 /** | |
86 * Tests whether native drop data matches this transfer type. | |
87 * | |
88 * @param result result of converting the native drop data to Java | |
89 * @return true if the native drop data does not match this transfer type. | |
90 * false otherwise. | |
91 */ | |
92 private bool isInvalidNativeType(Object result) { | |
93 return !(cast(ArrayWrapperByte)result ) | |
94 || !TYPE_NAME.equals(cast(char[])(cast(ArrayWrapperByte) result).array); | |
95 } | |
96 | |
97 /** | |
98 * Returns the type id used to identify this transfer. | |
99 * | |
100 * @return the type id used to identify this transfer. | |
101 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
31
diff
changeset
|
102 protected override int[] getTypeIds() { |
31 | 103 return [ TYPEID ]; |
104 } | |
105 | |
106 /** | |
107 * Returns the type name used to identify this transfer. | |
108 * | |
109 * @return the type name used to identify this transfer. | |
110 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
31
diff
changeset
|
111 protected override String[] getTypeNames() { |
31 | 112 return [ TYPE_NAME ]; |
113 } | |
114 | |
115 /** | |
116 * Overrides dwt.dnd.ByteArrayTransfer#javaToNative(Object, | |
117 * TransferData). | |
118 * Only encode the transfer type name since the selection is read and | |
119 * written in the same process. | |
120 * | |
121 * @see dwt.dnd.ByteArrayTransfer#javaToNative(java.lang.Object, dwt.dnd.TransferData) | |
122 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
31
diff
changeset
|
123 public override void javaToNative(Object object, TransferData transferData) { |
31 | 124 auto check = new ArrayWrapperByte( cast(byte[])TYPE_NAME ); |
125 super.javaToNative(check, transferData); | |
126 } | |
127 | |
128 /** | |
129 * Overrides dwt.dnd.ByteArrayTransfer#nativeToJava(TransferData). | |
130 * Test if the native drop data matches this transfer type. | |
131 * | |
132 * @see dwt.dnd.ByteArrayTransfer#nativeToJava(TransferData) | |
133 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
31
diff
changeset
|
134 public override Object nativeToJava(TransferData transferData) { |
31 | 135 Object result = super.nativeToJava(transferData); |
136 if (isInvalidNativeType(result)) { | |
137 Policy.getLog().log(new Status( | |
138 IStatus.ERROR, | |
139 Policy.JFACE, | |
140 IStatus.ERROR, | |
141 JFaceResources.getString("LocalSelectionTransfer.errorMessage"), null)); //$NON-NLS-1$ | |
142 } | |
143 return cast(Object) selection; | |
144 } | |
145 | |
146 /** | |
147 * Sets the transfer data for local use. | |
148 * | |
149 * @param s the transfer data | |
150 */ | |
151 public void setSelection(ISelection s) { | |
152 selection = s; | |
153 } | |
154 | |
155 /** | |
156 * Returns the time when the selection operation | |
157 * this transfer is associated with was started. | |
158 * | |
159 * @return the time when the selection operation has started | |
160 * | |
161 * @see dwt.events.TypedEvent#time | |
162 */ | |
163 public long getSelectionSetTime() { | |
164 return selectionSetTime; | |
165 } | |
166 | |
167 /** | |
168 * Sets the time when the selection operation this | |
169 * transfer is associated with was started. | |
170 * If assigning this from an DWT event, be sure to use | |
171 * <code>setSelectionTime(event.time & 0xFFFF)</code> | |
172 * | |
173 * @param time the time when the selection operation was started | |
174 * | |
175 * @see dwt.events.TypedEvent#time | |
176 */ | |
177 public void setSelectionSetTime(long time) { | |
178 selectionSetTime = time; | |
179 } | |
180 } |