Introduction

The platform (Windows, Mac) provided drag and drop (DnD) facilities are used in FlexGanttFX only to move an activity from one row and to another. All other editing operations are handled with standard mouse events (pressed, dragged).The new row might actually be a row in another Gantt chart. The default way to initiate a DnD is to move the mouse cursor into the center of an activity while pressing the SHIFT key. This will change the cursor to the DnD cursor if this kind of editing operation is supported by the targeted activity (see also "3.4.4 Activity Editing"). The DnD will terminate once the user lets go of the mouse button.

Events

Just like all the other editing operations DnD will also trigger several events during its execution. The following table lists them:

Event Type Description
DRAG_STARTED
DRAG_ONGOING
DRAG_FINISHED
These event types are fired if the editing operation is EditMode.DRAGGING.
VERTICAL_DRAG_STARTED
VERTICAL_DRAG_ONGOING
VERTICAL_DRAG_FINISHED
These event types are fired if the editing operation is EditMode.DRAGGING_VERTICAL.

The edit mode DRAGGING_HORIZONTAL does not use platform DnD. Hence the event types HORIZOTAL_DRAG_STARTED / ONGOING / FINISHED are not listed above.

Drag And Drop Info Property

A special property called dragAndDropInfo is available on the graphics view to monitor the DnD operation. This is in addition to the standard event types mentioned above. The info stored in this property provides the application with the most important information required about the dragged activity.

Field Description
row
The row over which the mouse cursor / the dragged activity is currently hovering.
activityBounds
The bouds of the dragged activity (contains an activity reference and the actual activity).
dragEvent
The last drag event (drag ongoing or drag dropped).
dropInterval
The time interval where the activity would be or was actually dropped.
offset
The offset where the mouse grabbed the activity (needed for visual feedback of the drag).

Feedback Types

FlexGanttFX provides different ways of visualizing the DnD feedback. The enumerator DragAndDropFeedback lists the following values which an be set by calling the setDragAndDropFeedback() method on GraphicsBase.

Value Description
NATIVE

A snapshot image of the activity will be taken and placed below the mouse cursor. The image will be set at the moment the drag gesture gets recognized. Optionally a drag image provider can be used.

The size of the image might be different than the size of the activity (platform-specific).

RENDERED

The dragged activity will be constantly rendered on a separate canvas on top of the graphics area. The activity is guaranteed to keep its original size.

RENDERED_GRID_SNAPPED

The dragged activity will be constantly rendered on a separate canvas on top of the graphics area. The activity is guaranteed to keep its original size. The currently active grid will be used to make the dragged activity snap to the grid locations.

Drag Image Provider

If the DnD feedback type has been set to NATIVE then it is possible to pass a custom image for the drag operation. This can be accomplished by setting a drag image provider on GraphicsBase by calling setDragImageProvider(). This method accepts a callback lambda expression. The input for the callback will be an ActivityRef and the output will be an image.

Drag Image Provider
GraphicsBase<?> graphics = ganttChart.getGraphics();
graphics.setDragImageProvider(ref -> createImage(ref));

The default image is a snapshot of the activity at the moment when the drag started.

 Drop Layer Provider

Drag and drop operations can be performed between two different Gantt charts with each chart managing its own list of layers. By default a dropped activity will be placed on the same layer as the one where is was dragged from. But if the target Gantt chart does not contain that layer then the application needs to be told which layer to use as the new home for the activity. This can be accomplished by setting a "drop layer provider" callback on target instance of GraphicsBase.

Drop Layer Provider
GraphicsBase<?> graphics = targetGanttChart.getGraphics();
targetGraphics.setDropLayerProvider(info -> targetLayer); // info is of type DragAndDropInfo

The default implementation of this callback looks like this:

Default Drop Layer Provider
info -> info.getActivityRef().getLayer(); // use same layer as before

If the drop layer provider returns no layer or if the returned layer is not a layer that was added to the target Gantt chart / graphics then we will see messages like this.

  • "the drop layer provider has returned no layer for the dropped activity"
  • "the drop layer provider has returned a layer that does not exist in the Gantt chart"