Dragging a workbench part is triggered by calling DragUtil.performDrag.
SWT controls can respond to drag / drop by registering an
IDragOverListener with DragUtil .addDragTarget. If multiple drag
listeners are registered for the same screen position, the one
associated with the most specific control gets precidence.
Rather than register drag listeners directly, LayoutParts implement a
getDropTarget method. When the window recieves a drag event, it
delegates to the top-level LayoutPart's getDropTarget. Each part either
delegates to one of its children or handles the drag event directly. If
the part returns null from getDropTarget, this means that the part has
no special preference for the drop event, and the parent may provide a
default behavior. Unlike IDragOverListener, getDropTarget works
top-down. The parent may overload any drag regions that are recognized
by the child, or provide default behaviors for drag regions not
recognized by the child.
Figure 14 shows regions of the workbench where LayoutParts can be
dropped. The workbench checks these regions in the following order:
1. green region
|
The fast view bar registers a
IDragOverListener that responds to views being dragged.
|
2. black regions
|
These areas are reserved by
PartSashContainer.getDropTarget. When the user drags a part over this
region, the PartSashContainer interprets this as a split and does not
ask its child to participate in the drag. This ensures that it is never
possible for the child to prevent splitting by reserving its entire
area as a drop region. The region outside the PartSashContainer's
client area is handled by an IDragOverListener registered with the
shell. This allows parts to be attached to the edge of the layout by
dragging over the window trim.
|
3. red regions
|
For most of the screen area,
PartSashContainer delegates to its child (PartStack.getDropTarget).
PartStack filters out objects that don't belong in the stack (no
editors in view stacks, etc) and delegates to the presentation
(StackPresentation.dragOver). The default presentation recognizes the
tabs and title area as drop targets, but returns null everywhere else.
This is the best practice for presentations and PartStack since it
permits PartSashContainer to extend the split regions where possible.
|
4. blue regions
|
If the child doesn't have any
particular use for the drop location, the PartSashContainer extends the
split regions. If the child allows objects of this type to be added
(determined by calling LayoutPart.allowsAdd), it uses the center of the
rectangle for stacking. Otherwise, the entire region is used for
splitting. The latter case occurs when dragging views over the editor
area or when dragging over a standalone view.
|
5. outside the window (not shown)
|
The workbench page registers an
IDragOverListener that responds to views being dragged outside the
workbench window, and interprets this as a detach operation.
|
By convention, all methods used for drag / drop work in display
coordinates.