com.vaadin.ui.Window

Here are the examples of the java api com.vaadin.ui.Window taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

8 Examples 7

19 Source : SubSetSelector.java
with Apache License 2.0
from ijazfx

protected void addEnreplacedy(String stringInput) {
    final ET newInstance = instantiateOption(stringInput);
    if (newInstanceForm != null) {
        String caption = "Add new " + elementType.getSimpleName();
        newInstanceForm.setEnreplacedy(newInstance);
        newInstanceForm.setSavedHandler(this);
        newInstanceForm.setResetHandler(this);
        Window w = newInstanceForm.openInModalPopup();
        w.setWidth("70%");
        w.setCaption(caption);
    } else {
        onSave(newInstance);
    }
}

19 Source : TRAbstractPanel.java
with Apache License 2.0
from ijazfx

public abstract clreplaced TRAbstractPanel extends MPanel {

    protected boolean isBuilt;

    private Component layout;

    private Component content;

    protected Window window;

    public TRAbstractPanel() {
        setCaption(panelreplacedle());
        setHeight(100.0f, Unit.PERCENTAGE);
        if (!isSpringComponent()) {
            postConstruct();
        }
    }

    protected boolean isSpringComponent() {
        return this.getClreplaced().getAnnotation(SpringComponent.clreplaced) != null;
    }

    @PostConstruct
    private void postConstruct() {
        postInitialize();
    }

    protected void postInitialize() {
    }

    protected void postBuild() {
    }

    protected void refresh() {
    }

    public TRAbstractPanel build() {
        if (!isBuilt) {
            setSizeFull();
            setStyleName(ValoTheme.PANEL_BORDERLESS);
            setCaption(null);
            content = createContent();
            MVerticalLayout layout = new MVerticalLayout();
            layout.setSizeFull();
            layout.addComponents(content);
            setContent(layout);
            postBuild();
            isBuilt = true;
        }
        return this;
    }

    private Component buildFooter() {
        MHorizontalLayout layout = new MHorizontalLayout().withSpacing(true).withFullWidth();
        layout.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
        layout.setDefaultComponentAlignment(footerAlignment());
        addButtonsToFooter(layout);
        for (int i = 0; i < layout.getComponentCount(); i++) {
            layout.setComponentAlignment(layout.getComponent(i), footerAlignment());
        // layout.setExpandRatio(layout.getComponent(i), 1);
        }
        MButton dismissButton = new MButton("Dismiss").withListener(event -> {
            closePopup();
        }).withVisible(shouldShowDismissButton());
        layout.add(dismissButton);
        return layout;
    }

    public Alignment footerAlignment() {
        return Alignment.MIDDLE_LEFT;
    }

    protected boolean shouldShowDismissButton() {
        return true;
    }

    protected abstract void addButtonsToFooter(MHorizontalLayout layout);

    protected abstract String panelreplacedle();

    protected Component createContent() {
        MVerticalLayout content = new MVerticalLayout();
        content.setSizeFull();
        MVerticalLayout contentLayout = new MVerticalLayout().withFullWidth().withStyleName("content-layout");
        contentLayout.setSizeFull();
        addComponentsToContentLayout(contentLayout);
        Panel detailsWrapper = new Panel(contentLayout);
        detailsWrapper.setSizeFull();
        detailsWrapper.addStyleName(ValoTheme.PANEL_BORDERLESS);
        detailsWrapper.addStyleName("scroll-divider");
        content.addComponent(detailsWrapper);
        content.setExpandRatio(detailsWrapper, 1f);
        content.addComponent(buildFooter());
        return content;
    }

    protected abstract void addComponentsToContentLayout(MVerticalLayout layout);

    public Window openInModalPopup() {
        build();
        window = new Window(panelreplacedle(), this);
        window.setStyleName("gx-popup");
        UI.getCurrent().addWindow(window);
        window.setModal(isPopupModal());
        window.setClosable(isPopupClosable());
        window.setResizable(isPopupResizable());
        window.setWidth(popupWidth());
        window.setHeight(popupHeight());
        window.setStyleName("popupWindow");
        window.addCloseShortcut(KeyCode.ESCAPE, null);
        // 
        // Responsive.makeResponsive(window);
        window.setCaption(panelreplacedle());
        focusFirst();
        return window;
    }

    public void closePopup() {
        if (window != null) {
            UI.getCurrent().removeWindow(window);
        }
    }

    public void focusFirst() {
        customFindFieldAndFocus(getContent());
    }

    private boolean customFindFieldAndFocus(Component compositionRoot) {
        if (compositionRoot instanceof AbstractComponentContainer) {
            AbstractComponentContainer cc = (AbstractComponentContainer) compositionRoot;
            Iterator<Component> iterator = cc.iterator();
            while (iterator.hasNext()) {
                Component component = iterator.next();
                if (component instanceof AbstractTextField) {
                    AbstractTextField abstractTextField = (AbstractTextField) component;
                    abstractTextField.selectAll();
                    return true;
                }
                if (component instanceof AbstractField) {
                    AbstractField abstractField = (AbstractField) component;
                    abstractField.focus();
                    return true;
                }
                if (component instanceof AbstractSingleComponentContainer) {
                    AbstractSingleComponentContainer container = (AbstractSingleComponentContainer) component;
                    if (customFindFieldAndFocus(container.getContent())) {
                        return true;
                    }
                }
                if (component instanceof AbstractComponentContainer) {
                    if (customFindFieldAndFocus(component)) {
                        return true;
                    }
                }
            }
        } else if (compositionRoot instanceof AbstractSingleComponentContainer) {
            AbstractSingleComponentContainer container = (AbstractSingleComponentContainer) compositionRoot;
            if (customFindFieldAndFocus(container.getContent())) {
                return true;
            }
        }
        return false;
    }

    protected boolean isPopupModal() {
        return true;
    }

    protected boolean isPopupClosable() {
        return true;
    }

    protected boolean isPopupResizable() {
        return true;
    }

    protected int browserWidth() {
        return VaadinUtils.browserWidth();
    }

    protected int browserHeight() {
        return VaadinUtils.browserHeight();
    }

    protected String safeWidthInPixels(int width) {
        return VaadinUtils.safeWidth(width) + "px";
    }

    protected String safeHeightInPixels(int height) {
        return VaadinUtils.safeHeight(height) + "px";
    }

    protected String popupWidth() {
        return safeWidthInPixels(browserWidth());
    }

    protected String popupHeight() {
        return safeHeightInPixels(browserHeight());
    }
}

18 Source : ViewUtil.java
with Apache License 2.0
from opensecuritycontroller

public static void addWindow(Window window) {
    UI.getCurrent().addWindow(window);
    window.focus();
}

18 Source : JobView.java
with Apache License 2.0
from opensecuritycontroller

@SuppressWarnings("serial")
private void buildGraph() {
    try {
        this.embeddedImage = new Embedded();
        this.embeddedImage.setSizeFull();
        refreshGraph();
        Button refresh = new Button("Refresh");
        refresh.addClickListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                try {
                    refreshGraph();
                } catch (Exception e) {
                    ViewUtil.showError("Error while building task graph DOT file.", e);
                }
            }
        });
        final HorizontalLayout toolbarLayout = new HorizontalLayout();
        toolbarLayout.addComponent(refresh);
        toolbarLayout.setSizeFull();
        toolbarLayout.setMargin(true);
        final VerticalLayout imageLayout = new VerticalLayout();
        imageLayout.addComponent(this.embeddedImage);
        imageLayout.setComponentAlignment(this.embeddedImage, Alignment.MIDDLE_CENTER);
        imageLayout.setSizeUndefined();
        final VerticalLayout layout = new VerticalLayout();
        layout.addComponent(refresh);
        layout.setComponentAlignment(refresh, Alignment.TOP_LEFT);
        layout.addComponent(imageLayout);
        layout.setSizeUndefined();
        final Window window = new Window();
        window.setContent(layout);
        window.setModal(true);
        window.setHeight("80%");
        window.setWidth("80%");
        window.setClosable(true);
        window.setResizable(true);
        window.setCaption("Task Graph for Job " + getParenreplacedemId());
        window.center();
        window.setWindowMode(WindowMode.MAXIMIZED);
        window.addCloseShortcut(ShortcutAction.KeyCode.ESCAPE, null);
        ViewUtil.addWindow(window);
        window.focus();
    } catch (Exception e) {
        ViewUtil.showError("Error while building task graph DOT file.", e);
    }
}

18 Source : TRAbstractForm.java
with Apache License 2.0
from ijazfx

@Override
public Window openInModalPopup() {
    if (formreplacedle() != null)
        setModalWindowreplacedle(formreplacedle());
    Window window = super.openInModalPopup();
    window.setResizable(isPopupResizable());
    window.setResizeLazy(true);
    window.setClosable(isPopupClosable());
    window.setModal(isPopupModal());
    window.setWidth(popupWidth());
    window.setHeight(popupHeight());
    window.setStyleName("popupWindow");
    Responsive.makeResponsive(window);
    return window;
}

17 Source : GxUserTaskForm.java
with Apache License 2.0
from ijazfx

@Override
public Window openInModalPopup() {
    GxUserTask task = getUserTask();
    boolean valid = task != null && (task.getStatus() == Status.Ready || task.getStatus() == Status.Reserved || task.getStatus() == Status.InProgress || task.getStatus() == Status.Created);
    Window popup = super.openInModalPopup();
    approveButton.setCaption(approveButtonCaption());
    approveButton.setVisible(valid);
    rejectButton.setCaption(rejectButtonCaption());
    rejectButton.setVisible(valid);
    completeButton.setCaption(completeButtonCaption());
    completeButton.setVisible(valid);
    skipButton.setVisible(valid && getUserTask().isSkipable());
    replacedignButton.setVisible(valid && isreplacedignable());
    return popup;
}

15 Source : AbstractForm.java
with Apache License 2.0
from ijazfx

/**
 * Abstract super clreplaced for simple editor forms.
 *
 * See {@link #createContent()} for usage information.
 *
 * @see <a href="https://github.com/viritin/viritin/wiki/AbstractForm">The
 * wiki</a>
 *
 * @param <T> the type of the bean edited
 */
public abstract clreplaced AbstractForm<T> extends CustomComponent implements FieldGroupListener<T> {

    private static final long serialVersionUID = -2368496151988753088L;

    private String modalWindowreplacedle = "Edit entry";

    private String saveCaption = "Save";

    private String deleteCaption = "Delete";

    private String cancelCaption = "Cancel";

    public static clreplaced ValidityChangedEvent<T> extends Component.Event {

        private static final long serialVersionUID = 7410354508832863756L;

        private static final Method method = ReflectTools.findMethod(ValidityChangedListener.clreplaced, "onValidityChanged", ValidityChangedEvent.clreplaced);

        public ValidityChangedEvent(Component source) {
            super(source);
        }

        @Override
        public AbstractForm<T> getComponent() {
            return (AbstractForm<T>) super.getComponent();
        }
    }

    public interface ValidityChangedListener<T> extends Serializable {

        public void onValidityChanged(ValidityChangedEvent<T> event);
    }

    private Window popup;

    public AbstractForm() {
        addAttachListener(new AttachListener() {

            private static final long serialVersionUID = 3193438171004932112L;

            @Override
            public void attach(AttachEvent event) {
                lazyInit();
                adjustResetButtonState();
            }
        });
    }

    protected void lazyInit() {
        if (getCompositionRoot() == null) {
            setCompositionRoot(createContent());
            adjustSaveButtonState();
            adjustResetButtonState();
        }
    }

    private MBeanFieldGroup<T> fieldGroup;

    /**
     * The validity checked and cached on last change. Should be pretty much
     * always up to date due to eager changes. At least after onFieldGroupChange
     * call.
     */
    boolean isValid = false;

    private RichText beanLevelViolations;

    @Override
    public void onFieldGroupChange(MBeanFieldGroup<T> beanFieldGroup) {
        boolean wasValid = isValid;
        isValid = fieldGroup.isValid();
        adjustSaveButtonState();
        adjustResetButtonState();
        if (wasValid != isValid) {
            fireValidityChangedEvent();
        }
        updateConstraintViolationsDisplay();
    }

    protected void updateConstraintViolationsDisplay() {
        if (beanLevelViolations != null) {
            Collection<String> errorMessages = getFieldGroup().getBeanLevelValidationErrors();
            if (!errorMessages.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                for (String e : errorMessages) {
                    sb.append(e);
                    sb.append("<br/>");
                }
                beanLevelViolations.setValue(sb.toString());
                beanLevelViolations.setVisible(true);
            } else {
                beanLevelViolations.setVisible(false);
                beanLevelViolations.setValue("");
            }
        }
    }

    public Component getConstraintViolationsDisplay() {
        if (beanLevelViolations == null) {
            beanLevelViolations = new RichText();
            beanLevelViolations.setVisible(false);
            beanLevelViolations.setStyleName(ValoTheme.LABEL_FAILURE);
        }
        return beanLevelViolations;
    }

    public boolean isValid() {
        return isValid;
    }

    protected void adjustSaveButtonState() {
        if (isEagerValidation() && isBound()) {
            boolean beanModified = fieldGroup.isBeanModified();
            getSaveButton().setEnabled(beanModified && isValid());
        }
    }

    protected boolean isBound() {
        return fieldGroup != null;
    }

    protected void adjustResetButtonState() {
        if (popup != null && popup.getParent() != null) {
            // replacedume cancel button in a form opened to a popup also closes
            // it, allows closing via cancel button by default
            getResetButton().setEnabled(true);
            return;
        }
        if (isEagerValidation() && isBound()) {
            boolean modified = fieldGroup.isBeanModified();
            getResetButton().setEnabled(modified || popup != null);
        }
    }

    public void addValidityChangedListener(ValidityChangedListener<T> listener) {
        addListener(ValidityChangedEvent.clreplaced, listener, ValidityChangedEvent.method);
    }

    public void removeValidityChangedListener(ValidityChangedListener<T> listener) {
        removeListener(ValidityChangedEvent.clreplaced, listener, ValidityChangedEvent.method);
    }

    private void fireValidityChangedEvent() {
        fireEvent(new ValidityChangedEvent<T>(this));
    }

    public interface SavedHandler<T> extends Serializable {

        void onSave(T enreplacedy);
    }

    public interface ResetHandler<T> extends Serializable {

        void onReset(T enreplacedy);
    }

    public interface DeleteHandler<T> extends Serializable {

        void onDelete(T enreplacedy);
    }

    private T enreplacedy;

    private SavedHandler<T> savedHandler;

    private ResetHandler<T> resetHandler;

    private DeleteHandler<T> deleteHandler;

    private boolean eagerValidation = true;

    public boolean isEagerValidation() {
        return eagerValidation;
    }

    /**
     * In case one is working with "detached enreplacedies" enabling eager validation
     * will highly improve usability. The validity of the form will be updated
     * on each changes and save/cancel buttons will reflect to the validity and
     * possible changes.
     *
     * @param eagerValidation true if the form should have eager validation
     */
    public void setEagerValidation(boolean eagerValidation) {
        this.eagerValidation = eagerValidation;
    }

    /**
     * Sets the object to be edited by this form. This method binds all fields
     * from this form to given objects.
     * <p>
     * If your form needs to manually configure something based on the state of
     * the edited object, you can override this method to do that either before
     * the object is bound to fields or to do something after the bean binding.
     *
     * @param enreplacedy the object to be edited by this form
     * @return the MBeanFieldGroup that is used to do the binding. Most often
     * you don't need to do anything with it.
     */
    public MBeanFieldGroup<T> setEnreplacedy(T enreplacedy) {
        this.enreplacedy = enreplacedy;
        lazyInit();
        if (enreplacedy != null) {
            if (isBound()) {
                fieldGroup.unbind();
            }
            fieldGroup = bindEnreplacedy(enreplacedy);
            try {
                fieldGroup.setValidationGroups(getValidationGroups());
            } catch (Throwable e) {
            // Probably no Validation API available
            }
            for (Map.Entry<MBeanFieldGroup.MValidator<T>, Collection<AbstractComponent>> e : mValidators.entrySet()) {
                fieldGroup.addValidator(e.getKey(), e.getValue().toArray(new AbstractComponent[e.getValue().size()]));
            }
            for (Map.Entry<Clreplaced<?>, AbstractComponent> e : validatorToErrorTarget.entrySet()) {
                fieldGroup.setValidationErrorTarget(e.getKey(), e.getValue());
            }
            isValid = fieldGroup.isValid();
            if (isEagerValidation()) {
                fieldGroup.withEagerValidation(this);
                adjustSaveButtonState();
                adjustResetButtonState();
            }
            fieldGroup.hideInitialEmpyFieldValidationErrors();
            setVisible(true);
            return fieldGroup;
        } else {
            setVisible(false);
            return null;
        }
    }

    /**
     * Creates a field group, configures the fields, binds the enreplacedy to those
     * fields
     *
     * @param enreplacedy The enreplacedy to bind
     * @return the fieldGroup created
     */
    protected MBeanFieldGroup<T> bindEnreplacedy(T enreplacedy) {
        return BeanBinder.bind(enreplacedy, this, getNestedProperties());
    }

    private String[] nestedProperties;

    public String[] getNestedProperties() {
        return nestedProperties;
    }

    public void setNestedProperties(String... nestedProperties) {
        this.nestedProperties = nestedProperties;
    }

    /**
     * Sets the given object to be a handler for saved,reset,deleted, based on
     * what it happens to implement.
     *
     * @param handler the handler to be set as saved/reset/delete handler
     */
    public void setHandler(Object handler) {
        if (handler != null) {
            if (handler instanceof SavedHandler) {
                setSavedHandler((SavedHandler<T>) handler);
            }
            if (handler instanceof ResetHandler) {
                setResetHandler((ResetHandler<T>) handler);
            }
            if (handler instanceof DeleteHandler) {
                setDeleteHandler((DeleteHandler<T>) handler);
            }
        }
    }

    public void setSavedHandler(SavedHandler<T> savedHandler) {
        this.savedHandler = savedHandler;
        getSaveButton().setVisible(this.savedHandler != null);
    }

    public void setResetHandler(ResetHandler<T> resetHandler) {
        this.resetHandler = resetHandler;
        getResetButton().setVisible(this.resetHandler != null);
    }

    public void setDeleteHandler(DeleteHandler<T> deleteHandler) {
        this.deleteHandler = deleteHandler;
        getDeleteButton().setVisible(this.deleteHandler != null);
    }

    public ResetHandler<T> getResetHandler() {
        return resetHandler;
    }

    public SavedHandler<T> getSavedHandler() {
        return savedHandler;
    }

    public DeleteHandler<T> getDeleteHandler() {
        return deleteHandler;
    }

    public Window openInModalPopup() {
        popup = new Window(getModalWindowreplacedle(), this);
        popup.setModal(true);
        UI.getCurrent().addWindow(popup);
        focusFirst();
        return popup;
    }

    /**
     * @return the last Popup into which the Form was opened with
     * #openInModalPopup method or null if the form hasn't been use in window
     */
    public Window getPopup() {
        return popup;
    }

    /**
     * If the form is opened into a popup window using openInModalPopup(), you
     * you can use this method to close the popup.
     */
    public void closePopup() {
        if (popup != null) {
            popup.close();
            popup = null;
        }
    }

    /**
     * @return A default toolbar containing save/cancel/delete buttons
     */
    public MHorizontalLayout getToolbar() {
        return new MHorizontalLayout(getSaveButton(), getResetButton(), getDeleteButton());
    }

    protected Button createCancelButton() {
        return new MButton(getCancelCaption()).withVisible(false);
    }

    private Button resetButton;

    public Button getResetButton() {
        if (resetButton == null) {
            setResetButton(createCancelButton());
        }
        return resetButton;
    }

    public void setResetButton(Button resetButton) {
        this.resetButton = resetButton;
        this.resetButton.addClickListener(new Button.ClickListener() {

            private static final long serialVersionUID = -19755976436277487L;

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

    protected Button createSaveButton() {
        return new PrimaryButton(getSaveCaption()).withVisible(false);
    }

    private Button saveButton;

    public void setSaveButton(Button saveButton) {
        this.saveButton = saveButton;
        saveButton.addClickListener(new Button.ClickListener() {

            private static final long serialVersionUID = -2058398434893034442L;

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

    public Button getSaveButton() {
        if (saveButton == null) {
            setSaveButton(createSaveButton());
        }
        return saveButton;
    }

    protected Button createDeleteButton() {
        return new DeleteButton(getDeleteCaption()).withVisible(false);
    }

    private Button deleteButton;

    public void setDeleteButton(final Button deleteButton) {
        this.deleteButton = deleteButton;
        deleteButton.addClickListener(new Button.ClickListener() {

            private static final long serialVersionUID = -2693734056915561664L;

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

    public Button getDeleteButton() {
        if (deleteButton == null) {
            setDeleteButton(createDeleteButton());
        }
        return deleteButton;
    }

    protected void save(Button.ClickEvent e) {
        savedHandler.onSave(getEnreplacedy());
        getFieldGroup().setBeanModified(false);
        adjustResetButtonState();
        adjustSaveButtonState();
    }

    protected void reset(Button.ClickEvent e) {
        resetHandler.onReset(getEnreplacedy());
        getFieldGroup().setBeanModified(false);
        adjustResetButtonState();
        adjustSaveButtonState();
    }

    protected void delete(Button.ClickEvent e) {
        deleteHandler.onDelete(getEnreplacedy());
    }

    /**
     * Focuses the first field found from the form. It often improves UX to call
     * this method, or focus another field, when you replacedign a bean for editing.
     */
    public void focusFirst() {
        Component compositionRoot = getCompositionRoot();
        findFieldAndFocus(compositionRoot);
    }

    private boolean findFieldAndFocus(Component compositionRoot) {
        if (compositionRoot instanceof AbstractComponentContainer) {
            AbstractComponentContainer cc = (AbstractComponentContainer) compositionRoot;
            for (Component component : cc) {
                if (component instanceof AbstractTextField) {
                    AbstractTextField abstractTextField = (AbstractTextField) component;
                    abstractTextField.selectAll();
                    return true;
                }
                if (component instanceof AbstractField) {
                    AbstractField abstractField = (AbstractField) component;
                    abstractField.focus();
                    return true;
                }
                if (component instanceof AbstractComponentContainer) {
                    if (findFieldAndFocus(component)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    /**
     * This method should return the actual content of the form, including
     * possible toolbar.
     *
     * Use setEnreplacedy(T enreplacedy) to fill in the data. Am example implementation
     * could look like this:
     * <pre><code>
     * public clreplaced PersonForm extends AbstractForm<Person> {
     *
     *     private TextField firstName = new MTextField("First Name");
     *     private TextField lastName = new MTextField("Last Name");
     *
     *    {@literal @}Override
     *     protected Component createContent() {
     *         return new MVerticalLayout(
     *                 new FormLayout(
     *                         firstName,
     *                         lastName
     *                 ),
     *                 getToolbar()
     *         );
     *     }
     * }
     * </code></pre>
     *
     * @return the content of the form
     */
    protected abstract Component createContent();

    public MBeanFieldGroup<T> getFieldGroup() {
        return fieldGroup;
    }

    public T getEnreplacedy() {
        return enreplacedy;
    }

    private final LinkedHashMap<MBeanFieldGroup.MValidator<T>, Collection<AbstractComponent>> mValidators = new LinkedHashMap<>();

    private final Map<Clreplaced<?>, AbstractComponent> validatorToErrorTarget = new LinkedHashMap<>();

    private Clreplaced<?>[] validationGroups;

    /**
     * @return the JSR 303 bean validation groups that should be used to
     * validate the bean
     */
    public Clreplaced<?>[] getValidationGroups() {
        if (validationGroups == null) {
            return new Clreplaced<?>[] { Default.clreplaced };
        }
        return validationGroups;
    }

    /**
     * @param validationGroups the JSR 303 bean validation groups that should be
     * used to validate the bean. Note, that groups currently only affect
     * cross-field/bean-level validation.
     */
    public void setValidationGroups(Clreplaced<?>... validationGroups) {
        this.validationGroups = validationGroups;
        if (getFieldGroup() != null) {
            getFieldGroup().setValidationGroups(validationGroups);
        }
    }

    public void setValidationErrorTarget(Clreplaced<?> aClreplaced, AbstractComponent errorTarget) {
        validatorToErrorTarget.put(aClreplaced, errorTarget);
        if (getFieldGroup() != null) {
            getFieldGroup().setValidationErrorTarget(aClreplaced, errorTarget);
        }
    }

    /**
     * EXPERIMENTAL: The cross field validation support is still experimental
     * and its API is likely to change.
     *
     * @param validator a validator that validates the whole bean making cross
     * field validation much simpler
     * @param fields the ui fields that this validator affects and on which a
     * possible error message is shown.
     * @return this FieldGroup
     */
    public AbstractForm<T> addValidator(MBeanFieldGroup.MValidator<T> validator, AbstractComponent... fields) {
        mValidators.put(validator, Arrays.asList(fields));
        if (getFieldGroup() != null) {
            getFieldGroup().addValidator(validator, fields);
        }
        return this;
    }

    public AbstractForm<T> removeValidator(MBeanFieldGroup.MValidator<T> validator) {
        Collection<AbstractComponent> remove = mValidators.remove(validator);
        if (remove != null) {
            if (getFieldGroup() != null) {
                getFieldGroup().removeValidator(validator);
            }
        }
        return this;
    }

    /**
     * Removes all MValidators added the MFieldGroup
     *
     * @return the instance
     */
    public AbstractForm<T> clearValidators() {
        mValidators.clear();
        if (getFieldGroup() != null) {
            getFieldGroup().clearValidators();
        }
        return this;
    }

    public void setRequired(Field... fields) {
        for (Field field : fields) {
            field.setRequired(true);
        }
    }

    public String getModalWindowreplacedle() {
        return modalWindowreplacedle;
    }

    public void setModalWindowreplacedle(String modalWindowreplacedle) {
        this.modalWindowreplacedle = modalWindowreplacedle;
    }

    public String getCancelCaption() {
        return cancelCaption;
    }

    public void setCancelCaption(String cancelCaption) {
        this.cancelCaption = cancelCaption;
    }

    public String getSaveCaption() {
        return saveCaption;
    }

    public void setSaveCaption(String saveCaption) {
        this.saveCaption = saveCaption;
    }

    public String getDeleteCaption() {
        return deleteCaption;
    }

    public void setDeleteCaption(String deleteCaption) {
        this.deleteCaption = deleteCaption;
    }

    public AbstractForm<T> withI18NCaption(String saveCaption, String deleteCaption, String cancelCaption) {
        this.saveCaption = saveCaption;
        this.deleteCaption = deleteCaption;
        this.cancelCaption = cancelCaption;
        return this;
    }

    public boolean isValidateOnlyBoundFields() {
        return fieldGroup.isValidateOnlyBoundFields();
    }

    /**
     * Tells that only bound fields from the bean (bound enreplacedy) should be validated.
     * Useful when the form does not contain all bean properties or, on the other hand, is not valid until all properties are valid.
     * By default, only bound bean properties are validated.
     * If set to false, all bean properties will be validated.
     *
     * @param validateOnlyBoundFields true if only bound fields should be validated
     */
    public void setValidateOnlyBoundFields(boolean validateOnlyBoundFields) {
        fieldGroup.setValidateOnlyBoundFields(validateOnlyBoundFields);
    }
}

14 Source : TRAbstractBaseForm.java
with Apache License 2.0
from ijazfx

/**
 * This form has been fixed to handle situation where the creation of the form
 * depends on the content of enreplacedy. Original form was copied from <a href=
 * "https://github.com/viritin/viritin/wiki/AbstractForm">https://github.com/viritin/viritin/wiki/AbstractForm</a>
 *
 * @author ijazfx
 * @param <T> - typically a java bean type
 */
public abstract clreplaced TRAbstractBaseForm<T> extends CustomComponent implements FieldGroupListener<T> {

    private static final long serialVersionUID = 1L;

    private boolean binding = false;

    private String modalWindowreplacedle = "Edit entry";

    private String saveCaption = "Save";

    private String deleteCaption = "Delete";

    private String cancelCaption = "Cancel";

    private ProgressBar busyIndicator = new ProgressBar();

    private Set<ValidationListener<T>> validationListeners = new HashSet<>();

    public static clreplaced ValidityChangedEvent<T> extends Component.Event {

        private static final Method method = ReflectTools.findMethod(ValidityChangedListener.clreplaced, "onValidityChanged", ValidityChangedEvent.clreplaced);

        public ValidityChangedEvent(Component source) {
            super(source);
        }

        @Override
        public TRAbstractBaseForm<T> getComponent() {
            return (TRAbstractBaseForm) super.getComponent();
        }
    }

    public interface ValidityChangedListener<T> extends Serializable {

        public void onValidityChanged(ValidityChangedEvent<T> event);
    }

    public interface ValidationListener<T> extends Serializable {

        public void onValidation(T enreplacedy, boolean isValid);
    }

    private Window popup;

    public TRAbstractBaseForm() {
        addAttachListener(new AttachListener() {

            @Override
            public void attach(AttachEvent event) {
                lazyInit();
            // adjustResetButtonState();
            }
        });
        addValidationListener(new ValidationListener<T>() {

            @Override
            public void onValidation(T enreplacedy, boolean isValid) {
                TRAbstractBaseForm.this.onValidation(enreplacedy, isValid);
            }
        });
    }

    protected void onValidation(T enreplacedy, boolean isValid) {
    }

    protected void lazyInit() {
        if (getCompositionRoot() == null) {
            setCompositionRoot(new MVerticalLayout());
        // adjustSaveButtonState();
        // adjustResetButtonState();
        }
    }

    private MBeanFieldGroup<T> fieldGroup;

    /**
     * The validity checked and cached on last change. Should be pretty much always
     * up to date due to eager changes. At least after onFieldGroupChange call.
     */
    boolean isValid = false;

    private RichText beanLevelViolations;

    @Override
    public void onFieldGroupChange(MBeanFieldGroup beanFieldGroup) {
        boolean wasValid = isValid;
        isValid = fieldGroup.isValid();
        notifyValidationListeners(isValid);
        adjustSaveButtonState();
        adjustResetButtonState();
        if (wasValid != isValid) {
            fireValidityChangedEvent();
        }
        updateConstraintViolationsDisplay();
    }

    private void notifyValidationListeners(boolean isValid) {
        validationListeners.forEach(validationListener -> {
            validationListener.onValidation(getEnreplacedy(), isValid);
        });
    }

    protected void updateConstraintViolationsDisplay() {
        if (beanLevelViolations != null) {
            Collection<String> errorMessages = getFieldGroup().getBeanLevelValidationErrors();
            if (!errorMessages.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                for (String e : errorMessages) {
                    sb.append(e);
                    sb.append("<br/>");
                }
                beanLevelViolations.setValue(sb.toString());
                beanLevelViolations.setVisible(true);
            } else {
                beanLevelViolations.setVisible(false);
                beanLevelViolations.setValue("");
            }
        }
    }

    public Component getConstraintViolationsDisplay() {
        if (beanLevelViolations == null) {
            beanLevelViolations = new RichText();
            beanLevelViolations.setVisible(false);
            beanLevelViolations.setStyleName(ValoTheme.LABEL_FAILURE);
        }
        return beanLevelViolations;
    }

    public boolean isValid() {
        return isValid;
    }

    protected void adjustSaveButtonState() {
        if (isEagerValidation() && isBound()) {
            // boolean beanModified = fieldGroup.isBeanModified();
            // getSaveButton().setEnabled(beanModified && isValid());
            getSaveButton().setEnabled(isValid());
        }
    }

    protected boolean isBound() {
        return fieldGroup != null;
    }

    protected void adjustResetButtonState() {
        if (popup != null && popup.getParent() != null) {
            // replacedume cancel button in a form opened to a popup also closes
            // it, allows closing via cancel button by default
            getResetButton().setEnabled(true);
            return;
        }
        if (isEagerValidation() && isBound()) {
            boolean modified = fieldGroup.isBeanModified();
            getResetButton().setEnabled(modified || popup != null);
        }
    }

    public void addValidationListener(ValidationListener<T> listener) {
        validationListeners.add(listener);
    }

    public void removeValidationListener(ValidationListener<T> listener) {
        validationListeners.remove(listener);
    }

    public void addValidityChangedListener(ValidityChangedListener<T> listener) {
        addListener(ValidityChangedEvent.clreplaced, listener, ValidityChangedEvent.method);
    }

    public void removeValidityChangedListener(ValidityChangedListener<T> listener) {
        removeListener(ValidityChangedEvent.clreplaced, listener, ValidityChangedEvent.method);
    }

    private void fireValidityChangedEvent() {
        fireEvent(new ValidityChangedEvent(this));
    }

    public interface SavedHandler<T> extends Serializable {

        void onSave(T enreplacedy);
    }

    public interface ResetHandler<T> extends Serializable {

        void onReset(T enreplacedy);
    }

    public interface DeleteHandler<T> extends Serializable {

        void onDelete(T enreplacedy);
    }

    private T enreplacedy;

    private SavedHandler<T> savedHandler;

    private ResetHandler<T> resetHandler;

    private DeleteHandler<T> deleteHandler;

    private boolean eagerValidation = true;

    public boolean isEagerValidation() {
        return eagerValidation;
    }

    /**
     * In case one is working with "detached enreplacedies" enabling eager validation
     * will highly improve usability. The validity of the form will be updated on
     * each changes and save/cancel buttons will reflect to the validity and
     * possible changes.
     *
     * @param eagerValidation true if the form should have eager validation
     */
    public void setEagerValidation(boolean eagerValidation) {
        this.eagerValidation = eagerValidation;
    }

    public MBeanFieldGroup<T> setEnreplacedy(Clreplaced<T> enreplacedyClreplaced, T originalEnreplacedy) {
        lazyInit();
        this.enreplacedy = originalEnreplacedy;
        if (enreplacedy != null) {
            setCompositionRoot(createContent());
            if (isBound()) {
                fieldGroup.unbind();
            }
            binding = true;
            fieldGroup = bindEnreplacedy(enreplacedy);
            binding = false;
            for (Map.Entry<MBeanFieldGroup.MValidator<T>, Collection<AbstractComponent>> e : mValidators.entrySet()) {
                fieldGroup.addValidator(e.getKey(), e.getValue().toArray(new AbstractComponent[e.getValue().size()]));
            }
            for (Map.Entry<Clreplaced, AbstractComponent> e : validatorToErrorTarget.entrySet()) {
                fieldGroup.setValidationErrorTarget(e.getKey(), e.getValue());
            }
            isValid = fieldGroup.isValid();
            if (isEagerValidation()) {
                fieldGroup.withEagerValidation(this);
                notifyValidationListeners(isValid);
                adjustSaveButtonState();
                adjustResetButtonState();
            }
            fieldGroup.hideInitialEmpyFieldValidationErrors();
            setVisible(true);
            return fieldGroup;
        } else {
            setVisible(false);
            return null;
        }
    }

    @Deprecated
    public MBeanFieldGroup<T> setEnreplacedy(T originalEnreplacedy) {
        if (originalEnreplacedy != null)
            return this.setEnreplacedy((Clreplaced<T>) originalEnreplacedy.getClreplaced(), originalEnreplacedy);
        return this.setEnreplacedy(null, null);
    }

    protected Component getBindingComponent() {
        return this;
    }

    /**
     * Creates a field group, configures the fields, binds the enreplacedy to those
     * fields
     *
     * @param enreplacedy The enreplacedy to bind
     * @return the fieldGroup created
     */
    protected MBeanFieldGroup<T> bindEnreplacedy(T enreplacedy) {
        return bindEnreplacedyWithComponent(enreplacedy, getBindingComponent());
    }

    final protected MBeanFieldGroup<T> bindEnreplacedyWithComponent(T enreplacedy, Component c) {
        return bindEnreplacedyWithComponentAndNestedProperties(enreplacedy, c, getNestedProperties());
    }

    final protected MBeanFieldGroup<T> bindEnreplacedyWithComponentAndNestedProperties(T enreplacedy, Component c, String... nestedProperties) {
        preBinding(enreplacedy);
        MBeanFieldGroup<T> beanFieldGroup = BeanBinder.bind(enreplacedy, c, nestedProperties);
        beanFieldGroup.setValidateAllProperties(false);
        postBinding(enreplacedy);
        return beanFieldGroup;
    }

    protected void preBinding(T enreplacedy) {
    }

    protected void postBinding(T enreplacedy) {
    }

    private String[] nestedProperties;

    public String[] getNestedProperties() {
        return nestedProperties;
    }

    public void setNestedProperties(String... nestedProperties) {
        this.nestedProperties = nestedProperties;
    }

    /**
     * Sets the given object to be a handler for saved,reset,deleted, based on what
     * it happens to implement.
     *
     * @param handler the handler to be set as saved/reset/delete handler
     */
    public void setHandler(Object handler) {
        if (handler != null) {
            if (handler instanceof SavedHandler) {
                setSavedHandler((SavedHandler<T>) handler);
            }
            if (handler instanceof ResetHandler) {
                setResetHandler((ResetHandler) handler);
            }
            if (handler instanceof DeleteHandler) {
                setDeleteHandler((DeleteHandler) handler);
            }
        }
    }

    public void setSavedHandler(SavedHandler<T> savedHandler) {
        this.savedHandler = savedHandler;
        getSaveButton().setVisible(this.savedHandler != null);
    }

    public void setResetHandler(ResetHandler<T> resetHandler) {
        this.resetHandler = resetHandler;
        getResetButton().setVisible(this.resetHandler != null);
    }

    public void setDeleteHandler(DeleteHandler<T> deleteHandler) {
        this.deleteHandler = deleteHandler;
        getDeleteButton().setVisible(this.deleteHandler != null);
    }

    public ResetHandler<T> getResetHandler() {
        return resetHandler;
    }

    public SavedHandler<T> getSavedHandler() {
        return savedHandler;
    }

    public DeleteHandler<T> getDeleteHandler() {
        return deleteHandler;
    }

    public Window openInModalPopup() {
        popup = new Window(getModalWindowreplacedle(), this);
        popup.setModal(true);
        UI.getCurrent().addWindow(popup);
        focusFirst();
        // localize popup...
        localizeRecursively(this);
        return popup;
    }

    /**
     * @return the last Popup into which the Form was opened with #openInModalPopup
     *         method or null if the form hasn't been use in window
     */
    public Window getPopup() {
        return popup;
    }

    /**
     * If the form is opened into a popup window using openInModalPopup(), you you
     * can use this method to close the popup.
     */
    public void closePopup() {
        if (popup != null) {
            popup.close();
            popup = null;
        }
    }

    /**
     * @return A default toolbar containing save/cancel/delete buttons
     */
    public MHorizontalLayout getToolbar() {
        MLabel spacer = new MLabel("").withFullWidth();
        busyIndicator.setVisible(false);
        busyIndicator.setIndeterminate(true);
        MHorizontalLayout layout = new MHorizontalLayout().withSpacing(true).withDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
        addButtonsToFooter(layout);
        layout.addComponents(spacer, busyIndicator, getSaveButton(), getResetButton(), getDeleteButton());
        layout.setExpandRatio(spacer, 1);
        return layout;
    }

    protected void addButtonsToFooter(MHorizontalLayout footer) {
    }

    protected Button createCancelButton() {
        return new MButton(getCancelCaption()).withVisible(false);
    }

    private Button resetButton;

    public Button getResetButton() {
        if (resetButton == null) {
            setResetButton(createCancelButton());
        }
        return resetButton;
    }

    public void setResetButton(Button resetButton) {
        this.resetButton = resetButton;
        this.resetButton.addClickListener(new Button.ClickListener() {

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

    protected Button createSaveButton() {
        return new PrimaryButton(getSaveCaption()).withVisible(false);
    }

    private Button saveButton;

    public void setSaveButton(Button saveButton) {
        this.saveButton = saveButton;
        saveButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                try {
                    saveButton.setEnabled(false);
                    busyIndicator.setVisible(true);
                    UI.getCurrent().push();
                    save(event);
                } finally {
                    saveButton.setEnabled(true);
                    busyIndicator.setVisible(false);
                    UI.getCurrent().push();
                }
            }
        });
    }

    public Button getSaveButton() {
        if (saveButton == null) {
            setSaveButton(createSaveButton());
        }
        return saveButton;
    }

    protected Button createDeleteButton() {
        return new DeleteButton(getDeleteCaption()).withVisible(false);
    }

    private Button deleteButton;

    public void setDeleteButton(final Button deleteButton) {
        this.deleteButton = deleteButton;
        deleteButton.addClickListener(new Button.ClickListener() {

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

    public Button getDeleteButton() {
        if (deleteButton == null) {
            setDeleteButton(createDeleteButton());
        }
        return deleteButton;
    }

    protected void save(Button.ClickEvent e) {
        savedHandler.onSave(getEnreplacedy());
        getFieldGroup().setBeanModified(false);
        adjustResetButtonState();
        adjustSaveButtonState();
    }

    protected void reset(Button.ClickEvent e) {
        resetHandler.onReset(getEnreplacedy());
        getFieldGroup().setBeanModified(false);
        adjustResetButtonState();
        adjustSaveButtonState();
    }

    protected void delete(Button.ClickEvent e) {
        deleteHandler.onDelete(getEnreplacedy());
    }

    /**
     * Focuses the first field found from the form. It often improves UX to call
     * this method, or focus another field, when you replacedign a bean for editing.
     */
    public void focusFirst() {
        Component compositionRoot = getCompositionRoot();
        findFieldAndFocus(compositionRoot);
    }

    private boolean findFieldAndFocus(Component compositionRoot) {
        if (compositionRoot instanceof AbstractComponentContainer) {
            AbstractComponentContainer cc = (AbstractComponentContainer) compositionRoot;
            Iterator<Component> iterator = cc.iterator();
            while (iterator.hasNext()) {
                Component component = iterator.next();
                if (component.isReadOnly())
                    continue;
                if (component instanceof AbstractTextField) {
                    AbstractTextField abstractTextField = (AbstractTextField) component;
                    abstractTextField.selectAll();
                    return true;
                }
                if (component instanceof AbstractField) {
                    AbstractField abstractField = (AbstractField) component;
                    abstractField.focus();
                    return true;
                }
                if (component instanceof AbstractSingleComponentContainer) {
                    AbstractSingleComponentContainer container = (AbstractSingleComponentContainer) component;
                    if (findFieldAndFocus(container.getContent())) {
                        return true;
                    }
                }
                if (component instanceof AbstractComponentContainer) {
                    if (findFieldAndFocus(component)) {
                        return true;
                    }
                }
            }
        } else if (compositionRoot instanceof AbstractSingleComponentContainer) {
            AbstractSingleComponentContainer container = (AbstractSingleComponentContainer) compositionRoot;
            if (findFieldAndFocus(container.getContent())) {
                return true;
            }
        }
        return false;
    }

    Set<Field> lockedFields = new HashSet<>();

    public void lockFields() {
        lockFields(getCompositionRoot());
    }

    private void lockFields(Component compositionRoot) {
        if (compositionRoot instanceof AbstractComponentContainer) {
            AbstractComponentContainer cc = (AbstractComponentContainer) compositionRoot;
            Iterator<Component> iterator = cc.iterator();
            while (iterator.hasNext()) {
                Component component = iterator.next();
                if (component.isReadOnly())
                    continue;
                if (component instanceof AbstractTextField) {
                    AbstractTextField abstractTextField = (AbstractTextField) component;
                    if (abstractTextField.isEnabled()) {
                        lockedFields.add(abstractTextField);
                    }
                }
                if (component instanceof AbstractField) {
                    AbstractField abstractField = (AbstractField) component;
                    if (abstractField.isEnabled()) {
                        lockedFields.add(abstractField);
                    }
                }
                if (component instanceof AbstractSingleComponentContainer) {
                    AbstractSingleComponentContainer container = (AbstractSingleComponentContainer) component;
                    lockFields(container.getContent());
                }
                if (component instanceof AbstractComponentContainer) {
                    lockFields(component);
                }
            }
        } else if (compositionRoot instanceof AbstractSingleComponentContainer) {
            AbstractSingleComponentContainer container = (AbstractSingleComponentContainer) compositionRoot;
            lockFields(container.getContent());
        }
        lockedFields.forEach(field -> {
            field.setReadOnly(true);
        });
    }

    public void unlockFields() {
        lockedFields.forEach(field -> {
            field.setReadOnly(false);
        });
        lockedFields.clear();
    }

    /**
     * This method should return the actual content of the form, including possible
     * toolbar. Use setEnreplacedy(T enreplacedy) to fill in the data. Am example
     * implementation could look like this:
     *
     * <pre>
     * <code>
     * public clreplaced PersonForm extends AbstractForm<Person> {
     *
     *     private TextField firstName = new MTextField("First Name");
     *     private TextField lastName = new MTextField("Last Name");
     *
     *    {@literal @}Override
     *     protected Component createContent() {
     *         return new MVerticalLayout(
     *                 new FormLayout(
     *                         firstName,
     *                         lastName
     *                 ),
     *                 getToolbar()
     *         );
     *     }
     * }
     * </code>
     * </pre>
     *
     * @return the content of the form
     */
    protected abstract Component createContent();

    public MBeanFieldGroup<T> getFieldGroup() {
        return fieldGroup;
    }

    public T getEnreplacedy() {
        return enreplacedy;
    }

    private final LinkedHashMap<MBeanFieldGroup.MValidator<T>, Collection<AbstractComponent>> mValidators = new LinkedHashMap<MBeanFieldGroup.MValidator<T>, Collection<AbstractComponent>>();

    private final Map<Clreplaced, AbstractComponent> validatorToErrorTarget = new LinkedHashMap<Clreplaced, AbstractComponent>();

    public void setValidationErrorTarget(Clreplaced aClreplaced, AbstractComponent errorTarget) {
        validatorToErrorTarget.put(aClreplaced, errorTarget);
        if (getFieldGroup() != null) {
            getFieldGroup().setValidationErrorTarget(aClreplaced, errorTarget);
        }
    }

    /**
     * EXPERIMENTAL: The cross field validation support is still experimental and
     * its API is likely to change.
     *
     * @param validator a validator that validates the whole bean making cross field
     *                  validation much simpler
     * @param fields    the ui fields that this validator affects and on which a
     *                  possible error message is shown.
     * @return this FieldGroup
     */
    public TRAbstractBaseForm<T> addValidator(MBeanFieldGroup.MValidator<T> validator, AbstractComponent... fields) {
        mValidators.put(validator, Arrays.asList(fields));
        if (getFieldGroup() != null) {
            getFieldGroup().addValidator(validator, fields);
        }
        return this;
    }

    public TRAbstractBaseForm<T> removeValidator(MBeanFieldGroup.MValidator<T> validator) {
        Collection<AbstractComponent> remove = mValidators.remove(validator);
        if (remove != null) {
            if (getFieldGroup() != null) {
                getFieldGroup().removeValidator(validator);
            }
        }
        return this;
    }

    /**
     * Removes all MValidators added the MFieldGroup
     *
     * @return the instance
     */
    public TRAbstractBaseForm<T> clearValidators() {
        mValidators.clear();
        if (getFieldGroup() != null) {
            getFieldGroup().clear();
        }
        return this;
    }

    public void setRequired(Field... fields) {
        for (Field field : fields) {
            field.setRequired(true);
        }
    }

    public String getModalWindowreplacedle() {
        return modalWindowreplacedle;
    }

    public void setModalWindowreplacedle(String modalWindowreplacedle) {
        this.modalWindowreplacedle = modalWindowreplacedle;
    }

    public String getCancelCaption() {
        return cancelCaption;
    }

    public void setCancelCaption(String cancelCaption) {
        this.cancelCaption = cancelCaption;
    }

    public String getSaveCaption() {
        return saveCaption;
    }

    public void setSaveCaption(String saveCaption) {
        this.saveCaption = saveCaption;
        if (saveButton != null)
            saveButton.setCaption(saveCaption);
    }

    public String getDeleteCaption() {
        return deleteCaption;
    }

    public void setDeleteCaption(String deleteCaption) {
        this.deleteCaption = deleteCaption;
    }

    public TRAbstractBaseForm<T> withI18NCaption(String saveCaption, String deleteCaption, String cancelCaption) {
        this.saveCaption = saveCaption;
        this.deleteCaption = deleteCaption;
        this.cancelCaption = cancelCaption;
        return this;
    }

    protected boolean isBinding() {
        return this.binding;
    }

    protected String localizedSingularValue(String key) {
        return VaadinUtils.localizedSingularValue(key);
    }

    protected String localizedPluralValue(String key) {
        return VaadinUtils.localizedSingularValue(key);
    }

    protected void localizeRecursively(Component component) {
        VaadinUtils.localizeRecursively(component);
    }

    protected String localizedSingularValue(Locale locale, String key) {
        return VaadinUtils.localizedSingularValue(key);
    }

    protected String localizedPluralValue(Locale locale, String key) {
        return VaadinUtils.localizedSingularValue(key);
    }

    protected void localizeRecursively(Locale locale, Component component) {
        VaadinUtils.localizeRecursively(component);
    }

    protected int browserWidth() {
        return VaadinUtils.browserWidth();
    }

    protected int browserHeight() {
        return VaadinUtils.browserHeight();
    }

    protected String safeWidthInPixels(int width) {
        return VaadinUtils.safeWidth(width) + "px";
    }

    protected String safeHeightInPixels(int height) {
        return VaadinUtils.safeHeight(height) + "px";
    }
}