1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.dnd;
16 import org.eclipse.swt.internal.*;
19 * The <code>DropTargetListener</code> class provides event notification to the application
20 * for DropTarget events.
22 * <p>As the user moves the cursor into, over and out of a Control that has been designated
23 * as a DropTarget, events indicate what operation can be performed and what data can be
24 * transferred if a drop where to occur at that point.
25 * The application can respond to these events and change the type of data that will
26 * be dropped by modifying event.currentDataType, or change the operation that will be performed
27 * by modifying the event.detail field or stop any drop from happening on the current target
28 * by setting the event.detail field to DND_DROP_NONE.</p>
30 * <p>When the user causes a drop to happen by releasing the mouse over a valid drop target,
31 * the application has one last chance to change the data type of the drop through the
32 * DropAccept event. If the drop is still allowed, the DropAccept event is immediately
33 * followed by the Drop event. In the Drop event, the application can still change the
34 * operation that is performed but the data type is fixed.</p>
36 * @see DropTargetEvent
39 public interface DropTargetListener extends SWTEventListener {
42 * The cursor has entered the drop target boundaries.
44 * <p>The following fields in the DropTargetEvent apply:</p>
51 * <li>(in,out)currentDataType
54 * <li>(in,out)feedback
57 * <p>The <code>operations</code> value is determined by the modifier keys pressed by the user.
58 * If no keys are pressed the <code>event.detail</code> field is set to DND.DROP_DEFAULT.
59 * If the application does not set the <code>event.detail</code> to something other
60 * than <code>DND.DROP_DEFAULT</code> the operation will be set to the platform defined standard
63 * <p>The <code>currentDataType</code> is determined by the first transfer agent specified in
64 * setTransfer() that matches a data type provided by the drag source.</p>
66 * <p>It is possible to get a DragEnter event when the drag source does not provide any matching data.
67 * In this case, the default operation is DND.DROP_NONE and the currentDataType is null.</p>
69 * <p>The application can change the operation that will be performed by modifying the
70 * <code>detail</code> field but the choice must be one of the values in the <code>operations</code>
71 * field or DND.DROP_NONE.</p>
73 * <p>The application can also change the type of data being requested by
74 * modifying the <code>currentDataTypes</code> field but the value must be one of the values
75 * in the <code>dataTypes</code> list.</p>
77 * @param event the information associated with the drag enter event
79 * @see DropTargetEvent
81 public void dragEnter(DropTargetEvent event);
84 * The cursor has left the drop target boundaries OR the drop has been cancelled OR the data
85 * is about to be dropped.
87 * <p>The following fields in the DropTargetEvent apply:</p>
94 * <li>(in)currentDataType
99 * @param event the information associated with the drag leave event
101 * @see DropTargetEvent
103 public void dragLeave(DropTargetEvent event);
106 * The operation being performed has changed (usually due to the user changing the selected modifier key(s)
109 * <p>The following fields in the DropTargetEvent apply:</p>
116 * <li>(in,out)currentDataType
119 * <li>(in,out)feedback
122 * <p>The <code>operations</code> value is determined by the modifier keys pressed by the user.
123 * If no keys are pressed the <code>event.detail</code> field is set to DND.DROP_DEFAULT.
124 * If the application does not set the <code>event.detail</code> to something other than
125 * <code>DND.DROP_DEFAULT</code> the operation will be set to the platform defined standard default.</p>
127 * <p>The <code>currentDataType</code> value is determined by the value assigned to
128 * <code>currentDataType</code> in previous dragEnter and dragOver calls.</p>
130 * <p>The application can change the operation that will be performed by modifying the
131 * <code>detail</code> field but the choice must be one of the values in the <code>operations</code>
134 * <p>The application can also change the type of data being requested by modifying
135 * the <code>currentDataTypes</code> field but the value must be one of the values in the
136 * <code>dataTypes</code> list.</p>
138 * @param event the information associated with the drag operation changed event
140 * @see DropTargetEvent
142 public void dragOperationChanged(DropTargetEvent event);
145 * The cursor is moving over the drop target.
147 * <p>The following fields in the DropTargetEvent apply:</p>
154 * <li>(in,out)currentDataType
157 * <li>(in,out)feedback
160 * <p>The <code>operations</code> value is determined by the value assigned to
161 * <code>currentDataType</code> in previous dragEnter and dragOver calls.</p>
163 * <p>The <code>currentDataType</code> value is determined by the value assigned to
164 * <code>currentDataType</code> in previous dragEnter and dragOver calls.</p>
166 * <p>The application can change the operation that will be performed by modifying the
167 * <code>detail</code> field but the choice must be one of the values in the <code>operations</code>
170 * <p>The application can also change the type of data being requested by modifying the
171 * <code>currentDataTypes</code> field but the value must be one of the values in the
172 * <code>dataTypes</code> list.</p>
174 * <p>NOTE: At this point the <code>data</code> field is null. On some platforms, it is possible
175 * to obtain the data being transferred before the transfer occurs but in most platforms this is
176 * not possible. On those platforms where the data is available, the application can access the
177 * data as follows:</p>
180 * public void dragOver(DropTargetEvent event) {
181 * TextTransfer textTransfer = TextTransfer.getInstance();
182 * String data = (String)textTransfer.nativeToJava(event.currentDataType);
183 * if (data != null) {
184 * System.out.println("Data to be dropped is (Text)"+data);
189 * @param event the information associated with the drag over event
191 * @see DropTargetEvent
193 public void dragOver(DropTargetEvent event);
196 * The data is being dropped. The data field contains java format of the data being dropped.
197 * To determine the type of the data object, refer to the documentation for the Transfer subclass
198 * specified in event.currentDataType.
200 * <p>The following fields in DropTargetEvent apply:</p>
207 * <li>(in)currentDataType
211 * <p>The application can refuse to perform the drop operation by setting the detail
212 * field to DND.DROP_NONE.</p>
214 * @param event the information associated with the drop event
216 * @see DropTargetEvent
218 public void drop(DropTargetEvent event);
221 * The drop is about to be performed.
222 * The drop target is given a last chance to change the nature of the drop.
224 * <p>The following fields in the DropTargetEvent apply:</p>
231 * <li>(in,out)currentDataType
236 * <p>The application can veto the drop by setting the <code>event.detail</code> field to
237 * <code>DND.DROP_NONE</code>.</p>
239 * <p>The application can change the operation that will be performed by modifying the
240 * <code>detail</code> field but the choice must be one of the values in the
241 * <code>operations</code> field.</p>
243 * <p>The application can also change the type of data being requested by modifying the
244 * <code>currentDataTypes</code> field but the value must be one of the values in the
245 * <code>dataTypes</code> list.</p>
247 * @param event the information associated with the drop accept event
249 * @see DropTargetEvent
251 public void dropAccept(DropTargetEvent event);