private void assignDsTag(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails taregtDet = event.getTargetDetails(); final Table distTable = (Table) taregtDet.getTarget(); final Set<DistributionSetIdName> distsSelected = getTableValue(distTable); final Set<Long> distList = new HashSet<>(); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); final Object distItemId = dropData.getItemIdOver(); if (!distsSelected.contains(distItemId)) { distList.add(((DistributionSetIdName) distItemId).getId()); } else { distList.addAll(distsSelected.stream().map(t -> t.getId()).collect(Collectors.toList())); } final String distTagName = HawkbitCommonUtil.removePrefix( event.getTransferable().getSourceComponent().getId(), SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS); final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distList, distTagName); uiNotification.displaySuccess( HawkbitCommonUtil.createAssignmentMessage(distTagName, result, i18n)); if (result.getAssigned() >= 1 && managementUIState.getDistributionTableFilters().isNoTagSelected()) { refreshFilter(); } }
/* * (non-Javadoc) * * @see * com.vaadin.event.dd.acceptCriteria.AcceptCriterion#accepts(com.vaadin * .event.dd.DragAndDropEvent) */ @Override public boolean accept(DragAndDropEvent dragEvent) { AbstractSelectTargetDetails dropTargetData = (AbstractSelectTargetDetails) dragEvent.getTargetDetails(); tree = (Tree) dragEvent.getTargetDetails().getTarget(); allowedItemIds = getAllowedItemIds(dragEvent, tree); return allowedItemIds.contains(dropTargetData.getItemIdOver()); }
/** * 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 using filter if (source instanceof ComponentContainer) { ComponentContainer sourceLayout = (ComponentContainer) source; sourceLayout.removeComponent(component); } // Add component to absolute layout layout.addComponent( component, "left:" + leftPixelPosition + "px;top:" + topPixelPosition + "px"); }
@Override protected void handleComponentReordering(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails(); DDTabSheet tabSheet = (DDTabSheet) details.getTarget(); Component c = transferable.getComponent(); Tab tab = tabSheet.getTab(c); HorizontalDropLocation location = details.getDropLocation(); int idx = details.getOverIndex(); if (location == HorizontalDropLocation.LEFT) { // Left of previous tab int originalIndex = tabSheet.getTabPosition(tab); if (originalIndex > idx) { tabSheet.setTabPosition(tab, idx); } else if (idx - 1 >= 0) { tabSheet.setTabPosition(tab, idx - 1); } } else if (location == HorizontalDropLocation.RIGHT) { // Right of previous tab int originalIndex = tabSheet.getTabPosition(tab); if (originalIndex > idx) { tabSheet.setTabPosition(tab, idx + 1); } else { tabSheet.setTabPosition(tab, idx); } } }
/* (non-Javadoc) * @see fi.jasoft.dragdroplayouts.drophandlers.DefaultCssLayoutDropHandler#handleComponentReordering(com.vaadin.event.dd.DragAndDropEvent) */ @Override protected void handleComponentReordering(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails(); // Get the components DDCssLayout layout = (DDCssLayout) details.getTarget(); Component comp = transferable.getComponent(); Component over = details.getOverComponent(); if (over == comp) { // If the component and the target are the same, ignore the // drag, the component was released "on itself" so no // reordering is required. return; } // We are using a CSS layout with float:left; we only care about // horizontal positioning HorizontalDropLocation horizontalDropLocation = details.getHorizontalDropLocation(); // Detach - remove current component first, then calculate index. layout.removeComponent(comp); int indexOfDropTarget = layout.getComponentIndex(over); // The layout has the component on top of which the drop occurred if (indexOfDropTarget > -1) { // If drop location is to the LEFT, add component before if (HorizontalDropLocation.LEFT.equals(horizontalDropLocation) || HorizontalDropLocation.CENTER.equals(horizontalDropLocation)) { layout.addComponent(comp, indexOfDropTarget); } else { // If drop target is RIGHT, add after indexOfDropTarget++; if (indexOfDropTarget < layout.getComponentCount()) { layout.addComponent(comp, indexOfDropTarget); } else { layout.addComponent(comp); } } } else { // The current layout doesn't have the component on top of which // it was dropped, most likely the drop was on the underlying // layout itself. In this case we could look at the vertical // drop position to determine if we should add the component at // the top or the bottom in the layout. layout.addComponent(comp); // The else could be left out if we want to force the user to // drop the component on another component, i.e. dropping on // layout is not supported. } }
@SuppressWarnings("unchecked") private void assignTargetToDs(final DragAndDropEvent event) { final TableTransferable transferable = (TableTransferable) event.getTransferable(); final AbstractTable<?, TargetIdName> source = (AbstractTable<?, TargetIdName>) transferable.getSourceComponent(); final Set<TargetIdName> targetDetailsList = source.getDeletedEntityByTransferable(transferable); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); final Object distItemId = dropData.getItemIdOver(); assignTargetToDs(getItem(distItemId), targetDetailsList); }
/** * 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); }
@Override protected void handleHTML5Drop(DragAndDropEvent event) { TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails(); HorizontalDropLocation location = details.getDropLocation(); DDTabSheet tabSheet = (DDTabSheet) details.getTarget(); int idx = details.getOverIndex(); Component c = resolveComponentFromHTML5Drop(event); c.setCaption(resolveCaptionFromHTML5Drop(event)); if (location == HorizontalDropLocation.LEFT) { tabSheet.addTab(c, idx); } else if (location == HorizontalDropLocation.RIGHT) { tabSheet.addTab(c, idx + 1); } }
/* * Uses enhanced server side check */ @Override public boolean accept(DragAndDropEvent dragEvent) { try { // must be over tree node and in the middle of it (not top or // bottom // part) TreeTargetDetails eventDetails = (TreeTargetDetails) dragEvent.getTargetDetails(); Object itemIdOver = eventDetails.getItemIdOver(); if (!eventDetails.getTarget().areChildrenAllowed(itemIdOver)) { return false; } // return true if directly over return eventDetails.getDropLocation() == VerticalDropLocation.MIDDLE; } catch (Exception e) { return false; } }
@Override public boolean accept(DragAndDropEvent dragEvent) { try { TreeTargetDetails eventDetails = (TreeTargetDetails) dragEvent.getTargetDetails(); if (eventDetails.getItemIdOver() != null) { Object itemId = eventDetails.getItemIdOver(); int i = 0; while (itemId != null && (depthToCheck == -1 || i <= depthToCheck)) { if (itemId.equals(rootId)) { return true; } itemId = getParent(itemId); i++; } } return false; } catch (Exception e) { return false; } }
@Override protected void handleDropFromLayout(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails(); DDTabSheet tabSheet = (DDTabSheet) details.getTarget(); Component c = transferable.getComponent(); HorizontalDropLocation location = details.getDropLocation(); int idx = details.getOverIndex(); ComponentContainer source = (ComponentContainer) transferable.getSourceComponent(); // Detach from old source if (source instanceof ComponentContainer) { ((ComponentContainer) source).removeComponent(c); } else if (source instanceof SingleComponentContainer) { ((SingleComponentContainer) source).setContent(null); } if (location == HorizontalDropLocation.LEFT) { tabSheet.addTab(c, idx); } else if (location == HorizontalDropLocation.RIGHT) { tabSheet.addTab(c, idx + 1); } }
private void assignTargetTag(final DragAndDropEvent event) { final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); final Object distItemId = dropData.getItemIdOver(); final String targetTagName = HawkbitCommonUtil.removePrefix( event.getTransferable().getSourceComponent().getId(), SPUIDefinitions.TARGET_TAG_ID_PREFIXS); // get all the targets assigned to the tag // assign dist to those targets final List<Target> assignedTargets = targetService.findTargetsByTag(targetTagName); if (!assignedTargets.isEmpty()) { final Set<TargetIdName> targetDetailsList = new HashSet<>(); assignedTargets.forEach( target -> targetDetailsList.add( new TargetIdName(target.getId(), target.getControllerId(), target.getName()))); assignTargetToDs(getItem(distItemId), targetDetailsList); } else { uiNotification.displaySuccess( i18n.get("message.no.targets.assiged.fortag", new Object[] {targetTagName})); } }
@Override public void drop(DragAndDropEvent event) { WrapperTargetDetails ed = (WrapperTargetDetails) event.getTargetDetails(); Transferable ctr = event.getTransferable(); // use "component" (from DragDropPane) if available, else take // the source component Component component = null; if (ctr instanceof WrapperTransferable) { component = ((WrapperTransferable) ctr).getDraggedComponent(); } else if (ctr instanceof DataBoundTransferable) { // Item has been dragged, construct a Label from // Item id Label l = new Label(); l.setSizeUndefined(); l.setValue("ItemId : " + ((DataBoundTransferable) ctr).getItemId()); component = l; } if (component != null) { if (component.getParent() != root) { root.addComponent(component); Integer left = ed.getAbsoluteLeft(); Integer top = ed.getAbsoluteTop(); MouseEventDetails eventDetails = ed.getMouseEvent(); int clientX = eventDetails.getClientX(); int clientY = eventDetails.getClientY(); try { root.getPosition(component).setTopValue(Float.valueOf(clientY - top)); root.getPosition(component).setLeftValue(Float.valueOf(clientX - left)); } catch (Exception e) { } } else { // drag started and ended inside the this Pane MouseEventDetails start = ((WrapperTransferable) event.getTransferable()).getMouseDownEvent(); MouseEventDetails eventDetails = ed.getMouseEvent(); int deltaX = eventDetails.getClientX() - start.getClientX(); int deltaY = eventDetails.getClientY() - start.getClientY(); ComponentPosition p = root.getPosition(component); p.setTopValue(p.getTopValue() + deltaY); p.setLeftValue(p.getLeftValue() + deltaX); } } else { // drag coming outside of Vaadin WrapperTransferable wtr = (WrapperTransferable) ctr; String object = wtr.getText(); // String html = wtr.getHtml(); // String url = (String) ctr.getData("Url"); final Label l = new Label(); l.setCaption("Generated from HTML5 drag:"); if (object != null) { if (object.length() > 80) { object = object.substring(0, 79); } l.setValue(object); } else { l.setValue("HTML5 dd"); } Html5File[] files = wtr.getFiles(); if (files != null) { for (Html5File html5File : files) { l.setCaption(html5File.getFileName()); html5File.setStreamVariable( new StreamVariable() { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); @Override public OutputStream getOutputStream() { return byteArrayOutputStream; } @Override public boolean listenProgress() { return false; } @Override public void onProgress(StreamingProgressEvent event) {} @Override public void streamingStarted(StreamingStartEvent event) {} @Override public void streamingFinished(StreamingEndEvent event) { l.setValue( (new String(byteArrayOutputStream.toByteArray()).substring(0, 80) + "...")); } @Override public void streamingFailed(StreamingErrorEvent event) {} @Override public boolean isInterrupted() { return false; } }); } } l.setSizeUndefined(); root.addComponent(l); } return; }
@Override @SuppressWarnings("static-access") public void drop(DragAndDropEvent dropEvent) { if (dropEvent.getTransferable().getSourceComponent() instanceof FileIcon) { // update the position DragAndDropWrapper.WrapperTransferable transferable = (WrapperTransferable) dropEvent.getTransferable(); MouseEventDetails mouseDownEvent = transferable.getMouseDownEvent(); WrapperTargetDetails dropTargetDetails = (WrapperTargetDetails) dropEvent.getTargetDetails(); MouseEventDetails mouseEvent = dropTargetDetails.getMouseEvent(); int deltaX = mouseEvent.getClientX() - mouseDownEvent.getClientX(); int deltaY = mouseEvent.getClientY() - mouseDownEvent.getClientY(); ComponentPosition position = l.getPosition(transferable.getSourceComponent()); position.setTop(position.getTopValue() + deltaY, UNITS_PIXELS); position.setLeft(position.getLeftValue() + deltaX, UNITS_PIXELS); } else if (dropEvent.getTransferable().getSourceComponent() == tree1) { // dragged something from tree to the folder shown File draggedFile = (File) ((DataBoundTransferable) dropEvent.getTransferable()).getItemId(); DDTest6.get().setParent(draggedFile, folder); } else { // expecting this to be an html5 drag WrapperTransferable tr = (WrapperTransferable) dropEvent.getTransferable(); Html5File[] files2 = tr.getFiles(); if (files2 != null) { for (Html5File html5File : files2) { String fileName = html5File.getFileName(); // int bytes = html5File.getFileSize(); final ByteArrayOutputStream bas = new ByteArrayOutputStream(); StreamVariable streamVariable = new StreamVariable() { @Override public OutputStream getOutputStream() { return bas; } @Override public boolean listenProgress() { return false; } @Override public void onProgress(StreamingProgressEvent event) {} @Override public void streamingStarted(StreamingStartEvent event) {} @Override public void streamingFinished(StreamingEndEvent event) {} @Override public void streamingFailed(StreamingErrorEvent event) {} @Override public boolean isInterrupted() { return false; } }; html5File.setStreamVariable(streamVariable); File file = new File(fileName, bas); file.setType(html5File.getType()); // FF don't know csv if (fileName.endsWith(".csv")) { file.setType("text/csv"); } DDTest6.get().fs1.addBean(file); DDTest6.get().tree1.setChildrenAllowed(file, false); DDTest6.get().setParent(file, folder); } } } }