Search in sources :

Example 1 with UserGroupChangedEvent

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);
        }
    });
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) DragAndDropEvent(com.vaadin.event.dd.DragAndDropEvent) ArrayList(java.util.ArrayList) CubaTree(com.haulmont.cuba.web.toolkit.ui.CubaTree) DataBoundTransferable(com.vaadin.event.DataBoundTransferable) UserGroupChangedEvent(com.haulmont.cuba.gui.app.security.group.browse.UserGroupChangedEvent) And(com.vaadin.event.dd.acceptcriteria.And) ArrayList(java.util.ArrayList) List(java.util.List) DropHandler(com.vaadin.event.dd.DropHandler) Component(com.vaadin.ui.Component) AcceptCriterion(com.vaadin.event.dd.acceptcriteria.AcceptCriterion)

Aggregations

UserGroupChangedEvent (com.haulmont.cuba.gui.app.security.group.browse.UserGroupChangedEvent)1 Group (com.haulmont.cuba.security.entity.Group)1 User (com.haulmont.cuba.security.entity.User)1 CubaTree (com.haulmont.cuba.web.toolkit.ui.CubaTree)1 DataBoundTransferable (com.vaadin.event.DataBoundTransferable)1 DragAndDropEvent (com.vaadin.event.dd.DragAndDropEvent)1 DropHandler (com.vaadin.event.dd.DropHandler)1 AcceptCriterion (com.vaadin.event.dd.acceptcriteria.AcceptCriterion)1 And (com.vaadin.event.dd.acceptcriteria.And)1 Component (com.vaadin.ui.Component)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1