Example usage for com.vaadin.ui Component getParent

List of usage examples for com.vaadin.ui Component getParent

Introduction

In this page you can find the example usage for com.vaadin.ui Component getParent.

Prototype

@Override
public HasComponents getParent();

Source Link

Document

Gets the parent component of the component.

Usage

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

License:Apache License

/**
 * Handle a drop from another layout/*w w  w . ja  v a2  s  . c  o  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.FVAbsoulte_WYSIWYG_DropHandler.java

License:Apache License

public void drop(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    DropTarget layout = details.getTarget();
    Component source = event.getTransferable().getSourceComponent();

    if (layout == source) {
        Globals.logString("Here in");
        handleComponentReordering(event);
    } else if (event.getTransferable() instanceof LayoutBoundTransferable) {
        LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
        Component comp = transferable.getComponent();

        if (comp == layout) {
            if (comp.getParent() instanceof DDAbsoluteLayout) {
                handleDropFromAbsoluteParentLayout(event);
            }/*  ww  w  .j  a v  a2 s  .c  o  m*/
        } else {
            handleDropFromLayout(event);
        }
    } else if (event.getTransferable() instanceof DataBoundTransferable) {

        DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();

        String name = t.getItemId() + "";

        Globals.logString("Item ID = " + t.getItemId());

        FVLayout targetLayout = (FVLayout) details.getTarget();

        FocXMLAttributes attributes = new FocXMLAttributes();
        attributes.addAttribute("", FXML.ATT_LEFT, FXML.ATT_LEFT, "CDATA", details.getRelativeLeft() + "px");
        attributes.addAttribute("", FXML.ATT_TOP, FXML.ATT_TOP, "CDATA", details.getRelativeTop() + "px");

        handleSourceContainer(t, targetLayout, name, attributes);

        Globals.logString(targetLayout.toString());
    }
}

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

License:Apache License

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

    // 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.FVDropHandler.java

License:Apache License

public ICentralPanel getCentralPanel() {
    if (centralPanel == null) {
        Component comp = (Component) fvLayout;
        while (comp.getParent() != null) {
            if (comp instanceof ICentralPanel) {
                centralPanel = (ICentralPanel) comp;
            }/*from   w w  w . jav a  2s  . com*/
            comp = comp.getParent();
        }
    }
    return centralPanel;
}

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;// ww  w.  j a v a  2 s  . c  o m

                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.FVGrid_WYSIWYG_DropHandler.java

License:Apache License

public void drop(DragAndDropEvent event) {
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    DropTarget layout = details.getTarget();
    Component source = event.getTransferable().getSourceComponent();

    if (layout == source) {
        handleComponentReordering(event);
    } else if (event.getTransferable() instanceof LayoutBoundTransferable) {
        LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
        Component comp = transferable.getComponent();

        if (comp == layout) {
            if (comp.getParent() instanceof DDAbsoluteLayout) {
                handleDropFromAbsoluteParentLayout(event);
            }/*from  w w w . j  a v a2  s .  c om*/
        } else {
            handleDropFromLayout(event);
        }
    } else if (event.getTransferable() instanceof DataBoundTransferable) {

        DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();

        String name = t.getItemId() + "";

        Globals.logString("Item ID = " + t.getItemId());

        FVLayout targetLayout = (FVLayout) details.getTarget();

        FocXMLAttributes attributes = new FocXMLAttributes();
        attributes.addAttribute("", FXML.ATT_ROW, FXML.ATT_ROW, "CDATA", details.getOverRow() + "");
        attributes.addAttribute("", FXML.ATT_COL, FXML.ATT_COL, "CDATA", details.getOverColumn() + "");

        handleSourceContainer(t, targetLayout, name, attributes);

        Globals.logString(targetLayout.toString());
    }
}

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   www.jav a  2s .c  o  m*/
    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/*from ww w . j a  v  a 2s  .  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
    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.FVHorizontal_WYSIWYG_DropHandler.java

License:Apache License

public void drop(DragAndDropEvent event) {
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) event.getTargetDetails();
    DropTarget layout = details.getTarget();
    Component source = event.getTransferable().getSourceComponent();

    if (layout == source) {
        Globals.logString("Here in");
        handleComponentReordering(event);
    } else if (event.getTransferable() instanceof LayoutBoundTransferable) {
        LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
        Component comp = transferable.getComponent();

        if (comp == layout) {
            if (comp.getParent() instanceof DDAbsoluteLayout) {
                handleDropFromAbsoluteParentLayout(event);
            }/*from w  w  w . j av a 2s. c  o  m*/
        } else {
            handleDropFromLayout(event);
        }
    } else if (event.getTransferable() instanceof DataBoundTransferable) {

        DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();

        String name = t.getItemId() + "";

        Globals.logString("Item ID = " + t.getItemId());

        FVLayout targetLayout = (FVLayout) details.getTarget();

        FocXMLAttributes attributes = new FocXMLAttributes();
        attributes.addAttribute("", FXML.ATT_IDX, FXML.ATT_IDX, "CDATA", details.getOverIndex() + "");

        handleSourceContainer(t, targetLayout, name, attributes);

        Globals.logString(targetLayout.toString());
    }
}

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  w  ww. j  ava  2s  .  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);
    }
}