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 WPF-like 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 WPF-like routed commands of its NavigationInputMode.
Class NavigationInputMode
supports
collapsing and expanding of selected group nodes in a folding-enabled graph via
WPF-like 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.
API Excerpt 3.11. Convenience methods in NavigationInputMode for collapsing and expanding group nodes
void CollapseGroup(INode groupNode) void ExpandGroup(INode groupNode)
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 virtual bool ShouldCollapseGroup(INode groupNode) protected virtual bool ShouldExpandGroup(INode groupNode)
Navigation in a hierarchy, i.e., entering group nodes or exiting the current group
node, is supported by NavigationInputMode through WPF-like 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 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.
GraphCommands provides a number of graph hierarchy-related commands that can be used for WPF-like command binding.
These commands rely on a commanding infrastructure very similar in concept and usage
to that present in Windows Presentation Foundation.
The classes that make up this support are CommandManager
,
CommandBinding
, and RoutedCommand
from the yWorks.Support.Windows
namespace.
Together, they realize the command pattern and the necessary command binding support
for WPF-like commands in yFiles.NET.
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 WPF-like command binding by class GraphEditorInputMode which binds them upon installation.
|
Copyright ©2006-2011, yWorks GmbH. All rights reserved. |