use of com.haulmont.cuba.gui.app.security.group.browse.UserGroupChangedEvent in project cuba by cuba-platform.
the class AccessGroupCompanion method initDragAndDrop.
@Override
public void initDragAndDrop(Table<User> usersTable, Tree<Group> groupsTree, Consumer<UserGroupChangedEvent> userGroupChangedHandler) {
com.vaadin.ui.Table vTable = usersTable.unwrap(com.vaadin.ui.Table.class);
vTable.setDragMode(com.vaadin.ui.Table.TableDragMode.MULTIROW);
CubaTree vTree = groupsTree.unwrap(CubaTree.class);
vTree.setDragMode(com.vaadin.ui.Tree.TreeDragMode.NODE);
vTree.setDropHandler(new DropHandler() {
@Override
public void drop(DragAndDropEvent dropEvent) {
DataBoundTransferable transferable = (DataBoundTransferable) dropEvent.getTransferable();
AbstractSelect.AbstractSelectTargetDetails dropData = ((AbstractSelect.AbstractSelectTargetDetails) dropEvent.getTargetDetails());
Component sourceComponent = transferable.getSourceComponent();
List<User> users = null;
if (sourceComponent instanceof com.vaadin.ui.Table) {
users = new ArrayList<>(usersTable.getSelected());
}
if (users == null) {
return;
}
if (users.isEmpty()) {
User user = convertToEntity(vTable.getItem(transferable.getItemId()), User.class);
users.add(user);
}
final Object targetItemId = dropData.getItemIdOver();
if (targetItemId == null) {
return;
}
Group group = convertToEntity(vTree.getItem(targetItemId), Group.class);
if (group == null) {
return;
}
userGroupChangedHandler.accept(new UserGroupChangedEvent(groupsTree, users, group));
}
@Override
public AcceptCriterion getAcceptCriterion() {
return new And(AbstractSelect.AcceptItem.ALL);
}
});
}
Aggregations