Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 197965 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/ViewerDropAdapter.java (-13 / +35 lines)
Lines 173-188 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= getDefaultDropOperation(currentTarget, lastValidOperation, event.currentDataType);
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;
187
    }
178
    }
188
179
Lines 193-198 Link Here
193
     */
184
     */
194
    public void dragEnter(DropTargetEvent event) {
185
    public void dragEnter(DropTargetEvent event) {
195
        currentTarget = determineTarget(event);
186
        currentTarget = determineTarget(event);
187
        lastValidOperation = event.detail;
196
        doDropValidation(event);
188
        doDropValidation(event);
197
    }
189
    }
198
190
Lines 203-208 Link Here
203
     */
195
     */
204
    public void dragOperationChanged(DropTargetEvent event) {
196
    public void dragOperationChanged(DropTargetEvent event) {
205
        currentTarget = determineTarget(event);
197
        currentTarget = determineTarget(event);
198
        lastValidOperation = event.detail;
206
        doDropValidation(event);
199
        doDropValidation(event);
207
    }
200
    }
208
201
Lines 247-255 Link Here
247
     * Last chance for the action to disable itself
240
     * Last chance for the action to disable itself
248
     */
241
     */
249
    public void dropAccept(DropTargetEvent event) {
242
    public void dropAccept(DropTargetEvent event) {
250
        if (!validateDrop(currentTarget, event.detail, event.currentDataType)) {
243
        event.detail= getDefaultDropOperation(currentTarget, event.detail, event.currentDataType);
251
            event.detail = DND.DROP_NONE;
252
        }
253
    }
244
    }
254
245
255
    /**
246
    /**
Lines 484-487 Link Here
484
     */
475
     */
485
    public abstract boolean validateDrop(Object target, int operation,
476
    public abstract boolean validateDrop(Object target, int operation,
486
            TransferData transferType);
477
            TransferData transferType);
478
    
479
    /**
480
     * Get the default drop operation on the given object. This method is called whenever some 
481
     * aspect of the drop operation changes.
482
     * <p>
483
     * The default operation is the one used when no modifier key is pressed by the user. 
484
     * </p>
485
     * <p>
486
     * Subclasses can overwrite this method to define which operation does make
487
     * sense on the drop target.
488
     * </p>
489
     * 
490
     * @param target the object that the mouse is currently hovering over, or
491
     *   <code>null</code> if the mouse is hovering over empty space
492
     * @param operation the current drag operation (copy, move, etc.)
493
     * @param transferType the current transfer type
494
     * @return the operation which will be executed if no modifier key is pressed
495
     * 		by the user
496
     * 
497
     * @see DND#DROP_NONE
498
	 * @see DND#DROP_MOVE
499
	 * @see DND#DROP_COPY
500
	 * @see DND#DROP_LINK
501
     */
502
    protected int getDefaultDropOperation(Object target, int operation, TransferData transferType) {
503
    	if (!validateDrop(target, operation, transferType)) {
504
    		return DND.DROP_NONE;
505
    	}
506
    		
507
    	return operation;
508
    }
487
}
509
}

Return to bug 197965