KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > navigator > CommonDragAdapterAssistant


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.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.Transfer;
18 import org.eclipse.swt.dnd.TransferData;
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;
23 import org.eclipse.ui.part.PluginTransfer;
24
25 /**
26  * Assist the {@link CommonDragAdapter} by providing new TransferTypes and the
27  * logic to handle setting up the transfer data. Clients must extend this class
28  * as part of the <b>org.eclipse.ui.navigator.viewer/dragAssistant</b>
29  * extension. By default, the Common Navigator supports
30  * {@link LocalSelectionTransfer} and {@link PluginTransfer}.
31  *
32  * <p>
33  * Clients may extend this class.
34  * </p>
35  *
36  * @see INavigatorDnDService
37  * @see CommonDragAdapter
38  * @see CommonDropAdapter
39  * @see CommonDropAdapterAssistant
40  * @see CommonViewer
41  * @see <a
42  * HREF="http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html">Drag
43  * and Drop: Adding Drag and Drop to an SWT Application</a>
44  * @see <a
45  * HREF="http://www.eclipse.org/articles/Article-Workbench-DND/drag_drop.html">Drag
46  * and Drop in the Eclipse UI (Custom Transfer Types)</a>
47  *
48  * @since 3.2
49  *
50  */

51 public abstract class CommonDragAdapterAssistant {
52
53     private INavigatorContentService contentService;
54
55     /**
56      * Extra TransferTypes allow the Navigator to generate different kinds of
57      * payloads for DND clients. By default, the {@link CommonDragAdapter}
58      * supports {@link LocalSelectionTransfer} and {@link PluginTransfer}.
59      *
60      * <p>
61      * CommonDragAdapterAssistants can extend the available TransferTypes that a
62      * Common Navigator Viewer can generate. Clients should return the set of
63      * Transfer Types they support. When a drop event occurs, the available drag
64      * assistants will be searched for a <i>enabled</i> assistants for the
65      * {@link DragSourceEvent}. Only if the drop event occurs will
66      * {@link #setDragData(DragSourceEvent, IStructuredSelection)} be called. If
67      * the drop event is cancelled,
68      * {@link #setDragData(DragSourceEvent, IStructuredSelection)} will not be
69      * called.
70      * </p>
71      *
72      * @return The added transfer types. (e.g. FileTransfer.getInstance()).
73      */

74     public abstract Transfer[] getSupportedTransferTypes();
75
76     /**
77      * Set the value of the {@link org.eclipse.swt.widgets.Event#data} field using the given selection.
78      * Clients will only have an opportunity to set the drag data if they have
79      * returned a matching Transfer Type from
80      * {@link #getSupportedTransferTypes()} for the
81      * {@link DragSourceEvent#dataType}.
82      * <p>
83      * Clients will only have an opportunity to set the data when the drop event
84      * occurs. If the drop operation is cancelled, then this method will not be
85      * called.
86      * </p>
87      *
88      * @param anEvent
89      * The event object should have its {@link Event#data} field set
90      * to a value that matches a supported {@link TransferData} type.
91      * @param aSelection
92      * The current selection from the viewer.
93      * @return True if the data could be set; false otherwise.
94      */

95     public abstract boolean setDragData(DragSourceEvent anEvent,
96             IStructuredSelection aSelection);
97
98     /**
99      * Accept and remember the content service this assistant is associated
100      * with.
101      *
102      * @param aContentService
103      */

104     public final void setContentService(INavigatorContentService aContentService) {
105         contentService = aContentService;
106     }
107
108     /**
109      *
110      * @return The associated content service.
111      */

112     public INavigatorContentService getContentService() {
113         return contentService;
114     }
115
116     /**
117      *
118      * @return The shell for the viewer this assistant is associated with or the
119      * shell of the active workbench window.
120      */

121     public final Shell getShell() {
122         if (contentService != null) {
123             ((NavigatorContentService) contentService).getShell();
124         }
125         return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
126     }
127
128 }
129
Popular Tags