Example usage for com.vaadin.ui VerticalLayout getComponentCount

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

Introduction

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

Prototype

@Override
public int getComponentCount() 

Source Link

Document

Gets the number of contained components.

Usage

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

License:Open Source License

@Override
protected Field<Object> createFieldComponent() {

    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);/*w  w  w .  jav  a  2s.c o  m*/

    try {

        final JcrNodeAdapter roleItem = (JcrNodeAdapter) item;

        final VerticalLayout aclLayout = new VerticalLayout();

        final Label emptyLabel = new Label(i18n.translate("security.web.field.noAccess"));

        // Since JcrNewNodeAdapter.getJcrItem() returns the parent node we need to skip this step because we don't want to inspect the parent node
        if (!(roleItem instanceof JcrNewNodeAdapter)) {
            Node roleNode = roleItem.getJcrItem();
            if (roleNode.hasNode(ACL_NODE_NAME)) {

                final Node aclNode = roleNode.getNode(ACL_NODE_NAME);
                AbstractJcrNodeAdapter aclItem = new JcrNodeAdapter(aclNode);
                roleItem.addChild(aclItem);

                for (Node entryNode : NodeUtil.getNodes(aclNode)) {

                    AbstractJcrNodeAdapter entryItem = new JcrNodeAdapter(entryNode);
                    aclItem.addChild(entryItem);

                    Component ruleRow = createRuleRow(aclLayout, entryItem, emptyLabel);
                    aclLayout.addComponent(ruleRow);
                }
            }
        }

        if (aclLayout.getComponentCount() == 0) {
            aclLayout.addComponent(emptyLabel);
        }

        final HorizontalLayout buttons = new HorizontalLayout();
        final Button addButton = new Button(i18n.translate("security.web.field.addNew"));
        addButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {

                try {
                    AbstractJcrNodeAdapter aclItem = getOrAddAclItem(roleItem, ACL_NODE_NAME);
                    JcrNewNodeAdapter newItem = addAclEntryItem(aclItem);
                    Component ruleRow = createRuleRow(aclLayout, newItem, emptyLabel);
                    aclLayout.removeComponent(emptyLabel);
                    aclLayout.addComponent(ruleRow, aclLayout.getComponentCount() - 1);

                } catch (RepositoryException e) {
                    throw new RuntimeRepositoryException(e);
                }
            }
        });
        buttons.addComponent(addButton);
        aclLayout.addComponent(buttons);

        layout.addComponent(aclLayout);

    } catch (RepositoryException e) {
        throw new RuntimeRepositoryException(e);
    }

    return new CustomField<Object>() {

        @Override
        protected Component initContent() {
            return layout;
        }

        @Override
        public Class<?> getType() {
            return Object.class;
        }
    };
}

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

License:Open Source License

@Override
protected Field<Object> createFieldComponent() {

    final String aclName = "acl_" + getFieldDefinition().getWorkspace();

    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);/*from   w  w w . j a  v  a  2 s .co m*/

    try {

        final JcrNodeAdapter roleItem = (JcrNodeAdapter) item;

        final VerticalLayout aclLayout = new VerticalLayout();

        final Label emptyLabel = new Label(i18n.translate("security.workspace.field.noAccess"));

        // Since JcrNewNodeAdapter.getJcrItem() returns the parent node we need to skip this step because we don't want to inspect the parent node
        if (!(roleItem instanceof JcrNewNodeAdapter)) {
            Node roleNode = roleItem.getJcrItem();
            if (roleNode.hasNode(aclName)) {

                final Node aclNode = roleNode.getNode(aclName);

                AccessControlList acl = new AccessControlList();
                acl.readEntries(aclNode);

                AbstractJcrNodeAdapter aclItem = new JcrNodeAdapter(aclNode);
                roleItem.addChild(aclItem);

                aclItem.addItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME,
                        new DefaultProperty<String>(String.class, "true"));

                final Set<AccessControlList.Entry> uniqueEntries = new HashSet<AccessControlList.Entry>();
                for (final Node aclEntryNode : NodeUtil.getNodes(aclNode)) {
                    AccessControlList.Entry entry = acl.getEntryByNode(aclEntryNode);
                    if (uniqueEntries.contains(entry)) {
                        continue;
                    }

                    uniqueEntries.add(entry);
                    long permissions = entry.getPermissions();
                    long accessType = entry.getAccessType();
                    String path = entry.getPath();

                    JcrNodeAdapter entryItem = new JcrNodeAdapter(aclEntryNode);
                    entryItem.addItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME,
                            new DefaultProperty<String>(String.class, "true"));
                    final Property<Long> permissionsProperty = DefaultPropertyUtil
                            .newDefaultProperty(Long.class, null);
                    entryItem.addItemProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME, permissionsProperty);
                    final Property<Long> accessProperty = DefaultPropertyUtil.newDefaultProperty(Long.class,
                            null);
                    entryItem.addItemProperty(ACCESS_TYPE_PROPERTY_NAME, accessProperty);
                    final Property<String> pathProperty = DefaultPropertyUtil.newDefaultProperty(String.class,
                            null);
                    entryItem.addItemProperty(AccessControlList.PATH_PROPERTY_NAME, pathProperty);

                    permissionsProperty.setValue(permissions);
                    accessProperty.setValue(accessType);
                    pathProperty.setValue(path);

                    aclItem.addChild(entryItem);

                    Component ruleRow = createRuleRow(aclLayout, entryItem, emptyLabel);
                    aclLayout.addComponent(ruleRow);
                }
            }
        }

        if (aclLayout.getComponentCount() == 0) {
            aclLayout.addComponent(emptyLabel);
        }

        final HorizontalLayout buttons = new HorizontalLayout();
        final Button addButton = new Button(i18n.translate("security.workspace.field.addButton"));
        addButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                try {

                    AbstractJcrNodeAdapter aclItem = getOrAddAclItem(roleItem, aclName);
                    if (aclItem.getItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME) == null) {
                        aclItem.addItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME,
                                new DefaultProperty<String>(String.class, "true"));
                    }

                    JcrNodeAdapter entryItem = addAclEntryItem(aclItem);
                    entryItem.addItemProperty(INTERMEDIARY_FORMAT_PROPERTY_NAME,
                            new DefaultProperty<String>(String.class, "true"));
                    entryItem.addItemProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME,
                            new DefaultProperty<Long>(Long.class, Permission.ALL));
                    entryItem.addItemProperty(ACCESS_TYPE_PROPERTY_NAME, new DefaultProperty<Long>(Long.class,
                            AccessControlList.ACCESS_TYPE_NODE_AND_CHILDREN));
                    entryItem.addItemProperty(AccessControlList.PATH_PROPERTY_NAME,
                            new DefaultProperty<String>(String.class, ""));

                    Component ruleRow = createRuleRow(aclLayout, entryItem, emptyLabel);
                    aclLayout.removeComponent(emptyLabel);
                    aclLayout.addComponent(ruleRow, aclLayout.getComponentCount() - 1);
                } catch (RepositoryException e) {
                    throw new RuntimeRepositoryException(e);
                }
            }
        });
        buttons.addComponent(addButton);
        aclLayout.addComponent(buttons);

        layout.addComponent(aclLayout);

    } catch (RepositoryException e) {
        throw new RuntimeRepositoryException(e);
    }

    return new CustomField<Object>() {

        @Override
        protected Component initContent() {
            return layout;
        }

        @Override
        public Class<?> getType() {
            return Object.class;
        }
    };
}

From source file:org.ikasan.dashboard.ui.mappingconfiguration.component.MappingConfigurationConfigurationValuesTable.java

License:BSD License

@SuppressWarnings("unchecked")
@Override/*www  .  j  ava2s.  c o  m*/
public void setEditable(boolean editable) {
    Collection<Long> itemIds = (Collection<Long>) this.getItemIds();

    Iterator<Long> itemIdsIter = itemIds.iterator();

    while (itemIdsIter.hasNext()) {
        Item item = this.getItem(itemIdsIter.next());
        Property<VerticalLayout> property = item.getItemProperty("Source Configuration Value");
        VerticalLayout layout = property.getValue();

        for (int i = 0; i < layout.getComponentCount(); i++) {
            ((TextField) layout.getComponent(i)).setReadOnly(!editable);
        }

        Property<TextField> targetProperty = item.getItemProperty("Target Configuration Value");
        targetProperty.getValue().setReadOnly(!editable);
    }

    super.setEditable(editable);
}

From source file:org.opennms.features.vaadin.config.EventAdminApplication.java

License:Open Source License

@Override
public void init(VaadinRequest request) {
    if (eventProxy == null)
        throw new RuntimeException("eventProxy cannot be null.");
    if (eventConfDao == null)
        throw new RuntimeException("eventConfDao cannot be null.");

    final VerticalLayout layout = new VerticalLayout();

    final HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.setMargin(true);/*from ww w.  ja v  a 2  s  .  c  o  m*/

    final Label comboLabel = new Label("Select Events Configuration File");
    toolbar.addComponent(comboLabel);
    toolbar.setComponentAlignment(comboLabel, Alignment.MIDDLE_LEFT);

    final File eventsDir = new File(ConfigFileConstants.getFilePathString(), "events");
    final XmlFileContainer container = new XmlFileContainer(eventsDir, true);
    container.addExcludeFile("default.events.xml"); // This is a protected file, should not be updated.
    final ComboBox eventSource = new ComboBox();
    toolbar.addComponent(eventSource);
    eventSource.setImmediate(true);
    eventSource.setNullSelectionAllowed(false);
    eventSource.setContainerDataSource(container);
    eventSource.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME);
    eventSource.addValueChangeListener(new ComboBox.ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            final File file = (File) event.getProperty().getValue();
            if (file == null)
                return;
            try {
                LOG.info("Loading events from {}", file);
                final Events events = JaxbUtils.unmarshal(Events.class, file);
                addEventPanel(layout, file, events);
            } catch (Exception e) {
                LOG.error("an error ocurred while saving the event configuration {}: {}", file, e.getMessage(),
                        e);
                Notification.show("Can't parse file " + file + " because " + e.getMessage());
            }
        }
    });

    final Button add = new Button("Add New Events File");
    toolbar.addComponent(add);
    add.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            PromptWindow w = new PromptWindow("New Events Configuration", "Events File Name") {
                @Override
                public void textFieldChanged(String fieldValue) {
                    final File file = new File(eventsDir, normalizeFilename(fieldValue));
                    LOG.info("Adding new events file {}", file);
                    final Events events = new Events();
                    addEventPanel(layout, file, events);
                }
            };
            addWindow(w);
        }
    });

    final Button remove = new Button("Remove Selected Events File");
    toolbar.addComponent(remove);
    remove.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (eventSource.getValue() == null) {
                Notification.show("Please select an event configuration file.");
                return;
            }
            final File file = (File) eventSource.getValue();
            ConfirmDialog.show(getUI(), "Are you sure?", "Do you really want to remove the file "
                    + file.getName()
                    + "?\nThis cannot be undone and OpenNMS won't be able to handle the events configured on this file.",
                    "Yes", "No", new ConfirmDialog.Listener() {
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                LOG.info("deleting file {}", file);
                                if (file.delete()) {
                                    try {
                                        // Updating eventconf.xml
                                        boolean modified = false;
                                        File configFile = ConfigFileConstants
                                                .getFile(ConfigFileConstants.EVENT_CONF_FILE_NAME);
                                        Events config = JaxbUtils.unmarshal(Events.class, configFile);
                                        for (Iterator<String> it = config.getEventFileCollection()
                                                .iterator(); it.hasNext();) {
                                            String fileName = it.next();
                                            if (file.getAbsolutePath().contains(fileName)) {
                                                it.remove();
                                                modified = true;
                                            }
                                        }
                                        if (modified) {
                                            JaxbUtils.marshal(config, new FileWriter(configFile));
                                            EventBuilder eb = new EventBuilder(
                                                    EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI, "WebUI");
                                            eventProxy.send(eb.getEvent());
                                        }
                                        // Updating UI Components
                                        eventSource.select(null);
                                        if (layout.getComponentCount() > 1)
                                            layout.removeComponent(layout.getComponent(1));
                                    } catch (Exception e) {
                                        LOG.error("an error ocurred while saving the event configuration: {}",
                                                e.getMessage(), e);
                                        Notification.show("Can't save event configuration. " + e.getMessage(),
                                                Notification.Type.ERROR_MESSAGE);
                                    }
                                } else {
                                    Notification.show("Cannot delete file " + file,
                                            Notification.Type.WARNING_MESSAGE);
                                }
                            }
                        }
                    });
        }
    });

    layout.addComponent(toolbar);
    layout.addComponent(new Label(""));
    layout.setComponentAlignment(toolbar, Alignment.MIDDLE_RIGHT);

    setContent(layout);
}

From source file:org.opennms.features.vaadin.config.EventAdminApplication.java

License:Open Source License

/**
 * Removes the event panel./*from w  w  w  .j a va2  s  .c o m*/
 *
 * @param layout the layout
 */
private void removeEventPanel(final VerticalLayout layout) {
    if (layout.getComponentCount() > 1)
        layout.removeComponent(layout.getComponent(1));
}

From source file:org.opennms.features.vaadin.mibcompiler.MibConsolePanel.java

License:Open Source License

/**
 * Scroll into view.//from w ww.  j  a  v  a2s .co  m
 */
private void scrollIntoView() {
    final VerticalLayout layout = (VerticalLayout) getContent();
    if (getUI() != null && layout.getComponentCount() > 0)
        getUI().scrollIntoView(layout.getComponent(layout.getComponentCount() - 1));
}

From source file:ru.codeinside.gses.webui.declarant.DeclarantFactory.java

License:Mozilla Public License

public static Component create() {

    // TODO: ??   ??!
    final ServiceQueryDefinition amSQ = new ServiceQueryDefinition(ProcedureType.Administrative);
    final LazyQueryContainer amSC = new LazyQueryContainer(amSQ, new ServiceQueryFactory(false));
    final ProcedureQueryDefinition amPQ = new ProcedureQueryDefinition(ProcedureType.Administrative);
    final LazyQueryContainer amPC = new LazyQueryContainer(amPQ,
            new ProcedureQueryFactory(Flash.login(), false));

    final ProcedureQueryDefinition mmQ = new ProcedureQueryDefinition(ProcedureType.Interdepartmental);
    final LazyQueryContainer mmC = new LazyQueryContainer(mmQ, new ProcedureQueryFactory(Flash.login(), false));

    final VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();/*from w  w w  .  j a v a 2 s .  co  m*/
    layout.setMargin(true);
    final Label header = new Label(
            " ?  ?? ?? ?");
    header.addStyleName("h1");
    layout.addComponent(header);

    final Select amS = new Select("", amPC);
    String selectWidth = "400px";
    amS.setWidth(selectWidth);
    amS.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
    amS.setItemCaptionPropertyId("name");
    amS.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
    amS.setNullSelectionAllowed(true);
    amS.setNewItemsAllowed(false);
    amS.setImmediate(true);

    final Select amSS = new Select("?", amSC);
    amSS.setWidth(selectWidth);
    amSS.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
    amSS.setItemCaptionPropertyId("name");
    amSS.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
    amSS.setNullSelectionAllowed(true);
    amSS.setNewItemsAllowed(false);
    amSS.setImmediate(true);

    final FormLayout amLayout = new FormLayout();

    final Panel amPanel = new Panel();
    amLayout.addComponent(amSS);
    amLayout.addComponent(amS);
    amPanel.addComponent(amLayout);

    final Select mmS = new Select("", mmC);
    mmS.setFilteringMode(Select.FILTERINGMODE_OFF);
    mmS.setWidth(selectWidth);
    mmS.setItemCaptionPropertyId("name");
    mmS.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
    mmS.setNullSelectionAllowed(true);
    mmS.setNewItemsAllowed(false);
    mmS.setImmediate(true);

    final FormLayout mmLayout = new FormLayout();
    final Panel mmPanel = new Panel();
    //    mmLayout.addComponent(mmSS);
    mmLayout.addComponent(mmS);
    mmPanel.addComponent(mmLayout);

    final VerticalLayout amWrapper = new VerticalLayout();
    amWrapper.setSizeFull();
    amWrapper.addComponent(amPanel);

    final VerticalLayout imWrapper = new VerticalLayout();
    imWrapper.setSizeFull();
    imWrapper.addComponent(mmPanel);

    final TabSheet typeSheet = new TabSheet();
    typeSheet.setSizeFull();
    typeSheet.addTab(amWrapper, "?? ");
    typeSheet.addTab(imWrapper, "? ");
    layout.addComponent(typeSheet);
    layout.setExpandRatio(typeSheet, 1);

    // 

    amSS.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            final Property prop = event.getProperty();
            if (prop.getValue() == null) {
                amPQ.serviceId = -1;
            } else {
                amPQ.serviceId = (Long) amSC.getItem(prop.getValue()).getItemProperty("id").getValue();
            }
            amS.select(null);
            amPC.refresh();
        }
    });

    final ProcedureSelectListener administrativeProcedureSelectListener = new ProcedureSelectListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void selectProcedure(long id) {
            if (amWrapper.getComponentCount() > 1) {
                amWrapper.removeComponent(amWrapper.getComponent(1));
            }
            if (id > 0) {
                final Component cmp = createStartEventForm(id, this, layout);
                if (cmp != null) {
                    amWrapper.addComponent(cmp);
                    amWrapper.setExpandRatio(cmp, 1f);
                } else {
                    amS.select(null);
                    amPC.refresh();
                    amSC.refresh();
                }
            }
        }
    };
    final ProcedureSelectListener interdepartamentalProcedureSelectListener = new ProcedureSelectListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void selectProcedure(long id) {
            if (imWrapper.getComponentCount() > 1) {
                imWrapper.removeComponent(imWrapper.getComponent(1));
            }
            if (id > 0) {
                final Component cmp = createStartEventForm(id, this, layout);
                if (cmp != null) {
                    imWrapper.addComponent(cmp);
                    imWrapper.setExpandRatio(cmp, 1f);
                }
            }
        }
    };
    amS.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            final Object itemId = event.getProperty().getValue();
            final long procedureId = itemId == null ? -1
                    : (Long) amPC.getItem(itemId).getItemProperty("id").getValue();
            administrativeProcedureSelectListener.selectProcedure(procedureId);
        }
    });
    mmS.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            final Object itemId = event.getProperty().getValue();
            final long procedureId = itemId == null ? -1
                    : (Long) mmC.getItem(itemId).getItemProperty("id").getValue();
            interdepartamentalProcedureSelectListener.selectProcedure(procedureId);
        }
    });

    return layout;
}