|
Lines 173-189
Link Here
|
| 173 |
* that it is still enabled. |
173 |
* that it is still enabled. |
| 174 |
*/ |
174 |
*/ |
| 175 |
private void doDropValidation(DropTargetEvent event) { |
175 |
private void doDropValidation(DropTargetEvent event) { |
| 176 |
//update last valid operation |
176 |
currentOperation= determineOperation(currentTarget, lastValidOperation, event.currentDataType, event.operations); |
| 177 |
if (event.detail != DND.DROP_NONE) { |
|
|
| 178 |
lastValidOperation = event.detail; |
| 179 |
} |
| 180 |
//valid drop and set event detail accordingly |
| 181 |
if (validateDrop(currentTarget, event.detail, event.currentDataType)) { |
| 182 |
currentOperation = lastValidOperation; |
| 183 |
} else { |
| 184 |
currentOperation = DND.DROP_NONE; |
| 185 |
} |
| 186 |
event.detail = currentOperation; |
177 |
event.detail = currentOperation; |
|
|
178 |
setFeedback(event, currentLocation); |
| 187 |
} |
179 |
} |
| 188 |
|
180 |
|
| 189 |
/* (non-Javadoc) |
181 |
/* (non-Javadoc) |
|
Lines 193-198
Link Here
|
| 193 |
*/ |
185 |
*/ |
| 194 |
public void dragEnter(DropTargetEvent event) { |
186 |
public void dragEnter(DropTargetEvent event) { |
| 195 |
currentTarget = determineTarget(event); |
187 |
currentTarget = determineTarget(event); |
|
|
188 |
currentLocation = determineLocation(event); |
| 189 |
lastValidOperation = event.detail; |
| 196 |
doDropValidation(event); |
190 |
doDropValidation(event); |
| 197 |
} |
191 |
} |
| 198 |
|
192 |
|
|
Lines 203-208
Link Here
|
| 203 |
*/ |
197 |
*/ |
| 204 |
public void dragOperationChanged(DropTargetEvent event) { |
198 |
public void dragOperationChanged(DropTargetEvent event) { |
| 205 |
currentTarget = determineTarget(event); |
199 |
currentTarget = determineTarget(event); |
|
|
200 |
lastValidOperation = event.detail; |
| 206 |
doDropValidation(event); |
201 |
doDropValidation(event); |
| 207 |
} |
202 |
} |
| 208 |
|
203 |
|
|
Lines 247-255
Link Here
|
| 247 |
* Last chance for the action to disable itself |
242 |
* Last chance for the action to disable itself |
| 248 |
*/ |
243 |
*/ |
| 249 |
public void dropAccept(DropTargetEvent event) { |
244 |
public void dropAccept(DropTargetEvent event) { |
| 250 |
if (!validateDrop(currentTarget, event.detail, event.currentDataType)) { |
245 |
event.detail= determineOperation(currentTarget, event.detail, event.currentDataType, event.operations); |
| 251 |
event.detail = DND.DROP_NONE; |
|
|
| 252 |
} |
| 253 |
} |
246 |
} |
| 254 |
|
247 |
|
| 255 |
/** |
248 |
/** |
|
Lines 484-487
Link Here
|
| 484 |
*/ |
477 |
*/ |
| 485 |
public abstract boolean validateDrop(Object target, int operation, |
478 |
public abstract boolean validateDrop(Object target, int operation, |
| 486 |
TransferData transferType); |
479 |
TransferData transferType); |
|
|
480 |
|
| 481 |
/** |
| 482 |
* Determine the operation which should be executed given the target and the operation |
| 483 |
* requested by the user. This method is called whenever some aspect of the drop operation |
| 484 |
* changes. The operation is one of DND#DROP_DEFAULT, DND#DROP_COPY, DND#DROP_MOVE, DND#DROP_LINK. |
| 485 |
* <p> |
| 486 |
* The method returns the operation valid in the given context. The result is one of |
| 487 |
* DND#DROP_NONE, DND#DROP_COPY, DND#DROP_MOVE, DND#DROP_LINK, DND#DROP_DEFAULT. |
| 488 |
* </p> |
| 489 |
* <p> |
| 490 |
* Subclasses can overwrite this method to define which operation does make |
| 491 |
* sense in the given context. |
| 492 |
* </p> |
| 493 |
* |
| 494 |
* @param target the object that the mouse is currently hovering over, or |
| 495 |
* <code>null</code> if the mouse is hovering over empty space |
| 496 |
* @param operation the current drag operation (copy, move, etc.) |
| 497 |
* @param transferType the current transfer type |
| 498 |
* @param operations a bitwise OR'ing of the operations that the DragSource can support |
| 499 |
* @return the operation which will be executed if no modifier key is pressed |
| 500 |
* by the user |
| 501 |
* |
| 502 |
* @see DND#DROP_NONE |
| 503 |
* @see DND#DROP_MOVE |
| 504 |
* @see DND#DROP_COPY |
| 505 |
* @see DND#DROP_LINK |
| 506 |
*/ |
| 507 |
protected int determineOperation(Object target, int operation, TransferData transferType, int operations) { |
| 508 |
if (!validateDrop(target, operation, transferType)) { |
| 509 |
return DND.DROP_NONE; |
| 510 |
} |
| 511 |
|
| 512 |
return operation; |
| 513 |
} |
| 487 |
} |
514 |
} |