Search in sources :

Example 1 with AbstractLegacyComponent

use of com.vaadin.v7.ui.AbstractLegacyComponent in project SORMAS-Project by hzi-braunschweig.

the class CommitDiscardWrapperComponent method setWrappedComponent.

protected void setWrappedComponent(C component, FieldGroup... fieldGroups) {
    this.wrappedComponent = component;
    this.fieldGroups = new ArrayList(Arrays.asList(fieldGroups));
    if (contentPanel != null) {
        contentPanel.setContent(wrappedComponent);
        return;
    }
    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);
        }
    }
    dirty = false;
    addDirtyHandler(fieldGroups);
}
Also used : Panel(com.vaadin.ui.Panel) Button(com.vaadin.ui.Button) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) ArrayList(java.util.ArrayList) AbstractLegacyComponent(com.vaadin.v7.ui.AbstractLegacyComponent) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

Button (com.vaadin.ui.Button)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Panel (com.vaadin.ui.Panel)1 FieldGroup (com.vaadin.v7.data.fieldgroup.FieldGroup)1 AbstractLegacyComponent (com.vaadin.v7.ui.AbstractLegacyComponent)1 ArrayList (java.util.ArrayList)1