Example usage for com.vaadin.event Transferable getSourceComponent

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

Introduction

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

Prototype

public Component getSourceComponent();

Source Link

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/*  w  ww . ja  va  2 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.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();//from   w  w w.j  a  v a  2  s .  co  m

    // 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 www . ja v a2 s. c o 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:info.magnolia.ui.workbench.tree.drop.TreeViewDropHandler.java

License:Open Source License

@Override
public void drop(DragAndDropEvent dropEvent) {
    // Called whenever a drop occurs on the component

    // Make sure the drag source is the same tree
    Transferable t = dropEvent.getTransferable();

    // First acceptance criteria.
    // Make sure the drag source is the same tree
    if (t.getSourceComponent() != tree || !(t instanceof DataBoundTransferable)) {
        return;/*from ww  w.  j a  va 2s.  co m*/
    }

    AbstractSelectTargetDetails target = (AbstractSelectTargetDetails) dropEvent.getTargetDetails();
    // Get id's of the target item
    Object targetItemId = target.getItemIdOver();
    // On which side of the target the item was dropped
    VerticalDropLocation location = target.getDropLocation();
    if (location == null) {
        log.debug("DropLocation is null. Do nothing.");
        return;
    }
    // Get id's of the dragged items
    Iterator<Object> selected = getItemIdsToMove(dropEvent).iterator();
    while (selected.hasNext()) {
        Object sourceItemId = selected.next();
        moveNode(sourceItemId, targetItemId, location);
    }
}

From source file:info.magnolia.ui.workbench.tree.drop.TreeViewDropHandler.java

License:Open Source License

/**
 * Returns a collection of itemIds to move:
 * <ul>//from  w  w w  .  jav a  2 s .  c om
 * <li>all <em>selected</em> itemIds if and only if the dragging node is <em>also</em> selected</li>
 * <li>only the dragging itemId if it's not selected</li>.
 * </ul>
 */
private Collection<Object> getItemIdsToMove(DragAndDropEvent dropEvent) {
    Transferable t = dropEvent.getTransferable();
    Object draggingItemId = ((DataBoundTransferable) t).getItemId();

    // all selected itemIds if and only if the dragging node is also selected
    Set<Object> selectedItemIds = (Set<Object>) ((TreeTable) t.getSourceComponent()).getValue();
    if (selectedItemIds.contains(draggingItemId)) {
        return selectedItemIds;
    }

    // only the dragging itemId if it's not selected
    return Arrays.asList(draggingItemId);
}

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/*from w  w w.  j a  v  a  2 s .c o  m*/
        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.apache.openaz.xacml.admin.components.PolicyWorkspace.java

License:Apache License

@Override
public void drop(DragAndDropEvent event) {
    Transferable t = event.getTransferable();
    Component source = t.getSourceComponent();
    if (source != this.treeWorkspace) {
        assert false;
        throw new IllegalArgumentException();
    }/*from   www . jav  a2 s  . c o m*/
    TableTransferable tt = (TableTransferable) t;
    File sourceFile = (File) tt.getItemId();

    AbstractSelectTargetDetails target = (AbstractSelectTargetDetails) event.getTargetDetails();
    File targetFile = (File) target.getItemIdOver();

    if (sourceFile.isFile() && targetFile != null && targetFile.isDirectory()) {
        //
        // Construct destination filename
        //
        Path dest = targetFile.toPath().resolve(sourceFile.getName());
        //
        // Check if the target domain exists
        //
        if (Files.exists(dest)) {
            //
            // Prompt the user
            //
            Notification.show("A policy file with that name already exists in that directory.",
                    Notification.Type.ERROR_MESSAGE);
        } else {
            //
            // Go ahead and rename it
            //
            this.renamePolicyFile(sourceFile, dest.toFile(), targetFile);
        }
    }
}

From source file:org.eclipse.hawkbit.ui.common.table.AbstractTable.java

License:Open Source License

protected boolean isDropValid(final DragAndDropEvent dragEvent) {
    final Transferable transferable = dragEvent.getTransferable();
    final Component compsource = transferable.getSourceComponent();

    final List<String> missingPermissions = hasMissingPermissionsForDrop();
    if (!missingPermissions.isEmpty()) {
        notification/*from ww  w . j a  v a2s.  co  m*/
                .displayValidationError(i18n.getMessage("message.permission.insufficient", missingPermissions));
        return false;
    }

    if (compsource instanceof Table) {
        return validateTable((Table) compsource)
                && validateDropList(getDraggedTargetList((TableTransferable) transferable, (Table) compsource));
    }

    if (compsource instanceof DragAndDropWrapper) {
        return validateDragAndDropWrapper((DragAndDropWrapper) compsource)
                && validateDropList(getDraggedTargetList(dragEvent));
    }
    notification.displayValidationError(i18n.getMessage(UIMessageIdProvider.MESSAGE_ACTION_NOT_ALLOWED));
    return false;
}

From source file:org.eclipse.hawkbit.ui.management.targettag.filter.TargetTagFilterButtons.java

License:Open Source License

/**
 * Validate the drop./*from   ww w.  jav a2s.  c  o m*/
 *
 * @param event
 *            DragAndDropEvent reference
 * @return Boolean
 */
private Boolean validate(final DragAndDropEvent event) {
    final Transferable transferable = event.getTransferable();
    final Component compsource = transferable.getSourceComponent();
    if (!(compsource instanceof AbstractTable)) {
        uiNotification.displayValidationError(getI18n().getMessage(getActionNotAllowedMessage()));
        return false;
    }

    final TableTransferable tabletransferable = (TableTransferable) transferable;

    final AbstractTable<?> source = (AbstractTable<?>) tabletransferable.getSourceComponent();

    if (!validateIfSourceIsTargetTable(source) && !hasTargetUpdatePermission()) {
        return false;
    }

    final Set<Long> deletedEntityByTransferable = source.getSelectedEntitiesByTransferable(tabletransferable);
    if (deletedEntityByTransferable.isEmpty()) {
        final String actionDidNotWork = getI18n().getMessage("message.action.did.not.work");
        uiNotification.displayValidationError(actionDidNotWork);
        return false;
    }

    return true;
}

From source file:org.eclipse.hawkbit.ui.management.targettag.TargetTagFilterButtons.java

License:Open Source License

/**
 * Validate the drop./*from  w  w  w .j  ava  2 s. co m*/
 *
 * @param event
 *            DragAndDropEvent reference
 * @return Boolean
 */
private Boolean validate(final DragAndDropEvent event) {
    final Transferable transferable = event.getTransferable();
    final Component compsource = transferable.getSourceComponent();
    if (!(compsource instanceof AbstractTable)) {
        notification.displayValidationError(i18n.getMessage(SPUILabelDefinitions.ACTION_NOT_ALLOWED));
        return false;
    }

    final TableTransferable tabletransferable = (TableTransferable) transferable;

    final AbstractTable<?> source = (AbstractTable<?>) tabletransferable.getSourceComponent();

    if (!validateIfSourceisTargetTable(source) && !hasTargetUpdatePermission()) {
        return false;
    }

    final Set<Long> deletedEntityByTransferable = source.getDeletedEntityByTransferable(tabletransferable);
    if (deletedEntityByTransferable.isEmpty()) {
        final String actionDidNotWork = i18n.getMessage("message.action.did.not.work", new Object[] {});
        notification.displayValidationError(actionDidNotWork);
        return false;
    }

    return true;
}