mxDefaultPopupMenu

Creates popupmenus for mouse events.  This object holds an XML node which is a description of the popup menu to be created.  In createMenu, the configuration is applied to the context and the resulting menu items are added to the menu dynamically.  See createMenu for a description of the configuration format.

This class does not create the DOM nodes required for the popup menu, it only parses an XML description to invoke the respective methods on an mxPopupMenu each time the menu is displayed.

Codec

This class uses the mxDefaultPopupMenuCodec to read configuration data into an existing instance, however, the actual parsing is done by this class during program execution, so the format is described below.

Summary
mxDefaultPopupMenuCreates popupmenus for mouse events.
Functions
mxDefaultPopupMenuConstructs a new popupmenu-factory based on given configuration.
Variables
imageBasePathBase path for all icon attributes in the config.
configXML node used as the description of new menu items.
Functions
createMenuThis function is called from mxEditor to add items to the given menu based on config.
addItemsRecursively adds the given items and all of its children into the given menu.
addActionHelper method to bind an action to a new menu item.
createConditionsEvaluates the default conditions for the given context.

Functions

mxDefaultPopupMenu

function mxDefaultPopupMenu(config)

Constructs a new popupmenu-factory based on given configuration.

Paramaters

configXML node that contains the configuration data.

Variables

imageBasePath

mxDefaultPopupMenu.prototype.imageBasePath

Base path for all icon attributes in the config.  Default is null.

config

mxDefaultPopupMenu.prototype.config

XML node used as the description of new menu items.  This node is used in createMenu to dynamically create the menu items if their respective conditions evaluate to true for the given arguments.

Functions

createMenu

mxDefaultPopupMenu.prototype.createMenu = function(editor,
menu,
cell,
evt)

This function is called from mxEditor to add items to the given menu based on config.  The config is a sequence of the following nodes and attributes.

Child Nodes

addAdds a new menu item.  See below for attributes.
separatorAdds a separator.  No attributes.
conditionAdds a custom condition.  Name attribute.

The add-node may have a child node that defines a function to be invoked before the action is executed (or instead of an action to be executed).

Attributes

asResource key for the label (needs entry in property file).
actionName of the action to execute in enclosing editor.
iconOptional icon (relative/absolute URL).
iconClsOptional CSS class for the icon.
ifOptional name of condition that must be true (see below).
enabled-ifOptional name of condition that specifies if the menu item should be enabled.
nameName of custom condition.  Only for condition nodes.

Conditions

nocellNo cell under the mouse.
ncellsMore than one cell selected.
notRootDrilling position is other than home.
cellCell under the mouse.
notEmptyExactly one cell with children under mouse.
expandableExactly one expandable cell under mouse.
collapsableExactly one collapsable cell under mouse.
validRootExactly one cell which is a possible root under mouse.
swimlaneExactly one cell which is a swimlane under mouse.

Example

To add a new item for a given action to the popupmenu

<mxDefaultPopupMenu as="popupHandler">
  <add as="delete" action="delete" icon="images/delete.gif" if="cell"/>
</mxDefaultPopupMenu>

To add a new item for a custom function

<mxDefaultPopupMenu as="popupHandler">
  <add as="action1"><![CDATA[
     function (editor, cell, evt)
     {
         editor.execute('action1', cell, 'myArg');
     }
  ]]></add>
</mxDefaultPopupMenu>

The above example invokes action1 with an additional third argument via the editor instance.  The third argument is passed to the function that defines action1.  If the add-node has no action-attribute, then only the function defined in the text content is executed, otherwise first the function and then the action defined in the action-attribute is executed.  The function in the text content has 3 arguments, namely the mxEditor instance, the mxCell instance under the mouse, and the native mouse event.

Custom Conditions

To add a new condition for popupmenu items

<condition name="condition1"><![CDATA[
  function (editor, cell, evt)
  {
    return cell != null;
  }
]]></condition>

The new condition can then be used in any item as follows

<add as="action1" action="action1" icon="action1.gif" if="condition1"/>

The order in which the items and conditions appear is not significant as all connditions are evaluated before any items are created.

Parameters

editorEnclosing mxEditor instance.
menumxPopupMenu that is used for adding items and separators.
cellOptional mxCell which is under the mousepointer.
evtOptional mouse event which triggered the menu.

addItems

mxDefaultPopupMenu.prototype.addItems = function(editor,
menu,
cell,
evt,
conditions,
item,
parent)

Recursively adds the given items and all of its children into the given menu.

Parameters

editorEnclosing mxEditor instance.
menumxPopupMenu that is used for adding items and separators.
cellOptional mxCell which is under the mousepointer.
evtOptional mouse event which triggered the menu.
conditionsArray of names boolean conditions.
itemXML node that represents the current menu item.
parentDOM node that represents the parent menu item.

addAction

mxDefaultPopupMenu.prototype.addAction = function(menu,
editor,
lab,
icon,
funct,
action,
cell,
parent,
iconCls,
enabled)

Helper method to bind an action to a new menu item.

Parameters

menumxPopupMenu that is used for adding items and separators.
editorEnclosing mxEditor instance.
labString that represents the label of the menu item.
iconOptional URL that represents the icon of the menu item.
actionOptional name of the action to execute in the given editor.
functOptional function to execute before the optional action.  The function takes an mxEditor, the mxCell under the mouse and the mouse event that triggered the call.
cellOptional mxCell to use as an argument for the action.
parentDOM node that represents the parent menu item.
iconClsOptional CSS class for the menu icon.
enabledOptional boolean that specifies if the menu item is enabled.  Default is true.

createConditions

mxDefaultPopupMenu.prototype.createConditions = function(editor,
cell,
evt)

Evaluates the default conditions for the given context.

function mxDefaultPopupMenu(config)
Constructs a new popupmenu-factory based on given configuration.
mxDefaultPopupMenu.prototype.imageBasePath
Base path for all icon attributes in the config.
mxDefaultPopupMenu.prototype.config
XML node used as the description of new menu items.
mxDefaultPopupMenu.prototype.createMenu = function(editor,
menu,
cell,
evt)
This function is called from mxEditor to add items to the given menu based on config.
Extends mxEventSource to implement an application wrapper for a graph that adds actions, I/O using mxCodec, auto-layout using mxLayoutManager, command history using undoManager, and standard dialogs and widgets, eg.
mxDefaultPopupMenu.prototype.addItems = function(editor,
menu,
cell,
evt,
conditions,
item,
parent)
Recursively adds the given items and all of its children into the given menu.
mxDefaultPopupMenu.prototype.addAction = function(menu,
editor,
lab,
icon,
funct,
action,
cell,
parent,
iconCls,
enabled)
Helper method to bind an action to a new menu item.
mxDefaultPopupMenu.prototype.createConditions = function(editor,
cell,
evt)
Evaluates the default conditions for the given context.
Basic popup menu.
Custom codec for configuring mxDefaultPopupMenus.
Cells are the elements of the graph model.
Close