Example usage for com.vaadin.ui AbstractOrderedLayout addComponent

List of usage examples for com.vaadin.ui AbstractOrderedLayout addComponent

Introduction

In this page you can find the example usage for com.vaadin.ui AbstractOrderedLayout addComponent.

Prototype

public void addComponent(Component c, int index) 

Source Link

Document

Adds a component into indexed position in this container.

Usage

From source file:com.expressui.core.view.menu.MainMenuBar.java

License:Open Source License

private void addPopupCodeIfEnabled() {
    if (isCodePopupEnabled()) {
        Button codePopupButton = codePopup.createPopupCodeButton(getMainApplication().getClass(),
                MainApplication.class);
        AbstractOrderedLayout layout = ((AbstractOrderedLayout) getCompositionRoot());
        layout.addComponent(codePopupButton, 1);
    }/*from  w  w  w. ja v a2  s. c  om*/
}

From source file:com.foc.vaadin.gui.layouts.FVHorizontal_WYSIWYG_DropHandler.java

License:Apache License

@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();

    // Detach//from   w  ww  . java 2s.c  om
    if (layout != null && comp != null)
        layout.removeComponent(comp);
    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++;
    }

    if (comp != null) {
        AttributesImpl newAttributes = removeNotNeededAttributes(((FocXMLGuiComponent) comp).getAttributes(),
                (FVLayout) comp.getParent());

        if (newAttributes.getIndex(FXML.ATT_IDX) != -1) {
            newAttributes.setValue(newAttributes.getIndex("idx"), idx + "");
        } else {
            newAttributes.addAttribute("", FXML.ATT_IDX, FXML.ATT_IDX, "CDATA", idx + "");
        }

        ((FocXMLGuiComponent) comp).setAttributes(newAttributes);

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

        if (comp instanceof FVLayout) {
            Globals.logString("Here3");
            ((FVLayout) comp).setDragDrop(true);
        }

        // Add component alignment if given
        if (dropAlignment != null && layout != null && comp != null) {
            layout.setComponentAlignment(comp, dropAlignment);
        }
    }
}

From source file:com.foc.vaadin.gui.layouts.FVHorizontal_WYSIWYG_DropHandler.java

License:Apache License

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) 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// ww  w .  ja  v a 2 s  . c om
    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.

    ComponentContainer sourceLayout = null;

    if (source instanceof ComponentContainer) {
        sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(comp);
    }

    // Increase index if component is dropped after or above a
    // previous
    // component
    HorizontalDropLocation loc = (details).getDropLocation();

    if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
        idx++;
    }

    AttributesImpl newAttributes = removeNotNeededAttributes(((FocXMLGuiComponent) comp).getAttributes(),
            (FVLayout) sourceLayout);

    if (newAttributes.getIndex(FXML.ATT_IDX) > -1) {
        newAttributes.setValue(newAttributes.getIndex(FXML.ATT_IDX), idx + "");
    }

    ((FocXMLGuiComponent) comp).setAttributes(newAttributes);

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

From source file:com.foc.vaadin.gui.layouts.FVVertical_WYSIWYG_DropHandler.java

License:Apache License

@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();

    // Detach//from ww w.  j av  a 2  s.c o m
    if (comp != null && layout != null)
        layout.removeComponent(comp);
    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 (layout != null) {
        if (idx >= 0) {
            layout.addComponent(comp, idx);
        } else {
            layout.addComponent(comp);
        }
    }

    if (comp instanceof FVLayout) {
        ((FVLayout) comp).setDragDrop(true);
    }

    // Add component alignment if given
    if (dropAlignment != null && layout != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}

From source file:com.foc.vaadin.gui.layouts.FVVertical_WYSIWYG_DropHandler.java

License:Apache License

@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//  ww w  . j a v  a2 s  .com
    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.

    ComponentContainer sourceLayout = null;

    if (source instanceof ComponentContainer) {
        sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(comp);
    }

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

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultFormLayoutDropHandler.java

License:Apache License

@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//from  ww  w .java  2s  .com
    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);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultFormLayoutDropHandler.java

License:Apache License

@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++;/*from w w  w  .  j ava2  s .c om*/
    }

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

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultHorizontalLayoutDropHandler.java

License:Apache License

/**
 * Called when a component changed location within the layout
 * /*from  w  w  w.  j av a  2s.c om*/
 * @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);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultHorizontalLayoutDropHandler.java

License:Apache License

/**
 * Handle a drop from another layout/*w w  w  . ja va  2  s.  com*/
 * 
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) 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
    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);
    }

    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultHorizontalLayoutDropHandler.java

License:Apache License

@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) event.getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
    Component source = event.getTransferable().getSourceComponent();
    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++;//ww w .  j a va2  s.c  om
    }

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