Example usage for com.vaadin.ui AbstractOrderedLayout removeComponent

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

Introduction

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

Prototype

@Override
public void removeComponent(Component c) 

Source Link

Document

Removes the component from this container.

Usage

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.  j av a  2 s .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.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//  w  w  w. j av a2  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.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultHorizontalLayoutDropHandler.java

License:Apache License

/**
 * Called when a component changed location within the layout
 * // w w  w  .ja  v  a  2s  . c  o  m
 * @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.DefaultVerticalLayoutDropHandler.java

License:Apache License

/**
 * Called when a component changed location within the layout
 * /* w ww  .  ja  v  a 2s . co m*/
 * @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);
    }

}

From source file:info.magnolia.security.app.dialog.field.WebAccessFieldFactory.java

License:Open Source License

private Component createRuleRow(final AbstractOrderedLayout parentContainer,
        final AbstractJcrNodeAdapter ruleItem, final Label emptyLabel) {

    final HorizontalLayout ruleLayout = new HorizontalLayout();
    ruleLayout.setSpacing(true);/*from   w w  w  . ja va  2 s .  c o m*/
    ruleLayout.setWidth("100%");

    NativeSelect accessRights = new NativeSelect();
    accessRights.addItem(Permission.ALL);
    accessRights.setItemCaption(Permission.ALL, i18n.translate("security.web.field.getPost"));
    accessRights.addItem(Permission.READ);
    accessRights.setItemCaption(Permission.READ, i18n.translate("security.web.field.get"));
    accessRights.addItem(Permission.NONE);
    accessRights.setItemCaption(Permission.NONE, i18n.translate("security.web.field.deny"));
    accessRights.setNullSelectionAllowed(false);
    accessRights.setImmediate(true);
    accessRights.setInvalidAllowed(false);
    accessRights.setNewItemsAllowed(false);
    Property permissionsProperty = ruleItem.getItemProperty(PERMISSIONS_PROPERTY_NAME);
    if (permissionsProperty == null) {
        permissionsProperty = new DefaultProperty<Long>(Long.class, Permission.ALL);
        ruleItem.addItemProperty(PERMISSIONS_PROPERTY_NAME, permissionsProperty);
    }
    accessRights.setPropertyDataSource(permissionsProperty);
    ruleLayout.addComponent(accessRights);

    TextField path = new TextField();
    path.setWidth("100%");
    Property pathProperty = ruleItem.getItemProperty(PATH_PROPERTY_NAME);
    if (pathProperty == null) {
        pathProperty = new DefaultProperty<String>(String.class, "/*");
        ruleItem.addItemProperty(PATH_PROPERTY_NAME, pathProperty);
    }
    path.setPropertyDataSource(pathProperty);
    ruleLayout.addComponent(path);
    ruleLayout.setExpandRatio(path, 1.0f);

    final Button deleteButton = new Button();
    deleteButton.setHtmlContentAllowed(true);
    deleteButton.setCaption("<span class=\"" + "icon-trash" + "\"></span>");
    deleteButton.addStyleName("inline");
    deleteButton.setDescription(i18n.translate("security.web.field.delete"));
    deleteButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            parentContainer.removeComponent(ruleLayout);
            ruleItem.getParent().removeChild(ruleItem);
            if (parentContainer.getComponentCount() == 1) {
                parentContainer.addComponent(emptyLabel, 0);
            }
        }
    });
    ruleLayout.addComponent(deleteButton);

    return ruleLayout;
}

From source file:info.magnolia.security.app.dialog.field.WorkspaceAccessFieldFactory.java

License:Open Source License

protected Component createRuleRow(final AbstractOrderedLayout parentContainer,
        final AbstractJcrNodeAdapter ruleItem, final Label emptyLabel) {

    final HorizontalLayout ruleLayout = new HorizontalLayout();
    ruleLayout.setSpacing(true);//from  ww  w  .j a v  a2s  .  co  m
    ruleLayout.setWidth("100%");

    NativeSelect accessRights = new NativeSelect();
    accessRights.setNullSelectionAllowed(false);
    accessRights.setImmediate(true);
    accessRights.setInvalidAllowed(false);
    accessRights.setNewItemsAllowed(false);
    accessRights.addItem(Permission.ALL);
    accessRights.setItemCaption(Permission.ALL, i18n.translate("security.workspace.field.readWrite"));
    accessRights.addItem(Permission.READ);
    accessRights.setItemCaption(Permission.READ, i18n.translate("security.workspace.field.readOnly"));
    accessRights.addItem(Permission.NONE);
    accessRights.setItemCaption(Permission.NONE, i18n.translate("security.workspace.field.denyAccess"));
    accessRights.setPropertyDataSource(ruleItem.getItemProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME));
    ruleLayout.addComponent(accessRights);

    NativeSelect accessType = new NativeSelect();
    accessType.setNullSelectionAllowed(false);
    accessType.setImmediate(true);
    accessType.setInvalidAllowed(false);
    accessType.setNewItemsAllowed(false);
    accessType.setWidth("150px");
    accessType.addItem(AccessControlList.ACCESS_TYPE_NODE);
    accessType.setItemCaption(AccessControlList.ACCESS_TYPE_NODE,
            i18n.translate("security.workspace.field.selected"));
    accessType.addItem(AccessControlList.ACCESS_TYPE_CHILDREN);
    accessType.setItemCaption(AccessControlList.ACCESS_TYPE_CHILDREN,
            i18n.translate("security.workspace.field.subnodes"));
    accessType.addItem(AccessControlList.ACCESS_TYPE_NODE_AND_CHILDREN);
    accessType.setItemCaption(AccessControlList.ACCESS_TYPE_NODE_AND_CHILDREN,
            i18n.translate("security.workspace.field.selectedSubnodes"));
    Property accessTypeProperty = ruleItem.getItemProperty(ACCESS_TYPE_PROPERTY_NAME);
    accessType.setPropertyDataSource(accessTypeProperty);
    ruleLayout.addComponent(accessType);

    final TextField path = new TextField();
    path.setWidth("100%");
    path.setPropertyDataSource(ruleItem.getItemProperty(AccessControlList.PATH_PROPERTY_NAME));
    ruleLayout.addComponent(path);
    ruleLayout.setExpandRatio(path, 1.0f);

    Button chooseButton = new Button(i18n.translate("security.workspace.field.choose"));
    chooseButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            openChooseDialog(path);
        }
    });
    ruleLayout.addComponent(chooseButton);

    Button deleteButton = new Button();
    deleteButton.setHtmlContentAllowed(true);
    deleteButton.setCaption("<span class=\"" + "icon-trash" + "\"></span>");
    deleteButton.addStyleName("inline");
    deleteButton.setDescription(i18n.translate("security.workspace.field.delete"));
    deleteButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            parentContainer.removeComponent(ruleLayout);
            ruleItem.getParent().removeChild(ruleItem);
            if (parentContainer.getComponentCount() == 1) {
                parentContainer.addComponent(emptyLabel, 0);
            }
        }
    });
    ruleLayout.addComponent(deleteButton);

    return ruleLayout;
}