Search code examples
javascriptselectiondraw2d-js

Update draw2d UI to match Selection


My page has in its center a Draw2D canvas. It may have a selection or not at any moment.

I need to update the selection manually. When the user (drags and) drops an element from the Toolbox (panel on the left of the page), it creates the element in the canvas. I want this element to be selected. To do so, I made this:

canvas.getSelection().clear().setPrimary(newFigure);

Triggers are attached to selection change. On the right side of the page, I have a Properties panel that shows information on what is selected.

When I drop my element, my UI updates so that the Properties panel's content to match the Figure that was just added. But the fact is that the blue dashed rectangle that is supposed to be around the selected element(s) is not updated. Consequence is that the user might be confused (imagine yourself seeing details on Foo when Bar is selected).

In this case, why isn't the visual selection updated? And how to do so, if it is possible?


Solution

  • Canvas has a setCurrentSelection method that takes any draw2d.Figure or a draw2d.util.ArrayList of figures