Example usage for com.vaadin.v7.data.fieldgroup FieldGroup isReadOnly

List of usage examples for com.vaadin.v7.data.fieldgroup FieldGroup isReadOnly

Introduction

In this page you can find the example usage for com.vaadin.v7.data.fieldgroup FieldGroup isReadOnly.

Prototype

public boolean isReadOnly() 

Source Link

Document

Returns the read only status that is used by default with all fields that have a writable data source.

Usage

From source file:de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.java

License:Open Source License

protected void setWrappedComponent(C component, FieldGroup... fieldGroups) {

    this.wrappedComponent = component;
    this.fieldGroups = fieldGroups;

    if (contentPanel != null) {
        contentPanel.setContent(wrappedComponent);
        return;//from  w  ww.  j  a va2  s . co m
    }

    setSpacing(false);
    setMargin(true);
    setSizeUndefined();

    contentPanel = new Panel(component);
    updateInternalWidth();
    updateInternalHeight();
    addComponent(contentPanel);
    setExpandRatio(contentPanel, 1);

    buttonsPanel = new HorizontalLayout();
    buttonsPanel.setMargin(false);
    buttonsPanel.setSpacing(true);
    buttonsPanel.setWidth(100, Unit.PERCENTAGE);

    Button discardButton = getDiscardButton();
    buttonsPanel.addComponent(discardButton);
    buttonsPanel.setComponentAlignment(discardButton, Alignment.BOTTOM_RIGHT);
    buttonsPanel.setExpandRatio(discardButton, 1);

    Button commitButton = getCommitButton();
    buttonsPanel.addComponent(commitButton);
    buttonsPanel.setComponentAlignment(commitButton, Alignment.BOTTOM_RIGHT);
    buttonsPanel.setExpandRatio(commitButton, 0);

    addComponent(buttonsPanel);
    setComponentAlignment(buttonsPanel, Alignment.BOTTOM_RIGHT);

    setShortcutsEnabled(shortcutsEnabled);

    if (fieldGroups != null && fieldGroups.length > 0) {
        // convention: set wrapper to read-only when all wrapped field groups are read-only
        boolean allReadOnly = true;
        for (FieldGroup fieldGroup : fieldGroups) {
            if (!fieldGroup.isReadOnly()) {
                allReadOnly = false;
                break;
            }
        }
        if (allReadOnly) {
            setReadOnly(true);
        }
    } else if (wrappedComponent != null) {
        if (wrappedComponent instanceof AbstractLegacyComponent
                && ((AbstractLegacyComponent) wrappedComponent).isReadOnly()) {
            setReadOnly(true);
        }
    }
}