View | Details | Raw Unified | Return to bug 129061 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/navigator/CommonDragAdapter.java (-16 / +88 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.navigator;
11
package org.eclipse.ui.navigator;
12
12
13
import java.util.LinkedHashSet;
14
import java.util.Set;
15
13
import org.eclipse.jface.util.LocalSelectionTransfer;
16
import org.eclipse.jface.util.LocalSelectionTransfer;
14
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.jface.viewers.ISelectionProvider;
18
import org.eclipse.jface.viewers.ISelectionProvider;
Lines 50-55 Link Here
50
 */
53
 */
51
public final class CommonDragAdapter extends DragSourceAdapter {
54
public final class CommonDragAdapter extends DragSourceAdapter {
52
55
56
	private static final boolean DEBUG = false;
57
53
	private final INavigatorContentService contentService;
58
	private final INavigatorContentService contentService;
54
59
55
	private final ISelectionProvider provider;
60
	private final ISelectionProvider provider;
Lines 70-99 Link Here
70
		provider = aProvider;
75
		provider = aProvider;
71
	}
76
	}
72
77
78
	/**
79
	 * 
80
	 * @return An array of supported Drag Transfer types. The list contains [
81
	 *         {@link LocalSelectionTransfer#getTransfer()},
82
	 *         {@link PluginTransfer#getInstance()}] in addition to any
83
	 *         supported types contributed by the
84
	 *         {@link CommonDragAdapterAssistant assistants}.
85
	 * @see CommonDragAdapterAssistant
86
	 * @see LocalSelectionTransfer
87
	 * @see PluginTransfer
88
	 */
89
	public Transfer[] getSupportDragTransfers() {
90
		CommonDragAdapterAssistant[] assistants = contentService
91
				.getDnDService().getCommonDragAssistants();
92
93
		Set supportedTypes = new LinkedHashSet();
94
		supportedTypes.add(PluginTransfer.getInstance());
95
		supportedTypes.add(LocalSelectionTransfer.getTransfer());
96
		Transfer[] transferTypes = null;
97
		for (int i = 0; i < assistants.length; i++) {
98
			transferTypes = assistants[i].getSupportedTransferTypes();
99
			for (int j = 0; j < transferTypes.length; j++) {
100
				if (transferTypes[j] != null)
101
					supportedTypes.add(transferTypes[j]);
102
			}
103
		}
104
		
105
		Transfer[] transfers = (Transfer[]) supportedTypes
106
				.toArray(new Transfer[supportedTypes.size()]);
107
		return transfers;
108
	}
109
73
	/*
110
	/*
74
	 * (non-Javadoc)
111
	 * (non-Javadoc)
75
	 * 
112
	 * 
76
	 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
113
	 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
77
	 */
114
	 */
78
	public void dragStart(DragSourceEvent event) {
115
	public void dragStart(DragSourceEvent event) {
116
		if (DEBUG)
117
			System.out.println("CommonDragAdapter.dragStart (begin): " + event); //$NON-NLS-1$
79
		try {
118
		try {
80
			// Workaround for 1GEUS9V
119
			// Workaround for 1GEUS9V
81
			DragSource dragSource = (DragSource) event.widget;
120
			DragSource dragSource = (DragSource) event.widget;
82
			Control control = dragSource.getControl();
121
			Control control = dragSource.getControl();
83
			if (control != control.getDisplay().getFocusControl()) {
122
			if (control == control.getDisplay().getFocusControl()) {
84
				event.doit = false;
123
				ISelection selection = provider.getSelection();
85
				return;
124
				if (!selection.isEmpty()) {
86
			}
125
					LocalSelectionTransfer.getTransfer()
87
			ISelection selection = provider.getSelection();
126
							.setSelection(selection);
88
			if (selection.isEmpty()) {
127
					event.doit = true;
128
				} else
129
					event.doit = false;
130
			} else
89
				event.doit = false;
131
				event.doit = false;
90
				return;
91
			}
92
			LocalSelectionTransfer.getTransfer().setSelection(selection);
93
			event.doit = true;
94
		} catch (RuntimeException e) {
132
		} catch (RuntimeException e) {
95
			NavigatorPlugin.logError(0, e.getMessage(), e);
133
			NavigatorPlugin.logError(0, e.getMessage(), e);
96
		}
134
		}
135
136
		if (DEBUG)
137
			System.out
138
					.println("CommonDragAdapter.dragStart (end): doit=" + event.doit); //$NON-NLS-1$
97
	}
139
	}
98
140
99
	/*
141
	/*
Lines 105-117 Link Here
105
147
106
		ISelection selection = LocalSelectionTransfer.getTransfer()
148
		ISelection selection = LocalSelectionTransfer.getTransfer()
107
				.getSelection();
149
				.getSelection();
150
151
		if (DEBUG)
152
			System.out
153
					.println("CommonDragAdapter.dragSetData (begin): event" + event + " selection=" + selection); //$NON-NLS-1$ //$NON-NLS-2$
154
108
		if (LocalSelectionTransfer.getTransfer()
155
		if (LocalSelectionTransfer.getTransfer()
109
				.isSupportedType(event.dataType))
156
				.isSupportedType(event.dataType)) {
110
			event.data = selection;
157
			event.data = selection;
111
		else if (PluginTransfer.getInstance().isSupportedType(event.dataType))
158
159
			if (DEBUG)
160
				System.out
161
						.println("CommonDragAdapter.dragSetData set LocalSelectionTransfer"); //$NON-NLS-1$
162
		} else if (PluginTransfer.getInstance().isSupportedType(event.dataType)) {
112
			event.data = NavigatorPluginDropAction
163
			event.data = NavigatorPluginDropAction
113
					.createTransferData(contentService);
164
					.createTransferData(contentService);
114
		else if (selection instanceof IStructuredSelection) {
165
			if (DEBUG)
166
				System.out
167
						.println("CommonDragAdapter.dragSetData set PluginTransfer"); //$NON-NLS-1$
168
		} else if (selection instanceof IStructuredSelection) {
169
			if (DEBUG)
170
				System.out
171
						.println("CommonDragAdapter.dragSetData looking for assistants"); //$NON-NLS-1$
172
115
			INavigatorDnDService dndService = contentService.getDnDService();
173
			INavigatorDnDService dndService = contentService.getDnDService();
116
			CommonDragAdapterAssistant[] assistants = dndService
174
			CommonDragAdapterAssistant[] assistants = dndService
117
					.getCommonDragAssistants();
175
					.getCommonDragAssistants();
Lines 123-128 Link Here
123
					if (supportedTransferTypes[j]
181
					if (supportedTransferTypes[j]
124
							.isSupportedType(event.dataType))
182
							.isSupportedType(event.dataType))
125
						try {
183
						try {
184
							if (DEBUG)
185
								System.out
186
										.println("CommonDragAdapter.dragSetData set assistant transfer type"); //$NON-NLS-1$
126
							assistants[i].setDragData(event,
187
							assistants[i].setDragData(event,
127
									(IStructuredSelection) selection);
188
									(IStructuredSelection) selection);
128
						} catch (RuntimeException re) {
189
						} catch (RuntimeException re) {
Lines 132-138 Link Here
132
				}
193
				}
133
			}
194
			}
134
195
135
		}
196
		} else
197
			event.doit = false;
198
199
		if (DEBUG)
200
			System.out.println("CommonDragAdapter.dragSetData (end): " + event); //$NON-NLS-1$
136
	}
201
	}
137
202
138
	/*
203
	/*
Lines 141-149 Link Here
141
	 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
206
	 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
142
	 */
207
	 */
143
	public void dragFinished(DragSourceEvent event) {
208
	public void dragFinished(DragSourceEvent event) {
209
210
		if (DEBUG)
211
			System.out.println("CommonDragAdapter.dragFinished()."); //$NON-NLS-1$
212
144
		LocalSelectionTransfer.getTransfer().setSelection(null);
213
		LocalSelectionTransfer.getTransfer().setSelection(null);
145
		if (event.doit == false)
214
146
			return;
215
		// TODO Handle clean up if drop target was outside of workbench
216
		// if (event.doit != false) {
217
		//			
218
		// }
147
	}
219
	}
148
220
149
}
221
}
(-)src/org/eclipse/ui/navigator/INavigatorDnDService.java (-8 / +35 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.ui.navigator;
12
package org.eclipse.ui.navigator;
13
13
14
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.swt.dnd.TransferData;
16
14
17
15
/**
18
/**
16
 * 
19
 * 
Lines 66-89 Link Here
66
	 * content extensions that are <i>visible</i> and <i>active</i> for the
69
	 * content extensions that are <i>visible</i> and <i>active</i> for the
67
	 * associated {@link INavigatorContentService}. The array is sorted by
70
	 * associated {@link INavigatorContentService}. The array is sorted by
68
	 * priority, with overrides taken into account.
71
	 * priority, with overrides taken into account.
69
	 * 
72
	 *  
70
	 * <p>
73
	 * <p>
71
	 * That is, if an extension X overrides extension Y (see
74
	 * The array should be processed from the first element to the last, asking
72
	 * <b>org.eclipse.ui.navigator.navigatorContent/override</b>), then X will
75
	 * each extension to
73
	 * occur before Y in the array. If X and Y override Z, but X has higher
76
	 * {@link CommonDropAdapterAssistant#validateDrop(Object, int, org.eclipse.swt.dnd.TransferData)}.
74
	 * priority than Y, then X will occur before Y, and Y will occur before Z.
77
	 * The first to successfully validate the drop operation will have the
78
	 * opportunity to
79
	 * {@link CommonDropAdapterAssistant#handleDrop(CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, Object) handle the drop}
75
	 * </p>
80
	 * </p>
81
	 * 
82
	 * @param aDropTarget
83
	 *            The target element in the viewer of the drop operation.
84
	 * @param theTransferType 
85
	 * 			  The transfer type of the current drop operation.
86
	 * @return An array of {@link CommonDropAdapterAssistant}s that are defined
87
	 *         by the set of
88
	 *         <b>org.eclipse.ui.navigator.navigatorContent/navigatorContent</b>
89
	 *         extensions that provide a <b>possibleChildren</b> expression
90
	 *         that matches the given drop target.
91
	 */
92
	CommonDropAdapterAssistant[] findCommonDropAdapterAssistants(
93
			Object aDropTarget, TransferData theTransferType);
94
	
95
	/**
96
	 * 
97
	 * This method returns an array of {@link CommonDropAdapterAssistant} from
98
	 * content extensions that are <i>visible</i> and <i>active</i> for the
99
	 * associated {@link INavigatorContentService}.  
100
	 *  
76
	 * <p>
101
	 * <p>
77
	 * The array should be processed from the first element to the last, asking
102
	 * The array should be processed from the first element to the last, asking
78
	 * each extension to
103
	 * each extension to
79
	 * {@link CommonDropAdapterAssistant#validateDrop(Object, int, org.eclipse.swt.dnd.TransferData)}.
104
	 * {@link CommonDropAdapterAssistant#validateDrop(Object, int, org.eclipse.swt.dnd.TransferData)}.
80
	 * The first to successfully validate the drop operation will have the
105
	 * The first to successfully validate the drop operation will have the
81
	 * opportunity to
106
	 * opportunity to
82
	 * {@link CommonDropAdapterAssistant#handleDrop(org.eclipse.swt.dnd.DropTargetEvent, Object)}.
107
	 * {@link CommonDropAdapterAssistant#handleDrop(CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, Object) handle the drop}
83
	 * </p>
108
	 * </p>
84
	 * 
109
	 * 
85
	 * @param aDropTarget
110
	 * @param aDropTarget
86
	 *            The target element in the viewer of the drop operation
111
	 *            The target element in the viewer of the drop operation.
112
	 * @param theDragSelection 
113
	 * 			  The drag selection of the current drop operation.
87
	 * @return An array of {@link CommonDropAdapterAssistant}s that are defined
114
	 * @return An array of {@link CommonDropAdapterAssistant}s that are defined
88
	 *         by the set of
115
	 *         by the set of
89
	 *         <b>org.eclipse.ui.navigator.navigatorContent/navigatorContent</b>
116
	 *         <b>org.eclipse.ui.navigator.navigatorContent/navigatorContent</b>
Lines 91-95 Link Here
91
	 *         that matches the given drop target.
118
	 *         that matches the given drop target.
92
	 */
119
	 */
93
	CommonDropAdapterAssistant[] findCommonDropAdapterAssistants(
120
	CommonDropAdapterAssistant[] findCommonDropAdapterAssistants(
94
			Object aDropTarget);
121
			Object aDropTarget, IStructuredSelection theDragSelection);
95
}
122
}
(-)src/org/eclipse/ui/navigator/INavigatorContentDescriptor.java (+9 lines)
Lines 12-17 Link Here
12
12
13
import java.util.Set;
13
import java.util.Set;
14
14
15
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.ui.internal.navigator.extensions.OverridePolicy;
16
import org.eclipse.ui.internal.navigator.extensions.OverridePolicy;
16
17
17
18
Lines 100-105 Link Here
100
	boolean isPossibleChild(Object anElement);
101
	boolean isPossibleChild(Object anElement);
101
	
102
	
102
	/**
103
	/**
104
	 * A convenience method to check all elements in a selection. 
105
	 * 
106
	 * @param aSelection A non-null selection
107
	 * @return True if and only if every element in the selection is a possible child.
108
	 */
109
	boolean arePossibleChildren(IStructuredSelection aSelection);
110
	
111
	/**
103
	 * @return Returns the suppressedExtensionId or null if none specified.
112
	 * @return Returns the suppressedExtensionId or null if none specified.
104
	 */
113
	 */
105
	String getSuppressedExtensionId();
114
	String getSuppressedExtensionId();
(-)src/org/eclipse/ui/navigator/CommonDropAdapterAssistant.java (-27 / +104 lines)
Lines 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.navigator;
11
package org.eclipse.ui.navigator;
12
12
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.Status;
13
import org.eclipse.jface.util.LocalSelectionTransfer;
15
import org.eclipse.jface.util.LocalSelectionTransfer;
16
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.swt.dnd.DropTargetEvent;
17
import org.eclipse.swt.dnd.DropTargetEvent;
15
import org.eclipse.swt.dnd.TransferData;
18
import org.eclipse.swt.dnd.TransferData;
19
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.ui.internal.navigator.NavigatorContentService;
16
import org.eclipse.ui.part.PluginTransfer;
21
import org.eclipse.ui.part.PluginTransfer;
17
22
18
/**
23
/**
Lines 29-39 Link Here
29
 * Whenever a match is found, the assistant will be given an opportunity to
34
 * Whenever a match is found, the assistant will be given an opportunity to
30
 * first {@link #validateDrop(Object, int, TransferData) }, and then if the
35
 * first {@link #validateDrop(Object, int, TransferData) }, and then if the
31
 * assistant returns true, the assist must
36
 * assistant returns true, the assist must
32
 * {@link #handleDrop(DropTargetEvent, Object) }. If multiple assistants match
37
 * {@link #handleDrop(CommonDropAdapter, DropTargetEvent, Object) }. If
33
 * the drop target, then the potential assistants are ordered based on priority
38
 * multiple assistants match the drop target, then the potential assistants are
34
 * and their override relationships and given an opportunity to validate the
39
 * ordered based on priority and their override relationships and given an
35
 * drop operation in turn. The first one to validate will have the opportunty to
40
 * opportunity to validate the drop operation in turn. The first one to validate
36
 * carry out the drop.
41
 * will have the opportunty to carry out the drop.
37
 * </p>
42
 * </p>
38
 * <p>
43
 * <p>
39
 * That is, if a content extension X overrides content extension Y (see
44
 * That is, if a content extension X overrides content extension Y (see
Lines 42-47 Link Here
42
 * than Y, then X will have an opportunity before Y, and Y will have an
47
 * than Y, then X will have an opportunity before Y, and Y will have an
43
 * opportunity before Z.
48
 * opportunity before Z.
44
 * </p>
49
 * </p>
50
 * 
51
 * <p>
52
 * Clients may handle DND operations that begin and end in the current viewer by
53
 * overriding the following methods:
54
 * <ul>
55
 * <li>{@link #validateDrop(Object, int, TransferData)}: Indicate whether this
56
 * assistant can handle a drop onto the current viewer.</li>
57
 * <li>{@link #handleDrop(CommonDropAdapter, DropTargetEvent, Object)}: Handle
58
 * the drop operation onto the current viewer.</li>
59
 * </ul>
60
 * </p>
61
 * <p>
62
 * If a user originates a drag operation to another viewer that cannot handle
63
 * one of the available drag transfer types, drop assistants may handle the drop
64
 * operation for the target viewer. Clients must override :
65
 * <ul>
66
 * <li>{@link #validatePluginTransferDrop(IStructuredSelection, Object)}:
67
 * Indicate whether this assistant can handle the drop onto another viewer.
68
 * <li>{@link #handlePluginTransferDrop(IStructuredSelection, Object)}: Handle
69
 * the drop operation onto the other viewer.</li>
70
 * </ul>
71
 * </p>
45
 * <p>
72
 * <p>
46
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
73
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
47
 * part of a work in progress. There is a guarantee neither that this API will
74
 * part of a work in progress. There is a guarantee neither that this API will
Lines 53-59 Link Here
53
 * </p>
80
 * </p>
54
 * 
81
 * 
55
 * @see INavigatorDnDService
82
 * @see INavigatorDnDService
56
 * @see INavigatorDnDService#findCommonDropAdapterAssistants(Object)
83
 * @see INavigatorDnDService#findCommonDropAdapterAssistants(Object,
84
 *      TransferData)
57
 * @since 3.2
85
 * @since 3.2
58
 * 
86
 * 
59
 */
87
 */
Lines 76-82 Link Here
76
	}
104
	}
77
105
78
	/**
106
	/**
79
	 * Override to perform any one-time intialization.
107
	 * Override to perform any one-time initialization.
80
	 */
108
	 */
81
	protected void doInit() {
109
	protected void doInit() {
82
110
Lines 88-94 Link Here
88
	 * <p>
116
	 * <p>
89
	 * Subclasses must implement this method to define which drops make sense.
117
	 * Subclasses must implement this method to define which drops make sense.
90
	 * If clients return true, then they will be allowed to handle the drop in
118
	 * If clients return true, then they will be allowed to handle the drop in
91
	 * {@link #handleDrop(DropTargetEvent, Object) }.
119
	 * {@link #handleDrop(CommonDropAdapter, DropTargetEvent, Object) }.
92
	 * </p>
120
	 * </p>
93
	 * 
121
	 * 
94
	 * @param target
122
	 * @param target
Lines 98-138 Link Here
98
	 *            the current drag operation (copy, move, etc.)
126
	 *            the current drag operation (copy, move, etc.)
99
	 * @param transferType
127
	 * @param transferType
100
	 *            the current transfer type
128
	 *            the current transfer type
101
	 * @return <code>true</code> if the drop is valid, and <code>false</code>
129
	 * @return A status indicating whether the drop is valid.
102
	 *         otherwise
103
	 */
130
	 */
104
	public abstract boolean validateDrop(Object target, int operation,
131
	public abstract IStatus validateDrop(Object target, int operation,
105
			TransferData transferType);
132
			TransferData transferType);
106
133
107
	/**
134
	/**
108
	 * Carry out the DND operation
135
	 * Carry out the DND operation.
109
	 * 
136
	 * 
137
	 * @param aDropAdapter
138
	 *            The Drop Adapter contains information that has already been
139
	 *            parsed from the drop event.
110
	 * @param aDropTargetEvent
140
	 * @param aDropTargetEvent
111
	 *            The drop target event.
141
	 *            The drop target event.
112
	 * @param aTarget
142
	 * @param aTarget
113
	 *            The object being dragged onto
143
	 *            The object being dragged onto
114
	 * @return True if the operation completed.
144
	 * @return A status indicating whether the drop completed OK.
115
	 */
145
	 */
116
	public abstract boolean handleDrop(DropTargetEvent aDropTargetEvent,
146
	public abstract IStatus handleDrop(CommonDropAdapter aDropAdapter,
117
			Object aTarget);
147
			DropTargetEvent aDropTargetEvent, Object aTarget);
148
149
	/**
150
	 * Clients may extend the supported transfer types beyond the default
151
	 * {@link LocalSelectionTransfer#getTransfer()} and
152
	 * {@link PluginTransfer#getInstance()} transfer types. When a transfer type
153
	 * other than one of these is encountered, the DND Service will query the
154
	 * <b>visible</b> and <b>active</b> descriptors that are <b>enabled</b>
155
	 * for the drop target of the current operation.
156
	 * 
157
	 * @param aTransferType
158
	 *            The transfer data from the drop operation
159
	 * @return True if the given TransferData can be understood by this
160
	 *         assistant.
161
	 */
162
	public boolean isSupportedType(TransferData aTransferType) {
163
		return LocalSelectionTransfer.getTransfer().isSupportedType(
164
				aTransferType);
165
	}
118
166
119
	/**
167
	/**
120
	 * When a drop opportunity presents itself, the available TransferData types
121
	 * will be supplied in the event. The DropAdapter must select one of these
122
	 * TransferData types for the DragAdapter to provide. By default the Common
123
	 * Navigator supports {@link LocalSelectionTransfer} and
124
	 * {@link PluginTransfer}. Clients are required to indicate if they support
125
	 * other TransferData types using this method.
126
	 * 
168
	 * 
169
	 * Return true if the client can handle the drop onto the target viewer of
170
	 * the drop operation.
127
	 * <p>
171
	 * <p>
128
	 * If none of the given TransferData types are supported, return null.
172
	 * The default behavior of this method is to return <b>Status.CANCEL_STATUS</b>.
129
	 * </p>
173
	 * </p>
130
	 * 
174
	 * 
131
	 * @param theAvailableTransferData
175
	 * @param aDragSelection
132
	 * @return The supported TransferData from the set.
176
	 *            The selection dragged from the viewer.
133
	 */
177
	 * @param aDropTarget
134
	public abstract TransferData findSupportedTransferData(
178
	 *            The target of the drop operation.
135
			TransferData[] theAvailableTransferData);
179
	 * 
180
	 * @return OK if the plugin transfer can be handled by this assistant.
181
	 */
182
	public IStatus validatePluginTransferDrop(
183
			IStructuredSelection aDragSelection, Object aDropTarget) {
184
		return Status.CANCEL_STATUS;
185
	}
186
187
	/**
188
	 * Handle the drop operation for the target viewer.
189
	 * <p>
190
	 * The default behavior of this method is to return <b>Status.CANCEL_STATUS</b>.
191
	 * </p>
192
	 * 
193
	 * @param aDragSelection
194
	 *            The selection dragged from the viewer.
195
	 * @param aDropTarget
196
	 *            The target of the drop operation.
197
	 * 
198
	 * @return OK if the drop operation succeeded.
199
	 */
200
	public IStatus handlePluginTransferDrop(
201
			IStructuredSelection aDragSelection, Object aDropTarget) {
202
		return Status.CANCEL_STATUS;
203
	}
136
204
137
	/**
205
	/**
138
	 * 
206
	 * 
Lines 142-145 Link Here
142
		return contentService;
210
		return contentService;
143
	}
211
	}
144
212
213
	/**
214
	 * 
215
	 * @return A shell for the viewer currently used by the
216
	 *         {@link INavigatorContentService}.
217
	 */
218
	protected final Shell getShell() {
219
		return ((NavigatorContentService) contentService).getShell();
220
	}
221
145
}
222
}
(-)src/org/eclipse/ui/navigator/CommonDragAdapterAssistant.java (-1 / +35 lines)
Lines 17-22 Link Here
17
import org.eclipse.swt.dnd.Transfer;
17
import org.eclipse.swt.dnd.Transfer;
18
import org.eclipse.swt.dnd.TransferData;
18
import org.eclipse.swt.dnd.TransferData;
19
import org.eclipse.swt.widgets.Event;
19
import org.eclipse.swt.widgets.Event;
20
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.internal.navigator.NavigatorContentService;
20
import org.eclipse.ui.part.PluginTransfer;
23
import org.eclipse.ui.part.PluginTransfer;
21
24
22
/**
25
/**
Lines 31-37 Link Here
31
 * </p>
34
 * </p>
32
 * 
35
 * 
33
 * @see INavigatorDnDService
36
 * @see INavigatorDnDService
34
 * @see CommonDragAdapter 
37
 * @see CommonDragAdapter
35
 * @see CommonDropAdapter
38
 * @see CommonDropAdapter
36
 * @see CommonDropAdapterAssistant
39
 * @see CommonDropAdapterAssistant
37
 * @see CommonViewer#initDragAndDrop()
40
 * @see CommonViewer#initDragAndDrop()
Lines 47-52 Link Here
47
 */
50
 */
48
public abstract class CommonDragAdapterAssistant {
51
public abstract class CommonDragAdapterAssistant {
49
52
53
	private INavigatorContentService contentService;
54
50
	/**
55
	/**
51
	 * Extra TransferTypes allow the Navigator to generate different kinds of
56
	 * Extra TransferTypes allow the Navigator to generate different kinds of
52
	 * payloads for DND clients. By default, the {@link CommonDragAdapter}
57
	 * payloads for DND clients. By default, the {@link CommonDragAdapter}
Lines 81-84 Link Here
81
	public abstract void setDragData(DragSourceEvent anEvent,
86
	public abstract void setDragData(DragSourceEvent anEvent,
82
			IStructuredSelection aSelection);
87
			IStructuredSelection aSelection);
83
88
89
	/**
90
	 * Accept and remember the content service this assistant is associated
91
	 * with.
92
	 * 
93
	 * @param aContentService
94
	 */
95
	public final void setContentService(INavigatorContentService aContentService) {
96
		contentService = aContentService;
97
	}
98
99
	/**
100
	 * 
101
	 * @return The associated content service.
102
	 */
103
	public INavigatorContentService getContentService() {
104
		return contentService;
105
	}
106
107
	/**
108
	 * 
109
	 * @return The shell for the viewer this assistant is associated with or the
110
	 *         shell of the active workbench window.
111
	 */
112
	public final Shell getShell() {
113
		if (contentService != null)
114
			((NavigatorContentService) contentService).getShell();
115
		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
116
	}
117
84
}
118
}
(-)src/org/eclipse/ui/navigator/CommonDropAdapter.java (-19 / +147 lines)
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.navigator;
11
package org.eclipse.ui.navigator;
12
12
13
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.jface.util.LocalSelectionTransfer;
14
import org.eclipse.jface.util.LocalSelectionTransfer;
14
import org.eclipse.jface.viewers.StructuredViewer;
15
import org.eclipse.jface.viewers.StructuredViewer;
15
import org.eclipse.swt.dnd.DND;
16
import org.eclipse.swt.dnd.DND;
16
import org.eclipse.swt.dnd.DropTargetEvent;
17
import org.eclipse.swt.dnd.DropTargetEvent;
17
import org.eclipse.swt.dnd.FileTransfer;
18
import org.eclipse.swt.dnd.FileTransfer;
19
import org.eclipse.swt.dnd.Transfer;
18
import org.eclipse.swt.dnd.TransferData;
20
import org.eclipse.swt.dnd.TransferData;
21
import org.eclipse.swt.graphics.Rectangle;
22
import org.eclipse.swt.widgets.Item;
23
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
24
import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
19
import org.eclipse.ui.internal.navigator.dnd.NavigatorPluginDropAction;
25
import org.eclipse.ui.internal.navigator.dnd.NavigatorPluginDropAction;
20
import org.eclipse.ui.part.PluginDropAdapter;
26
import org.eclipse.ui.part.PluginDropAdapter;
21
import org.eclipse.ui.part.PluginTransfer;
27
import org.eclipse.ui.part.PluginTransfer;
Lines 46-55 Link Here
46
 */
52
 */
47
public final class CommonDropAdapter extends PluginDropAdapter {
53
public final class CommonDropAdapter extends PluginDropAdapter {
48
54
49
	// private final StructuredViewer viewer;
55
	private static final Transfer[] SUPPORTED_DROP_TRANSFERS = new Transfer[] {
56
			LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(),
57
			PluginTransfer.getInstance() };
58
59
	private static final boolean DEBUG = false;
50
60
51
	private final INavigatorContentService contentService;
61
	private final INavigatorContentService contentService;
52
62
63
	private final NavigatorDnDService dndService;
64
53
	/**
65
	/**
54
	 * Create a DropAdapter that handles a drop based on the given content
66
	 * Create a DropAdapter that handles a drop based on the given content
55
	 * service and selection provider.
67
	 * service and selection provider.
Lines 62-69 Link Here
62
	public CommonDropAdapter(INavigatorContentService aContentService,
74
	public CommonDropAdapter(INavigatorContentService aContentService,
63
			StructuredViewer aStructuredViewer) {
75
			StructuredViewer aStructuredViewer) {
64
		super(aStructuredViewer);
76
		super(aStructuredViewer);
65
		// viewer = aStructuredViewer;
66
		contentService = aContentService;
77
		contentService = aContentService;
78
		dndService = (NavigatorDnDService) contentService.getDnDService();
79
	}
80
81
	/**
82
	 * 
83
	 * @return An array of Transfers allowed by the CommonDropAdapter. Includes
84
	 *         {@link LocalSelectionTransfer#getTransfer()},
85
	 *         {@link FileTransfer#getInstance()},
86
	 *         {@link PluginTransfer#getInstance()}.
87
	 * @see LocalSelectionTransfer
88
	 * @see FileTransfer
89
	 * @see PluginTransfer
90
	 */
91
	public Transfer[] getSupportedDropTransfers() {
92
		return SUPPORTED_DROP_TRANSFERS;
67
	}
93
	}
68
94
69
	/*
95
	/*
Lines 74-95 Link Here
74
	public void dragEnter(DropTargetEvent event) {
100
	public void dragEnter(DropTargetEvent event) {
75
		super.dragEnter(event);
101
		super.dragEnter(event);
76
102
77
		for (int i = 0; i < event.dataTypes.length; i++) {
103
		for (int i = 0; i < event.dataTypes.length; i++)
78
			if (LocalSelectionTransfer.getTransfer().isSupportedType(
104
			if (LocalSelectionTransfer.getTransfer().isSupportedType(
79
					event.dataTypes[i])) {
105
					event.dataTypes[i])) {
80
				event.currentDataType = event.dataTypes[i];
106
				event.currentDataType = event.dataTypes[i];
81
				return;
107
				return;
82
			} else if (FileTransfer.getInstance().isSupportedType(
108
			}
83
					event.dataTypes[i])) {
109
110
		for (int i = 0; i < event.dataTypes.length; i++)
111
			if (FileTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
84
				event.currentDataType = event.dataTypes[i];
112
				event.currentDataType = event.dataTypes[i];
85
				event.detail = DND.DROP_COPY;
113
				event.detail = DND.DROP_COPY;
86
				return;
114
				return;
87
			} else if (PluginTransfer.getInstance().isSupportedType(
115
			}
88
					event.dataTypes[i])) {
116
117
		for (int i = 0; i < event.dataTypes.length; i++)
118
119
			if (PluginTransfer.getInstance()
120
					.isSupportedType(event.dataTypes[i])) {
89
				event.currentDataType = event.dataTypes[i];
121
				event.currentDataType = event.dataTypes[i];
90
				return;
122
				return;
91
			}
123
			}
92
		}
124
93
		event.detail = DND.DROP_NONE;
125
		event.detail = DND.DROP_NONE;
94
126
95
	}
127
	}
Lines 116-123 Link Here
116
	public void drop(DropTargetEvent event) {
148
	public void drop(DropTargetEvent event) {
117
		if (PluginTransfer.getInstance().isSupportedType(event.currentDataType))
149
		if (PluginTransfer.getInstance().isSupportedType(event.currentDataType))
118
			super.drop(event);
150
			super.drop(event);
151
		else {
119
152
120
		// TODO Use the CommonDropAssistants to validate the drop.
153
			CommonDropAdapterAssistant[] assistants = dndService
154
					.findCommonDropAdapterAssistants(getCurrentTarget(),
155
							getCurrentTransfer());
156
157
			IStatus valid = null;
158
			for (int i = 0; i < assistants.length; i++) {
159
				try {
160
					valid = assistants[i].validateDrop(getCurrentTarget(),
161
							getCurrentOperation(), getCurrentTransfer());
162
					if (valid != null && valid.isOK()) {
163
						assistants[i].handleDrop(this, event,
164
								getCurrentTarget());
165
						return;
166
					}
167
				} catch (Throwable t) {
168
					NavigatorPlugin.logError(0, t.getMessage(), t);
169
				}
170
			}
171
		}
121
	}
172
	}
122
173
123
	/*
174
	/*
Lines 126-145 Link Here
126
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object,
177
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object,
127
	 *      int, org.eclipse.swt.dnd.TransferData)
178
	 *      int, org.eclipse.swt.dnd.TransferData)
128
	 */
179
	 */
129
	public boolean validateDrop(Object target, int operation,
180
	public boolean validateDrop(Object aDropTarget, int theDropOperation,
130
			TransferData transferType) {
181
			TransferData theTransferData) {
131
		/*
182
132
		 * should be called first sense the currentTransfer field is set in the
183
		if (DEBUG)
133
		 * parent in this method
184
			System.out.println("CommonDropAdapter.validateDrop (begin)"); //$NON-NLS-1$
134
		 */
185
135
		if (super.validateDrop(target, operation, transferType)) {
136
			return true;
137
		}
138
		boolean result = false;
186
		boolean result = false;
139
187
140
		// TODO Use the CommonDropAssistants to validate the drop.
188
		IStatus valid = null;
189
190
		if (super.validateDrop(aDropTarget, theDropOperation, theTransferData))
191
			result = true;
192
		else if (FileTransfer.getInstance().isSupportedType(theTransferData))
193
			// only allow copying when dragging from outside Eclipse
194
			// result = theDropOperation != DND.DROP_COPY;
195
			result = true;
196
		else {
197
			CommonDropAdapterAssistant[] assistants = dndService
198
					.findCommonDropAdapterAssistants(aDropTarget,
199
							theTransferData);
200
201
			for (int i = 0; i < assistants.length; i++) {
202
				try {
203
					valid = assistants[i].validateDrop(aDropTarget,
204
							theDropOperation, theTransferData);
205
				} catch (Throwable t) {
206
					NavigatorPlugin.logError(0, t.getMessage(), t);
207
				}
208
				if (valid != null && valid.isOK()) {
209
					result = true;
210
					break;
211
				}
212
			}
213
		}
214
215
		if (DEBUG)
216
			System.out
217
					.println("CommonDropAdapter.validateDrop (returning " + (valid != null ? valid.getSeverity() + ": " + valid.getMessage() : "" + result) + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
141
218
142
		return result;
219
		return result;
220
221
	}
222
223
	/*
224
	 * The visibility of the following methods is raised for downstream clients
225
	 * (assistants).
226
	 */
227
228
	/*
229
	 * (non-Javadoc)
230
	 * 
231
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#getBounds(org.eclipse.swt.widgets.Item)
232
	 */
233
	public Rectangle getBounds(Item item) {
234
		return super.getBounds(item);
235
	}
236
237
	/*
238
	 * (non-Javadoc)
239
	 * 
240
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#getCurrentLocation()
241
	 */
242
	public int getCurrentLocation() {
243
		return super.getCurrentLocation();
244
	}
245
246
	/*
247
	 * (non-Javadoc)
248
	 * 
249
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#getCurrentOperation()
250
	 */
251
	public int getCurrentOperation() {
252
		return super.getCurrentOperation();
253
	}
254
255
	/*
256
	 * (non-Javadoc)
257
	 * 
258
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#getCurrentTarget()
259
	 */
260
	public Object getCurrentTarget() {
261
		return super.getCurrentTarget();
262
	}
263
264
	/*
265
	 * (non-Javadoc)
266
	 * 
267
	 * @see org.eclipse.ui.part.PluginDropAdapter#getCurrentTransfer()
268
	 */
269
	public TransferData getCurrentTransfer() {
270
		return super.getCurrentTransfer();
143
	}
271
	}
144
272
145
}
273
}
(-)src/org/eclipse/ui/navigator/CommonViewer.java (-32 / +15 lines)
Lines 21-26 Link Here
21
import org.eclipse.jface.viewers.TreeViewer;
21
import org.eclipse.jface.viewers.TreeViewer;
22
import org.eclipse.jface.viewers.ViewerSorter;
22
import org.eclipse.jface.viewers.ViewerSorter;
23
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.dnd.DND;
24
import org.eclipse.swt.events.DisposeEvent;
25
import org.eclipse.swt.events.DisposeEvent;
25
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Item;
27
import org.eclipse.swt.widgets.Item;
Lines 304-312 Link Here
304
	 * By default, the following Transfer types are supported:
305
	 * By default, the following Transfer types are supported:
305
	 * <ul>
306
	 * <ul>
306
	 * <li>LocalSelectionTransfer.getInstance(),
307
	 * <li>LocalSelectionTransfer.getInstance(),
307
	 * <li>PluginTransfer.getInstance(),
308
	 * <li>PluginTransfer.getInstance()
308
	 * <li>FileTransfer.getInstance(), and
309
	 * <li>ResourceTransfer.getInstance()
310
	 * </ul>
309
	 * </ul>
311
	 * </p>
310
	 * </p>
312
	 * 
311
	 * 
Lines 314-348 Link Here
314
	 * @see CommonDropAdapter
313
	 * @see CommonDropAdapter
315
	 */
314
	 */
316
	protected void initDragAndDrop() {
315
	protected void initDragAndDrop() {
317
		
316
318
		// TODO initDragAndDrop is in progress.
317
		/* Handle Drag and Drop */
319
		
318
		int operations = DND.DROP_COPY | DND.DROP_MOVE;
320
//		/* Handle Drag and Drop */
319
321
//		int operations = DND.DROP_COPY | DND.DROP_MOVE;
320
		CommonDragAdapter dragAdapter = new CommonDragAdapter(contentService,
322
//
321
				this);
323
//		CommonDragAdapterAssistant[] assistants = contentService
322
		addDragSupport(operations, dragAdapter.getSupportDragTransfers(),
324
//				.getDnDService().getCommonDragAssistants();
323
				dragAdapter);
325
//
324
326
//		Set supportedTypes = new HashSet();
325
		CommonDropAdapter dropAdapter = new CommonDropAdapter(contentService,
327
//		supportedTypes.add(PluginTransfer.getInstance());
326
				this);
328
//		supportedTypes.add(LocalSelectionTransfer.getInstance());
327
		addDropSupport(operations, dropAdapter.getSupportedDropTransfers(),
329
//		Transfer[] transferTypes = null;
328
				dropAdapter);
330
//		for (int i = 0; i < assistants.length; i++) {
331
//			transferTypes = assistants[i].getSupportedTransferTypes();
332
//			for (int j = 0; j < transferTypes.length; j++) {
333
//				if (transferTypes[j] != null)
334
//					supportedTypes.add(transferTypes[j]);
335
//			}
336
//		}
337
//
338
//		Transfer[] transfers = (Transfer[]) supportedTypes
339
//				.toArray(new Transfer[supportedTypes.size()]);
340
//
341
//		addDragSupport(operations, transfers, new CommonDragAdapter(
342
//				contentService, this));
343
//		// TODO Should the Transfers be the same here?
344
//		addDropSupport(operations, transfers, new CommonDropAdapter(
345
//				contentService, this));
346
329
347
	}
330
	}
348
331
(-)schema/navigatorContent.exsd (-2 / +35 lines)
Lines 86-92 Link Here
86
            <element ref="actionProvider" minOccurs="0" maxOccurs="unbounded"/>
86
            <element ref="actionProvider" minOccurs="0" maxOccurs="unbounded"/>
87
            <element ref="commonSorter" minOccurs="0" maxOccurs="unbounded"/>
87
            <element ref="commonSorter" minOccurs="0" maxOccurs="unbounded"/>
88
            <element ref="override" minOccurs="0" maxOccurs="1"/>
88
            <element ref="override" minOccurs="0" maxOccurs="1"/>
89
            <element ref="commonDropAdapter" minOccurs="0" maxOccurs="1"/>
89
            <element ref="commonDropAdapter" minOccurs="0" maxOccurs="unbounded"/>
90
         </sequence>
90
         </sequence>
91
         <attribute name="id" type="string" use="required">
91
         <attribute name="id" type="string" use="required">
92
            <annotation>
92
            <annotation>
Lines 518-527 Link Here
518
   <element name="commonDropAdapter">
518
   <element name="commonDropAdapter">
519
      <annotation>
519
      <annotation>
520
         <documentation>
520
         <documentation>
521
            Provides a subclass of &lt;code&gt;org.eclipse.ui.navigator.CommonDropAdapterAssistant&lt;/code&gt; which can provide programatic validation for a drop operation, request additional transfer types, and handle the drop.
521
            Provides a subclass of &lt;code&gt;org.eclipse.ui.navigator.CommonDropAdapterAssistant&lt;/code&gt; which can provide programatic validation for a drop operation, request additional transfer types, and handle the drop operation. 
522
&lt;br&gt;&lt;br&gt;
523
A &lt;b&gt;commonDropAdapter&lt;/b&gt; will be invoked whenever elements that are dragged match the &lt;b&gt;possibleChildren&lt;/b&gt; expression of the containing &lt;b&gt;navigatorContent&lt;/b&gt; extension &lt;i&gt;and&lt;/i&gt; the drop target of the operation is described by the &lt;b&gt;possibleDropTargets&lt;/b&gt; expression of the &lt;b&gt;commonDropAdapter&lt;/b&gt; element.
524
&lt;br&gt;&lt;br&gt;
525
An extension may have multiple drop adapters with mutually exclusive &lt;b&gt;possibleDropTargets&lt;/b&gt; expressions. The first drop adapter found that matches the given drop target and returns an OK status for &lt;code&gt;CommonDropAdapterAssistant.validateDrop(...)&lt;/code&gt; will be given an opportunity to handle the drop. 
526
&lt;br&gt;&lt;br&gt;
527
 
522
         </documentation>
528
         </documentation>
523
      </annotation>
529
      </annotation>
524
      <complexType>
530
      <complexType>
531
         <sequence>
532
            <element ref="possibleDropTargets"/>
533
         </sequence>
525
         <attribute name="id" type="string" use="required">
534
         <attribute name="id" type="string" use="required">
526
            <annotation>
535
            <annotation>
527
               <documentation>
536
               <documentation>
Lines 542-547 Link Here
542
      </complexType>
551
      </complexType>
543
   </element>
552
   </element>
544
553
554
   <element name="possibleDropTargets">
555
      <annotation>
556
         <documentation>
557
            Describe the possible drop targets that a particular &lt;b&gt;commonDropAdapter&lt;/b&gt; can handle.
558
         </documentation>
559
      </annotation>
560
      <complexType>
561
         <sequence minOccurs="0" maxOccurs="unbounded">
562
            <element ref="not"/>
563
            <element ref="and"/>
564
            <element ref="or"/>
565
            <element ref="instanceof"/>
566
            <element ref="test"/>
567
            <element ref="systemTest"/>
568
            <element ref="equals"/>
569
            <element ref="count"/>
570
            <element ref="with"/>
571
            <element ref="resolve"/>
572
            <element ref="adapt"/>
573
            <element ref="iterate"/>
574
         </sequence>
575
      </complexType>
576
   </element>
577
545
   <annotation>
578
   <annotation>
546
      <appInfo>
579
      <appInfo>
547
         <meta.section type="since"/>
580
         <meta.section type="since"/>
(-)src/org/eclipse/ui/internal/navigator/dnd/NavigatorDnDService.java (-7 / +91 lines)
Lines 11-19 Link Here
11
11
12
package org.eclipse.ui.internal.navigator.dnd;
12
package org.eclipse.ui.internal.navigator.dnd;
13
13
14
import java.util.HashMap;
14
import java.util.Iterator;
15
import java.util.Iterator;
16
import java.util.LinkedHashSet;
17
import java.util.Map;
15
import java.util.Set;
18
import java.util.Set;
16
19
20
import org.eclipse.jface.util.LocalSelectionTransfer;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.swt.dnd.TransferData;
17
import org.eclipse.ui.internal.navigator.NavigatorContentService;
23
import org.eclipse.ui.internal.navigator.NavigatorContentService;
18
import org.eclipse.ui.internal.navigator.extensions.CommonDragAssistantDescriptor;
24
import org.eclipse.ui.internal.navigator.extensions.CommonDragAssistantDescriptor;
19
import org.eclipse.ui.internal.navigator.extensions.NavigatorViewerDescriptor;
25
import org.eclipse.ui.internal.navigator.extensions.NavigatorViewerDescriptor;
Lines 28-45 Link Here
28
 * {@link CommonDropAdapterAssistant} for the associated
34
 * {@link CommonDropAdapterAssistant} for the associated
29
 * {@link INavigatorContentService}.
35
 * {@link INavigatorContentService}.
30
 * 
36
 * 
37
 * <p>
38
 * Clients may not extend, instantiate or directly reference this class.
39
 * </p>
40
 * 
31
 * @since 3.2
41
 * @since 3.2
32
 * 
42
 * 
33
 */
43
 */
34
public class NavigatorDnDService implements INavigatorDnDService {
44
public class NavigatorDnDService implements INavigatorDnDService {
35
45
46
	private static final CommonDropAdapterAssistant[] NO_ASSISTANTS = new CommonDropAdapterAssistant[0];
47
36
	private NavigatorContentService contentService;
48
	private NavigatorContentService contentService;
37
49
38
	private CommonDragAdapterAssistant[] dragAssistants;
50
	private CommonDragAdapterAssistant[] dragAssistants;
39
51
52
	private final Map dropAssistants = new HashMap();
53
40
	/**
54
	/**
41
	 * 
55
	 * 
42
	 * @param aContentService The associated content service
56
	 * @param aContentService
57
	 *            The associated content service
43
	 */
58
	 */
44
	public NavigatorDnDService(NavigatorContentService aContentService) {
59
	public NavigatorDnDService(NavigatorContentService aContentService) {
45
		contentService = aContentService;
60
		contentService = aContentService;
Lines 62-73 Link Here
62
		return dragAssistants;
77
		return dragAssistants;
63
	}
78
	}
64
79
65
	/* (non-Javadoc)
80
	public CommonDropAdapterAssistant[] findCommonDropAdapterAssistants(
66
	 * @see org.eclipse.ui.navigator.INavigatorDnDService#findCommonDropAdapterAssistants(java.lang.Object)
81
			Object aDropTarget, TransferData aTransferType) {
67
	 */
82
 
68
	public CommonDropAdapterAssistant[] findCommonDropAdapterAssistants(Object aDropTarget) {
83
		// TODO Make sure descriptors are sorted by priority 
69
		// TODO Implement the search routine
84
		CommonDropAdapterDescriptor[] descriptors = CommonDropDescriptorManager
70
		return null;
85
				.getInstance().findCommonDropAdapterAssistants(aDropTarget,
86
						contentService);
87
88
		if (descriptors.length == 0)
89
			return NO_ASSISTANTS;
90
91
		if (LocalSelectionTransfer.getTransfer().isSupportedType(aTransferType)  
92
						&& LocalSelectionTransfer.getTransfer().getSelection() instanceof IStructuredSelection) 
93
			return getAssistantsBySelection(descriptors, (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection()); 
94
		return getAssistantsByTransferData(descriptors, aTransferType);
95
	}
96
	
97
98
	public CommonDropAdapterAssistant[] findCommonDropAdapterAssistants(
99
			Object aDropTarget, IStructuredSelection theDragSelection) {
100
 
101
		// TODO Make sure descriptors are sorted by priority 
102
		CommonDropAdapterDescriptor[] descriptors = CommonDropDescriptorManager
103
				.getInstance().findCommonDropAdapterAssistants(aDropTarget,
104
						contentService);
105
106
		if (descriptors.length == 0)
107
			return NO_ASSISTANTS;
108
109
		return getAssistantsBySelection(descriptors, theDragSelection);  
110
	}
111
112
	private CommonDropAdapterAssistant[] getAssistantsByTransferData(
113
			CommonDropAdapterDescriptor[] descriptors,
114
			TransferData aTransferType) {
115
116
		Set assistants = new LinkedHashSet();
117
		for (int i = 0; i < descriptors.length; i++) {
118
			CommonDropAdapterAssistant asst = getAssistant(descriptors[i]);
119
			if (asst.isSupportedType(aTransferType))
120
				assistants.add(asst);
121
		}
122
		return (CommonDropAdapterAssistant[]) assistants
123
				.toArray(new CommonDropAdapterAssistant[assistants.size()]);
124
125
	}
126
127
	private CommonDropAdapterAssistant[] getAssistantsBySelection(
128
			CommonDropAdapterDescriptor[] descriptors, IStructuredSelection aSelection) {
129
130
		Set assistants = new LinkedHashSet(); 
131
			
132
		for (int i = 0; i < descriptors.length; i++) 
133
			if(descriptors[i].areDragElementsSupported(aSelection))
134
				assistants.add(getAssistant(descriptors[i]));  
135
136
		return (CommonDropAdapterAssistant[]) assistants
137
				.toArray(new CommonDropAdapterAssistant[assistants.size()]);
138
	}
139
140
	private CommonDropAdapterAssistant getAssistant(
141
			CommonDropAdapterDescriptor descriptor) {
142
		CommonDropAdapterAssistant asst = (CommonDropAdapterAssistant) dropAssistants
143
				.get(descriptor);
144
		if (asst != null)
145
			return asst;
146
		synchronized (dropAssistants) {
147
			asst = (CommonDropAdapterAssistant) dropAssistants.get(descriptor);
148
			if (asst == null) {
149
				dropAssistants.put(descriptor, (asst = descriptor
150
						.createDropAssistant()));
151
				asst.init(contentService);
152
			}
153
		}
154
		return asst;
71
	}
155
	}
72
156
73
}
157
}
(-)src/org/eclipse/ui/internal/navigator/dnd/NavigatorPluginDropAction.java (-8 / +43 lines)
Lines 10-37 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.navigator.dnd;
11
package org.eclipse.ui.internal.navigator.dnd;
12
12
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.jface.util.LocalSelectionTransfer;
15
import org.eclipse.jface.viewers.IStructuredSelection;
16
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
13
import org.eclipse.ui.navigator.INavigatorContentService;
17
import org.eclipse.ui.navigator.INavigatorContentService;
14
import org.eclipse.ui.part.IDropActionDelegate;
18
import org.eclipse.ui.part.IDropActionDelegate;
15
import org.eclipse.ui.part.PluginTransferData;
19
import org.eclipse.ui.part.PluginTransferData;
16
20
17
/**
21
/**
18
 * 
22
 * 
19
 * <p>
20
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
21
 * part of a work in progress. There is a guarantee neither that this API will
22
 * work nor that it will remain the same. Please do not use this API without
23
 * consulting with the Platform/UI team.
24
 * </p>
25
 * 
23
 * 
26
 * @since 3.2
24
 * @since 3.2
27
 * 
25
 * 
28
 */
26
 */
29
public class NavigatorPluginDropAction implements IDropActionDelegate {
27
public class NavigatorPluginDropAction implements IDropActionDelegate {
30
28
29
	private static final boolean DEBUG = false;
30
31
	private static final String CN_PLUGIN_ACTION_ID = "org.eclipse.ui.navigator.PluginDropAction"; //$NON-NLS-1$
31
	private static final String CN_PLUGIN_ACTION_ID = "org.eclipse.ui.navigator.PluginDropAction"; //$NON-NLS-1$
32
32
33
	/**
33
	/**
34
	 * 
34
	 * A default no-args constructor is required by the
35
	 * <b>org.eclipse.ui.dropAdapters</b> extension point
35
	 */
36
	 */
36
	public NavigatorPluginDropAction() {
37
	public NavigatorPluginDropAction() {
37
		super();
38
		super();
Lines 45-51 Link Here
45
	 */
46
	 */
46
	public boolean run(Object sourceData, Object target) {
47
	public boolean run(Object sourceData, Object target) {
47
48
48
		// TODO Handle the callback for drop targets that cannot handle the drop
49
		if (DEBUG)
50
			System.out.println("NavigatorPluginDropAction.run (begin)"); //$NON-NLS-1$
51
52
		String sourceViewerId = new String((byte[]) sourceData);
53
54
		IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer
55
				.getTransfer().getSelection();
56
57
		INavigatorContentService contentService = NavigatorContentServiceTransfer
58
				.getInstance().findService(sourceViewerId);
59
60
		if (contentService == null)
61
			return false;
62
		try {
63
			CommonDropAdapterAssistant[] assistants = contentService
64
					.getDnDService().findCommonDropAdapterAssistants(target,
65
							selection); 
66
67
			IStatus valid = null;
68
			for (int i = 0; i < assistants.length; i++) {
69
				valid = assistants[i].validatePluginTransferDrop(selection, target);
70
				if (valid != null && valid.isOK()) {
71
					valid = assistants[i].handlePluginTransferDrop(selection, target);
72
					return valid != null && valid.isOK();
73
				}
74
			}
75
		} finally {
76
			NavigatorContentServiceTransfer.getInstance()
77
					.unregisterContentService(contentService);
78
		}
79
80
		if (DEBUG)
81
			System.out.println("NavigatorPluginDropAction.run (exit)"); //$NON-NLS-1$
49
82
50
		return false;
83
		return false;
51
	}
84
	}
Lines 59-64 Link Here
59
	 */
92
	 */
60
	public static PluginTransferData createTransferData(
93
	public static PluginTransferData createTransferData(
61
			INavigatorContentService aContentService) {
94
			INavigatorContentService aContentService) {
95
		NavigatorContentServiceTransfer.getInstance().registerContentService(
96
				aContentService);
62
		return new PluginTransferData(CN_PLUGIN_ACTION_ID, aContentService
97
		return new PluginTransferData(CN_PLUGIN_ACTION_ID, aContentService
63
				.getViewerId().getBytes());
98
				.getViewerId().getBytes());
64
	}
99
	}
(-)src/org/eclipse/ui/internal/navigator/dnd/CommonDropAdapterDescriptor.java (-21 / +31 lines)
Lines 16-25 Link Here
16
import org.eclipse.core.expressions.Expression;
16
import org.eclipse.core.expressions.Expression;
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.ui.internal.navigator.CustomAndExpression;
20
import org.eclipse.ui.internal.navigator.CustomAndExpression;
20
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
21
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
21
import org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtPtConstants;
22
import org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtPtConstants;
22
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
23
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
24
import org.eclipse.ui.navigator.INavigatorContentDescriptor;
23
25
24
/**
26
/**
25
 * @since 3.2
27
 * @since 3.2
Lines 28-56 Link Here
28
public final class CommonDropAdapterDescriptor implements
30
public final class CommonDropAdapterDescriptor implements
29
		INavigatorContentExtPtConstants {
31
		INavigatorContentExtPtConstants {
30
32
31
	private IConfigurationElement element;
33
	private final IConfigurationElement element;
32
34
33
	private Expression dragExpr;
35
	private final INavigatorContentDescriptor contentDescriptor;
34
36
35
	private Expression dropExpr;
37
	private Expression dropExpr;
36
38
37
	/* package */CommonDropAdapterDescriptor(
39
	/* package */CommonDropAdapterDescriptor(
38
			IConfigurationElement aConfigElement) {
40
			IConfigurationElement aConfigElement,
41
			INavigatorContentDescriptor aContentDescriptor) {
39
		element = aConfigElement;
42
		element = aConfigElement;
43
		contentDescriptor = aContentDescriptor;
40
		init();
44
		init();
41
	}
45
	}
42
46
43
	private void init() {
47
	private void init() {
44
48
		IConfigurationElement[] children = element.getChildren(TAG_POSSIBLE_DROP_TARGETS);
45
		IConfigurationElement[] children = element
46
				.getChildren(TAG_DRAG_EXPRESSION);
47
		if (children.length == 1)
48
			dragExpr = new CustomAndExpression(children[0]);
49
50
		children = element.getChildren(TAG_DROP_EXPRESSION);
51
		if (children.length == 1)
49
		if (children.length == 1)
52
			dropExpr = new CustomAndExpression(children[0]);
50
			dropExpr = new CustomAndExpression(children[0]);
53
54
	}
51
	}
55
52
56
	/**
53
	/**
Lines 60-74 Link Here
60
	 * @return True if the element matches the drag expression from the
57
	 * @return True if the element matches the drag expression from the
61
	 *         extension.
58
	 *         extension.
62
	 */
59
	 */
63
	public boolean isDragElementSupported(Object anElement) {
60
	public boolean isDragElementSupported(Object anElement) { 
64
		if (dragExpr != null)
61
		return contentDescriptor.isPossibleChild(anElement); 
65
			try {
62
	}
66
				return dragExpr
63
67
						.evaluate(new EvaluationContext(null, anElement)) == EvaluationResult.TRUE;
64
	/**
68
			} catch (CoreException e) {
65
	 * 
69
				NavigatorPlugin.logError(0, e.getMessage(), e);
66
	 * @param aSelection
70
			}
67
	 *            The set of elements being dragged.
71
		return false;
68
	 * @return True if the element matches the drag expression from the
69
	 *         extension.
70
	 */
71
	public boolean areDragElementsSupported(IStructuredSelection aSelection) {
72
		if (aSelection.isEmpty())
73
			return false;
74
		return contentDescriptor.arePossibleChildren(aSelection);
72
	}
75
	}
73
76
74
	/**
77
	/**
Lines 79-85 Link Here
79
	 *         extension.
82
	 *         extension.
80
	 */
83
	 */
81
	public boolean isDropElementSupported(Object anElement) {
84
	public boolean isDropElementSupported(Object anElement) {
82
		if (dropExpr != null)
85
		if (dropExpr != null && anElement != null)
83
			try {
86
			try {
84
				return dropExpr
87
				return dropExpr
85
						.evaluate(new EvaluationContext(null, anElement)) == EvaluationResult.TRUE;
88
						.evaluate(new EvaluationContext(null, anElement)) == EvaluationResult.TRUE;
Lines 105-111 Link Here
105
			NavigatorPlugin.logError(0, re.getMessage(), re);
108
			NavigatorPlugin.logError(0, re.getMessage(), re);
106
		}
109
		}
107
		return SkeletonCommonDropAssistant.INSTANCE;
110
		return SkeletonCommonDropAssistant.INSTANCE;
111
	}
108
112
113
	/**
114
	 * 
115
	 * @return The content descriptor that contains this drop descriptor.
116
	 */
117
	public INavigatorContentDescriptor getContentDescriptor() {
118
		return contentDescriptor;
109
	}
119
	}
110
120
111
}
121
}
(-)src/org/eclipse/ui/internal/navigator/dnd/CommonDropDescriptorManager.java (-12 / +71 lines)
Lines 11-23 Link Here
11
11
12
package org.eclipse.ui.internal.navigator.dnd;
12
package org.eclipse.ui.internal.navigator.dnd;
13
13
14
import java.util.HashMap;
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.LinkedHashSet;
17
import java.util.List;
15
import java.util.Map;
18
import java.util.Map;
19
import java.util.Set;
20
import java.util.TreeMap;
16
21
17
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IConfigurationElement;
23
import org.eclipse.ui.internal.navigator.extensions.ExtensionPriorityComparator;
18
import org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtPtConstants;
24
import org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtPtConstants;
19
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentRegistryReader;
25
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentRegistryReader;
20
import org.eclipse.ui.navigator.INavigatorContentDescriptor;
26
import org.eclipse.ui.navigator.INavigatorContentDescriptor;
27
import org.eclipse.ui.navigator.INavigatorContentService;
21
28
22
/**
29
/**
23
 * @since 3.2
30
 * @since 3.2
Lines 27-63 Link Here
27
34
28
	private static final CommonDropDescriptorManager INSTANCE = new CommonDropDescriptorManager();
35
	private static final CommonDropDescriptorManager INSTANCE = new CommonDropDescriptorManager();
29
36
37
	private static final CommonDropAdapterDescriptor[] NO_DESCRIPTORS = new CommonDropAdapterDescriptor[0];
38
30
	/**
39
	/**
31
	 * A map of (INavigatorContentDescriptor,
40
	 * A map of (INavigatorContentDescriptor,
32
	 * CommonDropAdapterDescriptor)-pairs.
41
	 * CommonDropAdapterDescriptor)-pairs.
33
	 */
42
	 */
34
	private final Map dropDescriptors = new HashMap();
43
	private final Map dropDescriptors = new TreeMap(ExtensionPriorityComparator.INSTANCE);
35
44
36
	/**
45
	/**
37
	 * 
46
	 * 
38
	 * @return An initialized singleton instance of the
47
	 * @return An initialized singleton instance of the
39
	 *         CommonDropDescriptorManager.
48
	 *         CommonDropDescriptorManager.
40
	 */
49
	 */
41
	public CommonDropDescriptorManager getInstance() {
50
	public static CommonDropDescriptorManager getInstance() {
42
		return INSTANCE;
51
		return INSTANCE;
43
	}
52
	}
44
53
45
	private CommonDropDescriptorManager() {
54
	private CommonDropDescriptorManager() {
46
		new CommonDropAdapterRegistry().readRegistry();
55
		new CommonDropAdapterRegistry().readRegistry();
47
	}
56
	}
48
	
57
49
	// TODO Add fetch Drop Adapters by match method.
58
	/**
59
	 * 
60
	 * @param aDropTarget
61
	 *            The drop target of the operation
62
	 * @param aContentService
63
	 *            The associated content service to filter results by.
64
	 * @return An array of drop descriptors that can handle the given drop
65
	 *         target and are <i>visible</i> and <i>active</i> for the given
66
	 *         service and <i>enabled</i> for the given drop target..
67
	 */
68
	public CommonDropAdapterDescriptor[] findCommonDropAdapterAssistants(Object aDropTarget, INavigatorContentService aContentService) {
69
70
		Set foundDescriptors = new LinkedHashSet();
71
		for (Iterator iter = dropDescriptors.keySet().iterator(); iter
72
				.hasNext();) {
73
			INavigatorContentDescriptor contentDescriptor = (INavigatorContentDescriptor) iter
74
					.next();
75
			if (aContentService.isVisible(contentDescriptor.getId())
76
					&& aContentService.isActive(contentDescriptor.getId())) {
77
				List dropDescriptors = getDropDescriptors(contentDescriptor);
78
				for (Iterator iterator = dropDescriptors.iterator(); iterator
79
						.hasNext();) {
80
					CommonDropAdapterDescriptor dropDescriptor = (CommonDropAdapterDescriptor) iterator
81
							.next();
82
					if (dropDescriptor.isDropElementSupported(aDropTarget))
83
						foundDescriptors.add(dropDescriptor);
84
				}
85
			}
86
		}
87
88
		if (foundDescriptors.isEmpty())
89
			return NO_DESCRIPTORS;
90
		return (CommonDropAdapterDescriptor[]) foundDescriptors
91
				.toArray(new CommonDropAdapterDescriptor[foundDescriptors
92
						.size()]);
93
	}
94
95
	private List getDropDescriptors(
96
			INavigatorContentDescriptor aContentDescriptor) {
97
		List descriptors = (List) dropDescriptors.get(aContentDescriptor);
98
		if (descriptors != null)
99
			return descriptors;
100
		synchronized (dropDescriptors) {
101
			descriptors = (List) dropDescriptors.get(aContentDescriptor);
102
			if (descriptors == null)
103
				dropDescriptors.put(aContentDescriptor,
104
						(descriptors = new ArrayList()));
105
106
		}
107
		return descriptors;
108
	}
50
109
51
	/**
110
	/**
52
	 * @param aContentDescriptor
111
	 * @param aContentDescriptor
53
	 *            A non-null content descriptor. 
112
	 *            A non-null content descriptor.
54
	 * @param aDropDescriptor
113
	 * @param aDropDescriptor
55
	 *            A non-null drop descriptor.
114
	 *            A non-null drop descriptor.
56
	 */
115
	 */
57
	private void addCommonDropAdapter(
116
	private void addCommonDropAdapter(
58
			INavigatorContentDescriptor aContentDescriptor,
117
			INavigatorContentDescriptor aContentDescriptor,
59
			CommonDropAdapterDescriptor aDropDescriptor) {
118
			CommonDropAdapterDescriptor aDropDescriptor) { 
60
		dropDescriptors.put(aContentDescriptor, aDropDescriptor);
119
		getDropDescriptors(aContentDescriptor).add(aDropDescriptor);
61
	}
120
	}
62
121
63
	private class CommonDropAdapterRegistry extends
122
	private class CommonDropAdapterRegistry extends
Lines 82-94 Link Here
82
							.getContentDescriptor(id);
141
							.getContentDescriptor(id);
83
					if (contentDescriptor != null) {
142
					if (contentDescriptor != null) {
84
143
85
						IConfigurationElement[] commonDropAdapter = element
144
						IConfigurationElement[] commonDropAdapters = element
86
								.getChildren(TAG_COMMON_DROP_ADAPTER);
145
								.getChildren(TAG_COMMON_DROP_ADAPTER);
87
146
88
						if (commonDropAdapter.length == 1) {
147
						for (int i = 0; i < commonDropAdapters.length; i++) {
89
							addCommonDropAdapter(contentDescriptor,
148
							addCommonDropAdapter(contentDescriptor,
90
									new CommonDropAdapterDescriptor(element));
149
									new CommonDropAdapterDescriptor(commonDropAdapters[i], contentDescriptor));
91
						}
150
						} 
92
					}
151
					}
93
				}
152
				}
94
153
(-)src/org/eclipse/ui/internal/navigator/dnd/SkeletonCommonDropAssistant.java (-17 / +21 lines)
Lines 11-18 Link Here
11
11
12
package org.eclipse.ui.internal.navigator.dnd;
12
package org.eclipse.ui.internal.navigator.dnd;
13
13
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
14
import org.eclipse.swt.dnd.DropTargetEvent;
16
import org.eclipse.swt.dnd.DropTargetEvent;
15
import org.eclipse.swt.dnd.TransferData;
17
import org.eclipse.swt.dnd.TransferData;
18
import org.eclipse.ui.navigator.CommonDropAdapter;
16
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
19
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
17
20
18
/**
21
/**
Lines 34-44 Link Here
34
	/*
37
	/*
35
	 * (non-Javadoc)
38
	 * (non-Javadoc)
36
	 * 
39
	 * 
37
	 * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.swt.dnd.DropTargetEvent,
40
	 * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter,
38
	 *      java.lang.Object)
41
	 *      org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object)
39
	 */
42
	 */
40
	public boolean handleDrop(DropTargetEvent aDropTargetEvent, Object aTarget) { 
43
	public IStatus handleDrop(CommonDropAdapter aDropAdapter,
41
		return false;
44
			DropTargetEvent aDropTargetEvent, Object aTarget) {
45
		return Status.CANCEL_STATUS;
42
	}
46
	}
43
47
44
	/*
48
	/*
Lines 47-67 Link Here
47
	 * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object,
51
	 * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object,
48
	 *      int, org.eclipse.swt.dnd.TransferData)
52
	 *      int, org.eclipse.swt.dnd.TransferData)
49
	 */
53
	 */
50
	public boolean validateDrop(Object target, int operation,
54
	public IStatus validateDrop(Object target, int operation,
51
			TransferData transferType) {
55
			TransferData transferType) {
52
56
		return Status.CANCEL_STATUS;
53
		return false;
54
	}
57
	}
55
58
56
	/*
59
	// /*
57
	 * (non-Javadoc)
60
	// * (non-Javadoc)
58
	 * 
61
	// *
59
	 * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#findSupportedTransferData(org.eclipse.swt.dnd.TransferData[])
62
	// * @see
60
	 */
63
	// org.eclipse.ui.navigator.CommonDropAdapterAssistant#findSupportedTransferData(org.eclipse.swt.dnd.TransferData[])
61
	public TransferData findSupportedTransferData(
64
	// */
62
			TransferData[] theAvailableTransferData) {
65
	// public TransferData findSupportedTransferData(
63
66
	// TransferData[] theAvailableTransferData) {
64
		return null;
67
	//
65
	}
68
	// return null;
69
	// }
66
70
67
}
71
}
(-)src/org/eclipse/ui/internal/navigator/extensions/NavigatorContentDescriptor.java (+21 lines)
Lines 11-16 Link Here
11
package org.eclipse.ui.internal.navigator.extensions;
11
package org.eclipse.ui.internal.navigator.extensions;
12
12
13
import java.util.HashSet;
13
import java.util.HashSet;
14
import java.util.Iterator;
14
import java.util.Set;
15
import java.util.Set;
15
16
16
import org.eclipse.core.expressions.ElementHandler;
17
import org.eclipse.core.expressions.ElementHandler;
Lines 22-27 Link Here
22
import org.eclipse.core.runtime.IConfigurationElement;
23
import org.eclipse.core.runtime.IConfigurationElement;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.jface.viewers.ILabelProvider;
25
import org.eclipse.jface.viewers.ILabelProvider;
26
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.jface.viewers.ITreeContentProvider;
27
import org.eclipse.jface.viewers.ITreeContentProvider;
26
import org.eclipse.osgi.util.NLS;
28
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.ui.IPluginContribution;
29
import org.eclipse.ui.IPluginContribution;
Lines 347-352 Link Here
347
		if ((enablement == null && possibleChildren == null)
349
		if ((enablement == null && possibleChildren == null)
348
				|| anElement == null)
350
				|| anElement == null)
349
			return false;
351
			return false;
352
		else if(anElement instanceof IStructuredSelection)
353
			return arePossibleChildren((IStructuredSelection) anElement);
350
354
351
		try {
355
		try {
352
			if (possibleChildren != null)
356
			if (possibleChildren != null)
Lines 360-365 Link Here
360
		}
364
		}
361
		return false;
365
		return false;
362
	}
366
	}
367
	
368
	/**
369
	 * A convenience method to check all elements in a selection. 
370
	 * 
371
	 * @param aSelection A non-null selection
372
	 * @return True if and only if every element in the selection is a possible child.
373
	 */
374
	public boolean arePossibleChildren(IStructuredSelection aSelection) {
375
		if(aSelection.isEmpty())
376
			return false;
377
		for (Iterator iter = aSelection.iterator(); iter.hasNext();) {
378
			Object element = iter.next();
379
			if(!isPossibleChild(element))
380
				return false;			
381
		}
382
		return true;
383
	}
363
384
364
	/**
385
	/**
365
	 * 
386
	 * 
(-)src/org/eclipse/ui/internal/navigator/extensions/NavigatorContentExtension.java (-3 / +2 lines)
Lines 120-129 Link Here
120
		return provider;
120
		return provider;
121
	}
121
	}
122
122
123
	/*
123
	/**
124
	 * (non-Javadoc)
125
	 * 
124
	 * 
126
	 * @see org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtension#getContentProvider()
125
	 * @return The internal content provider that is wrapped by this extension.
127
	 */
126
	 */
128
	public ITreeContentProvider internalGetContentProvider() {
127
	public ITreeContentProvider internalGetContentProvider() {
129
		if (contentProvider != null || contentProviderInitializationFailed)
128
		if (contentProvider != null || contentProviderInitializationFailed)
(-)src/org/eclipse/ui/internal/navigator/extensions/INavigatorContentExtPtConstants.java (-5 / +2 lines)
Lines 34-46 Link Here
34
	String TAG_COMMON_SORTER = "commonSorter"; //$NON-NLS-1$
34
	String TAG_COMMON_SORTER = "commonSorter"; //$NON-NLS-1$
35
	
35
	
36
	/** */
36
	/** */
37
	String TAG_COMMON_DROP_ADAPTER = "commonDropAdapter"; //$NON-NLS-1$	
37
	String TAG_COMMON_DROP_ADAPTER = "commonDropAdapter"; //$NON-NLS-1$	 
38
	
38
	
39
	/** */
39
	/** */
40
	String TAG_DRAG_EXPRESSION = "dragExpression"; //$NON-NLS-1$	 
40
	String TAG_POSSIBLE_DROP_TARGETS = "possibleDropTargets"; //$NON-NLS-1$	 
41
	
42
	/** */
43
	String TAG_DROP_EXPRESSION = "dropExpression"; //$NON-NLS-1$	 
44
	
41
	
45
	/** */
42
	/** */
46
	String TAG_OVERRIDE = "override"; //$NON-NLS-1$	
43
	String TAG_OVERRIDE = "override"; //$NON-NLS-1$	
(-)plugin.xml (-1 / +1 lines)
Lines 11-17 Link Here
11
         point="org.eclipse.ui.dropActions">
11
         point="org.eclipse.ui.dropActions">
12
      <action
12
      <action
13
            class="org.eclipse.ui.internal.navigator.dnd.NavigatorPluginDropAction"
13
            class="org.eclipse.ui.internal.navigator.dnd.NavigatorPluginDropAction"
14
            id="org.eclipse.ui.navigator.internal.dnd.PluginDropAction">
14
            id="org.eclipse.ui.navigator.PluginDropAction">
15
      </action>
15
      </action>
16
   </extension>
16
   </extension>
17
   
17
   
(-)src/org/eclipse/ui/internal/navigator/NavigatorContentService.java (-4 / +15 lines)
Lines 30-35 Link Here
30
import org.eclipse.jface.viewers.ITreeContentProvider;
30
import org.eclipse.jface.viewers.ITreeContentProvider;
31
import org.eclipse.jface.viewers.StructuredViewer;
31
import org.eclipse.jface.viewers.StructuredViewer;
32
import org.eclipse.jface.viewers.Viewer;
32
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.swt.widgets.Shell;
33
import org.eclipse.ui.IMemento;
34
import org.eclipse.ui.IMemento;
34
import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
35
import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
35
import org.eclipse.ui.internal.navigator.extensions.ExtensionPriorityComparator;
36
import org.eclipse.ui.internal.navigator.extensions.ExtensionPriorityComparator;
Lines 914-922 Link Here
914
			navigatorDnDService = new NavigatorDnDService(this);
915
			navigatorDnDService = new NavigatorDnDService(this);
915
		return navigatorDnDService;
916
		return navigatorDnDService;
916
	}
917
	}
917
918
	
918
	protected boolean isRootExtension(String anExtensionId) {
919
	/**
919
		return assistant.isRootExtension(anExtensionId);
920
	 * Non-API method to return a shell.
921
	 * @return A shell associated with the current viewer (if any) or <b>null</b>.
922
	 */
923
	public Shell getShell() {
924
		if(structuredViewerManager != null && structuredViewerManager.getViewer() != null)
925
			return structuredViewerManager.getViewer().getControl().getShell();
926
		return null;
920
	}
927
	}
921
928
922
	/*
929
	/*
Lines 935-942 Link Here
935
	 */
942
	 */
936
	public String toString() {
943
	public String toString() {
937
		return "ContentService[" + viewerDescriptor.getViewerId() + "]"; //$NON-NLS-1$//$NON-NLS-2$
944
		return "ContentService[" + viewerDescriptor.getViewerId() + "]"; //$NON-NLS-1$//$NON-NLS-2$
945
	} 
946
	
947
	protected boolean isRootExtension(String anExtensionId) {
948
		return assistant.isRootExtension(anExtensionId);
938
	}
949
	}
939
950
	
940
	private void notifyListeners(NavigatorContentExtension aDescriptorInstance) {
951
	private void notifyListeners(NavigatorContentExtension aDescriptorInstance) {
941
952
942
		if (listeners.size() == 0)
953
		if (listeners.size() == 0)
(-)src/org/eclipse/ui/internal/navigator/dnd/NavigatorContentServiceTransfer.java (+93 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.navigator.dnd;
13
14
import java.lang.ref.WeakReference;
15
import java.util.HashSet;
16
import java.util.Iterator;
17
import java.util.Set;
18
19
import org.eclipse.ui.navigator.INavigatorContentService;
20
21
/**
22
 * Caches instances of {@link INavigatorContentService} to facilitate the
23
 * handling of drop operations in other viewers.
24
 * 
25
 * @since 3.2
26
 * 
27
 */
28
public class NavigatorContentServiceTransfer {
29
	
30
	private static final NavigatorContentServiceTransfer instance = new NavigatorContentServiceTransfer(); 
31
	
32
	/**
33
	 * 
34
	 * @return The singleton instance of the transfer service.
35
	 */
36
	public static NavigatorContentServiceTransfer getInstance() {
37
		return instance;
38
	}
39
40
	private final Set registeredContentServices = new HashSet();
41
	
42
	/**
43
	 *  
44
	 * @param aContentService The Content Service to register.
45
	 */
46
	public synchronized void registerContentService(INavigatorContentService aContentService) { 
47
		if(findService(aContentService.getViewerId()) == null)
48
			registeredContentServices.add(new WeakReference(aContentService));
49
	}
50
	
51
	/**
52
	 *  
53
	 * @param aContentService The Content Service to unregister.
54
	 */
55
	public synchronized void unregisterContentService(INavigatorContentService aContentService) { 
56
  
57
		for (Iterator iter = registeredContentServices.iterator(); iter.hasNext();) {
58
			WeakReference ref = (WeakReference) iter.next();
59
			if(ref.get() == null) 
60
				iter.remove();
61
			else { 
62
				if(ref.get() == aContentService) {
63
					iter.remove(); 
64
					return;
65
				}
66
			}
67
		} 
68
	}
69
	
70
	/**
71
	 * 
72
	 * @param aViewerId A viewer id that should have previously been registered with the service.
73
	 * @return The registered content service for the given viewer id.
74
	 */
75
	public synchronized INavigatorContentService findService(String aViewerId) {
76
		if(aViewerId == null || aViewerId.length() == 0)
77
			return null;
78
		INavigatorContentService contentService;
79
		for (Iterator iter = registeredContentServices.iterator(); iter.hasNext();) {
80
			WeakReference ref = (WeakReference) iter.next();
81
			if(ref.get() == null) 
82
				iter.remove();
83
			else {
84
				contentService = (INavigatorContentService)ref.get();
85
				if(aViewerId.equals(contentService.getViewerId())) 
86
					return contentService; 
87
			}
88
		}
89
		return null;
90
	} 
91
	
92
93
}

Return to bug 129061