Search code examples
gwtselectdragareadrag-and-drop

Select area by dragging mouse in gwt


I am using gwt with gwt-dnd and I want to do the following:

1. Select rectangle area by dragging the mouse
2. Select all the elements that are in this area
3. drag all selected elements.

Is there any idea?


Solution

  • On MouseDownEvent record the coordinates of the pointer (event.getClientX() and eventGetClientY()).

    On MouseUpEvent do the same. If coordinates are different, you have a selected rectangular.

    Get the widget which contains all the widgets or elements that are selectable. Loop through its children.

    Compare coordinates of each widget with your rectangular (use getAbsoluteTop(), getAbdoluteLeft(), getOffsetHeight(), and getOffsetWidth()). Select widgets that are totally or partially inside the selected area.