C

EditLabelHelper

An IEditLabelHelper implementation which provides a number of methods that can be overridden to change the default behavior.
ImplementsInheritance Hierarchy

Remarks

This implementation exhibits the default behavior which is modeled after the behavior used by GraphEditorInputMode's startLabelAddition and startLabelEditing. It can be customized by overriding its various factory methods.

Examples

It is recommended to use the various protected methods to customize the wanted behavior while keeping the overall functionality unchanged.
Modifying the initial properties of a new edge label
class CustomEditLabelHelper extends BaseClass(EditLabelHelper) {
  protected onLabelAdding(
    context: IInputModeContext,
    evt: LabelEditingEventArgs,
  ): void {
    // let the base implementation do the work
    super.onLabelAdding(context, evt)
    // for new edge labels: use a custom parameter
    if (evt.owner instanceof IEdge) {
      evt.layoutParameter =
        new EdgeSegmentLabelModel().createParameterFromCenter()
    }
  }
}
The new implementation can be conveniently set using the GraphDecorator:
Setting a new EditLabelHelper for edges
graph.decorator.edges.editLabelHelper.addConstant(
  new CustomEditLabelHelper(),
)

See Also

Developer's Guide

Members

Show:

Properties

Gets or sets the graph instance to retrieve the default values from.
If this instance is not set, the implementation will try to retrieve the graph from the IInputModeContext's ILookup.
final

Property Value

The graph instance.

Methods

Handles adding the label upon finish.
This implementation uses addLabel to add the label to the graph. The graph is tried to retrieve from graph first. If graph is null, the context is asked for a graph implementation. If no graph is retrieved, null is returned.
protected

Parameters

context: IInputModeContext
The valid input mode context for this action.
evt: LabelEditingEventArgs
A template to get all properties to create the label from. Note that the preferredSize can be null. In this case it will be determined automatically.

Return Value

ILabel
The newly created label, or null if no graph is available.
Invoked if the label editing action has been canceled.
Implementations which maintain a state have to clean up here.
final

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.
Invoked after the label editing gesture has successfully finished.

Completes the gesture by applying the changes, according to action.

Depending on action, this method delegates to addLabel, setLabelText, removeLabel, and labelDropped.

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, the owner for newly added labels or the label to edit or remove, and the text to set
action: LabelEditingAction
Whether to ADD a new label or EDIT or REMOVE an existing label.

Return Value

ILabel
The added, edited, or removed label if the action has been completed successfully. null, otherwise.
Obtains the defaults for the label owner.
This implementation tries to get the defaults from the graph. If no graph is set, it tries to get a graph from the context and, if one is returned, to get the defaults from that graph.
protected

Parameters

context: IInputModeContext
The input mode context
owner: ILabelOwner
The owner to get the label defaults for

Return Value

ILabelDefaults
The label defaults.
Determines the label model parameter to use for the label, depending on the owner.
This method will obtain the default parameter instances from getDefaults considering the type of the current owner.
protected

Parameters

context: IInputModeContext
The input mode context.
owner: ILabelOwner
The label's owner.

Return Value

ILabelModelParameter
The layout parameter to use or null.
Determines the style to use for the label, depending on the owner.
This method will obtain the default style instances from getDefaults considering the type of the current owner.
protected

Parameters

context: IInputModeContext
The input mode context.
owner: ILabelOwner
The label's owner.

Return Value

ILabelStyle
The style to use or null.
Gets the preferred size for the label.
This implementation yields null to indicate that the preferred size should be calculated after the text has been entered.
protected

Parameters

context: IInputModeContext
The input mode context.
label: ILabel
The label to get the preferred size from.

Return Value

Size
The size to use or null.
Invoked at the beginning of a label adding or label editing gesture.
Delegates to onLabelAdding, onLabelEditing, onLabelDropping, and onLabelPasting depending on the action.

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
Whether to ADD a new label, EDIT an existing label, or create a new label during DROP or PASTE.
Handles adding the label upon finish after the drop action of a drag and drop operation.
This implementation uses addLabel to add the label to the given evt' owner. If this helper's graph is not null, said instance is used to add the label. If graph is null, this implementation tries to retrieve a graph from the given context. If the retrieved graph is not null, said instance is used to add the label. If the retrieved graph is null, this implementation returns null without adding a label.
protected

Parameters

context: IInputModeContext
The valid input mode context for this action.
evt: LabelEditingEventArgs
Provides the owner to add the label to and the label properties (such as style) for the new label. If evt' label properties are not set, the properties of evt' label are used instead.

Return Value

ILabel
The newly created label.
Will be called from initialize to initialize the helper for ADDing labels.
This method delegates to getLabelParameter, getLabelStyle, and getPreferredSize to set the appropriate properties on evt and sets the handled property to true. Label creation thus is always possible and will be handled by this instance.
protected

Parameters

context: IInputModeContext
The input mode context.
evt: LabelEditingEventArgs
The original event arguments.
Invoked from initialize to initialize the helper for adding labels after the drop action of a drag and drop operation.

Called by LabelDropInputMode when a label is dropped on the owner.

This implementation does nothing.

protected

Parameters

context: IInputModeContext
The input mode context.
evt: LabelEditingEventArgs
The original event arguments.
Will be called from initialize to initialize the helper for EDITing labels.

If label is set, this implementation does nothing which means that this label will be edited normally.

If label is null but owner is not null, this method sets the label of the given evt to the first of the labels that belong to said owner. If no label is found, this method sets the properties of the given evt to the values returned by getLabelParameter, getLabelStyle, and getPreferredSize to prepare defaults for label adding.

This method always sets the handled property of the given evt to true, so label editing is always possible and will be handled by this EditLabelHelper instance.

protected

Parameters

context: IInputModeContext
The input mode context.
evt: LabelEditingEventArgs
The original event arguments.
Invoked from initialize to initialize the helper for adding labels during paste from the GraphClipboard.

Called by GraphClipboard when a label is pasted.

This implementation uses getLabelParameter to provide a suitable layoutParameter if the item type of the model changed.

protected

Parameters

context: IInputModeContext
The input mode context.
evt: LabelEditingEventArgs
The original event arguments.
newOwner: ILabelOwner
The owner the new label will be pasted on.
originalLabel: ILabel
The original of the new label.
Handles removing the label upon finish.
This implementation uses remove to remove the label. The graph is tried to retrieve from graph first. If graph is null, the context is asked for a graph implementation. If no graph is retrieved, null is returned.
protected

Parameters

context: IInputModeContext
label: ILabel
The label to remove.

Return Value

boolean
Whether a label was removed.
Handles changing the label text upon finish.

This implementation uses setLabelText to add the label to the graph. The graph is tried to retrieve from graph first. If graph is null, the context is asked for a graph implementation. If no graph is retrieved, null is returned.

If the label's text is not changed, null is returned.

protected

Parameters

context: IInputModeContext
label: ILabel
The label on which to set the text.
text: string
The text to set on the label.

Return Value

boolean
Whether a new label text was set.