com.vaadin.shared.ui.dd.VerticalDropLocation Java Examples
The following examples show how to use
com.vaadin.shared.ui.dd.VerticalDropLocation.
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: VDDVerticalLayout.java From cuba with Apache License 2.0 | 6 votes |
/** * Removes any applies drag and drop style applied by emphasis() */ protected void deEmphasis() { if (currentlyEmphasised != null) { // Universal over style UIObject.setStyleName(currentlyEmphasised.getElement(), OVER, false); UIObject.setStyleName(currentlyEmphasised.getElement(), OVER_SPACED, false); // Vertical styles UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-" + VerticalDropLocation.TOP.toString().toLowerCase(), false); UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-" + VerticalDropLocation.MIDDLE.toString().toLowerCase(), false); UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-" + VerticalDropLocation.BOTTOM.toString().toLowerCase(), false); currentlyEmphasised = null; } }
Example #2
Source File: VDDFormLayout.java From cuba with Apache License 2.0 | 6 votes |
/** * Removes any applies drag and drop style applied by emphasis() */ protected void deEmphasis() { if (currentlyEmphasised != null) { // Universal over style setStyleName(currentlyEmphasised, OVER, false); setStyleName(currentlyEmphasised, OVER_SPACED, false); // Vertical styles setStyleName(currentlyEmphasised, OVER + "-" + VerticalDropLocation.TOP.toString().toLowerCase(), false); setStyleName(currentlyEmphasised, OVER + "-" + VerticalDropLocation.MIDDLE.toString().toLowerCase(), false); setStyleName(currentlyEmphasised, OVER + "-" + VerticalDropLocation.BOTTOM.toString().toLowerCase(), false); currentlyEmphasised = null; } }
Example #3
Source File: VDDAccordion.java From cuba with Apache License 2.0 | 6 votes |
/** * Returns the drop location of a tab * * @param tab * The tab that was dragged * @param event * The drag event * @return */ protected VerticalDropLocation getDropLocation(StackItem tab, VDragEvent event) { VerticalDropLocation location; if (tab.isOpen()) { location = VDragDropUtil.getVerticalDropLocation(tab.getElement(), Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), tabTopBottomDropRatio); } else { location = VDragDropUtil .getVerticalDropLocation(tab.getWidget(0).getElement(), Util.getTouchOrMouseClientY( event.getCurrentGwtEvent()), tabTopBottomDropRatio); } return location; }
Example #4
Source File: VDDAccordion.java From cuba with Apache License 2.0 | 6 votes |
/** * Updates the drop details while dragging. This is needed to ensure client * side criterias can validate the drop location. * * @param event * The drag event */ protected void updateDragDetails(VDragEvent event) { if (event.getElementOver() == null) { return; } StackItem tab = WidgetUtil.findWidget(event.getElementOver(), StackItem.class); if (tab != null && getElement().isOrHasChild(tab.getElement())) { Map<String, Object> dropDetails = event.getDropDetails(); int index = getTabPosition(tab); dropDetails.put(Constants.DROP_DETAIL_TO, index); VerticalDropLocation location = getDropLocation(tab, event); dropDetails.put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION, location); MouseEventDetails details = MouseEventDetailsBuilder .buildMouseEventDetails(event.getCurrentGwtEvent(), getElement()); dropDetails.put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize()); } }
Example #5
Source File: VDDVerticalLayout.java From cuba with Apache License 2.0 | 6 votes |
/** * Removes any applies drag and drop style applied by emphasis() */ protected void deEmphasis() { if (currentlyEmphasised != null) { // Universal over style setStyleName(currentlyEmphasised.getElement(), OVER, false); setStyleName(currentlyEmphasised.getElement(), OVER_SPACED, false); // Vertical styles setStyleName(currentlyEmphasised.getElement(), OVER + "-" + VerticalDropLocation.TOP.toString().toLowerCase(), false); setStyleName(currentlyEmphasised.getElement(), OVER + "-" + VerticalDropLocation.MIDDLE.toString().toLowerCase(), false); setStyleName(currentlyEmphasised.getElement(), OVER + "-" + VerticalDropLocation.BOTTOM.toString().toLowerCase(), false); currentlyEmphasised = null; } }
Example #6
Source File: VDragDropUtil.java From cuba with Apache License 2.0 | 6 votes |
/** * Get the vertical drop location in a ordered layout * * @param element * The target element or cell * @param offsetHeight * The height of the cell * @param clientY * The width of the cell * @param topBottomRatio * The ratio of the cell * @return The location of the drop */ public static VerticalDropLocation getVerticalDropLocation(Element element, int offsetHeight, int clientY, double topBottomRatio) { int absoluteTop = element.getAbsoluteTop(); int fromTop = clientY - absoluteTop; float percentageFromTop = (fromTop / (float) offsetHeight); if (percentageFromTop < topBottomRatio) { return VerticalDropLocation.TOP; } else if (percentageFromTop > 1 - topBottomRatio) { return VerticalDropLocation.BOTTOM; } else { return VerticalDropLocation.MIDDLE; } }
Example #7
Source File: DefaultAccordionDropHandler.java From cuba with Apache License 2.0 | 6 votes |
@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 #8
Source File: VDDGridLayout.java From cuba with Apache License 2.0 | 6 votes |
/** * Returns the vertical drop location * * @param cell * The cell details * @param event * The drag event * @return */ protected VerticalDropLocation getVerticalDropLocation(CellDetails cell, VDragEvent event) { // Get the vertical location VerticalDropLocation vdetail; int y = Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()) - getAbsoluteTop() - cell.y; assert(y >= 0 && y <= cell.height); if (y < cell.height * cellTopBottomDropRatio) { vdetail = VerticalDropLocation.TOP; } else if (y < cell.height * (1.0 - cellTopBottomDropRatio)) { vdetail = VerticalDropLocation.MIDDLE; } else { vdetail = VerticalDropLocation.BOTTOM; } return vdetail; }
Example #9
Source File: VDDVerticalSplitPanel.java From cuba with Apache License 2.0 | 5 votes |
/** * Updates the drop details while dragging. This is needed to ensure client * side criterias can validate the drop location. * * @param event * The drag event */ protected void updateDragDetails(VDragEvent event) { Element over = event.getElementOver(); // Resolve where the drop was made VerticalDropLocation location = null; Widget content = null; if (firstContainer.isOrHasChild(over)) { location = VerticalDropLocation.TOP; content = Util.findWidget(firstContainer, null); } else if (splitter.isOrHasChild(over)) { location = VerticalDropLocation.MIDDLE; content = this; } else if (secondContainer.isOrHasChild(over)) { location = VerticalDropLocation.BOTTOM; content = Util.findWidget(secondContainer, null); } event.getDropDetails().put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION, location); if (content != null) { event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, content.getClass().getName()); } else { event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, this.getClass().getName()); } // Add mouse event details MouseEventDetails details = MouseEventDetailsBuilder .buildMouseEventDetails(event.getCurrentGwtEvent(), getElement()); event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize()); }
Example #10
Source File: DefaultVerticalLayoutDropHandler.java From cuba with Apache License 2.0 | 5 votes |
@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 #11
Source File: DDVerticalSplitPanel.java From cuba with Apache License 2.0 | 5 votes |
protected VerticalSplitPanelTargetDetails( Map<String, Object> rawDropData) { super(rawDropData, DDVerticalSplitPanel.this); if (getDropLocation() == VerticalDropLocation.TOP) { over = getFirstComponent(); } else if (getDropLocation() == VerticalDropLocation.BOTTOM) { over = getSecondComponent(); } else { over = DDVerticalSplitPanel.this; } }
Example #12
Source File: DefaultCssLayoutDropHandler.java From cuba with Apache License 2.0 | 5 votes |
@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 #13
Source File: DefaultVerticalLayoutDropHandler.java From cuba with Apache License 2.0 | 5 votes |
@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 #14
Source File: DefaultFormLayoutDropHandler.java From cuba with Apache License 2.0 | 5 votes |
@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 #15
Source File: VDDFormLayout.java From cuba with Apache License 2.0 | 5 votes |
/** * Empasises the drop location of the component when hovering over a * ĆhildComponentContainer. Passing null as the container removes any * previous emphasis. * * @param widget * The container which we are hovering over * @param event * The drag event */ protected void emphasis(Widget widget, VDragEvent event) { // Remove emphasis from previous hovers deEmphasis(); // Validate if (widget == null || !getElement().isOrHasChild(widget.getElement())) { return; } /* * Get row for widget */ Element rowElement = getRowFromChildElement(widget.getElement(), VDDFormLayout.this.getElement()); currentlyEmphasised = rowElement; if (rowElement != this.getElement()) { VerticalDropLocation vl = getVerticalDropLocation(rowElement, event); setStyleName(rowElement, OVER + "-" + vl.toString().toLowerCase(), true); } else { setStyleName(rowElement, OVER, true); } }
Example #16
Source File: DefaultVerticalSplitPanelDropHandler.java From cuba with Apache License 2.0 | 5 votes |
@Override protected void handleDropFromLayout(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event .getTransferable(); VerticalSplitPanelTargetDetails details = (VerticalSplitPanelTargetDetails) event .getTargetDetails(); Component component = transferable.getComponent(); DDVerticalSplitPanel panel = (DDVerticalSplitPanel) details.getTarget(); ComponentContainer source = (ComponentContainer) transferable .getSourceComponent(); // Detach from old source if (source instanceof ComponentContainer) { ((ComponentContainer) source).removeComponent(component); } else if (source instanceof SingleComponentContainer) { ((SingleComponentContainer) source).setContent(null); } if (details.getDropLocation() == VerticalDropLocation.TOP) { // Dropped in the left area panel.setFirstComponent(component); } else if (details.getDropLocation() == VerticalDropLocation.BOTTOM) { // Dropped in the right area panel.setSecondComponent(component); } }
Example #17
Source File: VDDAccordion.java From cuba with Apache License 2.0 | 5 votes |
/** * Emphasisizes a container element * * @param element */ protected void emphasis(Element element, VDragEvent event) { // Find the tab StackItem tab = WidgetUtil.findWidget(element, StackItem.class); if (tab != null && getElement().isOrHasChild(tab.getElement()) && currentlyEmphasised != tab) { VerticalDropLocation location = getDropLocation(tab, event); if (location == VerticalDropLocation.MIDDLE) { if (tab.isOpen()) { tab.addStyleName(CLASSNAME_OVER); } else { tab.getWidget(0).addStyleName(CLASSNAME_OVER); } } else if (!spacer.isAttached()) { if (location == VerticalDropLocation.TOP) { insertSpacer(spacer, getElement(), getWidgetIndex(tab)); tab.setHeight( (tab.getOffsetHeight() - spacer.getOffsetHeight()) + "px"); } else if (location == VerticalDropLocation.BOTTOM) { insertSpacer(spacer, getElement(), getWidgetIndex(tab) + 1); int newHeight = tab.getOffsetHeight() - spacer.getOffsetHeight(); if (getWidgetIndex(spacer) == getWidgetCount() - 1) { newHeight -= spacer.getOffsetHeight(); } if (newHeight >= 0) { tab.setHeight(newHeight + "px"); } } } currentlyEmphasised = tab; } }
Example #18
Source File: VDDVerticalLayout.java From cuba with Apache License 2.0 | 5 votes |
/** * Empasises the drop location of the component when hovering over a * ĆhildComponentContainer. Passing null as the container removes any * previous emphasis. * * @param container * The container which we are hovering over * @param event * The drag event */ protected void emphasis(Widget container, VDragEvent event) { // Remove emphasis from previous hovers deEmphasis(); // validate container if (container == null || !getElement().isOrHasChild(container.getElement())) { return; } currentlyEmphasised = container; VerticalDropLocation location = null; // Add drop location specific style if (currentlyEmphasised != this) { location = getVerticalDropLocation(currentlyEmphasised, event); } else { location = VerticalDropLocation.MIDDLE; } UIObject.setStyleName(currentlyEmphasised.getElement(), OVER, true); UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-" + location.toString().toLowerCase(), true); }
Example #19
Source File: AccordionTargetDetails.java From cuba with Apache License 2.0 | 5 votes |
/** * Get the horizontal position of the dropped component within the * underlying cell. * * @return The drop location */ public VerticalDropLocation getDropLocation() { if (getData("vdetail") != null) { return VerticalDropLocation.valueOf((String) getData("vdetail")); } else { return null; } }
Example #20
Source File: VDDVerticalLayout.java From cuba with Apache License 2.0 | 5 votes |
/** * Empasises the drop location of the component when hovering over a * ĆhildComponentContainer. Passing null as the container removes any * previous emphasis. * * @param container * The container which we are hovering over * @param event * The drag event */ protected void emphasis(Widget container, VDragEvent event) { // Remove emphasis from previous hovers deEmphasis(); // validate container if (container == null || !getElement().isOrHasChild(container.getElement())) { return; } currentlyEmphasised = container; VerticalDropLocation location = null; // Add drop location specific style if (currentlyEmphasised != this) { location = getVerticalDropLocation(currentlyEmphasised, event); } else { location = VerticalDropLocation.MIDDLE; } setStyleName(currentlyEmphasised.getElement(), OVER, true); setStyleName(currentlyEmphasised.getElement(), OVER + "-" + location.toString().toLowerCase(), true); }
Example #21
Source File: DefaultVerticalSplitPanelDropHandler.java From cuba with Apache License 2.0 | 5 votes |
@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 #22
Source File: VDDGridLayout.java From cuba with Apache License 2.0 | 5 votes |
/** * Emphasizes a component container when user is hovering a dragged * component over the container. * * @param cell * The container * @param event */ protected void emphasis(CellDetails cell, VDragEvent event) { Style shadowStyle = dragShadow.getElement().getStyle(); shadowStyle.setPosition(Position.ABSOLUTE); shadowStyle.setWidth(cell.width, Unit.PX); shadowStyle.setHeight(cell.height, Unit.PX); shadowStyle.setLeft(cell.x, Unit.PX); shadowStyle.setTop(cell.y, Unit.PX); // Remove any existing empasis deEmphasis(); // Ensure we are not dragging ourself into ourself ComponentConnector draggedConnector = (ComponentConnector) event .getTransferable() .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT); if (draggedConnector != null && draggedConnector.getWidget() == VDDGridLayout.this) { return; } HorizontalDropLocation hl = getHorizontalDropLocation(cell, event); VerticalDropLocation vl = getVerticalDropLocation(cell, event); // Apply over style setStyleName(dragShadow.getElement(), OVER, true); // Add vertical location dependent style setStyleName(dragShadow.getElement(), OVER + "-" + vl.toString().toLowerCase(), true); // Add horizontal location dependent style setStyleName(dragShadow.getElement(), OVER + "-" + hl.toString().toLowerCase(), true); }
Example #23
Source File: DefaultAccordionDropHandler.java From cuba with Apache License 2.0 | 5 votes |
/** * Adds a new tab from the drop * * @param event * The drag and drop event */ @Override protected void handleDropFromLayout(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event .getTransferable(); // Get the target details AccordionTargetDetails details = (AccordionTargetDetails) event .getTargetDetails(); DDAccordion acc = (DDAccordion) details.getTarget(); Component c = transferable.getComponent(); int idx = details.getOverIndex(); VerticalDropLocation location = details.getDropLocation(); // Detach from old source Component source = transferable.getSourceComponent(); if (source instanceof ComponentContainer) { ((ComponentContainer) source).removeComponent(c); } else if (source instanceof SingleComponentContainer) { ((SingleComponentContainer) source).setContent(null); } if (location == VerticalDropLocation.TOP) { acc.addTab(c, idx); } else if (location == VerticalDropLocation.BOTTOM) { acc.addTab(c, idx + 1); } else { acc.addTab(c); } }
Example #24
Source File: VDDGridLayout.java From cuba with Apache License 2.0 | 5 votes |
/** * Removes any emphasis previously set by emphasis */ protected void deEmphasis() { setStyleName(dragShadow.getElement(), OVER, false); // Horizontal styles setStyleName(dragShadow.getElement(), OVER + "-" + HorizontalDropLocation.LEFT.toString().toLowerCase(), false); setStyleName(dragShadow.getElement(), OVER + "-" + HorizontalDropLocation.CENTER.toString().toLowerCase(), false); setStyleName(dragShadow.getElement(), OVER + "-" + HorizontalDropLocation.RIGHT.toString().toLowerCase(), false); // Vertical styles setStyleName(dragShadow.getElement(), OVER + "-" + VerticalDropLocation.TOP.toString().toLowerCase(), false); setStyleName(dragShadow.getElement(), OVER + "-" + VerticalDropLocation.MIDDLE.toString().toLowerCase(), false); setStyleName(dragShadow.getElement(), OVER + "-" + VerticalDropLocation.BOTTOM.toString().toLowerCase(), false); }
Example #25
Source File: TreeToolEditor.java From chipster with MIT License | 4 votes |
private void initTree() { this.setSizeFull(); this.setImmediate(true); this.setSelectable(true); this.addItemClickListener(this); this.addContainerProperty("", String.class, null); this.addContainerProperty(ACTIONS, HorizontalLayout.class, null ); this.addItem(new Object[] {TOOL, getActionLayout(false, false, TOOL)}, TOOL); this.setItemDescriptionGenerator(new ItemDescriptionGenerator() { private static final long serialVersionUID = -1913286695570843896L; @Override public String generateDescription(Component source, Object itemId, Object propertyId) { String description = "Show all "; if(itemId.equals(TOOL)) description += "elements"; else if (itemId.equals(INPUTS)) description += "inputs"; else if (itemId.equals(OUTPUTS)) description += "outputs"; else if (itemId.equals(PARAMETERS)) description += "parameters"; else return null; return description; } }); this.setCollapsed(TOOL, false); String[] rootToolElements = new String[] {INPUTS, OUTPUTS, PARAMETERS}; for(String element : rootToolElements) { this.addItem(new Object[] {element, getActionLayout(true, false, element)}, element); this.setParent(element, TOOL); this.setCollapsed(element, false); } this.setDragMode(TableDragMode.ROW); this.setDropHandler(new DropHandler() { private static final long serialVersionUID = -4415321436294383112L; @Override public AcceptCriterion getAcceptCriterion() { return new Or(Tree.TargetItemAllowsChildren.get(), new Not(VerticalLocationIs.MIDDLE)); } @Override public void drop(DragAndDropEvent event) { final Transferable t = event.getTransferable(); if (t.getSourceComponent() != TreeToolEditor.this || !(t instanceof DataBoundTransferable)) { return; } final AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) event.getTargetDetails()); final Object sourceItemId = ((DataBoundTransferable) t).getItemId(); final Object targetItemId = dropData.getItemIdOver(); final VerticalDropLocation location = dropData.getDropLocation(); moveNode(sourceItemId, targetItemId, location); } }); }
Example #26
Source File: DefaultFormLayoutDropHandler.java From cuba with Apache License 2.0 | 4 votes |
@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 #27
Source File: DefaultFormLayoutDropHandler.java From cuba with Apache License 2.0 | 4 votes |
@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 #28
Source File: DefaultCssLayoutDropHandler.java From cuba with Apache License 2.0 | 4 votes |
@Override protected void handleDropFromLayout(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event .getTransferable(); CssLayoutTargetDetails details = (CssLayoutTargetDetails) event .getTargetDetails(); DDCssLayout layout = (DDCssLayout) details.getTarget(); HorizontalDropLocation hl = details.getHorizontalDropLocation(); VerticalDropLocation vl = details.getVerticalDropLocation(); Component source = event.getTransferable().getSourceComponent(); int idx = (details).getOverIndex(); Component comp = transferable.getComponent(); Component over = details.getOverComponent(); 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++; } } // 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(); } // If source is an instance of a component container then remove // it // from there, // the component cannot have two parents. if (source instanceof ComponentContainer) { ComponentContainer sourceLayout = (ComponentContainer) source; sourceLayout.removeComponent(comp); } // Add component if (idx >= 0 && idx < layout.getComponentCount()) { layout.addComponent(comp, idx); } else { layout.addComponent(comp); } }
Example #29
Source File: DefaultVerticalLayoutDropHandler.java From cuba with Apache License 2.0 | 4 votes |
/** * 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); } }
Example #30
Source File: DefaultVerticalLayoutDropHandler.java From cuba with Apache License 2.0 | 4 votes |
/** * 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); } }