Java Code Examples for com.vaadin.event.dd.DragAndDropEvent#getTargetDetails()

The following examples show how to use com.vaadin.event.dd.DragAndDropEvent#getTargetDetails() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultGridLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void addComponent(DragAndDropEvent event, Component component,
        int column, int row) {
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event
            .getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();

    // If no components exist in the grid, then just add the
    // component
    if (!layout.getComponentIterator().hasNext()) {
        layout.addComponent(component, column, row);
        return;
    }

    // If component was dropped on top of another component, abort
    if (layout.getComponent(column, row) != null) {
        return;
    }

    // Add the component

    layout.addComponent(component, column, row);
    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(component, dropAlignment);
    }
}
 
Example 2
Source File: DefaultAccordionDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@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);
    } else if (location == VerticalDropLocation.BOTTOM) {
        acc.addTab(c, idx + 1);
    } else {
        acc.addTab(c);
    }
}
 
Example 3
Source File: AbstractDefaultLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
public void drop(DragAndDropEvent event) {
    // Get information about the drop
    TargetDetails details = event.getTargetDetails();
    DropTarget layout = details.getTarget();
    Component source = event.getTransferable().getSourceComponent();

    if (event.getTransferable().getData("html5Data") != null) {
        handleHTML5Drop(event);
    } else if (layout == source) {
        handleComponentReordering(event);
    } else if (event.getTransferable() instanceof LayoutBoundTransferable) {
        LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
                .getTransferable();
        Component comp = transferable.getComponent();
        if (comp == layout) {
            if (comp.getParent() instanceof DDAbsoluteLayout) {
                handleDropFromAbsoluteParentLayout(event);
            }
        } else {
            handleDropFromLayout(event);
        }
    }
}
 
Example 4
Source File: DefaultCssLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    // Component re-ordering
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    CssLayoutTargetDetails details = (CssLayoutTargetDetails) event
            .getTargetDetails();
    DDCssLayout layout = (DDCssLayout) details.getTarget();
    Component comp = transferable.getComponent();
    int idx = details.getOverIndex();

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

    // Add component
    if (idx >= 0 && idx < layout.getComponentCount()) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }
}
 
Example 5
Source File: DefaultAbsoluteLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Called when a component changed location within the layout
 * 
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event
            .getTargetDetails();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    Component component = transferable.getComponent();

    // Get top-left pixel position
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();

    ComponentPosition position = layout.getPosition(component);

    position.setLeft((float) leftPixelPosition, Sizeable.UNITS_PIXELS);
    position.setTop((float) topPixelPosition, Sizeable.UNITS_PIXELS);
}
 
Example 6
Source File: DefaultPanelDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    PanelTargetDetails details = (PanelTargetDetails) event
            .getTargetDetails();
    Component component = transferable.getComponent();
    DDPanel panel = (DDPanel) details.getTarget();

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

    // Attach to new source
    panel.setContent(component);
}
 
Example 7
Source File: TargetTagFilterButtons.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private void processTargetDrop(final DragAndDropEvent event) {
    final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails();
    final TableTransferable transferable = (TableTransferable) event.getTransferable();

    final TargetTable targetTable = (TargetTable) transferable.getSourceComponent();
    final Set<Long> targetList = targetTable.getSelectedEntitiesByTransferable(transferable);
    final String targTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(),
            SPUIDefinitions.TARGET_TAG_ID_PREFIXS);

    if (!hasTargetUpdatePermission()) {
        return;
    }

    final TargetTagAssignmentResult result = targetTable.toggleTagAssignment(targetList, targTagName);

    publishAssignTargetTagEvent(result);

    publishUnAssignTargetTagEvent(targTagName, result);
}
 
Example 8
Source File: DistributionTagDropEvent.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private void processDistributionDrop(final DragAndDropEvent event) {

        final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails();

        final TableTransferable transferable = (TableTransferable) event.getTransferable();
        final AbstractTable<?> source = (AbstractTable<?>) transferable.getSourceComponent();

        final Set<Long> distSelected = source.getSelectedEntitiesByTransferable(transferable);

        final String distTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(),
                SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS);

        final List<String> tagsClickedList = distFilterParameters.getClickedDistSetTags();
        final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distSelected,
                distTagName);

        notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(distTagName, result, i18n));
        if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty()) {
            eventBus.publish(this, TargetFilterEvent.FILTER_BY_TAG);
        }
    }
 
Example 9
Source File: DefaultVerticalSplitPanelDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    VerticalSplitPanelTargetDetails details = (VerticalSplitPanelTargetDetails) event
            .getTargetDetails();
    DDVerticalSplitPanel panel = (DDVerticalSplitPanel) details.getTarget();

    if (details.getDropLocation() == VerticalDropLocation.TOP) {
        // Dropped in the left area
        panel.setFirstComponent(resolveComponentFromHTML5Drop(event));

    } else if (details.getDropLocation() == VerticalDropLocation.BOTTOM) {
        // Dropped in the right area
        panel.setSecondComponent(resolveComponentFromHTML5Drop(event));
    }
}
 
Example 10
Source File: DefaultFormLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    FormLayoutTargetDetails details = (FormLayoutTargetDetails) event
            .getTargetDetails();
    int idx = details.getOverIndex();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details
            .getTarget();

    // 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(resolveComponentFromHTML5Drop(event), idx);
    } else {
        layout.addComponent(resolveComponentFromHTML5Drop(event));
    }

    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(resolveComponentFromHTML5Drop(event),
                dropAlignment);
    }
}
 
Example 11
Source File: AbstractTable.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
protected Set<Long> getDraggedTargetList(final DragAndDropEvent event) {
    final com.vaadin.event.dd.TargetDetails targetDet = event.getTargetDetails();
    final Table targetTable = (Table) targetDet.getTarget();
    final Set<Long> targetSelected = getTableValue(targetTable);

    final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails();
    final Long targetItemId = (Long) dropData.getItemIdOver();

    if (entityToBeDeletedIsSelectedInTable(targetItemId, targetSelected)) {
        return targetSelected;
    }
    return Sets.newHashSet(targetItemId);
}
 
Example 12
Source File: DistributionSetTable.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onDropEventFromTable(final DragAndDropEvent event) {
    final TableTransferable transferable = (TableTransferable) event.getTransferable();
    final AbstractTable<?> source = (AbstractTable<?>) transferable.getSourceComponent();
    final Set<Long> softwareModulesIdList = source.getSelectedEntitiesByTransferable(transferable);
    selectDraggedEntities(source, softwareModulesIdList);

    final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails();

    final Object distItemId = dropData.getItemIdOver();
    if (distItemId != null) {
        handleSmToDsAssignment(softwareModulesIdList, (long) distItemId);
    }
}
 
Example 13
Source File: DefaultHorizontalLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) event
            .getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details
            .getTarget();

    int idx = (details).getOverIndex();

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

    Component comp = resolveComponentFromHTML5Drop(event);

    // 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);
    }
}
 
Example 14
Source File: TargetTable.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private void assignDsToTarget(final DragAndDropEvent event) {
    final TableTransferable transferable = (TableTransferable) event.getTransferable();
    final AbstractTable<?> source = (AbstractTable<?>) transferable.getSourceComponent();

    final Set<Long> dsIds = filterDistributionSetsToAssign(source.getSelectedEntitiesByTransferable(transferable));
    if (dsIds.isEmpty()) {
        getNotification().displayWarning(getI18n().getMessage(DISTRIBUTIONSET_NOT_EXISTS));
        return;
    }

    selectDraggedEntities(source, dsIds);
    final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails();
    final Object targetItemId = dropData.getItemIdOver();
    LOG.debug("Drop target: {} ", targetItemId);
    if (targetItemId == null) {
        getNotification().displayWarning(getI18n().getMessage(TARGETS_NOT_EXISTS, ""));
        return;
    }

    final Long targetId = (Long) targetItemId;
    selectDroppedEntities(targetId);
    final Optional<Target> target = targetManagement.get(targetId);
    if (!target.isPresent()) {
        getNotification().displayWarning(getI18n().getMessage(TARGETS_NOT_EXISTS, ""));
        return;
    }

    final List<DistributionSet> distributionSets = distributionSetManagement.get(dsIds);
    if (distributionSets.isEmpty()) {
        getNotification().displayWarning(getI18n().getMessage(DISTRIBUTIONSET_NOT_EXISTS));
        return;
    }
    openConfirmationWindowForAssignments(target.get(), distributionSets);
}
 
Example 15
Source File: DefaultCssLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@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;
        } 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));
    }
}
 
Example 16
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event
            .getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details
            .getTarget();
    int idx = (details).getOverIndex();

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

    Component comp = resolveComponentFromHTML5Drop(event);

    // 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);
    }

}
 
Example 17
Source File: DefaultHorizontalSplitPanelDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    ComponentContainer source = (ComponentContainer) transferable
            .getSourceComponent();
    HorizontalSplitPanelTargetDetails details = (HorizontalSplitPanelTargetDetails) event
            .getTargetDetails();
    Component component = transferable.getComponent();
    DDHorizontalSplitPanel panel = (DDHorizontalSplitPanel) details
            .getTarget();

    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(component);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    if (details.getDropLocation() == HorizontalDropLocation.LEFT) {
        // Dropped in the left area
        panel.setFirstComponent(component);

    } else if (details.getDropLocation() == HorizontalDropLocation.RIGHT) {
        // Dropped in the right area
        panel.setSecondComponent(component);
    }
}
 
Example 18
Source File: DefaultFormLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    FormLayoutTargetDetails details = (FormLayoutTargetDetails) 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
    Component parent = layout.getParent();
    while (parent != null) {
        if (parent == comp) {
            return;
        }
        parent = parent.getParent();
    }

    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(comp);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    // 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);
    }
}
 
Example 19
Source File: DefaultFormLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@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;
    }

    // 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);
    }
}
 
Example 20
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * Handle a drop from another layout
 * 
 * @param event
 *            The drag and drop event
 */
@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
    Component parent = layout.getParent();
    while (parent != null) {
        if (parent == comp) {
            return;
        }
        parent = parent.getParent();
    }

    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(comp);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    // 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);
    }
}