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

The following examples show how to use com.vaadin.event.dd.DragAndDropEvent#getTransferable() . 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: 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 2
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 3
Source File: TargetTableHeader.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validation for drag event.
 *
 * @param dragEvent
 * @return
 */
private Boolean doValidations(final DragAndDropEvent dragEvent) {
    final Component compsource = dragEvent.getTransferable().getSourceComponent();
    Boolean isValid = Boolean.TRUE;
    if (compsource instanceof Table && !isComplexFilterViewDisplayed) {
        final TableTransferable transferable = (TableTransferable) dragEvent.getTransferable();
        final Table source = transferable.getSourceComponent();

        if (!source.getId().equals(UIComponentIdProvider.DIST_TABLE_ID)) {
            notification.displayValidationError(i18n.getMessage(UIMessageIdProvider.MESSAGE_ACTION_NOT_ALLOWED));
            isValid = Boolean.FALSE;
        } else {
            if (getDropppedDistributionDetails(transferable).size() > 1) {
                notification.displayValidationError(i18n.getMessage("message.onlyone.distribution.dropallowed"));
                isValid = Boolean.FALSE;
            }
        }
    } else {
        notification.displayValidationError(i18n.getMessage(UIMessageIdProvider.MESSAGE_ACTION_NOT_ALLOWED));
        isValid = Boolean.FALSE;
    }
    return isValid;
}
 
Example 4
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 5
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 6
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 7
Source File: TargetTableHeader.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private void filterByDroppedDist(final DragAndDropEvent event) {
    if (doValidations(event)) {
        final TableTransferable tableTransferable = (TableTransferable) event.getTransferable();
        final Table source = tableTransferable.getSourceComponent();
        if (!UIComponentIdProvider.DIST_TABLE_ID.equals(source.getId())) {
            return;
        }
        final Set<Long> distributionIdSet = getDropppedDistributionDetails(tableTransferable);
        if (CollectionUtils.isEmpty(distributionIdSet)) {
            return;
        }
        final Long distributionSetId = distributionIdSet.iterator().next();
        final Optional<DistributionSet> distributionSet = distributionSetManagement.get(distributionSetId);
        if (!distributionSet.isPresent()) {
            notification.displayWarning(i18n.getMessage("distributionset.not.exists"));
            return;
        }
        final DistributionSetIdName distributionSetIdName = new DistributionSetIdName(distributionSet.get());
        getManagementUIState().getTargetTableFilters().setDistributionSet(distributionSetIdName);
        addFilterTextField(distributionSetIdName);
    }
}
 
Example 8
Source File: DefaultGridLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event
            .getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    Component comp = transferable.getComponent();

    int row = details.getOverRow();
    int column = details.getOverColumn();
    if (layout.getComponent(column, row) == null) {
        layout.removeComponent(comp);
        addComponent(event, comp, column, row);
    }
}
 
Example 9
Source File: TargetTagFilterButtons.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validate the drop.
 *
 * @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;
}
 
Example 10
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 11
Source File: DistributionTable.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private void assignTargetToDs(final DragAndDropEvent event) {
    final TableTransferable transferable = (TableTransferable) event.getTransferable();
    final TargetTable targetTable = (TargetTable) transferable.getSourceComponent();
    final Set<Long> targetIdSet = targetTable.getSelectedEntitiesByTransferable(transferable);
    selectDraggedEntities(targetTable, targetIdSet);
    final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails();
    final Object distItemId = dropData.getItemIdOver();
    assignTargetToDs(getItem(distItemId), targetManagement.get(targetIdSet));
}
 
Example 12
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 13
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 14
Source File: UploadDropAreaLayout.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isFilesDropped(final DragAndDropEvent event) {
    if (event.getTransferable() instanceof WrapperTransferable) {
        final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
        return files != null;
    }
    return false;
}
 
Example 15
Source File: DistributionTagDropEvent.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void drop(final DragAndDropEvent event) {
    if (validate(event) && isNoTagAssigned(event)) {
        final TableTransferable tbl = (TableTransferable) event.getTransferable();
        final Table source = tbl.getSourceComponent();

        if (source.getId().equals(UIComponentIdProvider.DIST_TABLE_ID)) {
            processDistributionDrop(event);
        }
    }
}
 
Example 16
Source File: DefaultAbsoluteLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a drop from another layout
 * 
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event
            .getTargetDetails();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    Component component = transferable.getComponent();
    Component source = event.getTransferable().getSourceComponent();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();

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

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

    // Add component to absolute layout
    layout.addComponent(component, "left:" + leftPixelPosition + "px;top:"
            + topPixelPosition + "px");
}
 
Example 17
Source File: DefaultHorizontalLayoutDropHandler.java    From cuba with Apache License 2.0 4 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) {
    // Component re-ordering
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) event
            .getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details
            .getTarget();
    Component comp = transferable.getComponent();
    int idx = details.getOverIndex();
    int oldIndex = layout.getComponentIndex(comp);

    if (idx == oldIndex) {
        // Index did not change
        return;
    }

    // Detach
    layout.removeComponent(comp);

    // Account for detachment if new index is bigger then old index
    if (idx > oldIndex) {
        idx--;
    }

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

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

    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}
 
Example 18
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 4 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) {
    // 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();
    int oldIndex = layout.getComponentIndex(comp);

    if (idx == oldIndex) {
        // Index did not change
        return;
    }

    // Detach
    layout.removeComponent(comp);

    // Account for detachment if new index is bigger then old index
    if (idx > oldIndex) {
        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 19
Source File: DefaultHorizontalLayoutDropHandler.java    From cuba with Apache License 2.0 4 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) {
    // Component re-ordering
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) event
            .getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details
            .getTarget();
    Component comp = transferable.getComponent();
    int idx = details.getOverIndex();
    int oldIndex = layout.getComponentIndex(comp);

    if (idx == oldIndex) {
        // Index did not change
        return;
    }

    // Detach
    layout.removeComponent(comp);

    // Account for detachment if new index is bigger then old index
    if (idx > oldIndex) {
        idx--;
    }

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

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

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