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 101993 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/packageview/FileTransferDropAdapter.java (-6 / +13 lines)
Lines 74-80 Link Here
74
	/**
74
	/**
75
	 * {@inheritDoc}
75
	 * {@inheritDoc}
76
	 */
76
	 */
77
	public int validateDrop(Object target, int operation, TransferData transferType) {
77
	public boolean validateDrop(Object target, int operation, TransferData transferType) {
78
		return getDefaultDropOperation(target, operation, transferType) != DND.DROP_NONE;
79
	}
80
	
81
	/**
82
	 * {@inheritDoc}
83
	 */
84
	protected int getDefaultDropOperation(Object target, int operation, TransferData transferType) {
78
	
85
	
79
		boolean isPackageFragment= target instanceof IPackageFragment;
86
		boolean isPackageFragment= target instanceof IPackageFragment;
80
		boolean isJavaProject= target instanceof IJavaProject;
87
		boolean isJavaProject= target instanceof IJavaProject;
Lines 100-115 Link Here
100
	/**
107
	/**
101
	 * {@inheritDoc}
108
	 * {@inheritDoc}
102
	 */
109
	 */
103
	public int performDrop(final Object data) {
110
	public boolean performDrop(final Object data) {
104
		try {
111
		try {
105
			int operation= getCurrentOperation();
112
			int operation= getCurrentOperation();
106
113
107
			if (data == null || !(data instanceof String[]) || operation != DND.DROP_COPY)
114
			if (data == null || !(data instanceof String[]) || operation != DND.DROP_COPY)
108
				return DND.DROP_NONE;
115
				return false;
109
116
110
			final IContainer target= getActualTarget(getCurrentTarget());
117
			final IContainer target= getActualTarget(getCurrentTarget());
111
			if (target == null)
118
			if (target == null)
112
				return DND.DROP_NONE;
119
				return false;
113
			
120
			
114
			// Run the import operation asynchronously. 
121
			// Run the import operation asynchronously. 
115
			// Otherwise the drag source (e.g., Windows Explorer) will be blocked 
122
			// Otherwise the drag source (e.g., Windows Explorer) will be blocked 
Lines 121-134 Link Here
121
				}
128
				}
122
			});
129
			});
123
			
130
			
124
			return DND.DROP_COPY;
131
			return false;
125
		} catch (JavaModelException e) {
132
		} catch (JavaModelException e) {
126
			String title= PackagesMessages.DropAdapter_errorTitle; 
133
			String title= PackagesMessages.DropAdapter_errorTitle; 
127
			String message= PackagesMessages.DropAdapter_errorMessage; 
134
			String message= PackagesMessages.DropAdapter_errorMessage; 
128
			ExceptionHandler.handle(e, getShell(), title, message);
135
			ExceptionHandler.handle(e, getShell(), title, message);
129
		}
136
		}
130
		
137
		
131
		return DND.DROP_NONE;
138
		return true;
132
	}
139
	}
133
	
140
	
134
	private IContainer getActualTarget(Object dropTarget) throws JavaModelException{
141
	private IContainer getActualTarget(Object dropTarget) throws JavaModelException{
(-)ui/org/eclipse/jdt/internal/ui/packageview/SelectionTransferDropAdapter.java (-3 / +10 lines)
Lines 106-116 Link Here
106
		fCopyProcessor= null;
106
		fCopyProcessor= null;
107
		fCanCopyElements= 0;
107
		fCanCopyElements= 0;
108
	}
108
	}
109
110
	/**
111
	 * {@inheritDoc}
112
	 */
113
	public boolean validateDrop(Object target, int operation, TransferData transferType) {
114
		return getDefaultDropOperation(target, operation, transferType) != DND.DROP_NONE;
115
	}
109
	
116
	
110
	/**
117
	/**
111
	 * {@inheritDoc}
118
	 * {@inheritDoc}
112
	 */
119
	 */
113
	public int validateDrop(Object target, int operation, TransferData transferType) {
120
	protected int getDefaultDropOperation(Object target, int operation, TransferData transferType) {
114
		
121
		
115
		initializeSelection();
122
		initializeSelection();
116
		
123
		
Lines 162-168 Link Here
162
	/**
169
	/**
163
	 * {@inheritDoc}
170
	 * {@inheritDoc}
164
	 */
171
	 */
165
	public int performDrop(Object data) {
172
	public boolean performDrop(Object data) {
166
		try{
173
		try{
167
			switch(getCurrentOperation()) {
174
			switch(getCurrentOperation()) {
168
				case DND.DROP_MOVE: handleDropMove(getCurrentTarget()); break;
175
				case DND.DROP_MOVE: handleDropMove(getCurrentTarget()); break;
Lines 178-184 Link Here
178
		// The drag source listener must not perform any operation
185
		// The drag source listener must not perform any operation
179
		// since this drop adapter did the remove of the source even
186
		// since this drop adapter did the remove of the source even
180
		// if we moved something.
187
		// if we moved something.
181
		return DND.DROP_NONE;
188
		return false;
182
		
189
		
183
	}
190
	}
184
	
191
	
(-)ui/org/eclipse/jdt/internal/ui/packageview/WorkingSetDropAdapter.java (-4 / +25 lines)
Lines 55-64 Link Here
55
	private Set fCurrentElements;
55
	private Set fCurrentElements;
56
	private IWorkingSet fWorkingSet;
56
	private IWorkingSet fWorkingSet;
57
57
58
	private int fLocation;
59
58
	public WorkingSetDropAdapter(PackageExplorerPart part) {
60
	public WorkingSetDropAdapter(PackageExplorerPart part) {
59
		super(part.getTreeViewer());
61
		super(part.getTreeViewer());
60
		fPackageExplorer= part;
62
		fPackageExplorer= part;
61
		
63
		
64
		fLocation= -1;
65
		
62
		setScrollEnabled(true);
66
		setScrollEnabled(true);
63
		setExpandEnabled(true);
67
		setExpandEnabled(true);
64
		setFeedbackEnabled(false);
68
		setFeedbackEnabled(false);
Lines 96-102 Link Here
96
	/**
100
	/**
97
	 * {@inheritDoc}
101
	 * {@inheritDoc}
98
	 */
102
	 */
99
	public int validateDrop(Object target, int operation, TransferData transferType) {
103
	public boolean validateDrop(Object target, int operation, TransferData transferType) {
104
		return getDefaultDropOperation(target, operation, transferType) != DND.DROP_NONE;
105
	}
106
	
107
	/**
108
	 * {@inheritDoc}
109
	 */
110
	protected int getDefaultDropOperation(Object target, int operation, TransferData transferType) {
100
		switch(operation) {
111
		switch(operation) {
101
			case DND.DROP_DEFAULT:
112
			case DND.DROP_DEFAULT:
102
			case DND.DROP_COPY:
113
			case DND.DROP_COPY:
Lines 200-213 Link Here
200
	/**
211
	/**
201
	 * {@inheritDoc}
212
	 * {@inheritDoc}
202
	 */
213
	 */
203
	public int performDrop(Object data) {
214
	public boolean performDrop(Object data) {
204
		if (isWorkingSetSelection()) {
215
		if (isWorkingSetSelection()) {
205
			performWorkingSetReordering();
216
			performWorkingSetReordering();
206
		} else {
217
		} else {
207
			performElementRearrange(getCurrentOperation());
218
			performElementRearrange(getCurrentOperation());
208
		}
219
		}
209
		// drag adapter has nothing to do, even on move.
220
		// drag adapter has nothing to do, even on move.
210
		return DND.DROP_NONE;
221
		return false;
211
	}
222
	}
212
223
213
	private void performWorkingSetReordering() {
224
	private void performWorkingSetReordering() {
Lines 285-290 Link Here
285
	}
296
	}
286
297
287
	public void internalTestSetLocation(int location) {
298
	public void internalTestSetLocation(int location) {
288
		setCurrentLocation(location);
299
		fLocation= location;
300
	}
301
	
302
	/**
303
	 * {@inheritDoc}
304
	 */
305
	protected int getCurrentLocation() {
306
		if (fLocation == -1)
307
			return super.getCurrentLocation();
308
		
309
		return fLocation;
289
	}
310
	}
290
}
311
}
(-)ui/org/eclipse/jdt/internal/ui/dnd/ViewerInputDropAdapter.java (-4 / +4 lines)
Lines 40-46 Link Here
40
	/**
40
	/**
41
	 * {@inheritDoc}
41
	 * {@inheritDoc}
42
	 */
42
	 */
43
	public int validateDrop(Object target, int operation, TransferData transferType) {
43
	protected int getDefaultDropOperation(Object target, int operation, TransferData transferType) {
44
44
45
		setSelectionFeedbackEnabled(true);
45
		setSelectionFeedbackEnabled(true);
46
		setExpandEnabled(true);
46
		setExpandEnabled(true);
Lines 48-54 Link Here
48
		initializeSelection();
48
		initializeSelection();
49
49
50
		if (target != null) {
50
		if (target != null) {
51
			return super.validateDrop(target, operation, transferType);
51
			return super.getDefaultDropOperation(target, operation, transferType);
52
		} else if (getInputElement(getSelection()) != null) {
52
		} else if (getInputElement(getSelection()) != null) {
53
			setSelectionFeedbackEnabled(false);
53
			setSelectionFeedbackEnabled(false);
54
			setExpandEnabled(false);
54
			setExpandEnabled(false);
Lines 61-67 Link Here
61
	/**
61
	/**
62
	 * {@inheritDoc}
62
	 * {@inheritDoc}
63
	 */
63
	 */
64
	public int performDrop(Object data) {
64
	public boolean performDrop(Object data) {
65
		setSelectionFeedbackEnabled(true);
65
		setSelectionFeedbackEnabled(true);
66
		setExpandEnabled(true);
66
		setExpandEnabled(true);
67
67
Lines 73-79 Link Here
73
		if (input != null)
73
		if (input != null)
74
			doInputView(input);
74
			doInputView(input);
75
75
76
		return DND.DROP_NONE;
76
		return false;
77
	}
77
	}
78
78
79
	/**
79
	/**
(-)ui/org/eclipse/jdt/internal/ui/dnd/JdtViewerDropAdapter.java (-12 / +37 lines)
Lines 181-187 Link Here
181
     * that it is still enabled.
181
     * that it is still enabled.
182
     */
182
     */
183
    private void doDropValidation(DropTargetEvent event) {
183
    private void doDropValidation(DropTargetEvent event) {
184
        currentOperation= validateDrop(currentTarget, lastValidOperation, event.currentDataType);
184
        currentOperation= getDefaultDropOperation(currentTarget, lastValidOperation, event.currentDataType);
185
        event.detail = currentOperation;
185
        event.detail = currentOperation;
186
    }
186
    }
187
187
Lines 237-244 Link Here
237
        currentLocation = determineLocation(event);
237
        currentLocation = determineLocation(event);
238
238
239
        //perform the drop behavior
239
        //perform the drop behavior
240
        currentOperation= performDrop(event.data);
240
        if (!performDrop(event.data)) {
241
        event.detail= currentOperation;
241
            event.detail = DND.DROP_NONE;
242
        }
243
        currentOperation = event.detail;
242
    }
244
    }
243
245
244
    /* (non-Javadoc)
246
    /* (non-Javadoc)
Lines 246-252 Link Here
246
     * Last chance for the action to disable itself
248
     * Last chance for the action to disable itself
247
     */
249
     */
248
    public void dropAccept(DropTargetEvent event) {
250
    public void dropAccept(DropTargetEvent event) {
249
    	event.detail= validateDrop(currentTarget, event.detail, event.currentDataType);
251
        event.detail= getDefaultDropOperation(currentTarget, event.detail, event.currentDataType);
250
    }
252
    }
251
253
252
    /**
254
    /**
Lines 367-373 Link Here
367
     * @return <code>true</code> if the drop was successful, and 
369
     * @return <code>true</code> if the drop was successful, and 
368
     *   <code>false</code> otherwise
370
     *   <code>false</code> otherwise
369
     */
371
     */
370
    public abstract int performDrop(Object data);
372
    public abstract boolean performDrop(Object data);
371
373
372
    /* (non-Javadoc)
374
    /* (non-Javadoc)
373
     * Method declared on DropTargetAdapter.
375
     * Method declared on DropTargetAdapter.
Lines 479-492 Link Here
479
     * @return <code>true</code> if the drop is valid, and <code>false</code>
481
     * @return <code>true</code> if the drop is valid, and <code>false</code>
480
     *   otherwise
482
     *   otherwise
481
     */
483
     */
482
    public abstract int validateDrop(Object target, int operation,
484
    public abstract boolean validateDrop(Object target, int operation,
483
            TransferData transferType);
485
            TransferData transferType);
484
    
486
    
485
    /**
487
    /**
486
     * For testing only. The location should not be set otherwise.
488
     * Get the default drop operation on the given object. This method is called whenever some 
487
     * @param location the location to assume
489
     * aspect of the drop operation changes.
488
     */
490
     * <p>
489
    protected void setCurrentLocation(int location) {
491
     * The default operation is the one used when no modifier key is pressed by the user. 
490
    	currentLocation= location;
492
     * </p>
491
	}
493
     * <p>
494
     * Subclasses can overwrite this method to define which operation does make
495
     * sense on the drop target.
496
     * </p>
497
     * 
498
     * @param target the object that the mouse is currently hovering over, or
499
     *   <code>null</code> if the mouse is hovering over empty space
500
     * @param operation the current drag operation (copy, move, etc.)
501
     * @param transferType the current transfer type
502
     * @return the operation which will be executed if no modifier key is pressed
503
     * 		by the user
504
     * 
505
     * @see DND#DROP_NONE
506
	 * @see DND#DROP_MOVE
507
	 * @see DND#DROP_COPY
508
	 * @see DND#DROP_LINK
509
     */
510
    protected int getDefaultDropOperation(Object target, int operation, TransferData transferType) {
511
    	if (!validateDrop(target, operation, transferType)) {
512
    		return DND.DROP_NONE;
513
    	}
514
    		
515
    	return operation;
516
    }
492
}
517
}

Return to bug 101993