Introduction
The graphics view fires standard JavaFX events in order to let applications react to change. The concepts used for event handler support in FlexGanttFX are the same as the ones found in the standard JavaFX controls.
Activity Events
Activity events are fired whenever the user deletes or edits an activity. To receive an activity event simply register an event handler with the graphics view via one of the convenience methods.
GraphicsBase<?> graphics = ganttChart.getGraphics(); graphics.setOnActivityChangeFinished(evt -> System.out.println("An activity has changed"));
If you need to register more than one handler for a specific event type then use this approach:
GraphicsBase<?> graphics = ganttChart.getGraphics(); graphics.addEventHandler(ActivityEvent.ACTIVITY_CHANGE_FINISHED, evt -> System.out.println("Listener 1")); graphics.addEventHandler(ActivityEvent.ACTIVITY_CHANGE_FINISHED, evt -> System.out.println("Listener 2"));
The following table lists all supported activity event types and the convenience setter methods of the graphics view. These methods are used to quickly register an event handler for the given event type.
Event Types | Methods | Description |
---|---|---|
ACTIVITY_DELETED |
setOnActivityDeleted() |
Fired whenever the user deletes an activity via the backspace key. |
ACTIVITY_CHANGE |
setOnActivityChanged() |
The parent event type of all activity changes. Can be used to to receive a notification for any kind of activity change. |
ACTIVITY_CHANGE_STARTED ACTIVITY_CHANGE_ONGOING ACTIVITY_CHANGE_FINISHED |
setOnActivityChangeStarted() setOnActivityChangeOngoing() setOnActivityChangeFinished() |
Fired whenever an activity change has started, is ongoing, or has finished. |
CHART_HIGH_VALUE_CHANGE_STARTED CHART_HIGH_VALUE_CHANGE_ONGOING CHART_HIGH_VALUE_CHANGE_FINISHED |
setOnChartHighValueChangeStarted(); setOnChartHighValueChangeOngoing(); setOnChartHighValueChangeFinished(); |
Fired whenever the user has started editing, is in the process of editing, or has finished editing the "high" value of a high / low chart activity. |
CHART_LOW_VALUE_CHANGE_STARTED CHART_LOW_VALUE_CHANGE_ONGOING CHART_LOW_VALUE_CHANGE_FINISHED |
setOnChartLowValueChangeStarted(); setOnChartLowValueChangeOngoing(); setOnChartLowValueChangeFinished(); |
Fired whenever the user has started editing, is in the process of editing, or has finished editing the "low" value of a high / low chart activity. |
CHART_VALUE_CHANGE_STARTED CHART_VALUE_CHANGE_ONGOING CHART_VALUE_CHANGE_FINISHED |
setOnChartValueChangeStarted(); setOnChartValueChangeOngoing(); setOnChartValueChangeFinished(); |
Fired whenever the user has started editing, is in the process of editing, or has finished editing a chart value of a chart activity. |
DRAG_STARTED DRAG_ONGOING DRAG_FINISHED |
setOnActivityDragStarted(); setOnActivityDragOngoing(); setOnActivityDragFinished(); |
Fired whenever the user has started dragging, is in the process of dragging, or has finished dragging an activity via platform-provided drag & drop. This event type is used when the user can freely move the activity around, vertically and horizontally. |
END_TIME_CHANGE_STARTED END_TIME_CHANGE_ONGOING END_TIME_CHANGE_FINISHED |
setOnActivityEndTimeChangeStarted(); setOnActivityEndTimeChangeOngoing(); setOnActivityEndTimeChangeFinished(); |
Fired whenever the user has started changing, is in the process of changing, or has finished changing the end time of an activity. |
HORIZONTAL_DRAG_STARTED HORIZONTAL_DRAG_ONGOING HORIZONTAL_DRAG_FINISHED |
setOnActivityHorizontalDragStarted(); setOnActivityHorizontalDragOngoing(); setOnActivityHorizontalDragFinished(); |
Fired whenever the user has started changing, is in the process of changing, or has finished changing the time interval (start and end time) of an activity. Changing this time interval makes the activity move horizontally, either to the right (future) or the left (past). |
PERCENTAGE_CHANGE_STARTED PERCENTAGE_CHANGE_ONGOING PERCENTAGE_CHANGE_FINISHED |
setOnActivityPercentageChangeStarted(); setOnActivityPercentageChangeOngoing(); setOnActivityPercentageChangeFinished(); |
Fired whenever the user has started changing, is in the process of changing, or has finished changing the "percentage complete" value of an activity. |
START_TIME_CHANGE_STARTED START_TIME_CHANGE_ONGOING START_TIME_CHANGE_FINISHED |
setOnActivityStartTimeChangeStarted(); setOnActivityStartTimeChangeOngoing(); setOnActivityStartTimeChangeFinished(); |
Fired whenever the user has started changing, is in the process of changing, or has finished changing the start time of an activity. |
VERTICAL_DRAG_STARTED VERTICAL_DRAG_ONGOING VERTICAL_DRAG_FINISHED |
setOnActivityVerticalDragStarted(); setOnActivityVerticalDragOngoing(); setOnActivityVerticalDragFinished(); |
Fired whenever the user has started dragging, is in the process of dragging, or has finished dragging an activity via platform-provided drag & drop. This event type is used when the user can only drag the activity vertically (reassign an activity to a different row). |
Activity Events Hierarchy
The event types defined in the ActivityEvent class are defining an event hierarchy. All events are input events (InputEvent.ANY) and they change the activity. Some of them get fired when the user starts the change, some while the change is ongoing, and some when the change is finished.
-
InputEvent.ANY
-
ACTIVITY_CHANGE
-
ACTIVITY_DELETED
-
ACTIVITY_CHANGE_STARTED // All event types that signal "start"
-
CHART_VALUE_CHANGE_STARTED
-
CHART_HIGH_VALUE_CHANGE_STARTED
-
CHART_LOW_VALUE_CHANGE_STARTED
-
-
DRAG_STARTED
-
END_TIME_CHANGE_STARTED
-
HORIZONTAL_DRAG_STARTED
-
PERCENTAGE_CHANGE_STARTED
-
START_TIME_CHANGE_STARTED
-
VERTICAL_DRAG_STARTED
-
-
ACTIVITY_CHANGE_ONGOING // All event types that signal "ongoing"
-
CHART_VALUE_CHANGE_ONGOING
-
CHART_HIGH_VALUE_CHANGE_ONGOING
-
CHART_LOW_VALUE_CHANGE_ONGOING
-
-
DRAG_ONGOING
-
END_TIME_CHANGE_ONGOING
-
HORIZONTAL_DRAG_ONGOING
-
PERCENTAGE_CHANGE_ONGOING
-
START_TIME_CHANGE_ONGOING
-
VERTICAL_DRAG_ONGOING
-
-
ACTIVITY_CHANGE_FINISHED // All event types that signal "finished"
-
CHART_VALUE_CHANGE_FINISHED
-
CHART_HIGH_VALUE_CHANGE_FINISHED
-
CHART_LOW_VALUE_CHANGE_FINISHED
-
-
DRAG_FINISHED
-
END_TIME_CHANGE_FINISHED
-
HORIZONTAL_DRAG_FINISHED
-
PERCENTAGE_CHANGE_FINISHED
-
START_TIME_CHANGE_FINISHED
-
VERTICAL_DRAG_FINISHED
-
-
-
Activity Event Properties
Applications are obviously interested in the attributes of an activity. Not only the new values of these attributes (for example the new start time) but also the old values (start time before the change). The new values are already available on the activity as they are being set while the user performs the change. The old values are stored on the event object. The following table lists the methods on ActivityEvent to retrieve these values.
Method | Description | Event Types |
---|---|---|
getOldTime() |
Returns the old start or end time of the activity. |
END_TIME_CHANGE_ START_TIME_CHANGE_ |
getOldTimeInterval() |
Returns the old start and end time of the activity. |
DRAG_ HORIZONTAL_DRAG_ VERTICAL_DRAG_ |
getOldRow() |
Returns the old row where the activity was located before. |
DRAG_ VERTICAL_DRAG_ |
getOldValue() |
Returns the old value of "percentage complete" or "chart value". |
CHART_VALUE_CHANGE_ CHART_HIGH_VALUE_ CHART_LOW_VALUE_ PERCENTAGE_CHANGE_ |
Lasso Events
The user can use a lasso to select activities. Events are fired when this happens. To receive a lasso event simply register an event handler with the graphics view via one of the convenience methods.
GraphicsBase<?> graphics = ganttChart.getGraphics(); graphics.setOnLassoFinished(evt -> System.out.println("The lasso was used"));
If you need to register more than one handler for a specific event type then use this approach:
GraphicsBase<?> graphics = ganttChart.getGraphics(); graphics.addEventHandler(LassoEvent.SELECTION_FINISHED, evt -> System.out.println("Listener 1")); graphics.addEventHandler(LassoEvent.SELECTION_FINISHED, evt -> System.out.println("Listener 2"));
The following table lists the event types and the convenience setter methods of the graphics view.
Event Type | Method | Description |
---|---|---|
ALL |
setOnLassoSelection() |
Any lasso operation (start, ongoing, finished). |
SELECTION_STARTED |
setOnLassoSelectionStarted() |
The user has pressed the mouse button and started a drag. The lasso has become visible. |
SELECTION_ONGOING |
setOnLassoSelectionOngoing() |
The user is changing the size of the lasso. |
SELECTION_FINISHED |
setOnLassoSelectionFinished() |
The user has finished the lasso selection. The lasso is no longer visible. |
Lasso Event Hierarchy
The event types defined in the LassoEvent class are defining an event hierarchy. All events are input events (InputEvent.ANY).
-
InputEvent.ANY
-
LassoEvent.ALL
-
LassoEvent.SELECTION_STARTED
-
LassoEvent.SELECTION_ONGOING
-
LassoEvent.SELECTION_FINISHED
-
-
Lasso Info
The lasso automatically performs selections of activities but sometimes we might want to know more about the exact nature of this selection or we want to use the lasso for another use case (e.g. for creating new activities). For this reason instances of LassoEvent also provide an object of type LassoInfo, which carries many attributes that the application can use to react accordingly. The lasso information can be retrieved by calling LassoEvent.getInfo(). The following table lists the attributes of LassoInfo.
Method | Description |
---|---|
List<ActivityRef<?>> getActivities(); |
Returns all activities that were selected by the lasso. |
Instant getStartTime(); Instant getEndTime(); |
Returns the start and end time of the lasso according to the location of the left and right edge of the lasso. |
LocalTime getLocalStartTime(); LocalTime getLocalEndTime(); |
Returns the local start and end time. These values are only provided if the upper or lower edge of the lasso is located in an area that uses the AgendaLayout. |
List<Row<?,?,?>> getRows(); |
Returns the rows that were touched by the lasso. |