Example usage for com.vaadin.shared.ui.dd VerticalDropLocation BOTTOM

List of usage examples for com.vaadin.shared.ui.dd VerticalDropLocation BOTTOM

Introduction

In this page you can find the example usage for com.vaadin.shared.ui.dd VerticalDropLocation BOTTOM.

Prototype

VerticalDropLocation BOTTOM

To view the source code for com.vaadin.shared.ui.dd VerticalDropLocation BOTTOM.

Click Source Link

Usage

From source file:com.esofthead.mycollab.module.project.view.task.TaskGroupReorderViewImpl.java

License:Open Source License

private void constructHeader() {
    CssLayout headerWrapper = new CssLayout();
    headerWrapper.setWidth("100%");
    headerWrapper.addStyleName("taskgroup-header");

    HorizontalLayout header = new HorizontalLayout();
    header.setSpacing(true);//from   w  w  w. j a  v a2 s.  co  m
    header.setWidth("100%");
    Label headerLbl = new Label("All Tasks");
    headerLbl.setStyleName("h2");
    header.addComponent(headerLbl);
    header.setComponentAlignment(headerLbl, Alignment.MIDDLE_LEFT);
    header.setExpandRatio(headerLbl, 1.0f);

    Button backToListBtn = new Button("Back to dashboard", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            EventBusFactory.getInstance().post(new TaskListEvent.GotoTaskListScreen(this, null));
        }
    });
    backToListBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    header.addComponent(backToListBtn);
    header.setComponentAlignment(backToListBtn, Alignment.MIDDLE_RIGHT);

    saveOrderBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE), new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            EventBusFactory.getInstance().post(new TaskListEvent.SaveReoderTaskList(event, changeSet));
        }
    });
    saveOrderBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    header.addComponent(saveOrderBtn);
    header.setComponentAlignment(saveOrderBtn, Alignment.MIDDLE_RIGHT);

    headerWrapper.addComponent(header);

    this.addComponent(headerWrapper);

    final DDVerticalLayout ddLayout = new DDVerticalLayout();
    ddLayout.addStyleName("taskgroup-reorder");
    ddLayout.setComponentVerticalDropRatio(0.3f);
    ddLayout.setDragMode(LayoutDragMode.CLONE);
    ddLayout.setDropHandler(new DropHandler() {
        private static final long serialVersionUID = 1L;

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return new Not(VerticalLocationIs.MIDDLE);
        }

        @Override
        public void drop(DragAndDropEvent event) {
            LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();

            DDVerticalLayout.VerticalLayoutTargetDetails details = (DDVerticalLayout.VerticalLayoutTargetDetails) event
                    .getTargetDetails();

            TaskListComponent comp = (TaskListComponent) transferable.getComponent();

            int currentIndex = ddLayout.getComponentIndex(comp);
            int newIndex = details.getOverIndex();

            ddLayout.removeComponent(comp);

            if (currentIndex > newIndex && details.getDropLocation() == VerticalDropLocation.BOTTOM) {
                newIndex++;
            }

            SimpleTaskList dropTaskList = comp.getTaskList();
            dropTaskList.setGroupindex(newIndex);
            changeSet.add(dropTaskList);
            ddLayout.addComponent(comp, newIndex);

            // change affected task list items
            for (int i = 0; i < ddLayout.getComponentCount(); i++) {
                TaskListComponent affectedComp = (TaskListComponent) ddLayout.getComponent(i);
                SimpleTaskList affectedTaskList = affectedComp.getTaskList();
                affectedTaskList.setGroupindex(i);
                changeSet.add(affectedTaskList);
            }
        }
    });

    taskLists = new BeanList<ProjectTaskListService, TaskListSearchCriteria, SimpleTaskList>(null,
            ApplicationContextUtil.getSpringBean(ProjectTaskListService.class), TaskListRowDisplayHandler.class,
            ddLayout);
    this.addComponent(taskLists);
}

From source file:com.foc.vaadin.gui.layouts.FVVertical_WYSIWYG_DropHandler.java

License:Apache License

@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    // Component re-ordering
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event.getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
    Component comp = transferable.getComponent();
    int idx = (details).getOverIndex();

    // Detach//w  ww  . ja  v a  2s .c o m
    if (comp != null && layout != null)
        layout.removeComponent(comp);
    idx--;

    // Increase index if component is dropped after or above a previous
    // component
    VerticalDropLocation loc = details.getDropLocation();
    if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) {
        idx++;
    }

    // Add component
    if (layout != null) {
        if (idx >= 0) {
            layout.addComponent(comp, idx);
        } else {
            layout.addComponent(comp);
        }
    }

    if (comp instanceof FVLayout) {
        ((FVLayout) comp).setDragDrop(true);
    }

    // Add component alignment if given
    if (dropAlignment != null && layout != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}

From source file:com.foc.vaadin.gui.layouts.FVVertical_WYSIWYG_DropHandler.java

License:Apache License

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event.getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
    Component source = event.getTransferable().getSourceComponent();
    int idx = (details).getOverIndex();
    Component comp = transferable.getComponent();

    // Check that we are not dragging an outer layout into an inner
    // layout//from w w w . j av  a  2s .  com
    Component parent = layout.getParent();
    while (parent != null) {
        if (parent == comp) {
            return;
        }
        parent = parent.getParent();
    }

    // If source is an instance of a component container then remove
    // it
    // from there,
    // the component cannot have two parents.

    ComponentContainer sourceLayout = null;

    if (source instanceof ComponentContainer) {
        sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(comp);
    }

    // Increase index if component is dropped after or above a
    // previous
    // component
    VerticalDropLocation loc = (details).getDropLocation();
    if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) {
        idx++;
    }

    // Add component
    if (idx >= 0) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }

    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebFilterHelper.java

License:Apache License

@Override
public void initConditionsDragAndDrop(final Tree tree, final ConditionsTree conditions) {
    final com.vaadin.ui.Tree vTree = tree.unwrap(com.vaadin.ui.Tree.class);
    vTree.setDragMode(com.vaadin.ui.Tree.TreeDragMode.NODE);
    vTree.setDropHandler(new DropHandler() {
        @Override//from w  w  w. java2 s.c  o  m
        public void drop(DragAndDropEvent event) {
            Transferable t = event.getTransferable();

            if (t.getSourceComponent() != vTree)
                return;

            com.vaadin.ui.Tree.TreeTargetDetails target = (com.vaadin.ui.Tree.TreeTargetDetails) event
                    .getTargetDetails();

            VerticalDropLocation location = target.getDropLocation();
            Object sourceItemId = t.getData("itemId");
            Object targetItemId = target.getItemIdOver();

            if (targetItemId == null)
                return;

            CollectionDatasource datasource = tree.getDatasource();

            AbstractCondition sourceCondition = (AbstractCondition) datasource.getItem(sourceItemId);
            AbstractCondition targetCondition = (AbstractCondition) datasource.getItem(targetItemId);

            Node<AbstractCondition> sourceNode = conditions.getNode(sourceCondition);
            Node<AbstractCondition> targetNode = conditions.getNode(targetCondition);

            if (isAncestorOf(targetNode, sourceNode))
                return;

            boolean moveToTheSameParent = Objects.equals(sourceNode.getParent(), targetNode.getParent());

            if (location == VerticalDropLocation.MIDDLE) {
                if (sourceNode.getParent() == null) {
                    conditions.getRootNodes().remove(sourceNode);
                } else {
                    sourceNode.getParent().getChildren().remove(sourceNode);
                }
                targetNode.addChild(sourceNode);
                refreshConditionsDs();
                tree.expand(targetCondition.getId());
            } else {
                List<Node<AbstractCondition>> siblings;
                if (targetNode.getParent() == null)
                    siblings = conditions.getRootNodes();
                else
                    siblings = targetNode.getParent().getChildren();

                int targetIndex = siblings.indexOf(targetNode);
                if (location == VerticalDropLocation.BOTTOM)
                    targetIndex++;

                int sourceNodeIndex;
                if (sourceNode.getParent() == null) {
                    sourceNodeIndex = conditions.getRootNodes().indexOf(sourceNode);
                    conditions.getRootNodes().remove(sourceNode);
                } else {
                    sourceNodeIndex = sourceNode.getParent().getChildren().indexOf(sourceNode);
                    sourceNode.getParent().getChildren().remove(sourceNode);
                }

                //decrease drop position index if dragging from top to bottom inside the same parent node
                if (moveToTheSameParent && (sourceNodeIndex < targetIndex))
                    targetIndex--;

                if (targetNode.getParent() == null) {
                    sourceNode.parent = null;
                    conditions.getRootNodes().add(targetIndex, sourceNode);
                } else {
                    targetNode.getParent().insertChildAt(targetIndex, sourceNode);
                }

                refreshConditionsDs();
            }
        }

        protected boolean isAncestorOf(Node childNode, Node possibleParentNode) {
            while (childNode.getParent() != null) {
                if (childNode.getParent().equals(possibleParentNode))
                    return true;
                childNode = childNode.getParent();
            }
            return false;
        }

        protected void refreshConditionsDs() {
            tree.getDatasource().refresh(Collections.singletonMap("conditions", conditions));
        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return new Or(new AbstractSelect.TargetItemIs(vTree, getGroupConditionIds().toArray()),
                    new Not(AbstractSelect.VerticalLocationIs.MIDDLE));
        }

        protected List<UUID> getGroupConditionIds() {
            List<UUID> groupConditions = new ArrayList<>();
            List<AbstractCondition> list = conditions.toConditionsList();
            for (AbstractCondition condition : list) {
                if (condition instanceof GroupCondition)
                    groupConditions.add(condition.getId());
            }
            return groupConditions;
        }
    });
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultAccordionDropHandler.java

License:Apache License

/**
 * Called when tabs are being rearranged
 * /*from   w  w  w  . j a  v  a 2  s  .  c o m*/
 * @param event
 *            A drag and drop event
 */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    AccordionTargetDetails details = (AccordionTargetDetails) event.getTargetDetails();
    DDAccordion acc = (DDAccordion) details.getTarget();
    VerticalDropLocation location = details.getDropLocation();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component c = transferable.getComponent();
    int idx = details.getOverIndex();

    Tab tab = acc.getTab(c);

    if (location == VerticalDropLocation.TOP) {
        // Left of previous tab
        int originalIndex = acc.getTabPosition(tab);
        if (originalIndex > idx) {
            acc.setTabPosition(tab, idx);
        } else if (idx - 1 >= 0) {
            acc.setTabPosition(tab, idx - 1);
        }

    } else if (location == VerticalDropLocation.BOTTOM) {
        // Right of previous tab
        int originalIndex = acc.getTabPosition(tab);
        if (originalIndex > idx) {
            acc.setTabPosition(tab, idx + 1);
        } else {
            acc.setTabPosition(tab, idx);
        }
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultAccordionDropHandler.java

License:Apache License

/**
 * Adds a new tab from the drop/*from  ww w  . j av  a  2s  .  co m*/
 * 
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();

    // Get the target details
    AccordionTargetDetails details = (AccordionTargetDetails) event.getTargetDetails();
    DDAccordion acc = (DDAccordion) details.getTarget();
    Component c = transferable.getComponent();
    int idx = details.getOverIndex();
    VerticalDropLocation location = details.getDropLocation();

    // Detach from old source
    Component source = transferable.getSourceComponent();
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(c);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    if (location == VerticalDropLocation.TOP) {
        acc.addTab(c, idx);
    } else if (location == VerticalDropLocation.BOTTOM) {
        acc.addTab(c, idx + 1);
    } else {
        acc.addTab(c);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultAccordionDropHandler.java

License:Apache License

@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    AccordionTargetDetails details = (AccordionTargetDetails) event.getTargetDetails();
    VerticalDropLocation location = details.getDropLocation();
    DDAccordion acc = (DDAccordion) details.getTarget();
    int idx = details.getOverIndex();

    Component c = resolveComponentFromHTML5Drop(event);
    c.setCaption(resolveCaptionFromHTML5Drop(event));

    if (location == VerticalDropLocation.TOP) {
        acc.addTab(c, idx);//from w  ww.j  a va2  s . c  o  m
    } else if (location == VerticalDropLocation.BOTTOM) {
        acc.addTab(c, idx + 1);
    } else {
        acc.addTab(c);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultCssLayoutDropHandler.java

License:Apache License

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails();
    DDCssLayout layout = (DDCssLayout) details.getTarget();
    HorizontalDropLocation hl = details.getHorizontalDropLocation();
    VerticalDropLocation vl = details.getVerticalDropLocation();
    Component source = event.getTransferable().getSourceComponent();
    int idx = (details).getOverIndex();
    Component comp = transferable.getComponent();
    Component over = details.getOverComponent();

    if (over == layout) {
        if (vl == VerticalDropLocation.TOP || hl == HorizontalDropLocation.LEFT) {
            idx = 0;//from  www . j  a v a 2 s .  co  m
        } else if (vl == VerticalDropLocation.BOTTOM || hl == HorizontalDropLocation.RIGHT) {
            idx = -1;
        }
    } else {
        if (vl == VerticalDropLocation.BOTTOM || hl == HorizontalDropLocation.RIGHT) {
            idx++;
        }
    }

    // Check that we are not dragging an outer layout into an inner
    // layout
    Component parent = layout.getParent();
    while (parent != null) {
        if (parent == comp) {
            return;
        }
        parent = parent.getParent();
    }

    // If source is an instance of a component container then remove
    // it
    // from there,
    // the component cannot have two parents.
    if (source instanceof ComponentContainer) {
        ComponentContainer sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(comp);
    }

    // Add component
    if (idx >= 0 && idx < layout.getComponentCount()) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultCssLayoutDropHandler.java

License:Apache License

@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails();
    Component over = details.getOverComponent();
    DDCssLayout layout = (DDCssLayout) details.getTarget();
    int idx = (details).getOverIndex();
    HorizontalDropLocation hl = details.getHorizontalDropLocation();
    VerticalDropLocation vl = details.getVerticalDropLocation();

    if (over == layout) {
        if (vl == VerticalDropLocation.TOP || hl == HorizontalDropLocation.LEFT) {
            idx = 0;// w w  w .  j av a  2 s.c o  m
        } else if (vl == VerticalDropLocation.BOTTOM || hl == HorizontalDropLocation.RIGHT) {
            idx = -1;
        }
    } else {
        if (vl == VerticalDropLocation.BOTTOM || hl == HorizontalDropLocation.RIGHT) {
            idx++;
        }
    }

    if (idx >= 0 && idx < layout.getComponentCount()) {
        layout.addComponent(resolveComponentFromHTML5Drop(event), idx);
    } else {
        layout.addComponent(resolveComponentFromHTML5Drop(event));
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultFormLayoutDropHandler.java

License:Apache License

@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    FormLayoutTargetDetails details = (FormLayoutTargetDetails) event.getTargetDetails();
    DDFormLayout layout = (DDFormLayout) details.getTarget();

    Component comp = transferable.getComponent();
    int idx = details.getOverIndex();
    int oldIdx = layout.getComponentIndex(comp);

    if (idx == oldIdx) {
        // Dropping on myself
        return;/*from   w ww.j av  a2s.  c  o m*/
    }

    // Detach
    layout.removeComponent(comp);
    if (idx > 0 && idx > oldIdx) {
        idx--;
    }

    // Increase index if component is dropped after or above a previous
    // component
    VerticalDropLocation loc = details.getDropLocation();
    if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) {
        idx++;
    }

    // Add component
    if (idx >= 0) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }

    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}