1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2006, 2009 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.navigator;
|
13
|
|
14
|
import org.eclipse.jface.util.LocalSelectionTransfer;
|
15
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
16
|
import org.eclipse.swt.dnd.DragSourceEvent;
|
17
|
import org.eclipse.swt.dnd.DragSourceListener;
|
18
|
import org.eclipse.swt.dnd.Transfer;
|
19
|
import org.eclipse.swt.dnd.TransferData;
|
20
|
import org.eclipse.swt.widgets.Event;
|
21
|
import org.eclipse.swt.widgets.Shell;
|
22
|
import org.eclipse.ui.PlatformUI;
|
23
|
import org.eclipse.ui.internal.navigator.NavigatorContentService;
|
24
|
import org.eclipse.ui.part.PluginTransfer;
|
25
|
|
26
|
/**
|
27
|
* Assist the {@link CommonDragAdapter} by providing new TransferTypes and the
|
28
|
* logic to handle setting up the transfer data. Clients must extend this class
|
29
|
* as part of the <b>org.eclipse.ui.navigator.viewer/dragAssistant</b>
|
30
|
* extension. By default, the Common Navigator supports
|
31
|
* {@link LocalSelectionTransfer} and {@link PluginTransfer}.
|
32
|
*
|
33
|
* <p>
|
34
|
* Clients may extend this class.
|
35
|
* </p>
|
36
|
*
|
37
|
* @see INavigatorDnDService
|
38
|
* @see CommonDragAdapter
|
39
|
* @see CommonDropAdapter
|
40
|
* @see CommonDropAdapterAssistant
|
41
|
* @see CommonViewer
|
42
|
* @see <a
|
43
|
* href="http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html">Drag
|
44
|
* and Drop: Adding Drag and Drop to an SWT Application</a>
|
45
|
* @see <a
|
46
|
* href="http://www.eclipse.org/articles/Article-Workbench-DND/drag_drop.html">Drag
|
47
|
* and Drop in the Eclipse UI (Custom Transfer Types)</a>
|
48
|
*
|
49
|
* @since 3.2
|
50
|
*
|
51
|
*/
|
52
|
public abstract class CommonDragAdapterAssistant {
|
53
|
|
54
|
private INavigatorContentService contentService;
|
55
|
|
56
|
/**
|
57
|
* Extra TransferTypes allow the Navigator to generate different kinds of
|
58
|
* payloads for DND clients. By default, the {@link CommonDragAdapter}
|
59
|
* supports {@link LocalSelectionTransfer} and {@link PluginTransfer}.
|
60
|
*
|
61
|
* <p>
|
62
|
* CommonDragAdapterAssistants can extend the available TransferTypes that a
|
63
|
* Common Navigator Viewer can generate. Clients should return the set of
|
64
|
* Transfer Types they support. When a drop event occurs, the available drag
|
65
|
* assistants will be searched for a <i>enabled</i> assistants for the
|
66
|
* {@link DragSourceEvent}. Only if the drop event occurs will
|
67
|
* {@link #setDragData(DragSourceEvent, IStructuredSelection)} be called. If
|
68
|
* the drop event is cancelled,
|
69
|
* {@link #setDragData(DragSourceEvent, IStructuredSelection)} will not be
|
70
|
* called.
|
71
|
* </p>
|
72
|
*
|
73
|
* @return The added transfer types. (e.g. FileTransfer.getInstance()).
|
74
|
*/
|
75
|
public abstract Transfer[] getSupportedTransferTypes();
|
76
|
|
77
|
/**
|
78
|
* Set the value of the {@link org.eclipse.swt.widgets.Event#data} field using the given selection.
|
79
|
* Clients will only have an opportunity to set the drag data if they have
|
80
|
* returned a matching Transfer Type from
|
81
|
* {@link #getSupportedTransferTypes()} for the
|
82
|
* {@link DragSourceEvent#dataType}.
|
83
|
* <p>
|
84
|
* Clients will only have an opportunity to set the data when the drop event
|
85
|
* occurs. If the drop operation is cancelled, then this method will not be
|
86
|
* called.
|
87
|
* </p>
|
88
|
*
|
89
|
* @param anEvent
|
90
|
* The event object should have its {@link Event#data} field set
|
91
|
* to a value that matches a supported {@link TransferData} type.
|
92
|
* @param aSelection
|
93
|
* The current selection from the viewer.
|
94
|
* @return True if the data could be set; false otherwise.
|
95
|
*/
|
96
|
public abstract boolean setDragData(DragSourceEvent anEvent,
|
97
|
IStructuredSelection aSelection);
|
98
|
|
99
|
/**
|
100
|
*
|
101
|
* Allows the drag assistant indicate it wants to participate in the drag operation.
|
102
|
* This is called at {@link DragSourceListener#dragStart(DragSourceEvent)}
|
103
|
* time.
|
104
|
*
|
105
|
* @param anEvent
|
106
|
* The event object should return doit = true if it wants to participate
|
107
|
* in the drag and set doit = false if it does not want to further
|
108
|
* participate.
|
109
|
* @param aSelection
|
110
|
* The current selection from the viewer.
|
111
|
*
|
112
|
* @since 3.4
|
113
|
*/
|
114
|
public void dragStart(DragSourceEvent anEvent,
|
115
|
IStructuredSelection aSelection) {
|
116
|
// May be subclassed
|
117
|
}
|
118
|
|
119
|
/**
|
120
|
*
|
121
|
* Allows the drag assistant to do any necessary cleanup after the drop operation
|
122
|
* is done. This is called at {@link DragSourceListener#dragFinished(DragSourceEvent)}
|
123
|
* time. This is called on the same assistant that was called for the set data.
|
124
|
*
|
125
|
* @param anEvent
|
126
|
* The event object should have its {@link Event#data} field set
|
127
|
* to a value that matches a supported {@link TransferData} type.
|
128
|
* @param aSelection
|
129
|
* The current selection from the viewer.
|
130
|
*
|
131
|
* @since 3.4
|
132
|
*/
|
133
|
public void dragFinished(DragSourceEvent anEvent,
|
134
|
IStructuredSelection aSelection) {
|
135
|
// May be subclassed
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Accept and remember the content service this assistant is associated
|
140
|
* with.
|
141
|
*
|
142
|
* @param aContentService
|
143
|
*/
|
144
|
public final void setContentService(INavigatorContentService aContentService) {
|
145
|
contentService = aContentService;
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
*
|
150
|
* @return The associated content service.
|
151
|
*/
|
152
|
public INavigatorContentService getContentService() {
|
153
|
return contentService;
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
*
|
158
|
* @return The shell for the viewer this assistant is associated with or the
|
159
|
* shell of the active workbench window.
|
160
|
*/
|
161
|
public final Shell getShell() {
|
162
|
if (contentService != null) {
|
163
|
((NavigatorContentService) contentService).getShell();
|
164
|
}
|
165
|
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
|
166
|
}
|
167
|
|
168
|
}
|