Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

WorkingWithSelection

StarUML edited this page Jan 18, 2015 · 6 revisions

Working with Selection

In this chapter, we're going to learn how to get selected elements, enforce to select elements, and do something by listening selection changed events.

Getting selected elements

Users can select elements in a diagram or in Explorer. Sometimes we may need to access only the selected elements. To get selected elements we need SelectionManager module.

var SelectionManager = app.getModule('engine/SelectionManager');

Before to get detail, we need to distinguish between selected views and selected models. If you select the Book class in a diagram, then there are a selected view (UMLClassView) and a selected model (UMLClass). If you select the Author class in Explorer, then there is a selected model (UMLClass) and no selected views.

We can access to selected elements using SelectionManager as following:

var selectedViews = SelectionManager.getSelectedViews();
var selectedModels = SelectionManager.getSelectedModels();
var selected = SelectionManager.getSelected(); // === selectedModels[0]

Enforce to select particular elements

TODO...

Listening selection changed event

TODO...

Clone this wiki locally