FlexGanttFX Developer Manual : 3.4.4 Activity Editing

Introduction

Two different callbacks on the graphics view are used to control the editing behaviour of activities. The first maps a mouse event / mouse location to an editing mode. The second callback is used to determine whether a given editing mode / operation can be applied to an activity at all. Most applications will only need to work with the second callback and keep the defaults for the edit mode locations (for example: right edge used to change end time, left edge used to change start time). The enum GraphicsBase.EditMode lists all available editing operations that can be performed on an activity. 

Mode Description
AGENDA_ASSIGNING Assign an activity in AgendaLayout to another row.

AGENDA_DRAGGING

Drag an activity in AgendaLayout up and down or sideways within the same row.
AGENDA_END_TIME_CHANGE Change the end time of an activity in AgendaLayout.
AGENDA_START_TIME_CHANGE Chagne the start time of an activity in AgendaLayout.
CHART_VALUE_CHANGE Change the value of a ChartActivity.
CHART_VALUE_HIGH_CHANGE Change the "high" value of a HighLowActivity.
CHART_VALUE_LOW_CHANGE Change the "low" value of a HighLowActivity.
DRAGGING Perform a drag and drop in all directions on an activity.
DRAGGING_HORIZONTAL Move an activity horizontally within its own row (change start and end time).
DRAGGING_VERTICAL Perform a drag and drop on an activity in vertical direction only.
END_TIME_CHANGE Change the end time of an activity.
NONE Do nothing.
PERCENTAGE_COMPLETE_CHANGE Change the "percentage complete" value of a CompletableActivity.
START_TIME_CHANGE Change the start time of an activity.

Edit Mode Callback

The edit mode callback is used to determine the edit mode at the given mouse location. Instances of this callback can be registered via the GraphicsBase.setEditModeCallback() method which maps the callback to a combination of activity type and layout type.

Edit Mode Callback Registration
public final void setEditModeCallback(
			Class<? extends MutableActivity> activityType,
			Class<? extends Layout> layoutType,
			Callback<EditModeCallbackParameter, EditMode> callback);

Edit Mode Callback Parameter

The parameter object passed to the edit mode callback is of type EditModeCallbackParameter and contains the following information:

Field Description
activityBounds The bounds of the activity over which the mouse cursor is hovering. The x and y coordinates are relative to the coordinate space of the row where the activity is displayed.
mouseEvent The mouse event that triggered the lookup of the edit mode (normally a MOUSE_OVER).

Edit Mode Callback Example

 The following is a simple example of an editing mode callback.

Edit Mode Callback Example
public class MyEditModeCallback implements Callback<EditModeCallbackParameter, EditMode> {
 
	public EditMode call(EditModeCallbackParameter param) {
		MouseEvent event = param.getMouseEvent();
		ActivityBounds bounds = param.getActivityBounds();
 
		/*
		 * If the mouse cursor is touching the left edge of the activity
 		 * then begin a change of the start time of the activity.
		 */
		if (event.getX() - bounds.getMinX() < 5) {
			return EditMode.CHANGE_START_TIME;
		}
 
		return EditMode.NONE;
	}
}

This callback can now be registered like this:

Edit Mode Callback Registration
GraphicsBase<?> graphics = ganttChart.getGraphics();
graphics.setEditModeCallback(
			ActivityBase.class, 
			GanttLayout.class, 
			new MyEditModeCallback());

We could have used a lambda expression for the entire callback instance but decided against it in favor of verbosity.

Editing Callback

The editing callback is used to determine if a specific edit mode is currently usable for a given activity. Instances of this callback can be registered via the GraphicsBase.setActivityEditingCallback() method which maps the callback to an activity type.

Edit Mode Callback Registration
public final void setActivityEditingCallback(
			Class<? extends MutableActivity> activityType,
			Callback<EditingCallbackParameter, Boolean> callback);

Editing Callback Parameter

The parameter object passed to the editing callback is of type EditingCallbackParameter and contains the following information:

Field Description
activityRef The reference to the activity for which to perform the check.
editMode The edit mode that needs a check.

Editing Callback Example

The following is a simple example of an editing callback.

Edit Callback Example
public class MyEditingCallback implements Callback<EditingCallbackParameter, Boolean> {
 
	public Boolean call(EditingCallbackParameter param) {
		ActivityRef ref = param.getActivityRef();
		Activity activity = ref.getActivity();
 
		/*
		 * Only allow editing for activities that that have not
		 * started, yet.
		 */
		if (activity.getStartTime().isAfter(Instant.now())) {
 
			/*
			 * Only allow changes to the start and end time
			 * of the activity.
			 */
			switch (param.getEditMode()) {
				case CHANGE_START_TIME:
				case CHANGE_END_TIME:
					return true;
				default:
					return false;
			}
  		} 
 
		return false;
	}
}

This callback can now be registered like this:

Editing Callback Registration
GraphicsBase<?> graphics = ganttChart.getGraphics();
graphics.setActivityEditingCallback(
			ActivityBase.class, 
			new MyEditingCallback());