Example usage for com.vaadin.ui Layout addComponent

List of usage examples for com.vaadin.ui Layout addComponent

Introduction

In this page you can find the example usage for com.vaadin.ui Layout addComponent.

Prototype

public void addComponent(Component c);

Source Link

Document

Adds the component into this container.

Usage

From source file:com.ocs.dynamo.ui.composite.form.DetailsEditTable.java

License:Apache License

/**
 * Constructs the button bar/*from www .  j a  va  2s  . c om*/
 * 
 * @param parent
 *            the layout to which to add the button bar
 */
protected void constructButtonBar(Layout parent) {
    Layout buttonBar = new DefaultHorizontalLayout();
    parent.addComponent(buttonBar);

    constructAddButton(buttonBar);
    constructSearchButton(buttonBar);
    constructRemoveButton(buttonBar);

    postProcessButtonBar(buttonBar);
}

From source file:com.ocs.dynamo.ui.composite.form.DetailsEditTable.java

License:Apache License

/**
 * Constructs the remove button/*from  www .  j  ava  2s  .  com*/
 * 
 * @param buttonBar
 */
protected void constructRemoveButton(Layout buttonBar) {
    removeButton = new Button(messageService.getMessage("ocs.remove"));
    removeButton.setEnabled(false);
    removeButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            container.removeItem(getSelectedItem());
            items.remove(getSelectedItem());
            // callback method so the entity can be removed from its
            // parent
            removeEntity(getSelectedItem());
            parentForm.signalDetailsTableValid(DetailsEditTable.this,
                    VaadinUtils.allFixedTableFieldsValid(table));
            setSelectedItem(null);
            onSelect(null);
        }

    });
    removeButton.setDescription(messageService.getMessage("ocs.select.row.to.delete"));
    removeButton.setVisible(!viewMode && formOptions.isShowRemoveButton());
    buttonBar.addComponent(removeButton);
}

From source file:com.ocs.dynamo.ui.composite.form.DetailsEditTable.java

License:Apache License

/**
 * Constructs a button that brings up a search dialog
 * //from w ww  .  j  a v  a2s .c  o m
 * @param buttonBar
 */
protected void constructSearchButton(Layout buttonBar) {
    searchDialogButton = new Button(messageService.getMessage("ocs.search"));
    searchDialogButton.setDescription(messageService.getMessage("ocs.search.description"));
    searchDialogButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            ModelBasedSearchDialog<ID, T> dialog = new ModelBasedSearchDialog<ID, T>(service,
                    searchDialogEntityModel != null ? searchDialogEntityModel : entityModel,
                    searchDialogFilters, searchDialogSortOrder, true, true) {
                @Override
                protected boolean doClose() {

                    // add the selected items to the table
                    Collection<T> selected = getSelectedItems();
                    if (selected != null) {
                        afterItemsSelected(selected);
                        for (T t : selected) {
                            container.addBean(t);
                        }
                    }
                    return true;
                }
            };
            dialog.build();
            UI.getCurrent().addWindow(dialog);
        }
    });
    searchDialogButton.setVisible(!viewMode && formOptions.isShowSearchDialogButton());
    buttonBar.addComponent(searchDialogButton);
}

From source file:com.ocs.dynamo.ui.composite.form.ModelBasedEditForm.java

License:Apache License

/**
 * Adds a field for a certain attribute// w w w .  jav  a2 s  . co  m
 * 
 * @param parent
 * @param entityModel
 * @param attributeModel
 */
private void addField(Layout parent, EntityModel<T> entityModel, AttributeModel attributeModel, int count) {
    AttributeType type = attributeModel.getAttributeType();
    if (attributeModel.isVisible() && (AttributeType.BASIC.equals(type) || AttributeType.LOB.equals(type)
            || attributeModel.isComplexEditable())) {
        if (attributeModel.isReadOnly() || isViewMode()) {
            if (attributeModel.isUrl()
                    || (AttributeType.ELEMENT_COLLECTION.equals(type) && attributeModel.isComplexEditable())) {
                // display a complex component in read-only mode
                constructField(parent, entityModel, attributeModel, true, count);
            } else if (AttributeType.DETAIL.equals(type) && attributeModel.isComplexEditable()) {
                Field<?> f = constructCustomField(entityModel, attributeModel, viewMode);
                if (f instanceof DetailsEditTable) {
                    // a details edit table must be displayed
                    constructField(parent, entityModel, attributeModel, true, count);
                } else {
                    // otherwise display a label
                    Component label = constructLabel(entity, attributeModel);
                    labels.get(isViewMode()).put(attributeModel, label);
                    parent.addComponent(label);
                }
            } else {
                // otherwise display a label
                Component label = constructLabel(entity, attributeModel);
                labels.get(isViewMode()).put(attributeModel, label);
                parent.addComponent(label);
            }
        } else {
            // display an editable field
            if (AttributeType.BASIC.equals(type) || AttributeType.MASTER.equals(type)
                    || AttributeType.DETAIL.equals(type) || AttributeType.ELEMENT_COLLECTION.equals(type)) {
                constructField(parent, entityModel, attributeModel, false, count);
            } else if (AttributeType.LOB.equals(type)) {
                // for a LOB field we need to construct a rather
                // elaborate upload component
                UploadComponent uploadForm = constructUploadField(attributeModel);
                parent.addComponent(uploadForm);
                uploads.get(isViewMode()).put(attributeModel, uploadForm);
            }
        }
    }
}

From source file:com.ocs.dynamo.ui.composite.form.ModelBasedEditForm.java

License:Apache License

/**
 * Constructs the main layout of the screen
 * /*from   w w  w.ja v a2s.c om*/
 * @param entityModel
 * @return
 */
protected VerticalLayout buildMainLayout(EntityModel<T> entityModel) {
    VerticalLayout layout = new VerticalLayout();

    titleLabels.put(isViewMode(), constructTitleLabel());

    // horizontal layout that contains title label and buttons

    titleBars.put(isViewMode(), new DefaultHorizontalLayout(false, true, true));
    titleBars.get(isViewMode()).addComponent(titleLabels.get(isViewMode()));

    HorizontalLayout buttonBar = constructButtonBar();
    buttonBar.setSizeUndefined();
    titleBars.get(isViewMode()).addComponent(buttonBar);
    layout.addComponent(titleBars.get(isViewMode()));

    Layout form = null;
    if (entityModel.usesDefaultGroupOnly()) {
        form = new FormLayout();
    } else {
        form = new DefaultVerticalLayout(false, true);
    }

    // in case of vertical layout (the default), don't use the entire screen
    if (ScreenMode.VERTICAL.equals(getFormOptions().getScreenMode())) {
        form.setStyleName(DynamoConstants.CSS_CLASS_HALFSCREEN);
    }

    int count = 0;
    if (!entityModel.usesDefaultGroupOnly()) {
        // display the attributes in groups

        TabSheet tabSheet = null;
        boolean tabs = AttributeGroupMode.TABSHEET.equals(getFormOptions().getAttributeGroupMode());
        if (tabs) {
            tabSheet = new TabSheet();
            form.addComponent(tabSheet);
        }

        if (getParentGroupHeaders() != null && getParentGroupHeaders().length > 0) {
            // extra layer of grouping
            for (String parentGroupHeader : getParentGroupHeaders()) {
                Layout innerForm = constructAttributeGroupLayout(form, tabs, tabSheet, parentGroupHeader,
                        false);

                // add a tab sheet on the inner level if needed
                TabSheet innerTabSheet = null;
                boolean innerTabs = !tabs;
                if (innerTabs) {
                    innerTabSheet = new TabSheet();
                    innerForm.addComponent(innerTabSheet);
                }

                // add all appropriate inner groups
                int tempCount = processParentHeaderGroup(parentGroupHeader, innerForm, innerTabs, innerTabSheet,
                        count);
                count += tempCount;
            }
        } else {
            // just one layer of attribute groups
            for (String attributeGroup : entityModel.getAttributeGroups()) {
                if (entityModel.isAttributeGroupVisible(attributeGroup, viewMode)) {
                    Layout innerForm = constructAttributeGroupLayout(form, tabs, tabSheet,
                            getAttributeGroupCaption(attributeGroup), true);

                    for (AttributeModel attributeModel : entityModel
                            .getAttributeModelsForGroup(attributeGroup)) {
                        addField(innerForm, entityModel, attributeModel, count);
                        count++;
                    }
                }
            }
        }
    } else {
        // iterate over the attributes and add them to the form (without any
        // grouping)
        for (AttributeModel attributeModel : entityModel.getAttributeModels()) {
            addField(form, entityModel, attributeModel, count);
            count++;
        }
    }

    layout.addComponent(form);

    if (firstField != null) {
        firstField.focus();
    }

    buttonBar = constructButtonBar();
    buttonBar.setSizeUndefined();
    layout.addComponent(buttonBar);
    checkSaveButtonState();

    return layout;
}

From source file:com.ocs.dynamo.ui.composite.form.ModelBasedEditForm.java

License:Apache License

/**
 * Construct the layout (form and panel) for an attribute group
 * //ww  w.ja  va  2  s . co  m
 * @param parent
 *            the parent component
 * @param tabs
 *            whether to include the component in a tab sheet
 * @param tabSheet
 *            the parent tab sheet (only used if the "tabs" parameter is true)
 * @param caption
 *            caption of the panel or tab sheet
 * @param lowest
 *            indicates whether this is the lowest level
 * @return
 */
private Layout constructAttributeGroupLayout(Layout parent, boolean tabs, TabSheet tabSheet, String caption,
        boolean lowest) {
    Layout innerLayout = null;
    if (lowest) {
        innerLayout = new FormLayout();
        ((FormLayout) innerLayout).setMargin(true);
        if (!tabs) {
            ((FormLayout) innerLayout).setStyleName(DynamoConstants.CSS_CLASS_HALFSCREEN);
        }
    } else {
        innerLayout = new DefaultVerticalLayout(true, true);
    }

    if (tabs) {
        tabSheet.addTab(innerLayout, caption);
    } else {
        Panel panel = new Panel();
        panel.setStyleName("attributePanel");
        panel.setCaption(caption);
        panel.setContent(innerLayout);
        parent.addComponent(panel);
    }
    return innerLayout;
}

From source file:com.ocs.dynamo.ui.composite.form.ModelBasedEditForm.java

License:Apache License

/**
 * Constructs a field for a certain attribute
 * //  w w  w.ja  va  2s . co  m
 * @param form
 * @param entityModel
 * @param attributeModel
 */
@SuppressWarnings("unchecked")
private void constructField(Layout form, EntityModel<T> entityModel, AttributeModel attributeModel,
        boolean viewMode, int count) {

    EntityModel<?> em = getFieldEntityModel(attributeModel);
    // allow the user to override the construction of a field
    Field<?> field = constructCustomField(entityModel, attributeModel, viewMode);
    if (field == null) {
        // if no custom field is defined, then use the default
        field = fieldFactory.constructField(attributeModel, getFieldFilters(), em);
    }

    if (field instanceof URLField) {
        ((URLField) field).setEditable(!isViewMode());
    }

    // set view mode if appropriate
    if (field instanceof CollectionTable) {
        ((CollectionTable<?>) field).setViewMode(isViewMode());
    }

    // set view mode if appropriate
    if (field instanceof QuickAddListSelect) {
        ((QuickAddListSelect<?, ?>) field).setViewMode(isViewMode());
    }

    if (field != null) {
        groups.get(viewMode).bind(field, attributeModel.getName());
        field.setSizeFull();
        form.addComponent(field);
    }

    // set the default value for new objects
    if (entity.getId() == null && attributeModel.getDefaultValue() != null) {
        field.getPropertyDataSource().setValue(attributeModel.getDefaultValue());
    }

    // store a reference to the first field so we can give it focus
    if (count == 0) {
        firstField = field;
    }
}

From source file:com.ocs.dynamo.ui.composite.form.ModelBasedFlexibleSearchForm.java

License:Apache License

@Override
protected void constructButtonBar(Layout buttonBar) {

    // construct button for adding a new filter
    addFilterButton = new Button(message("ocs.add.filter"));
    addFilterButton.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = 3509270848120570068L;

        @Override/*  ww  w . ja  v  a  2s. co  m*/
        public void buttonClick(ClickEvent event) {
            addFilter();
        }
    });

    buttonBar.addComponent(addFilterButton);
    buttonBar.addComponent(constructSearchButton());
    buttonBar.addComponent(constructClearButton());
    buttonBar.addComponent(constructToggleButton());
}

From source file:com.ocs.dynamo.ui.composite.form.ModelBasedSearchForm.java

License:Apache License

@Override
protected void constructButtonBar(Layout buttonBar) {
    buttonBar.addComponent(constructToggleButton());
    buttonBar.addComponent(constructSearchButton());
    buttonBar.addComponent(constructClearButton());
}

From source file:com.ocs.dynamo.ui.composite.form.UploadForm.java

License:Apache License

@Override
protected void doBuildLayout(Layout main) {
    FormLayout form = new FormLayout();
    form.setMargin(true);/*from   ww w . j a v  a2  s  .com*/
    if (ScreenMode.VERTICAL.equals(screenMode)) {
        form.setStyleName(DynamoConstants.CSS_CLASS_HALFSCREEN);
    }

    main.addComponent(form);

    // add custom components
    doBuildForm(form);

    // add file upload field
    UploadReceiver receiver = new UploadReceiver();

    Upload upload = new Upload(message("ocs.uploadform.title"), receiver);

    upload.addSucceededListener(receiver);
    form.addComponent(upload);

    if (showCancelButton) {
        Button cancelButton = new Button(message("ocs.cancel"));
        cancelButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                cancel();
            }
        });
        main.addComponent(cancelButton);
    }
}