The input modes described in the section called “User Interaction” provide support for grouped 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. This functionality is also accessible via routed commands.
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 grouped 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.9, “Customizing the re-parenting gesture” illustrates an IMapper-based scheme of a custom re-parenting gesture.
Example 3.9. Customizing the re-parenting gesture
protected virtual IInputMode CreateEditorMode(IGraph graph) {
return new GraphEditorInputMode {
ReparentNodeHandler = new MyReparentNodeHandler()
};
}
public class MyReparentNodeHandler : ReparentNodeHandler {
// Only re-parent, if the new group node allows so.
public override bool IsValidParent(IInputModeContext context,
INode node, INode newParent) {
var graph = context.GetGraph();
if (graph != null) {
var validReparentTarget =
graph.MapperRegistry.GetMapper<INode, bool>("validReparentTarget");
if (validReparentTarget != null) {
return validReparentTarget.GetValue(newParent);
}
}
return false;
}
}
By default, GraphEditorInputMode allows re-parenting of all nodes in a grouped graph. It recognizes the re-parenting mouse gesture when the Control key is pressed while moving nodes.
Collapsing and expanding of selected group nodes in a folding-enabled graph is supported by GraphEditorInputMode via the routed commands of its NavigationInputMode.
Class NavigationInputMode
supports collapsing and expanding of selected group nodes in a folding-enabled
graph via routed commands.
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:
Collapsing and expanding can also be controlled on a per-group node basis by overriding the following predicate methods:
protected virtual bool ShouldCollapseGroup(INode groupNode) |
Navigation in a hierarchy, i.e., entering group nodes or exiting the current
group node, is supported by NavigationInputMode through routed commands 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 following methods. In particular, for complete customization of the behavior, the predicate methods can be easily overridden.
void EnterGroup(INode groupNode) |
|
| Description | Methods for navigating the hierarchy of nodes. |
protected virtual bool ShouldEnterGroup(INode groupNode) |
|
| Description | Predicate methods for customization. |
GraphCommands provides a number of graph hierarchy-related commands that can be used for command binding. Note that all commands are of type RoutedUICommand.
Table 3.5. GraphCommands's graph hierarchy-related commands
| Command Name | Description |
|---|---|
| GroupSelectionCommand | Creates a new group node that contains all currently selected nodes. |
| UngroupSelectionCommand | Regroups all currently selected nodes from their respective group nodes to under the hierarchy of nodes's root element. |
| AdjustGroupNodeSizeCommand | Changes the size of all currently selected group nodes such that they enclose their respective contents using minimum margins. Supports a command parameter that can be of type INode or type IEnumerable<INode>. |
| CollapseGroupCommand | Collapses all currently selected group nodes. Supports a command parameter of type INode. |
| ExpandGroupCommand | Expands all currently selected collapsed group nodes. Supports a command parameter of type INode. |
| ToggleGroupStateCommand | Collapses all currently selected group nodes, respectively expands all currently selected collapsed group nodes. Supports a command parameter of type INode. |
| EnterGroupCommand | Displays the contents of a given group node in the current GraphControl. Supports a command parameter of type INode. |
| ExitGroupCommand | Switches from displaying the contents of a group node to displaying the contents of the group node's parent level in the current GraphControl. |
Note that commands that support a command parameter allow to specify a group node (or a set of group nodes) to be used instead of the current selection.
By default, these commands are used for command binding by class GraphEditorInputMode which binds them upon installation.
|
Copyright ©2008-2011, yWorks GmbH. All rights reserved. |