Java Code Examples for com.vaadin.shared.ui.dd.VerticalDropLocation#MIDDLE
The following examples show how to use
com.vaadin.shared.ui.dd.VerticalDropLocation#MIDDLE .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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); } }
Example 11
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 12
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); } }
Example 13
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 14
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 15
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); } }