User Interaction

The input modes described in the section called “User Interaction” provide support for hierarchically organized graphs. In particular, this covers mouse gestures as well as keyboard shortcuts for modifying the hierarchy of nodes, for collapsing and expanding group nodes, and for navigating the hierarchy.

Class GraphEditorInputMode

GraphEditorInputMode directly supports grouping and ungrouping of selected nodes using keyboard shortcuts. The groupSelectionAllowed and ungroupSelectionAllowed properties can be used to enable or disable these shortcuts.

Additionally, whether re-parenting of nodes is allowed in a hierarchically organized graph can be easily enabled or disabled by means of the reparentNodesAllowed property. Fine-grained control over re-parenting, depending, for example, on the involved node to be re-parented and its new group node, can be achieved by setting a custom implementation of interface IReparentNodeHandler with the reparentNodeHandler property.

Example 3.10, “Customizing the re-parenting gesture” illustrates an IMapper-based scheme of a custom re-parenting gesture.

Example 3.10. Customizing the re-parenting gesture

override protected function createEditorMode(graph:IGraph):IInputMode {
  var geim:GraphEditorInputMode = new GraphEditorInputMode(graph);
  geim.reparentNodeHandler = new MyReparentNodeHandler(geim);
  return geim;
}

public class MyReparentNodeHandler extends IReparentNodeHandler {
  protected var rnh:IReparentNodeHandler;
  protected var validReparentTarget:IMapper;
  
  public MyReparentNodeHandler(geim:GraphEditorInputMode) {
    this.rnh = geim.reparentNodeHandler;
    var reg:IMapperRegistry = geim.graph.mapperRegistry;
    validReparentTarget = 
      (reg != null ? reg.getMapper("validReparentTarget") : null);
  }
  
  // Same gesture as with the previously set ReparentNodeHandler.
  override public function isReparentGesture(context:IInputModeContext, 
                                             node:INode):Boolean {
    return rnh.isReparentGesture(context, node);
  }
  
  // All nodes can be re-parented.
  override public function canReparent(context:IInputModeContext, 
                                       node:INode):Boolean {
    return true;
  }
  
  // Only re-parent, if the new group node allows so.
  override public function isValidParent(context:IInputModeContext, 
                                         node:INode, newParent:INode):Boolean {
    if (validReparentTarget != null) {
      return validReparentTarget.lookupValue(newParent);
    }
    return false;
  }
}

By default, GraphEditorInputMode allows re-parenting of all nodes in a hierarchically organized graph. It recognizes the re-parenting mouse gesture when the Shift key is pressed while moving nodes.

Class NavigationInputMode

Class NavigationInputMode supports collapsing and expanding of selected group nodes in a folding-enabled graph. The collapsingGroupsAllowed and expandingGroupsAllowed properties can be used to enable or disable these commands.

NavigationInputMode furthermore provides convenient access to IFoldedGraph's functionality for collapsing or expanding group nodes by means of the following methods.

API Excerpt 3.11. Convenience methods in NavigationInputMode for collapsing and expanding group nodes

function collapseGroup( groupNode:INode ):void
function expandGroup(groupNode:INode):void

Collapsing and expanding can also be controlled on a per-group node basis by overriding the predicate methods listed in API Excerpt 3.12, “Predicates for collapsing and expanding group nodes”.

API Excerpt 3.12. Predicates for collapsing and expanding group nodes

protected function shouldCollapseGroup(node:INode):Boolean
protected function shouldExpandGroup(node:INode):Boolean

Navigation in a hierarchy, i.e., entering group nodes or exiting the current group node, is supported by NavigationInputMode also. The enteringGroupsAllowed and exitingGroupAllowed properties can be used to enable or disable these navigation facilities.

Controlling navigation on a per-group node basis can be achieved by using the methods listed in API Excerpt 3.13, “Methods for navigating the hierarchy of nodes”. In particular, for complete customization of the behavior, the predicate methods can be easily overridden.

API Excerpt 3.13. Methods for navigating the hierarchy of nodes

// Navigation in the hierarchy.
function enterGroup(node:INode):void
function exitGroup():void

// Predicate methods for customization.
protected function shouldEnterGroup(node:INode):Boolean
protected function shouldExitGroup():Boolean