Search in sources :

Example 11 with InvalidValueException

use of com.vaadin.data.Validator.InvalidValueException in project Activiti by Activiti.

the class FormPropertiesForm method initListeners.

protected void initListeners() {
    submitFormButton.addListener(new ClickListener() {

        private static final long serialVersionUID = -6091586145870618870L;

        public void buttonClick(ClickEvent event) {
            // Extract the submitted values from the form. Throws exception when validation fails.
            try {
                Map<String, String> formProperties = formPropertiesComponent.getFormPropertyValues();
                fireEvent(new FormPropertiesEvent(FormPropertiesForm.this, FormPropertiesEvent.TYPE_SUBMIT, formProperties));
                submitFormButton.setComponentError(null);
            } catch (InvalidValueException ive) {
            // Error is presented to user by the form component
            }
        }
    });
    cancelFormButton.addListener(new ClickListener() {

        private static final long serialVersionUID = -8980500491522472381L;

        public void buttonClick(ClickEvent event) {
            fireEvent(new FormPropertiesEvent(FormPropertiesForm.this, FormPropertiesEvent.TYPE_CANCEL));
            submitFormButton.setComponentError(null);
        }
    });
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ClickEvent(com.vaadin.ui.Button.ClickEvent) Map(java.util.Map) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 12 with InvalidValueException

use of com.vaadin.data.Validator.InvalidValueException in project VaadinUtils by rlsutton1.

the class ReportParameter method validateField.

protected boolean validateField(AbstractField<T> field) {
    boolean valid = false;
    try {
        field.setComponentError(null);
        if (validateListener != null) {
            validateListener.setComponentError(null);
        }
        field.validate();
        valid = true;
    } catch (final InvalidValueException e) {
        ErrorMessage componentError = new ErrorMessage() {

            private static final long serialVersionUID = -2976235476811651668L;

            @Override
            public String getFormattedHtmlMessage() {
                return e.getHtmlMessage();
            }

            @Override
            public ErrorLevel getErrorLevel() {
                return ErrorLevel.ERROR;
            }
        };
        field.setComponentError(componentError);
        if (validateListener != null) {
            validateListener.setComponentError(componentError);
        }
    }
    return valid;
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ErrorMessage(com.vaadin.server.ErrorMessage)

Example 13 with InvalidValueException

use of com.vaadin.data.Validator.InvalidValueException in project VaadinUtils by rlsutton1.

the class BaseCrudView method handleInvalidValueException.

protected void handleInvalidValueException(InvalidValueException m) {
    String causeMessage = "";
    for (InvalidValueException cause : m.getCauses()) {
        causeMessage += cause.getMessage() + ". ";
    }
    if (m.getMessage() != null && m.getMessage().length() > 0) {
        causeMessage += m.getMessage() + ". ";
    }
    Notification.show("Please fix the form errors and then try again.\n\n " + causeMessage, Type.ERROR_MESSAGE);
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException)

Example 14 with InvalidValueException

use of com.vaadin.data.Validator.InvalidValueException in project VaadinUtils by rlsutton1.

the class BaseCrudView method save.

@Override
public void save() {
    boolean selected = false;
    try {
        commitFieldGroup();
        validateChildren();
        CrudEventType eventType = CrudEventType.EDIT;
        if (newEntity != null) {
            if (!okToSave(newEntity)) {
                return;
            }
            eventType = CrudEventType.CREATE;
            interceptSaveValues(newEntity);
            Object id = container.addEntity(newEntity.getEntity());
            EntityItem<E> item = container.getItem(id);
            fieldGroup.setItemDataSource(item);
            selected = true;
            if (restoreDelete) {
                activateEditMode(false);
                restoreDelete = false;
            }
            searchField.setReadOnly(false);
            clearButton.setEnabled(true);
        } else {
            EntityItem<E> current = entityTable.getCurrent();
            if (current != null) {
                if (!okToSave(current)) {
                    return;
                }
                interceptSaveValues(current);
            }
        }
        // commit the row to the database, and retrieve the possibly new
        // entity
        E newEntity = commitContainerAndGetEntityFromDB();
        if (newEntity == null) {
            throw new RuntimeException("An error occurred, unable to retrieve updated record. Failed to save changes");
        }
        newEntity = EntityManagerProvider.getEntityManager().merge(newEntity);
        for (ChildCrudListener<E> commitListener : childCrudListeners) {
            // of children
            if (commitListener.isDirty()) {
                commitListener.committed(newEntity);
            }
        }
        EntityManagerProvider.getEntityManager().flush();
        // children may have been added to the parent, evict the parent from
        // the JPA cache so it will get updated
        EntityManagerProvider.getEntityManager().getEntityManagerFactory().getCache().evict(entityClass, newEntity.getId());
        newEntity = EntityManagerProvider.merge(newEntity);
        postSaveAction(newEntity);
        EntityManagerProvider.getEntityManager().flush();
        reloadDataFromDB(newEntity.getId());
        CrudEventDistributer.publishEvent(this, eventType, newEntity);
        if (eventType == CrudEventType.CREATE) {
            addFilterToShowNewRow(newEntity);
            container.discard();
        }
        this.newEntity = null;
        searchField.setReadOnly(false);
        clearButton.setEnabled(true);
        // select has been moved to here because when it happens earlier,
        // child cruds are caused to discard their data before saving it for
        // a new record
        entityTable.select(newEntity.getId());
        splitPanel.showFirstComponent();
        Notification.show("Changes Saved", "Any changes you have made have been saved.", Type.HUMANIZED_MESSAGE);
        // return save/edit buttons to default settings
        buttonLayout.setDefaultState();
    } catch (Exception e) {
        if (e instanceof InvalidValueException) {
            handleInvalidValueException((InvalidValueException) e);
        } else if (e.getCause() instanceof InvalidValueException) {
            handleInvalidValueException((InvalidValueException) e.getCause());
        } else {
            ErrorWindow.showErrorWindow(e);
        }
    } finally {
        if (newEntity != null) {
            if (selected && entityTable.getCurrent() != null) {
                container.removeItem(entityTable.getCurrent());
            }
        }
        buttonLayout.setDefaultState();
    }
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) CrudEventType(au.com.vaadinutils.crud.events.CrudEventType) CommitException(com.vaadin.data.fieldgroup.FieldGroup.CommitException) EntityNotFoundException(javax.persistence.EntityNotFoundException) InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ExecutionException(java.util.concurrent.ExecutionException)

Example 15 with InvalidValueException

use of com.vaadin.data.Validator.InvalidValueException in project VaadinUtils by rlsutton1.

the class JasperReportScheduleLayout method interceptSaveValues.

@Override
protected void interceptSaveValues(EntityItem<ReportEmailScheduleEntity> entityItem) {
    ReportEmailScheduleEntity entity = entityItem.getEntity();
    entity.setNextScheduledRunTime(entity.getScheduleMode().getNextRuntime(entity, new Date()));
    List<ReportEmailRecipient> recips = entity.getRecipients();
    Set<ReportEmailRecipient> matchedRecips = new HashSet<ReportEmailRecipient>();
    for (EmailTargetLine line : emailTargetLayout.getTargets()) {
        // check if the recipient exists
        String email = (String) line.targetAddress.getValue();
        if (email != null && email.length() > 0) {
            // String email = (String)
            // item.getItemProperty("id").getValue();
            boolean found = false;
            for (ReportEmailRecipient recip : recips) {
                if (recip.getEmail() != null && recip.getEmail().equalsIgnoreCase(email)) {
                    found = true;
                    recip.setVisibility((ReportEmailRecipientVisibility) line.targetTypeCombo.getValue());
                    matchedRecips.add(recip);
                    break;
                }
            }
            // if not then add them
            if (!found) {
                ReportEmailRecipient reportEmailRecipient = new ReportEmailRecipient();
                reportEmailRecipient.setEmail(email);
                reportEmailRecipient.setVisibility((ReportEmailRecipientVisibility) line.targetTypeCombo.getValue());
                recips.add(reportEmailRecipient);
                matchedRecips.add(reportEmailRecipient);
            }
        }
    }
    recips.clear();
    recips.addAll(matchedRecips);
    if (recips.size() == 0) {
        throw new InvalidValueException("Select at least one Recipient");
    }
    saveChangesToReportParameters(entity);
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ReportEmailRecipient(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient) ReportEmailScheduleEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

InvalidValueException (com.vaadin.data.Validator.InvalidValueException)17 TextField (com.vaadin.ui.TextField)6 Date (java.util.Date)5 Button (com.vaadin.ui.Button)4 Property (com.vaadin.data.Property)3 Validator (com.vaadin.data.Validator)3 ClickEvent (com.vaadin.ui.Button.ClickEvent)3 ClickListener (com.vaadin.ui.Button.ClickListener)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 Label (com.vaadin.ui.Label)3 NativeButton (com.vaadin.ui.NativeButton)3 VerticalLayout (com.vaadin.ui.VerticalLayout)3 StringLengthValidator (com.vaadin.data.validator.StringLengthValidator)2 ErrorMessage (com.vaadin.server.ErrorMessage)2 ComboBox (com.vaadin.ui.ComboBox)2 InlineDateField (com.vaadin.ui.InlineDateField)2 PasswordField (com.vaadin.ui.PasswordField)2 ParseException (java.text.ParseException)2 CrudEventType (au.com.vaadinutils.crud.events.CrudEventType)1 ReportEmailRecipient (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient)1