# com.bea.ide.sourceeditor.driver
SourceViewDragDropDriver Class

public class SourceViewDragDropDriver
extends `DefaultDragDropDriver`

A TransferHandler to handle both drags originating in the source view, and drops onto the source view that come from the same source view, another source view, or anywhere else.

A derived class may want to override some of the methods to handle additional drag flavors. The methods to consider overriding include:
`isDragSupported()```
`getInsertionPosition()```
`getInsertionString()```

Generally, I would discourage overriding anything else.

Hierarchy
  `Object`
  `DefaultDragDropDriver`
  `SourceViewDragDropDriver`

All Implemented Interfaces
  `IDragDropDriver`

## Nested Class Summary

Nested classes from com.bea.ide.core.datatransfer`.`DefaultDragDropDriver``
``DefaultDragDropDriver.DragSourceInfo``

## Field Summary

`protected `ISourceDocument`` | `_sourceDoc` ISourceDocument
`protected `ISourceView`` | `_sourceView` ISourceView
`protected `JTextComponent`` | `_textView` JTextComponent

## Constructor Summary

SourceViewDragDropDriver(`ISourceDocument` doc)

## Method Summary

`public void` | `attach`(`ISourceView` sv, `JTextComponent` view)
`public void` | `dragComplete`(`Transferable` t, boolean success, int action, `Component` c) Called on the source driver when a drag is done, whether or not it was ever dropped.
`public void` | `dragExit`(`Component` c) Called on the target driver when a drag is cancelled, or at least temporarily disabled because the mouse has moved outside of the component.
`public int` | `dragOver`(`IDragDropContext` dc) Called during a drag to confirm that this target driver can accept the dragged object.
`public boolean` | `drop`(`IDragDropContext` dc) Called on the target driver when something is dropped on it.
`public `IDragDropDriver.IDragSourceInfo`` | `getDragInfo`(`Component` c, `Point` pt) Called on the source driver to initiate a drag.
`protected int` | `getInsertionPosition`(`IDragDropContext` dc) When something is being dragged over the source view, `SourceViewDragDropDriver.dragOver(IDragDropContext)``` calls this method to ascertain where to show a drop caret.
`protected `String`` | `getInsertionString`(`IDragDropContext` dc) Called by `SourceViewDragDropDriver.drop(IDragDropContext)``` to convert a drag-drop context into a string to insert into the document.
`protected int` | `isDragSupported`(`IDragDropContext` dc) When something is being dragged over the source view, `SourceViewDragDropDriver.dragOver(IDragDropContext)``` calls this method to ascertain whether or not it may be dropped into our view.
`protected boolean` | `isSourceAndTarget`() Determines if the user is dragging an object within a single view.
`protected void` | `updateInsertionCaret`(int pos) Tells the TextView to draw a special caret icon where the dragged text would be dropped.

Methods from class `java.lang.`Object``
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods from interface `com.bea.ide.core.datatransfer.`IDragDropDriver``
``dragComplete`, `dragExit`, `dragOver`, `drop`, `getDragInfo``

## Field Detail

### _sourceDoc

    protected ISourceDocument _sourceDoc

### _sourceView

    protected ISourceView _sourceView

### _textView

    protected JTextComponent _textView

## Constructor Detail

### SourceViewDragDropDriver

    public SourceViewDragDropDriver(ISourceDocument doc)

## Method Detail

### attach(ISourceView, JTextComponent) Method

    public void attach(ISourceView sv,
                       JTextComponent view)

### dragComplete(Transferable, boolean, int, Component) Method

    public void dragComplete(Transferable t,
                             boolean success,
                             int action,
                             Component c)

Called on the source driver when a drag is done, whether or not it was ever dropped. If the drag succeeded, and the action was a move (rather than a copy), then the source text should be removed from the document.

Overrides
  `DefaultDragDropDriver.dragComplete(Transferable, boolean, int, Component)`

#### Parameters

t
  Transferable that was used in the transfer

success
  Boolean value indicating whether or not the drop completed successfully

action
  DnDConstants integer value indicating the type of action the drop represented

c
  Component that was the source of the drag and drop

Related Topics

``DefaultDragDropDriver.dragComplete(Transferable, boolean, int, Component)``

### dragExit(Component) Method

    public void dragExit(Component c)

Called on the target driver when a drag is cancelled, or at least temporarily disabled because the mouse has moved outside of the component.

Overrides
  `DefaultDragDropDriver.dragExit(Component)`

#### Parameters

c
  the component for which the drag is cancelled

Related Topics

``DefaultDragDropDriver.dragExit(Component)``

### dragOver(IDragDropContext) Method

    public int dragOver(IDragDropContext dc)

Called during a drag to confirm that this target driver can accept the dragged object.

Do not override this method. Rather, override `SourceViewDragDropDriver.isDragSupported(IDragDropContext)``` and `SourceViewDragDropDriver.getInsertionPosition(IDragDropContext)``` to indicate what and how data may be dragged.

Overrides
  `DefaultDragDropDriver.dragOver(IDragDropContext)`

#### Parameters

dc
  the drag context object to use in determining the action for a drop

#### Returns

DnDConstants.ACTION_NONE if a drop cannot be done at the current location otherwise, the action that will be performed given a drop at the current location

Related Topics

``DefaultDragDropDriver.dragOver(IDragDropContext)``

### drop(IDragDropContext) Method

    public boolean drop(IDragDropContext dc)

Called on the target driver when something is dropped on it.

Do not override this method. Rather, override `SourceViewDragDropDriver.getInsertionString(IDragDropContext)``` and `SourceViewDragDropDriver.getInsertionPosition(IDragDropContext)``` to indicate what string to insert and where to insert it, or to indicate that the drop should be cancelled.

Overrides
  `DefaultDragDropDriver.drop(IDragDropContext)`

#### Parameters

dc
  the drop context object to use in determining the information for the drop

#### Returns

true if the transfer completes successfully, false otherwise

Related Topics

``DefaultDragDropDriver.drop(IDragDropContext)``

### getDragInfo(Component, Point) Method

    public IDragDropDriver.IDragSourceInfo getDragInfo(Component c,
                                                       Point pt)

Called on the source driver to initiate a drag.

Overrides
  `DefaultDragDropDriver.getDragInfo(Component, Point)`

#### Parameters

c
  Component where the drag is starting

pt
  Point representing the start of the drag

#### Returns

interface to a drag source information object or null if drag is not valid

Related Topics

``DefaultDragDropDriver.getDragInfo(Component, Point)``

### getInsertionPosition(IDragDropContext) Method

    protected int getInsertionPosition(IDragDropContext dc)

When something is being dragged over the source view, `SourceViewDragDropDriver.dragOver(IDragDropContext)``` calls this method to ascertain where to show a drop caret. The drop caret indicates the precise position in the document at which the dropped text would be inserted.

This method is only called after calling `SourceViewDragDropDriver.isDragSupported(IDragDropContext)```, so there is a presumption that a drop would be valid.

#### Parameters

dc
  Context to evaluate for drop operation. It contains information regarding the type of operation (move, copy or link), the coordinates of the dragging mouse, the data being dragged, and more.

#### Returns

a character position in the document. While dragging, the drop caret is shown at this position. When dropped, the dragged data is insert at this position.

Note that when dragging and dropping within one source view, if the position returned is inside of the selection being dragged, then the drag-drop will do nothing.

### getInsertionString(IDragDropContext) Method

    protected String getInsertionString(IDragDropContext dc)

Called by `SourceViewDragDropDriver.drop(IDragDropContext)``` to convert a drag-drop context into a string to insert into the document.

By default, we only support string flavors.

If derived classes add more formats to `SourceViewDragDropDriver.isDragSupported(IDragDropContext)```, then those classes need to override this method as well to convert those other formats to strings.

If the derived class doesn't want to insert anything, but instead wants to launch a wizard or something, they should launch the wizard from within this method, and then return null.

#### Parameters

dc
  Context to evaluate for drop operation. It contains information regarding the type of operation (move, copy or link), the coordinates of the dragging mouse, the data being dragged, and more.

#### Returns

the text to be inserted into the document.

"" may be returned if no text should be inserted.

Return null to indicate the drop actually failed.

### isDragSupported(IDragDropContext) Method

    protected int isDragSupported(IDragDropContext dc)

When something is being dragged over the source view, `SourceViewDragDropDriver.dragOver(IDragDropContext)``` calls this method to ascertain whether or not it may be dropped into our view.

The default implementation is to only support drag-dropping of strings.

Derived classes may recognize other data flavors, constrain drop coordinates, or whatever.

#### Parameters

dc
  Context to evaluate for drop operation. It contains information regarding the type of operation (move, copy or link), the coordinates of the dragging mouse, the data being dragged, and more.

#### Returns

a code to indicate how the drag is supported.
DnDConstrants.ACTION_NONE indicates the object may not be dropped on this view. A no-drop cursor should be shown.
DnDConstrants.ACTION_COPY or ACTION_MOVE both indicate support, but only if they coincide with the drag source action.
Generally, DnDConstrants.ACTION_LINK is not used, but there's no reason why it couldn't be.

Related Topics

``DataFlavor``

### isSourceAndTarget() Method

    protected boolean isSourceAndTarget()

Determines if the user is dragging an object within a single view.

#### Returns

true if this driver is both the source and target of a drag-drop.

### updateInsertionCaret(int) Method

    protected void updateInsertionCaret(int pos)

Tells the TextView to draw a special caret icon where the dragged text would be dropped. This will look slightly different than the cursor, so as not to confuse the user.

#### Parameters

pos
  The character position at which to draw the drop caret.

  if pos is negative, the drop caret is hidden.