Selection interactors

The following sections explain how to use the selection interactors.

SelectionInteractor

The SelectionInteractor manages the interaction between its graph and its Selection object, by adding and removing the selected elements. By default, when you click an element, the selection is empty, and the clicked element is selected. If you click an element while holding the Ctrl key, the clicked element is added to the selection. If the element is already selected, it is removed from the selection. If you click a free area of the diagram, the selection is empty.
The SelectionInteractor can be used also without a Diagram widget, by enabling it in the graph:
graph = surface.createGraph();
graph.setSelect(true);

MarqueeSelectionInteractor

The MarqueeSelectionInteractor is available in the DiagramEditor widget. It allows you to select multiple elements by selecting a rectangular area of the diagram.
When you click a free area of the diagram and drag the mouse, a translucent rectangle is drawn in the Viewport. When you release the mouse button, the bounded elements are selected. By default, partially bounded elements are included in the marquee selection. However, if you want to include only fully bounded elements in the marquee selection, you can set the setPartialSelectionEnabled method to false.
The modes of the MarqueeSelectionInteractor can be changed through the DiagramEditor by using the setMarqueeMode(mode) method.
  • Top level only:
    Default mode. Selects only the top-level elements (the ones that are created in the graph). Set this mode by using the topLevelOnly constant.
  • Top parent:
    Selects only the highest parent of the selected elements. For example, if a complete subgraph is bounded, just the subgraph is selected, but not its children. If the subgraph is not bounded by the marquee, its bounded children are selected. Set this mode by using the topParent constant.
  • All:
    Selects all the bounded elements. Set this mode by using the all constant.
Multiple selection is also possible. If the user repeats the marquee selection with the appropriate modifier key pressed (Ctrl, by default), the selected elements are added to the selection, without clearing the pre-existent ones.