001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.navigator;
011:
012: import org.eclipse.jface.util.LocalSelectionTransfer;
013: import org.eclipse.jface.viewers.IStructuredSelection;
014: import org.eclipse.swt.dnd.DragSourceEvent;
015: import org.eclipse.swt.dnd.Transfer;
016: import org.eclipse.swt.dnd.TransferData;
017: import org.eclipse.swt.widgets.Event;
018: import org.eclipse.swt.widgets.Shell;
019: import org.eclipse.ui.PlatformUI;
020: import org.eclipse.ui.internal.navigator.NavigatorContentService;
021: import org.eclipse.ui.part.PluginTransfer;
022:
023: /**
024: * Assist the {@link CommonDragAdapter} by providing new TransferTypes and the
025: * logic to handle setting up the transfer data. Clients must extend this class
026: * as part of the <b>org.eclipse.ui.navigator.viewer/dragAssistant</b>
027: * extension. By default, the Common Navigator supports
028: * {@link LocalSelectionTransfer} and {@link PluginTransfer}.
029: *
030: * <p>
031: * Clients may extend this class.
032: * </p>
033: *
034: * @see INavigatorDnDService
035: * @see CommonDragAdapter
036: * @see CommonDropAdapter
037: * @see CommonDropAdapterAssistant
038: * @see CommonViewer
039: * @see <a
040: * href="http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html">Drag
041: * and Drop: Adding Drag and Drop to an SWT Application</a>
042: * @see <a
043: * href="http://www.eclipse.org/articles/Article-Workbench-DND/drag_drop.html">Drag
044: * and Drop in the Eclipse UI (Custom Transfer Types)</a>
045: *
046: * @since 3.2
047: *
048: */
049: public abstract class CommonDragAdapterAssistant {
050:
051: private INavigatorContentService contentService;
052:
053: /**
054: * Extra TransferTypes allow the Navigator to generate different kinds of
055: * payloads for DND clients. By default, the {@link CommonDragAdapter}
056: * supports {@link LocalSelectionTransfer} and {@link PluginTransfer}.
057: *
058: * <p>
059: * CommonDragAdapterAssistants can extend the available TransferTypes that a
060: * Common Navigator Viewer can generate. Clients should return the set of
061: * Transfer Types they support. When a drop event occurs, the available drag
062: * assistants will be searched for a <i>enabled</i> assistants for the
063: * {@link DragSourceEvent}. Only if the drop event occurs will
064: * {@link #setDragData(DragSourceEvent, IStructuredSelection)} be called. If
065: * the drop event is cancelled,
066: * {@link #setDragData(DragSourceEvent, IStructuredSelection)} will not be
067: * called.
068: * </p>
069: *
070: * @return The added transfer types. (e.g. FileTransfer.getInstance()).
071: */
072: public abstract Transfer[] getSupportedTransferTypes();
073:
074: /**
075: * Set the value of the {@link org.eclipse.swt.widgets.Event#data} field using the given selection.
076: * Clients will only have an opportunity to set the drag data if they have
077: * returned a matching Transfer Type from
078: * {@link #getSupportedTransferTypes()} for the
079: * {@link DragSourceEvent#dataType}.
080: * <p>
081: * Clients will only have an opportunity to set the data when the drop event
082: * occurs. If the drop operation is cancelled, then this method will not be
083: * called.
084: * </p>
085: *
086: * @param anEvent
087: * The event object should have its {@link Event#data} field set
088: * to a value that matches a supported {@link TransferData} type.
089: * @param aSelection
090: * The current selection from the viewer.
091: * @return True if the data could be set; false otherwise.
092: */
093: public abstract boolean setDragData(DragSourceEvent anEvent,
094: IStructuredSelection aSelection);
095:
096: /**
097: * Accept and remember the content service this assistant is associated
098: * with.
099: *
100: * @param aContentService
101: */
102: public final void setContentService(
103: INavigatorContentService aContentService) {
104: contentService = aContentService;
105: }
106:
107: /**
108: *
109: * @return The associated content service.
110: */
111: public INavigatorContentService getContentService() {
112: return contentService;
113: }
114:
115: /**
116: *
117: * @return The shell for the viewer this assistant is associated with or the
118: * shell of the active workbench window.
119: */
120: public final Shell getShell() {
121: if (contentService != null) {
122: ((NavigatorContentService) contentService).getShell();
123: }
124: return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
125: .getShell();
126: }
127:
128: }
|