Extension SDK 9.0.5

oracle.jdeveloper.ceditor
Class DropHandlerPlugin

java.lang.Object
  extended byoracle.jdeveloper.ceditor.DropHandlerPlugin
All Implemented Interfaces:
EditorPlugin, java.util.EventListener, java.beans.PropertyChangeListener

public abstract class DropHandlerPlugin
extends java.lang.Object
implements EditorPlugin

The DropHandlerPlugin is an abstract class that allows code editor clients to extend the drop functionality of Drag & Drop for the code editor to support additional data flavors or even custom drop behavior.

Since this is an EditorPlugin implementation, it should be installed into an editor through an EditorPluginsFactory instance.


Constructor Summary
DropHandlerPlugin()
          Constructs a new DropHandlerPlugin instance.
 
Method Summary
 void deinstall(BasicEditorPane editor)
          Called when the plugin is being removed from the BasicEditorPane (for example when the editor is closed.) This is used to notify plugins that they should unregister any listeners that were attached.
protected abstract  java.awt.datatransfer.DataFlavor[] getDataFlavors()
          Fetch an array of supported DataFlavor objects, indicating what flavors the data can be provided in.
protected  BasicDocument getDocument()
          Fetch the document of the editor.
protected  EditDescriptor getDropDescriptor()
          Fetch the edit descriptor that should be used for the undoable event associated with this drop operation.
protected  BasicEditorPane getEditorPane()
          Fetch the editor.
protected abstract  java.lang.String getTransferText(java.awt.datatransfer.Transferable transferable)
          Fetch the text to drop in the editor based on the transferable in the drag and drop operation.
protected  void insertDropText(java.awt.datatransfer.Transferable transferable, int offset)
          Perform the actual insertion of text for the drop operation.
 void install(BasicEditorPane editor)
          Called when this plugin is being installed into the BasicEditorPane.
protected  boolean performDrop(java.awt.datatransfer.Transferable transferable, int offset)
          Perform the actual drop operation for the given transferable and offset.
protected  void postInsertDropText(java.awt.datatransfer.Transferable transferable, int offset)
          Perform any additional text editing within the same undo as the drop (which has already been performed.) This allows any implementations to perform any extra text edits (such as adding import-type statements) associated with the text that was dropped.
 void propertyChange(java.beans.PropertyChangeEvent event)
          This method gets called when a bound property is changed.
protected  void raiseEditorToFront()
          Utility routine which will raise the window containing the editor to the front, and place focus in the editor.
protected  boolean shouldAllowDrag(java.awt.datatransfer.DataFlavor dataFlavor, int offset)
          Fetch whether the drag of the given transferable data flavor should be allowed over the given offset location.
protected  boolean shouldPaintDragLocation(java.awt.datatransfer.DataFlavor dataFlavor)
          Fetch whether the drag target location should be painted for the given data flavor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DropHandlerPlugin

public DropHandlerPlugin()
Constructs a new DropHandlerPlugin instance.

Method Detail

install

public final void install(BasicEditorPane editor)
Called when this plugin is being installed into the BasicEditorPane.

Specified by:
install in interface EditorPlugin
Parameters:
editor - the editor pane

deinstall

public void deinstall(BasicEditorPane editor)
Called when the plugin is being removed from the BasicEditorPane (for example when the editor is closed.) This is used to notify plugins that they should unregister any listeners that were attached.

Specified by:
deinstall in interface EditorPlugin
Parameters:
editor - the editor pane

getEditorPane

protected final BasicEditorPane getEditorPane()
Fetch the editor.

Returns:
the editor

getDocument

protected final BasicDocument getDocument()
Fetch the document of the editor.

Returns:
the editor document

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
This method gets called when a bound property is changed.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
event - A PropertyChangeEvent object describing the event source and the property that has changed.

raiseEditorToFront

protected final void raiseEditorToFront()
Utility routine which will raise the window containing the editor to the front, and place focus in the editor.


getDataFlavors

protected abstract java.awt.datatransfer.DataFlavor[] getDataFlavors()
Fetch an array of supported DataFlavor objects, indicating what flavors the data can be provided in. Implementations should specify any custom data flavors that should be supported. Do not specify the default String and Unicode data flavors, or else it may cause unexpected results during actual drop operations.

Returns:
an array of data flavors in which this data can be transferred

getTransferText

protected abstract java.lang.String getTransferText(java.awt.datatransfer.Transferable transferable)
Fetch the text to drop in the editor based on the transferable in the drag and drop operation.

Parameters:
transferable - the transferable involved
Returns:
the text contained in the transferable

shouldPaintDragLocation

protected boolean shouldPaintDragLocation(java.awt.datatransfer.DataFlavor dataFlavor)
Fetch whether the drag target location should be painted for the given data flavor. The specified data flavor will be one of the data flavors specified as supported by this handler.

In general, drops that will insert text into the code editor should paint the target location. If you add extra data flavors that may not result in an edit (i.e., open an editor), then false should be returned here for those data flavors.

Parameters:
dataFlavor - the current data flavor

shouldAllowDrag

protected boolean shouldAllowDrag(java.awt.datatransfer.DataFlavor dataFlavor,
                                  int offset)
Fetch whether the drag of the given transferable data flavor should be allowed over the given offset location. Note that this is called in response to a drag event (not a drop event) where our editor is the current drop container. The specified data flavor will be one of the data flavors specified as supported by this handler.

In general, drags should be allowed unless your data flavor has restrictions on where in the container the drop can be allowed.

Parameters:
dataFlavor - the current data flavor
offset - the offset location that is the drop location

performDrop

protected boolean performDrop(java.awt.datatransfer.Transferable transferable,
                              int offset)
Perform the actual drop operation for the given transferable and offset. Note that this is called when the drop actually occurs (user released mouse), and will be called only when the data flavor of the transferable matches one of this implementation's supported data flavors.

Implementations should not need to override this routine unless the drop operation is some other task besides dropping the text content of the transferable (such as opening another window.)

Parameters:
transferable - the transferable associated with the drop
offset - the location of the drop

insertDropText

protected void insertDropText(java.awt.datatransfer.Transferable transferable,
                              int offset)
                       throws javax.swing.text.BadLocationException
Perform the actual insertion of text for the drop operation. Implementations can override this routine if the drop operation should not insert the given transferred text (i.e., it may edit the given text near the offset area in some other fashion.)

Parameters:
transferable - the transferable associated with the drop
offset - the offset associated with the drop
Throws:
javax.swing.text.BadLocationException

postInsertDropText

protected void postInsertDropText(java.awt.datatransfer.Transferable transferable,
                                  int offset)
                           throws javax.swing.text.BadLocationException
Perform any additional text editing within the same undo as the drop (which has already been performed.) This allows any implementations to perform any extra text edits (such as adding import-type statements) associated with the text that was dropped.

Parameters:
transferable - the transferable that was dropped
offset - the offset where the drop had occurred
Throws:
javax.swing.text.BadLocationException

getDropDescriptor

protected EditDescriptor getDropDescriptor()
Fetch the edit descriptor that should be used for the undoable event associated with this drop operation. Implementations that want to use their own edit descriptor (with a different undo text description) may override this.

Returns:
the undo edit descriptor to use

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.