Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EditorToolbarCodec

Custom codec for configuring s. This class is created and registered dynamically at load time and used implicitly via and the . This codec only reads configuration data for existing toolbars handlers, it does not encode or create toolbars.

Hierarchy

Index

Constructors

constructor

Properties

exclude

exclude: string[]

Array containing the variable names that should be ignored by the codec.

idrefs

idrefs: string[]

Array containing the variable names that should be turned into or converted from references. See Codec.getId and Codec.getObject.

mapping

mapping: {}

Maps from from fieldnames to XML attribute names.

Type declaration

  • [key: string]: string

reverse

reverse: {}

Maps from from XML attribute names to fieldnames.

Type declaration

  • [key: string]: string

template

template: any

Holds the template object associated with this codec.

Static allowEval

allowEval: boolean = false

Static global switch that specifies if expressions in arrays are allowed. Default is false. NOTE: Enabling this carries a possible security risk.

static

Methods

addObjectValue

  • addObjectValue(obj: any, fieldname: string, value: any, template: any): void
  • Sets the decoded child node as a value of the given object. If the object is a map, then the value is added with the given fieldname as a key. If the fieldname is not empty, then setFieldValue is called or else, if the object is a collection, the value is added to the collection. For strongly typed languages it may be required to override this with the correct code to add an entry to an object.

    Parameters

    • obj: any
    • fieldname: string
    • value: any
    • template: any

    Returns void

afterDecode

  • afterDecode(dec: Codec, node: null | Element, obj?: any): any
  • Hook for subclassers to post-process the object after decoding. This implementation returns the given object without any changes. The return value of this method is returned to the decoder from decode.

    Parameters

    • dec: Codec
    • node: null | Element

      XML node to be decoded.

    • Optional obj: any

      Object that represents the default decoding.

    Returns any

afterEncode

  • afterEncode(enc: Codec, obj: any, node: Element): Element
  • Hook for subclassers to post-process the node for the given object after encoding and return the post-processed node. This implementation returns the input node. The return value of this method is returned to the encoder from encode.

    Parameters

    • enc: Codec

      Codec that controls the encoding process.

    • obj: any

      Object to be encoded.

    • node: Element

      XML node that represents the default encoding.

    Returns Element

beforeDecode

  • beforeDecode(dec: Codec, node: Element, obj: any): null | Element
  • Hook for subclassers to pre-process the node for the specified object and return the node to be used for further processing by decode. The object is created based on the template in the calling method and is never null. This implementation returns the input node. The return value of this function is used in decode to perform the default decoding into the given object.

    Parameters

    • dec: Codec

      Codec that controls the decoding process.

    • node: Element

      XML node to be decoded.

    • obj: any

      Object to encode the node into.

    Returns null | Element

beforeEncode

  • beforeEncode(enc: Codec, obj: any, node?: Element): any
  • Hook for subclassers to pre-process the object before encoding. This returns the input object. The return value of this function is used in encode to perform the default encoding into the given node.

    Parameters

    • enc: Codec

      Codec that controls the encoding process.

    • obj: any

      Object to be encoded.

    • Optional node: Element

      XML node to encode the object into.

    Returns any

cloneTemplate

  • cloneTemplate(): any

convertAttributeFromXml

  • convertAttributeFromXml(dec: Codec, attr: any, obj: any): any

convertAttributeToXml

  • convertAttributeToXml(enc: Codec, obj: any, name: null | string, value: any, node: Element): any

decode

  • decode(dec: Codec, _node: Element, into: any): any
  • Reads a sequence of the following child nodes and attributes:

    Child Nodes:

    add - Adds a new item to the toolbar. See below for attributes. separator - Adds a vertical separator. No attributes. hr - Adds a horizontal separator. No attributes. br - Adds a linefeed. No attributes.

    Attributes:

    as - Resource key for the label. action - Name of the action to execute in enclosing editor. mode - Modename (see below). template - Template name for cell insertion. style - Optional style to override the template style. icon - Icon (relative/absolute URL). pressedIcon - Optional icon for pressed state (relative/absolute URL). id - Optional ID to be used for the created DOM element. toggle - Optional 0 or 1 to disable toggling of the element. Default is 1 (true).

    The action, mode and template attributes are mutually exclusive. The style can only be used with the template attribute. The add node may contain another sequence of add nodes with as and action attributes to create a combo box in the toolbar. If the icon is specified then a list of the child node is expected to have its template attribute set and the action is ignored instead.

    Nodes with a specified template may define a function to be used for inserting the cloned template into the graph. Here is an example of such a node:

    <add as="Swimlane" template="swimlane" icon="images/swimlane.gif"><![CDATA[
    function (editor, cell, evt, targetCell)
    {
    let pt = mxUtils.convertPoint(
    editor.graph.container, mxEvent.getClientX(evt),
    mxEvent.getClientY(evt));
    return editor.addVertex(targetCell, cell, pt.x, pt.y);
    }
    ]]></add>

    In the above function, editor is the enclosing instance, cell is the clone of the template, evt is the mouse event that represents the drop and targetCell is the cell under the mousepointer where the drop occurred. The targetCell is retrieved using {@link Graph#getCellAt}.

    Futhermore, nodes with the mode attribute may define a function to be executed upon selection of the respective toolbar icon. In the example below, the default edge style is set when this specific connect-mode is activated:

    <add as="connect" mode="connect"><![CDATA[
    function (editor)
    {
    if (editor.defaultEdge != null)
    {
    editor.defaultEdge.style = 'straightEdge';
    }
    }
    ]]></add>

    Both functions require <DefaultToolbarCodec.allowEval> to be set to true.

    Modes:

    select - Left mouse button used for rubberband- & cell-selection. connect - Allows connecting vertices by inserting new edges. pan - Disables selection and switches to panning on the left button.

    Example:

    To add items to the toolbar:

    <EditorToolbar as="toolbar">
    <add as="save" action="save" icon="images/save.gif"/>
    <br/><hr/>
    <add as="select" mode="select" icon="images/select.gif"/>
    <add as="connect" mode="connect" icon="images/connect.gif"/>
    </EditorToolbar>

    Parameters

    • dec: Codec
    • _node: Element
    • into: any

    Returns any

decodeAttribute

  • decodeAttribute(dec: Codec, attr: any, obj?: any): void

decodeAttributes

  • decodeAttributes(dec: Codec, node: Element, obj: any): void

decodeChild

  • decodeChild(dec: Codec, child: Element, obj: any): void

decodeChildren

  • decodeChildren(dec: Codec, node: Element, obj?: any): void

decodeNode

  • decodeNode(dec: Codec, node: null | Element, obj: any): void

encode

  • encode(enc: any, obj: any): null

encodeObject

  • encodeObject(enc: Codec, obj: any, node: Element): void

encodeValue

  • encodeValue(enc: Codec, obj: any, name: null | string, value: any, node: Element): void
  • Converts the given value according to the mappings and id-refs in this codec and uses writeAttribute to write the attribute into the given node.

    Parameters

    • enc: Codec

      Codec that controls the encoding process.

    • obj: any

      Object whose property is going to be encoded.

    • name: null | string

      XML node that contains the encoded object.

    • value: any

      Value of the property to be encoded.

    • node: Element

      XML node that contains the encoded object.

    Returns void

getAttributeName

  • getAttributeName(fieldname: null | string): null | string

getFieldName

  • getFieldName(attributename: string): string

getFieldTemplate

  • getFieldTemplate(obj: any, fieldname: string, child: Element): any
  • Returns the template instance for the given field. This returns the value of the field, null if the value is an array or an empty collection if the value is a collection. The value is then used to populate the field for a new instance. For strongly typed languages it may be required to override this to return the correct collection instance based on the encoded child.

    Parameters

    • obj: any
    • fieldname: string
    • child: Element

    Returns any

getName

  • getName(): string
  • Returns the name used for the nodenames and lookup of the codec when classes are encoded and nodes are decoded. For classes to work with this the codec registry automatically adds an alias for the classname if that is different than what this returns. The default implementation returns the classname of the template class.

    Returns string

isBooleanAttribute

  • isBooleanAttribute(enc: Codec, obj: any, name: null | string, value: any): boolean
  • Returns true if the given object attribute is a boolean value.

    Parameters

    • enc: Codec

      Codec that controls the encoding process.

    • obj: any

      Objec to convert the attribute for.

    • name: null | string

      Name of the attribute to be converted.

    • value: any

      Value of the attribute to be converted.

    Returns boolean

isExcluded

  • isExcluded(obj: any, attr: string, value: any, write?: boolean): boolean
  • Returns true if the given attribute is to be ignored by the codec. This implementation returns true if the given fieldname is in exclude or if the fieldname equals ObjectIdentity.FIELD_NAME.

    Parameters

    • obj: any

      Object instance that contains the field.

    • attr: string

      Fieldname of the field.

    • value: any

      Value of the field.

    • Optional write: boolean

      Boolean indicating if the field is being encoded or decoded. Write is true if the field is being encoded, else it is being decoded.

    Returns boolean

isIgnoredAttribute

  • isIgnoredAttribute(dec: Codec, attr: any, obj?: any): boolean
  • Returns true if the given attribute should be ignored. This implementation returns true if the attribute name is "as" or "id".

    Parameters

    • dec: Codec

      Codec that controls the decoding process.

    • attr: any

      XML attribute to be decoded.

    • Optional obj: any

      Objec to encode the attribute into.

    Returns boolean

isNumericAttribute

  • isNumericAttribute(dec: Codec, attr: any, obj: any): boolean

isReference

  • isReference(obj: any, attr: string, value: any, write?: boolean): boolean
  • Returns true if the given fieldname is to be treated as a textual reference (ID). This implementation returns true if the given fieldname is in idrefs.

    Parameters

    • obj: any

      Object instance that contains the field.

    • attr: string

      Fieldname of the field.

    • value: any

      Value of the field.

    • Optional write: boolean

      Boolean indicating if the field is being encoded or decoded. Write is true if the field is being encoded, else it is being decoded.

    Returns boolean

processInclude

  • processInclude(dec: Codec, node: Element, into?: any): boolean
  • Returns true if the given node is an include directive and executes the include by decoding the XML document. Returns false if the given node is not an include directive.

    Parameters

    • dec: Codec

      Codec that controls the encoding/decoding process.

    • node: Element

      XML node to be checked.

    • Optional into: any

      Optional object to pass-thru to the codec.

    Returns boolean

writeAttribute

  • writeAttribute(enc: Codec, obj: any, name: null | string, value: any, node: Element): void

writeComplexAttribute

  • writeComplexAttribute(enc: Codec, obj: any, name: null | string, value: any, node: Element): void

writePrimitiveAttribute

  • writePrimitiveAttribute(enc: Codec, obj: any, name: null | string, value: any, node: Element): void

Generated using TypeDoc