Example usage for com.vaadin.ui ComponentContainer removeComponent

List of usage examples for com.vaadin.ui ComponentContainer removeComponent

Introduction

In this page you can find the example usage for com.vaadin.ui ComponentContainer removeComponent.

Prototype

public void removeComponent(Component c);

Source Link

Document

Removes the component from this container.

Usage

From source file:com.esofthead.mycollab.module.project.view.bug.components.BugRowComponent.java

License:Open Source License

private void deleteBug() {
    IGroupComponent root = UIUtils.getRoot(this, IGroupComponent.class);
    ComponentContainer parent = (ComponentContainer) this.getParent();
    if (parent != null) {
        parent.removeComponent(this);
        if (root != null) {
            ComponentContainer parentRoot = (ComponentContainer) root.getParent();
            if (parentRoot != null && parent.getComponentCount() == 0) {
                parentRoot.removeComponent(root);
            }/*from   w w  w .j a va 2  s .  c o  m*/
        }
    }
}

From source file:com.esofthead.mycollab.module.project.view.task.components.TaskRowRenderer.java

License:Open Source License

private void deleteTask() {
    IGroupComponent root = UIUtils.getRoot(this, IGroupComponent.class);
    ComponentContainer parent = (ComponentContainer) this.getParent();
    if (parent != null) {
        parent.removeComponent(this);
        if (root != null) {
            ComponentContainer parentRoot = (ComponentContainer) root.getParent();
            if (parentRoot != null && parent.getComponentCount() == 0) {
                parentRoot.removeComponent(root);
            }/*  w  w  w  .  j av a2s  . co  m*/
        }
    }
}

From source file:com.esofthead.mycollab.vaadin.ui.VerticalTabsheet.java

License:Open Source License

public void replaceContainer(ComponentContainer newContainer, ComponentContainer newPosition) {
    ComponentContainer containerParent = (ComponentContainer) tabContainer.getParent();
    if (containerParent != null) {
        containerParent.removeComponent(tabContainer);
    }/*from w  ww .  j ava2  s. c  o m*/
    if (newPosition == null)
        newPosition = newContainer;
    newPosition.addComponent(tabContainer);
    contentWrapper.addComponent(newContainer);
}

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

License:Apache License

/**
 * Handle a drop from another layout/*w  ww  .  j a v  a  2  s.co  m*/
 * 
 * @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();
    }

    ComponentContainer sourceLayout = null;

    // remove component from source
    if (source instanceof ComponentContainer) {
        sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(component);
    }

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

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

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

    ((FocXMLGuiComponent) component).setAttributes(newAttributes);

    // Add component to absolute layout
    layout.addComponent(component, "left:" + leftPixelPosition + "px;top:" + topPixelPosition + "px");
}

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

License:Apache License

/**
 * Handle a drop from another layout/*from  ww w  .ja  v  a  2 s .c om*/
 * 
 * @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 sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(component);
    }

    // Add component to absolute layout
    layout.addComponent(component, "left:" + leftPixelPosition + "px;top:" + topPixelPosition + "px");

    layout.removeAllComponents();
    layout.addComponent(FVIconFactory.getInstance().getFVIcon(FVIconFactory.ICON_TRASH, false));
}

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

License:Apache License

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();
    Component source = event.getTransferable().getSourceComponent();
    Component comp = transferable.getComponent();

    ComponentContainer sourceLayout = null;
    if (comp != null) {
        if (comp == layout) {
            // Dropping myself on myself, if parent is absolute layout then
            // move
            if (comp.getParent() instanceof DDAbsoluteLayout) {
                MouseEventDetails mouseDown = transferable.getMouseDownEvent();
                MouseEventDetails mouseUp = details.getMouseEvent();
                int movex = mouseUp.getClientX() - mouseDown.getClientX();
                int movey = mouseUp.getClientY() - mouseDown.getClientY();

                DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent();
                ComponentPosition position = parent.getPosition(comp);

                sourceLayout = parent;//from   w w  w  .  j ava 2  s.  c om

                float x = position.getLeftValue() + movex;
                float y = position.getTopValue() + movey;
                position.setLeft(x, Sizeable.Unit.PIXELS);
                position.setTop(y, Sizeable.Unit.PIXELS);

                return;
            }

        } else {

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

            // Remove component from its source
            if (source instanceof ComponentContainer) {
                sourceLayout = (ComponentContainer) source;
                sourceLayout.removeComponent(comp);
            }
        }

        int row = details.getOverRow();
        int column = details.getOverColumn();

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

        if (newAttributes.getValue(FXML.ATT_COL) != null) {
            newAttributes.setValue(newAttributes.getIndex(FXML.ATT_COL), column + "");
        } else {
            newAttributes.addAttribute("", FXML.ATT_COL, FXML.ATT_COL, "CDATA", column + "");
        }

        if (newAttributes.getValue(FXML.ATT_ROW) != null) {
            newAttributes.setValue(newAttributes.getIndex(FXML.ATT_ROW), row + "");
        } else {
            newAttributes.addAttribute("", FXML.ATT_ROW, FXML.ATT_ROW, "CDATA", row + "");
        }

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

        addComponent(event, comp, column, row);
    }
}

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//w  w  w  .  ja  va2s  . 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
    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 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/*from  ww  w .j  av a2  s  .  c o m*/
    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.DefaultCssLayoutDropHandler.java

License:Apache License

@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;// w w w.  jav a2  s . c om
        } 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);
    }
}

From source file:com.mycollab.module.project.ui.components.BlockRowRender.java

License:Open Source License

public void selfRemoved() {
    IBlockContainer blockContainer = UIUtils.getRoot(this, IBlockContainer.class);
    ComponentContainer container = (ComponentContainer) getParent();
    if (container != null) {
        container.removeComponent(this);
    }/*from w  w w. j a v  a  2s .  c  o m*/
    if (blockContainer != null) {
        blockContainer.refresh();
    }
}