Example usage for com.vaadin.ui AbstractOrderedLayout getComponentCount

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

Introduction

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

Prototype

@Override
public int getComponentCount() 

Source Link

Document

Gets the number of contained components.

Usage

From source file:edu.kit.dama.ui.admin.utils.UIComponentTools.java

License:Apache License

private static void setLockedComponents(AbstractOrderedLayout layout, boolean locked) {
    for (int i = 0; i < layout.getComponentCount(); i++) {
        if (layout.getComponent(i).getClass().equals(Button.class)) {
            layout.getComponent(i).setEnabled(!locked);
        } else if (layout.getComponent(i).getClass().equals(ComboBox.class)) {
            layout.getComponent(i).setEnabled(!locked);
            layout.getComponent(i).setReadOnly(locked);
        } else {/*ww w  . ja va  2 s .c o  m*/
            layout.getComponent(i).setReadOnly(locked);
        }
    }
}

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   ww  w .  j  a va  2s.com
    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);//  w  w  w  .  ja  v a  2s  . c o  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;
}