Remarks
Implementations of this interface are by default retrieved from the ILookup of ILabelOwners and ILabels. If needed, different implementations can be decorated so that it is possible to tweak the behavior on a case by case basis. Hiding the implementation for both an ILabel and its owner can prevent adding or editing labels interactively.
Implementations have to handle ADDing or removing labels or changing a label's text upon finish. Unless developers want to implement all of these actions themselves, it is recommended to either wrap the default implementation or extend EditLabelHelper and call its base methods.
Developers who simply want to change the editing behavior via the LabelEditingEventArgs might also consider handling the query-label-adding and query-label-editing events.
Examples
class WrappingEditLabelHelper extends BaseClass(IEditLabelHelper) {
private wrapped!: IEditLabelHelper
public WrappingEditLabelHelper(wrapped: IEditLabelHelper) {
this.wrapped = wrapped
}
public initialize(
context: IInputModeContext,
evt: LabelEditingEventArgs,
action: LabelEditingAction,
): void {
// let the wrapped implementation do the work
this.wrapped.initialize(context, evt, action)
// for new edge labels: use a custom parameter
if (action == LabelEditingAction.ADD && evt.owner instanceof IEdge) {
evt.layoutParameter =
new EdgeSegmentLabelModel().createParameterFromCenter()
}
}
// Finish completely delegates to the wrapped implementation
public finish(
context: IInputModeContext,
evt: LabelEditingEventArgs,
action: LabelEditingAction,
): ILabel | null {
return this.wrapped.finish(context, evt, action)
}
// Cancel completely delegates to the wrapped implementation
public cancel(
context: IInputModeContext,
evt: LabelEditingEventArgs,
): void {
this.wrapped.cancel(context, evt)
}
}graph.decorator.edges.editLabelHelper.addWrapperFactory(
(label, helper) => new WrappingEditLabelHelper(helper),
)See Also
Developer's Guide
API
- EditLabelHelper, startLabelEditing, startLabelAddition, query-label-adding, query-label-editing
Members
Methods
Invoked if the label editing action has been canceled.
Parameters
- context: IInputModeContext
- The current input mode context.
- evt: LabelEditingEventArgs
- Additional information about the label or label owner and whether the editing operation has been canceled programmatically.
See Also
Developer's Guide
Implemented in
EditLabelHelper.cancelInvoked after the label editing gesture has successfully finished.
Depending on the action, implementations have to either ADD a new label, change the text of the given label, or REMOVE the given label.
For operations that fail or are not supported by the implementation, this method has to return null.
Implementations which maintain a state have to clean up here.
Parameters
- context: IInputModeContext
- The input mode context from the input mode which invoked that method.
- evt: LabelEditingEventArgs
- The LabelEditingEventArgs which provide the information for the label to be added or edited. In particular,
evtprovides the owner for newly added labels or the label to edit or remove, and the text to set when adding or editing labels. - action: LabelEditingAction
Return Value
- ILabel
- The added, edited, or removed label if the action has been completed successfully and
nullotherwise.
See Also
Developer's Guide
Implemented in
EditLabelHelper.finishInvoked at the beginning of a label adding or label editing gesture.
The LabelEditingEventArgs can be configured to customize the label editing behavior. It is also possible to set a custom label or owner. Finally, label editing can be prevented by setting cancel to true.
Implementations which need to maintain a state can configure the state here and clean it up in both finish and cancel. It is important, that these implementations set LabelEditingEventArgs's handled to true to make sure that no other IEditLabelHelper implementation takes over.
Parameters
- context: IInputModeContext
- The input mode context from the input mode which invoked that method.
- evt: LabelEditingEventArgs
- A configuration object which supports customizing the label editing.
- action: LabelEditingAction
See Also
Developer's Guide