Example usage for com.vaadin.event Transferable getData

List of usage examples for com.vaadin.event Transferable getData

Introduction

In this page you can find the example usage for com.vaadin.event Transferable getData.

Prototype

public Object getData(String dataFlavor);

Source Link

Document

Returns the data from Transferable by its data flavor (aka data type).

Usage

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 .j av a2  s  .c om*/
        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.lizardtech.expresszip.vaadin.SetupMapViewComponent.java

License:Apache License

public SetupMapViewComponent() {

    listeners = new ArrayList<SetupMapViewListener>();
    cmbProjection = new ComboBox();
    cmbProjection.setTextInputAllowed(false);
    HorizontalLayout projectionLayout = new HorizontalLayout();
    projectionLayout.addComponent(cmbProjection);
    projectionLayout.setWidth(100f, UNITS_PERCENTAGE);

    setSizeFull();//w  w w .  j  a v a 2  s  .  com

    // main layout
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSizeFull();

    // instruction banner
    Label step = new Label("Step 2: Select Export Region");
    step.addStyleName("step");
    layout.addComponent(step);

    //
    // setup tree data source
    //
    treeHier = new HierarchicalContainer();
    treeHier.addContainerProperty(ExpressZipTreeTable.LAYER, ExpressZipLayer.class, null);
    treeHier.addContainerProperty(DRAG_PROPERTY, Embedded.class, null);

    // table holding layers
    treeTable = new ExpressZipTreeTable();
    treeTable.setContainerDataSource(treeHier);

    treeTable.setDragMode(TableDragMode.ROW);
    treeTable.setColumnHeaders(new String[] { ExpressZipTreeTable.LAYER, "" });
    treeTable.setColumnExpandRatio(ExpressZipTreeTable.LAYER, 1);
    treeTable.setColumnWidth(DRAG_PROPERTY, 23);

    // upload shape file
    btnUploadShapeFile.setFieldType(FieldType.BYTE_ARRAY);
    btnUploadShapeFile.setButtonCaption("");
    btnUploadShapeFile.setSizeUndefined();
    btnUploadShapeFile.addStyleName("shapefile");

    // remove shape file
    btnRemoveShapeFile.addListener(this);
    btnRemoveShapeFile.setSizeUndefined();
    btnRemoveShapeFile.setVisible(false);
    btnRemoveShapeFile.setIcon(new ThemeResource("img/RemoveShapefileStandard23px.png"));
    btnRemoveShapeFile.setStyleName(BaseTheme.BUTTON_LINK);
    btnRemoveShapeFile.addStyleName("shapefile");
    HorizontalLayout hznUpload = new HorizontalLayout();

    Panel coordPanel = new Panel("Export Extent");

    layout.addComponent(treeTable);
    layout.addComponent(new Panel(PROJECTION, projectionLayout));
    layout.addComponent(new Panel(SHAPEFILE_UPLOAD, hznUpload));
    layout.addComponent(coordPanel);

    layout.setSpacing(true);

    hznUpload.addComponent(btnUploadShapeFile);
    hznUpload.addComponent(btnRemoveShapeFile);
    hznUpload.addComponent(lblCurrentShapeFile);
    hznUpload.setExpandRatio(lblCurrentShapeFile, 1f);
    hznUpload.setComponentAlignment(lblCurrentShapeFile, Alignment.MIDDLE_LEFT);
    hznUpload.setWidth("100%");

    cmbProjection.setWidth("100%");

    topTextField.setWidth(150, UNITS_PIXELS);
    topTextField.setImmediate(true);
    topTextField.setRequired(true);
    topTextField.addListener(topListener);

    leftTextField.setWidth(150, UNITS_PIXELS);
    leftTextField.setImmediate(true);
    leftTextField.setRequired(true);
    leftTextField.addListener(leftListener);

    bottomTextField.setWidth(150, UNITS_PIXELS);
    bottomTextField.setImmediate(true);
    bottomTextField.setRequired(true);
    bottomTextField.addListener(bottomListener);

    rightTextField.setWidth(150, UNITS_PIXELS);
    rightTextField.setImmediate(true);
    rightTextField.setRequired(true);
    rightTextField.addListener(rightListener);

    VerticalLayout coordLayout = new VerticalLayout();
    coordLayout.setSizeFull();
    coordPanel.setContent(coordLayout);
    coordLayout.addComponent(topTextField);

    HorizontalLayout leftRightLayout = new HorizontalLayout();
    leftRightLayout.setWidth("100%");
    leftRightLayout.addComponent(leftTextField);
    leftRightLayout.addComponent(rightTextField);
    leftRightLayout.setComponentAlignment(leftTextField, Alignment.MIDDLE_LEFT);
    leftRightLayout.setComponentAlignment(rightTextField, Alignment.MIDDLE_RIGHT);
    coordLayout.addComponent(leftRightLayout);

    coordLayout.addComponent(bottomTextField);
    coordLayout.setComponentAlignment(topTextField, Alignment.TOP_CENTER);
    coordLayout.setComponentAlignment(bottomTextField, Alignment.BOTTOM_CENTER);

    btnNext = new ExpressZipButton("Next", Style.STEP, this);
    btnBack = new ExpressZipButton("Back", Style.STEP, this);

    HorizontalLayout backNextLayout = new HorizontalLayout();
    backNextLayout.addComponent(btnBack);
    backNextLayout.addComponent(btnNext);
    btnNext.setEnabled(false);

    backNextLayout.setComponentAlignment(btnBack, Alignment.BOTTOM_LEFT);
    backNextLayout.setComponentAlignment(btnNext, Alignment.BOTTOM_RIGHT);
    backNextLayout.setWidth("100%");

    VerticalLayout navLayout = new VerticalLayout();
    navLayout.addComponent(backNextLayout);
    navLayout.setSpacing(true);

    ThemeResource banner = new ThemeResource("img/ProgressBar2.png");
    navLayout.addComponent(new Embedded(null, banner));

    layout.addComponent(navLayout);
    layout.setComponentAlignment(navLayout, Alignment.BOTTOM_CENTER);

    layout.setExpandRatio(treeTable, 1.0f);
    setCompositionRoot(layout);

    // notify when selection changes
    treeTable.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            for (SetupMapViewListener listener : listeners) {
                listener.layersSelectedEvent((Set<ExpressZipLayer>) treeTable.getValue());
            }

        }
    });
    treeTable.addActionHandler(this);
    treeHier.removeAllItems();

    //
    // drag n' drop behavior
    //
    treeTable.setDropHandler(new DropHandler() {
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }

        // Make sure the drag source is the same tree
        public void drop(DragAndDropEvent event) {
            // Wrapper for the object that is dragged
            Transferable t = event.getTransferable();

            // Make sure the drag source is the same tree
            if (t.getSourceComponent() != treeTable)
                return;

            AbstractSelectTargetDetails target = (AbstractSelectTargetDetails) event.getTargetDetails();

            // Get ids of the dragged item and the target item
            Object sourceItemId = t.getData("itemId");
            Object targetItemId = target.getItemIdOver();

            // if we drop on ourselves, ignore
            if (sourceItemId == targetItemId)
                return;

            // On which side of the target the item was dropped
            VerticalDropLocation location = target.getDropLocation();

            // place source after target
            treeHier.moveAfterSibling(sourceItemId, targetItemId);

            // if top, switch them
            if (location == VerticalDropLocation.TOP) {
                treeHier.moveAfterSibling(targetItemId, sourceItemId);
            }

            Collection<ExpressZipLayer> layers = (Collection<ExpressZipLayer>) treeHier.rootItemIds();
            for (SetupMapViewListener listener : listeners)
                listener.layerMovedEvent(layers);
        }
    });

    cmbProjection.setImmediate(true);
    cmbProjection.setNullSelectionAllowed(false);
    cmbProjection.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = -5188369735622627751L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (cmbProjection.getValue() != null) {
                selectedEpsg = (String) cmbProjection.getValue();
                String currentProjection = ((ExpressZipWindow) getApplication().getMainWindow())
                        .getExportProps().getMapProjection();
                if (!selectedEpsg.equals(currentProjection))
                    for (SetupMapViewListener listener : new ArrayList<SetupMapViewListener>(listeners))
                        listener.projectionChangedEvent(selectedEpsg);
            }
        }
    });
}

From source file:de.fzi.fhemapi.view.vaadin.ui.HWindow.java

License:Apache License

private void fillTree() {

    initDevicesContainer();//from   w  w  w.j  ava2s.co  m
    devicesTree.setContainerDataSource(devicesContainer);
    for (Object id : devicesTree.rootItemIds()) {
        devicesTree.expandItemsRecursively(id);
    }

    devicesTree.setImmediate(true);
    devicesTree.addListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent event) {
            if (event.getButton() == ItemClickEvent.BUTTON_LEFT) {
                if (!server.getStructureManager().structureExists((String) event.getItemId())) {
                    fillRightSideForDevice((String) event.getItemId());
                } else {
                    mainSplitPanel.setSecondComponent(new Tree());
                }
            }
        }
    });
    devicesTree.setDragMode(TreeDragMode.NODE);
    devicesTree.setDropHandler(new DropHandler() {

        @Override
        public AcceptCriterion getAcceptCriterion() {
            //            AcceptCriterion crit = new ClientSideCriterion() {
            //               
            //               @Override
            //               public boolean accept(DragAndDropEvent dragEvent) {
            //                    Transferable t = dragEvent.getTransferable();
            //                  TreeTargetDetails target = (TreeTargetDetails) dragEvent.getTargetDetails();
            //                  Object sourceItemId = t.getData("itemId");
            //                    Object targetItemId = target.getItemIdOver();
            //                    if(devicesContainer.getParent(sourceItemId) == null)
            //                       return false;
            //                    return true;
            //               }
            //            };
            //            return crit;
            return AcceptAll.get();
        }

        @Override
        public void drop(DragAndDropEvent event) {
            Transferable t = event.getTransferable();
            if (t.getSourceComponent() != devicesTree)
                return;
            TreeTargetDetails target = (TreeTargetDetails) event.getTargetDetails();
            Object sourceItemId = t.getData("itemId");
            Object targetItemId = target.getItemIdOver();
            VerticalDropLocation location = target.getDropLocation();
            HierarchicalContainer container = (HierarchicalContainer) devicesTree.getContainerDataSource();

            // Drop right on an item -> make it a child
            if (location == VerticalDropLocation.MIDDLE) {
                if (container.getParent(targetItemId) == null) {
                    server.getStructureManager().addDeviceToStructure((String) targetItemId,
                            (String) sourceItemId);
                } else {
                    server.getStructureManager().addDeviceToStructure(
                            (String) container.getParent(targetItemId), (String) sourceItemId);
                }
                server.getStructureManager().rereadFromFHEM();
                reloadTree();
            }
        }
    });

}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI.java

License:Apache License

private void createTree() {
    tree = new ProjectTreeComponent();
    // Set the tree in drag source mode
    tree.setDragMode(TreeDragMode.NODE);
    // Allow the tree to receive drag drops and handle them
    tree.setDropHandler(new DropHandler() {
        @Override//ww w.j  av a 2s. com
        public AcceptCriterion getAcceptCriterion() {
            TreeDropCriterion criterion = new TreeDropCriterion() {
                @Override
                protected Set<Object> getAllowedItemIds(DragAndDropEvent dragEvent, Tree tree) {
                    HashSet<Object> allowed = new HashSet<>();
                    tree.getItemIds().stream()
                            .filter((itemId) -> (itemId instanceof Step) || (itemId instanceof Requirement))
                            .forEachOrdered((itemId) -> {
                                allowed.add(itemId);
                            });
                    return allowed;
                }
            };
            return criterion;
        }

        @Override
        public void drop(DragAndDropEvent event) {
            // Wrapper for the object that is dragged
            Transferable t = event.getTransferable();

            // Make sure the drag source is the same tree
            if (t.getSourceComponent() != tree) {
                return;
            }

            TreeTargetDetails target = (TreeTargetDetails) event.getTargetDetails();

            // Get ids of the dragged item and the target item
            Object sourceItemId = t.getData("itemId");
            Object targetItemId = target.getItemIdOver();

            LOG.log(Level.INFO, "Source: {0}", sourceItemId);
            LOG.log(Level.INFO, "Target: {0}", targetItemId);

            // On which side of the target the item was dropped
            VerticalDropLocation location = target.getDropLocation();

            HierarchicalContainer container = (HierarchicalContainer) tree.getContainerDataSource();

            if (null != location) // Drop right on an item -> make it a child
            {
                switch (location) {

                case MIDDLE:
                    if (tree.areChildrenAllowed(targetItemId)) {
                        tree.setParent(sourceItemId, targetItemId);
                    }
                    break;
                case TOP: {
                    boolean valid = false;
                    //for Steps we need to update the sequence number
                    if (sourceItemId instanceof Step && targetItemId instanceof Step) {
                        Step targetItem = (Step) targetItemId;
                        Step sourceItem = (Step) sourceItemId;
                        StepJpaController stepController = new StepJpaController(
                                DataBaseManager.getEntityManagerFactory());
                        if (targetItem.getTestCase().equals(sourceItem.getTestCase())) {
                            //Same Test Case, just re-arrange
                            LOG.info("Same Test Case!");
                            SortedMap<Integer, Step> map = new TreeMap<>();
                            targetItem.getTestCase().getStepList().forEach((s) -> {
                                map.put(s.getStepSequence(), s);
                            });
                            //Now swap the two that switched
                            swapValues(map, sourceItem.getStepSequence(), targetItem.getStepSequence());
                            //Now update the sequence numbers
                            int count = 0;
                            for (Entry<Integer, Step> entry : map.entrySet()) {
                                entry.getValue().setStepSequence(++count);
                                try {
                                    stepController.edit(entry.getValue());
                                } catch (Exception ex) {
                                    LOG.log(Level.SEVERE, null, ex);
                                }
                            }
                            valid = true;
                        } else {
                            //Diferent Test Case
                            LOG.info("Different Test Case!");
                            //                                    //Remove from source test case
                            //                                    SortedMap<Integer, Step> map = new TreeMap<>();
                            //                                    sourceItem.getTestCase().getStepList().forEach((s) -> {
                            //                                        map.put(s.getStepSequence(), s);
                            //                                    });
                            //                                    //Now swap the two that switched
                            //                                    //First we remove the one from the source Test Case
                            //                                    Step removed = map.remove(sourceItem.getStepSequence() - 1);
                            //                                    sourceItem.getTestCase().getStepList().remove(removed);
                            //                                    removed.setTestCase(targetItem.getTestCase());
                            //                                    try {
                            //                                        stepController.edit(removed);
                            //                                        tcController.edit(sourceItem.getTestCase());
                            //                                    } catch (NonexistentEntityException ex) {
                            //                                         LOG.log(Level.SEVERE, null, ex);
                            //                                    } catch (Exception ex) {
                            //                                         LOG.log(Level.SEVERE, null, ex);
                            //                                    }
                            //                                    //Now update the sequence numbers
                            //                                    int count = 0;
                            //                                    for (Entry<Integer, Step> entry : map.entrySet()) {
                            //                                        entry.getValue().setStepSequence(++count);
                            //                                        try {
                            //                                            stepController.edit(entry.getValue());
                            //                                        } catch (Exception ex) {
                            //                                             LOG.log(Level.SEVERE, null, ex);
                            //                                        }
                            //                                    }
                            //                                    //And add it to the target test Case
                            //                                    SortedMap<Integer, Step> map2 = new TreeMap<>();
                            //                                    targetItem.getTestCase().getStepList().forEach((s) -> {
                            //                                        map2.put(s.getStepSequence(), s);
                            //                                    });
                            //                                    map2.put(targetItem.getStepSequence() - 1, removed);
                            //                                    count = 0;
                            //                                    for (Entry<Integer, Step> entry : map2.entrySet()) {
                            //                                        entry.getValue().setStepSequence(++count);
                            //                                        try {
                            //                                            stepController.edit(entry.getValue());
                            //                                        } catch (Exception ex) {
                            //                                             LOG.log(Level.SEVERE, null, ex);
                            //                                        }
                            //                                    }
                            //                                    //Add it to the Test Case
                            //                                    targetItem.getTestCase().getStepList().add(removed);
                        }
                    }
                    if (valid) {
                        // Drop at the top of a subtree -> make it previous
                        Object parentId = container.getParent(targetItemId);
                        container.setParent(sourceItemId, parentId);
                        container.moveAfterSibling(sourceItemId, targetItemId);
                        container.moveAfterSibling(targetItemId, sourceItemId);
                        buildProjectTree(targetItemId);
                        updateScreen();
                    }
                    break;
                }
                case BOTTOM: {
                    // Drop below another item -> make it next
                    Object parentId = container.getParent(targetItemId);
                    container.setParent(sourceItemId, parentId);
                    container.moveAfterSibling(sourceItemId, targetItemId);
                    break;
                }
                default:
                    break;
                }
            }
        }
    });
    tree.addValueChangeListener((Property.ValueChangeEvent event) -> {
        displayObject(tree.getValue());
    });
    //Select item on right click as well
    tree.addItemClickListener((ItemClickEvent event) -> {
        if (event.getSource() == tree && event.getButton() == MouseButton.RIGHT) {
            if (event.getItem() != null) {
                Item clicked = event.getItem();
                tree.select(event.getItemId());
            }
        }
    });
    ContextMenu contextMenu = new ContextMenu(tree, true);
    tree.addItemClickListener((ItemClickEvent event) -> {
        if (event.getButton() == MouseButton.RIGHT) {
            contextMenu.removeItems();
            if (tree.getValue() instanceof Project) {
                createProjectMenu(contextMenu);
            } else if (tree.getValue() instanceof Requirement) {
                createRequirementMenu(contextMenu);
            } else if (tree.getValue() instanceof RequirementSpec) {
                createRequirementSpecMenu(contextMenu);
            } else if (tree.getValue() instanceof RequirementSpecNode) {
                createRequirementSpecNodeMenu(contextMenu);
            } else if (tree.getValue() instanceof TestProject) {
                createTestProjectMenu(contextMenu);
            } else if (tree.getValue() instanceof Step) {
                createStepMenu(contextMenu);
            } else if (tree.getValue() instanceof TestCase) {
                createTestCaseMenu(contextMenu);
            } else if (tree.getValue() instanceof String) {
                String val = (String) tree.getValue();
                if (val.startsWith("tce")) {
                    createTestExecutionMenu(contextMenu);
                } else if (val.startsWith("executions")) {
                    createExecutionsMenu(contextMenu);
                } else {
                    //We are at the root
                    createRootMenu(contextMenu);
                }
            } else if (tree.getValue() instanceof TestPlan) {
                createTestPlanMenu(contextMenu);
            } else if (tree.getValue() instanceof TestCaseExecution) {
                createTestCaseExecutionPlanMenu(contextMenu);
            } else if (tree.getValue() instanceof Baseline) {
                //                        createBaselineMenu(contextMenu);
            }
        }
    });
    tree.setImmediate(true);
    tree.expandItem(projTreeRoot);
    tree.setSizeFull();
    updateProjectList();
}

From source file:org.peergreen.vaadin.diagram.DiagramDropHandler.java

License:Apache License

@Override
public void drop(final DragAndDropEvent event) {
    TargetDetails targetDetails = event.getTargetDetails();
    Transferable transferable = event.getTransferable();

    MouseEventDetails mouseEventDetails = MouseEventDetails
            .deSerialize((String) targetDetails.getData("mouseEvent"));
    Integer absoluteLeft = (Integer) targetDetails.getData("absoluteLeft");
    Integer absoluteTop = (Integer) targetDetails.getData("absoluteTop");

    diagram.drop(mouseEventDetails.getClientX() - absoluteLeft, mouseEventDetails.getClientY() - absoluteTop,
            (String) transferable.getData("component-type"));
}

From source file:pl.exsio.frameset.vaadin.module.management.frames.FramesTree.java

License:Open Source License

private void setTreeDropHandler(final JPAContainer<Frame> frames) {
    this.tree.setDropHandler(new DropHandler() {
        @Override/* w  ww.ja  v a2  s  .  co m*/
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }

        @Override
        public void drop(DragAndDropEvent event) {
            Transferable t = event.getTransferable();

            if (t.getSourceComponent() != tree) {
                return;
            }

            TreeTargetDetails target = (TreeTargetDetails) event.getTargetDetails();

            Object sourceItemId = t.getData("itemId");
            Object targetItemId = target.getItemIdOver();
            Frame sourceFrame = frames.getItem(sourceItemId).getEntity();
            Frame targetFrame = frames.getItem(targetItemId).getEntity();

            VerticalDropLocation location = target.getDropLocation();
            FrameDao<Frame> frameDao = coreRepositories.getFrameRepository();
            try {
                // Drop right on an item -> make it a child
                if (location == VerticalDropLocation.MIDDLE) {
                    frameDao.insertAsLastChildOf(sourceFrame, targetFrame);
                } // Drop at the top of a subtree -> make it previous
                else if (location == VerticalDropLocation.TOP && !targetFrame.isRoot()) {
                    frameDao.insertAsPrevSiblingOf(sourceFrame, targetFrame);
                } // Drop below another item -> make it next 
                else if (location == VerticalDropLocation.BOTTOM && !targetFrame.isRoot()) {
                    frameDao.insertAsNextSiblingOf(sourceFrame, targetFrame);
                }
                frames.refresh();
            } catch (InvalidNodesHierarchyException ex) {
                Notification.show(t("core.management.frames.tree.wrong_operation"),
                        Notification.Type.ERROR_MESSAGE);
            }
        }
    });
}