Example usage for com.vaadin.server UserError UserError

List of usage examples for com.vaadin.server UserError UserError

Introduction

In this page you can find the example usage for com.vaadin.server UserError UserError.

Prototype

public UserError(String textErrorMessage) 

Source Link

Document

Creates a textual error message of level ERROR.

Usage

From source file:edu.kit.dama.ui.admin.wizard.AdministratorAccountCreation.java

License:Apache License

@Override
public boolean validateSettings() {
    if (!UIUtils7.validate(getMainLayout())) {
        return false;
    }//from w  w w  .j av a  2s .c o m

    if (adminPassword.getValue().equals(adminPasswordCheck.getValue())) {
        if (adminEMail.getValue().contains("@")) {
            adminPasswordCheck.setComponentError(null);
            adminEMail.setComponentError(null);
            return true;
        } else {
            adminEMail.setComponentError(new UserError("A valid email is needed."));
        }
    } else {
        adminPasswordCheck.setComponentError(new UserError("Passwords are different."));
    }
    return false;
}

From source file:edu.kit.dama.ui.commons.util.UIUtils7.java

License:Apache License

/**
 * Validate a single component. If a component is invalid, an appropriate
 * component error will be set and the method returns 'FALSE'. For valid
 * components, the component error will be removed. If the component is valid
 * according to their setup, 'TRUE' will be returned. A component can be
 * invalid because://from  w w  w .j  a va 2  s.co m
 *
 * <ul>
 *
 * <li>A validator installed by <i>Component.addValidator()</i> fails</li>
 *
 * <li>The component is marked as 'required' and contains no value</li>
 *
 * </ul>
 *
 * @param pComponent The component to validate.
 *
 * @return TRUE if the component is valid.
 */
public static boolean validate(Component pComponent) {
    boolean result = true;
    if (pComponent instanceof AbstractField) {
        try {
            ((AbstractField) pComponent).validate();
            ((AbstractField) pComponent).setComponentError(null);
        } catch (Validator.InvalidValueException e) {
            ((AbstractComponent) pComponent)
                    .setComponentError(new UserError("The value of this field is invalid."));
            result = false;
        }
    } else if (pComponent instanceof AbstractComponentContainer) {
        if (!validate((AbstractComponentContainer) pComponent)) {
            result = false;
        }
    }
    return result;
}

From source file:fi.semantum.strategia.widget.Datatype.java

License:Open Source License

public AbstractField<?> getEditor(final Main main, final Base base, final Indicator indicator,
        final boolean forecast, final CommentCallback callback) {

    Object value = forecast ? indicator.getForecast() : indicator.getValue();
    final String formatted = indicator.getDatatype(main.getDatabase()).format(value);

    final TextField tf = new TextField();
    tf.setValue(formatted);//w ww.j  a v  a 2s  . co m

    if (main.canWrite(base)) {

        tf.addValidator(new Validator() {

            private static final long serialVersionUID = 9043601075831736114L;

            @Override
            public void validate(Object value) throws InvalidValueException {

                try {
                    BigDecimal.valueOf(Double.parseDouble((String) value));
                } catch (NumberFormatException e) {
                    throw new InvalidValueException("Arvon tulee olla numero");
                }

            }

        });
        tf.addValueChangeListener(new ValueChangeListener() {

            private static final long serialVersionUID = 3547126051252580446L;

            @Override
            public void valueChange(ValueChangeEvent event) {

                try {
                    final BigDecimal number = BigDecimal.valueOf(Double.parseDouble(tf.getValue()));
                    indicator.updateWithComment(main, base, number, forecast, new AbstractCommentCallback() {

                        public void canceled() {
                            tf.setValue(formatted);
                            if (callback != null)
                                callback.canceled();
                        }

                        public void runWithComment(String shortComment, String comment) {
                            if (callback != null)
                                callback.runWithComment(shortComment, comment);
                        }

                    });
                } catch (NumberFormatException e) {
                    tf.setComponentError(new UserError("Arvon tulee olla numero"));
                }

            }

        });

    } else {

        tf.setReadOnly(true);

    }

    return tf;

}

From source file:fi.semantum.strategia.widget.Indicator.java

License:Open Source License

public static String updateIndicatorValue(final Main main, HorizontalLayout hl, final Base base,
        final Indicator indicator, boolean canWrite) {

    final Database database = main.getDatabase();

    Datatype dt = indicator.getDatatype(database);
    if (dt != null) {

        final AbstractField<?> field = dt.getEditor(main, base, indicator, false, null);
        field.setWidth("150px");
        field.setReadOnly(!canWrite);/*from  w ww.jav a2 s.  c o  m*/
        hl.addComponent(field);
        hl.setComponentAlignment(field, Alignment.MIDDLE_LEFT);
        Object value = field.getValue();
        return value != null ? value.toString() : "";

    } else {

        Object value = indicator.getValue();
        final String formatted = value != null ? value.toString() : "";

        final TextField tf = new TextField();
        tf.setValue(formatted);
        tf.addValueChangeListener(new ValueChangeListener() {

            private static final long serialVersionUID = 3547126051252580446L;

            @Override
            public void valueChange(ValueChangeEvent event) {
                try {
                    double value = Double.parseDouble(tf.getValue());
                    indicator.updateWithComment(main, base, value, main.getUIState().forecastMeters,
                            new AbstractCommentCallback() {

                                public void canceled() {
                                    tf.setValue(formatted);
                                }

                            });
                } catch (NumberFormatException e) {
                    tf.setComponentError(new UserError("Arvon tulee olla numero"));
                }
            }
        });
        tf.setWidth("150px");
        tf.setReadOnly(!canWrite);
        hl.addComponent(tf);
        hl.setComponentAlignment(tf, Alignment.MIDDLE_LEFT);
        return tf.getValue();

    }

}

From source file:fr.ortec.dsi.pointage.presentation.ihm.view.TextFields.java

License:Apache License

public TextFields() {
    setMargin(true);/*  w  w w  .j a v a2s  . co  m*/
    setSpacing(true);

    Label h1 = new Label("Text Fields");
    h1.addStyleName(ValoTheme.LABEL_H1);
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName(ValoTheme.LAYOUT_HORIZONTAL_WRAPPING);
    addComponent(row);

    TextField tf = new TextField("Normal");
    tf.setIcon(testIcon.get());
    row.addComponent(tf);

    tf = new TextField("Custom color");
    tf.addStyleName("color1");
    row.addComponent(tf);

    tf = new TextField("User Color");
    tf.addStyleName("color2");
    row.addComponent(tf);

    tf = new TextField("Themed");
    tf.addStyleName("color3");
    row.addComponent(tf);

    tf = new TextField("Error");
    tf.setValue("Somethings wrong");
    tf.setComponentError(new UserError("Fix it, now!"));
    row.addComponent(tf);

    tf = new TextField("Error, borderless");
    tf.setValue("Somethings wrong");
    tf.setComponentError(new UserError("Fix it, now!"));
    tf.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS);
    row.addComponent(tf);

    tf = new TextField("Small");
    tf.setValue("Field value");
    tf.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    row.addComponent(tf);

    tf = new TextField("Large");
    tf.setValue("Field value");
    tf.addStyleName(ValoTheme.TEXTFIELD_LARGE);
    tf.setIcon(testIcon.get(true));
    row.addComponent(tf);

    tf = new TextField();
    tf.setValue("Font, no caption");
    tf.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    tf.setIcon(testIcon.get());
    row.addComponent(tf);

    tf = new TextField();
    tf.setValue("Image, no caption");
    tf.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    tf.setIcon(testIcon.get(true, 16));
    row.addComponent(tf);

    CssLayout group = new CssLayout();
    group.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    row.addComponent(group);

    Button button = new Button("Do It");
    // button.addStyleName(ValoTheme.BUTTON_PRIMARY);
    group.addComponent(button);

    tf = new TextField("Right-aligned");
    tf.setValue("1,234");
    tf.addStyleName(ValoTheme.TEXTFIELD_ALIGN_RIGHT);
    row.addComponent(tf);

    tf = new TextField("Tiny");
    tf.setValue("Field value");
    tf.addStyleName(ValoTheme.TEXTFIELD_TINY);
    row.addComponent(tf);

    tf = new TextField("Huge");
    tf.setValue("Field value");
    tf.addStyleName(ValoTheme.TEXTFIELD_HUGE);
    row.addComponent(tf);

    h1 = new Label("Text Areas");
    h1.addStyleName(ValoTheme.LABEL_H1);
    addComponent(h1);

    row = new HorizontalLayout();
    row.addStyleName(ValoTheme.LAYOUT_HORIZONTAL_WRAPPING);
    addComponent(row);

    RichTextArea rta = new RichTextArea();
    rta.setValue("<b>Some</b> <i>rich</i> content");
    row.addComponent(rta);

    rta = new RichTextArea("Read-only");
    rta.setValue("<b>Some</b> <i>rich</i> content");
    rta.setReadOnly(true);
    row.addComponent(rta);
}

From source file:gov.osti.doecode.RepositoryForm.java

/**
 * Create a basic form UI for editing software metadata information.
 * /*from   w w  w  .j ava 2  s.c  o m*/
 * @param ui link to the MyUI parent UI
 */
public RepositoryForm(MyUI ui) {
    this.ui = ui;

    setSizeUndefined();

    agentGrid.setColumns("firstName", "lastName", "email");
    agentGrid.setHeightMode(HeightMode.ROW);
    agentGrid.setHeightByRows(8);

    idGrid.setColumns("relationType", "identifierType", "value");
    idGrid.setHeightMode(HeightMode.ROW);
    idGrid.setHeightByRows(8);

    idForm = new IdentifierForm(this);
    agentForm = new AgentForm(this);

    TabSheet tabs = new TabSheet();
    tabs.addStyleName(ValoTheme.TABSHEET_FRAMED);
    tabs.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);

    addComponent(tabs);

    HorizontalLayout main = new HorizontalLayout();
    main.setSpacing(true);
    main.setMargin(true);

    FormLayout left = new FormLayout();
    FormLayout right = new FormLayout();

    countryCode.addItems(countryCodes);

    left.addComponents(url, loadButton, name, openSource, siteOwnershipCode, acronym, doi, countryCode);
    right.addComponents(keywords, rights, license, operatingSystem, siteAccessionNumber, otherRequirements);

    loadButton.addClickListener(e -> {
        try {
            SoftwareRepository repo = Reader.loadRepository("doecode");

            setSoftwareRepository(repo);

        } catch (IOException ex) {
            setComponentError(new UserError("Unable to load: " + ex.getMessage()));
        }
    });

    main.addComponents(left, right);

    tabs.addTab(main, "Metadata");

    Button agentAddButton = new Button("New");
    agentAddButton.setStyleName(BaseTheme.BUTTON_LINK);
    agentAddButton.setIcon(FontAwesome.PLUS);

    agentAddButton.addClickListener(e -> {
        agentForm.setAgent(new Agent());
    });

    VerticalLayout innerAgent = new VerticalLayout(agentAddButton, agentGrid);
    innerAgent.setSizeUndefined();
    HorizontalLayout agentLayout = new HorizontalLayout(innerAgent, agentForm);
    agentLayout.setSpacing(true);
    agentLayout.setMargin(true);

    tabs.addTab(agentLayout, "Agents");

    Button idAddButton = new Button("New");
    idAddButton.setIcon(FontAwesome.PLUS);
    idAddButton.setStyleName(BaseTheme.BUTTON_LINK);
    idAddButton.setSizeUndefined();

    idAddButton.addClickListener(e -> {
        idForm.setIdentifier(new Identifier());
    });

    VerticalLayout innerId = new VerticalLayout(idAddButton, idGrid);
    HorizontalLayout idTab = new HorizontalLayout(innerId, idForm);
    idTab.setSpacing(true);
    idTab.setMargin(true);

    tabs.addTab(idTab, "Identifiers");

    agentGrid.addSelectionListener(e -> {
        if (!e.getSelected().isEmpty()) {
            Agent agent = (Agent) e.getSelected().iterator().next();
            agentForm.setAgent(agent);
            System.out.println("Selected " + agent.getFirstName());
        }
    });
    idGrid.addSelectionListener(e -> {
        if (!e.getSelected().isEmpty()) {
            Identifier identifier = (Identifier) e.getSelected().iterator().next();
            idForm.setIdentifier(identifier);
        }
    });

}

From source file:org.azrul.langkuik.framework.webgui.BeanView.java

private void handleFieldsError(BeanFieldGroup fieldGroup) {
    List<com.vaadin.ui.Field<?>> invFields = validateFields(fieldGroup);
    if (invFields.size() > 0) {
        invFields.iterator().next().focus();
        for (com.vaadin.ui.Field<?> invf : invFields) {
            if (invf instanceof AbstractComponent) {
                ((AbstractComponent) invf).setComponentError(new UserError("Invalid value"));
            }/*from w ww .  j  a v  a2 s  .  c  o m*/
        }
    }
    Notification.show("Invalid value in a field", Notification.Type.HUMANIZED_MESSAGE);
}

From source file:org.eclipse.emf.ecp.view.core.vaadin.AbstractControlRendererVaadin.java

License:Open Source License

@Override
protected void applyValidation() {
    // TODO: FIXME Register
    final AbstractComponent abstractComponent = (AbstractComponent) getControlComponent();
    abstractComponent.setComponentError(null);

    if (getVElement().getDiagnostic() == null) {
        return;/*from ww w .java2  s . c o m*/
    }
    if (Diagnostic.ERROR == getVElement().getDiagnostic().getHighestSeverity()) {
        abstractComponent.setComponentError(new UserError(getVElement().getDiagnostic().getMessage()));
    }
}

From source file:org.jdal.vaadin.ui.bind.UserErrorProcessor.java

License:Apache License

/**
 * {@inheritDoc}//from w  w w . j a v  a 2  s. c  o m
 */
public void processError(Object control, FieldError error) {
    if (control instanceof AbstractField) {
        AbstractField<?> f = (AbstractField<?>) control;
        f.setComponentError(new UserError(StaticMessageSource.getMessage(error)));
        fieldSet.add(f);
    }
}

From source file:org.jpos.qi.minigl.EntryGrid.java

License:Open Source License

public void validate() throws BLException {
    if (transaction.getEntries().size() == 0) {
        setComponentError(new UserError("Transaction has no entries"));
        throw new BLException("Transaction has no entries");
    }//from  ww w  .  ja  v  a2s . co m
}