Search in sources :

Example 6 with InvalidValueException

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

the class TimePicker method buildUI.

protected void buildUI(String title) {
    field = new TextField();
    field.setWidth("125");
    field.setImmediate(true);
    displayTime.setImmediate(true);
    displayTime.addValidator(timeValidator);
    field.addValidator(timeValidator);
    field.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("deprecation")
        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
            try {
                final Date parsedDate = parseDate((String) event.getProperty().getValue());
                if (parsedDate != null) {
                    dateTime.set(Calendar.HOUR_OF_DAY, parsedDate.getHours());
                    dateTime.set(Calendar.MINUTE, parsedDate.getMinutes());
                    isSet = true;
                    setNewValue();
                }
                TimePicker.this.valueChange(event);
                field.setComponentError(null);
            } catch (final InvalidValueException e) {
                field.setComponentError(new ErrorMessage() {

                    private static final long serialVersionUID = 1L;

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

                    @Override
                    public ErrorLevel getErrorLevel() {
                        return ErrorLevel.ERROR;
                    }
                });
            }
        }
    });
    this.title = title;
    CssLayout hl = new CssLayout();
    hl.addStyleName("v-component-group");
    hl.setWidth("100%");
    hl.setHeight("35");
    pickerButton = new Button();
    pickerButton.setIcon(FontAwesome.CLOCK_O);
    hl.addComponent(pickerButton);
    hl.addComponent(field);
    pickerButton.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            showPopupTimePicker();
        }
    });
    addComponent(hl);
}
Also used : ClickEvent(com.vaadin.ui.Button.ClickEvent) Date(java.util.Date) InvalidValueException(com.vaadin.data.Validator.InvalidValueException) CssLayout(com.vaadin.ui.CssLayout) NativeButton(com.vaadin.ui.NativeButton) Button(com.vaadin.ui.Button) TextField(com.vaadin.ui.TextField) ErrorMessage(com.vaadin.server.ErrorMessage) Property(com.vaadin.data.Property) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 7 with InvalidValueException

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

the class TimePicker24 method showPopupTimePicker.

private void showPopupTimePicker() {
    String value = field.getValue();
    try {
        String[] parts = value.split(":");
        hour = parts[0];
        String[] np = parts[1].split(" ");
        minute = np[0];
        displayTime.setValue(value);
    } catch (Exception e) {
        clearValue();
    }
    final Window window = new Window(title);
    window.setModal(true);
    window.setResizable(false);
    window.setWidth("430");
    window.setHeight("240");
    window.setClosable(false);
    HorizontalLayout layout = new HorizontalLayout();
    layout.setSizeFull();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setStyleName(Reindeer.BUTTON_SMALL);
    displayTime.setWidth("100");
    VerticalLayout hourPanelLabelWrapper = new VerticalLayout();
    Label hourLabel = new Label("Hour");
    // hourLabel.setBackgroundColor(headerColor);
    hourLabel.setWidth("230");
    // hourLabel.setHeight("30");
    // hourLabel.setAutoFit(false);
    HorizontalLayout innerHourLabelPanel = new HorizontalLayout();
    // innerHourLabelPanel.setPadding(5);
    innerHourLabelPanel.addComponent(hourLabel);
    innerHourLabelPanel.setWidth("100");
    // innerHourLabelPanel.setHeight("30");
    hourPanelLabelWrapper.addComponent(innerHourLabelPanel);
    VerticalLayout minuteLabelWrapper = new VerticalLayout();
    minuteLabelWrapper.setWidth("60");
    Label minuteLabel = new Label("Minute");
    // minuteLabel.setBackgroundColor(headerColor);
    // minuteLabel.setStyleName("njadmin-search-colour");
    minuteLabel.setWidth("45");
    // minuteLabel.setHeight("30");
    // minuteLabel.setAutoFit(false);
    VerticalLayout innerMinuteLabelPanel = new VerticalLayout();
    // innerMinuteLabelPanel.setPadding(5);
    innerMinuteLabelPanel.addComponent(minuteLabel);
    innerMinuteLabelPanel.setWidth("45");
    // innerMinuteLabelPanel.setHeight("30");
    minuteLabelWrapper.addComponent(innerMinuteLabelPanel);
    HorizontalLayout hourPanel = new HorizontalLayout();
    // hourPanel.setPadding(5);
    HorizontalLayout hourButtonPanel = new HorizontalLayout();
    hourPanel.addComponent(hourButtonPanel);
    addHourButtons(hourButtonPanel, 3, 8);
    HorizontalLayout minutePanel = new HorizontalLayout();
    // minutePanel.setPadding(5);
    HorizontalLayout minuteButtonPanel = new HorizontalLayout();
    minutePanel.addComponent(minuteButtonPanel);
    addMinuteButtons(minuteButtonPanel, 2, 4);
    HorizontalLayout amPmHourWrapper = new HorizontalLayout();
    amPmHourWrapper.addComponent(hourPanel);
    hourPanelLabelWrapper.addComponent(amPmHourWrapper);
    layout.addComponent(hourPanelLabelWrapper);
    minuteLabelWrapper.addComponent(minutePanel);
    layout.addComponent(minuteLabelWrapper);
    layout.setExpandRatio(hourPanelLabelWrapper, 0.7f);
    layout.setExpandRatio(minuteLabelWrapper, 0.3f);
    HorizontalLayout okcancel = new HorizontalLayout();
    okcancel.setSizeFull();
    Button ok = new Button("OK");
    ok.setWidth("75");
    ok.addClickListener(new ClickListener() {

        /**
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                displayTime.validate();
                if (displayTime.getValue().equals(EMPTY)) {
                    field.setValue("");
                } else {
                    field.setValue(displayTime.getValue());
                }
                window.close();
            } catch (InvalidValueException e) {
            }
        }
    });
    Button cancel = new Button("Cancel");
    cancel.setWidth("75");
    cancel.addClickListener(new ClickListener() {

        /**
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            window.close();
        }
    });
    okcancel.addComponent(displayTime);
    okcancel.addComponent(cancel);
    okcancel.addComponent(ok);
    okcancel.setMargin(true);
    okcancel.setSpacing(true);
    okcancel.setExpandRatio(displayTime, 0.50f);
    // okcancel.setExpandRatio(ok, 0.25f);
    // okcancel.setExpandRatio(cancel, 0.25f);
    VerticalLayout wrapper = new VerticalLayout();
    // wrapper.setStyleName("njadmin-search-colour");
    wrapper.setSizeFull();
    wrapper.addComponent(layout);
    wrapper.addComponent(okcancel);
    wrapper.setExpandRatio(layout, 0.9f);
    wrapper.setExpandRatio(okcancel, 0.5f);
    window.setContent(wrapper);
    UI.getCurrent().addWindow(window);
}
Also used : Window(com.vaadin.ui.Window) ClickEvent(com.vaadin.ui.Button.ClickEvent) Label(com.vaadin.ui.Label) InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ParseException(java.text.ParseException) HorizontalLayout(com.vaadin.ui.HorizontalLayout) InvalidValueException(com.vaadin.data.Validator.InvalidValueException) NativeButton(com.vaadin.ui.NativeButton) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 8 with InvalidValueException

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

the class NewCasePopupWindow method handleFormSubmit.

protected void handleFormSubmit() {
    try {
        // Check for errors
        // will throw exception in case validation is false
        form.commit();
        // Create task
        Task task = taskService.newTask();
        task.setName(nameField.getValue().toString());
        task.setDescription(descriptionArea.getValue().toString());
        task.setDueDate((Date) dueDateField.getValue());
        task.setPriority(priorityComboBox.getPriority());
        task.setOwner(ExplorerApp.get().getLoggedInUser().getId());
        taskService.saveTask(task);
        // close popup and navigate to new group
        close();
        ExplorerApp.get().getViewManager().showTasksPage(task.getId());
    } catch (InvalidValueException e) {
        // Do nothing: the Form component will render the errormsgs automatically
        setHeight(350, UNITS_PIXELS);
    }
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) Task(org.activiti.engine.task.Task)

Example 9 with InvalidValueException

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

the class NewGroupPopupWindow method initInputFields.

protected void initInputFields() {
    // Input fields
    form.addField("id", new TextField(i18nManager.getMessage(Messages.GROUP_ID)));
    // Set id field to required
    form.getField("id").setRequired(true);
    form.getField("id").setRequiredError(i18nManager.getMessage(Messages.GROUP_ID_REQUIRED));
    form.getField("id").focus();
    // Set id field to be unique
    form.getField("id").addValidator(new Validator() {

        public void validate(Object value) throws InvalidValueException {
            if (!isValid(value)) {
                throw new InvalidValueException(i18nManager.getMessage(Messages.GROUP_ID_UNIQUE));
            }
        }

        public boolean isValid(Object value) {
            if (value != null) {
                return identityService.createGroupQuery().groupId(value.toString()).singleResult() == null;
            }
            return false;
        }
    });
    form.addField("name", new TextField(i18nManager.getMessage(Messages.GROUP_NAME)));
    ComboBox typeComboBox = new ComboBox(i18nManager.getMessage(Messages.GROUP_TYPE), Arrays.asList("assignment", "security-role"));
    typeComboBox.select("assignment");
    form.addField("type", typeComboBox);
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ComboBox(com.vaadin.ui.ComboBox) TextField(com.vaadin.ui.TextField) Validator(com.vaadin.data.Validator)

Example 10 with InvalidValueException

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

the class CreateAttachmentPopupWindow method saveAttachment.

protected void saveAttachment() {
    try {
        // Creation and persistence of attachment is done in editor
        Attachment attachment = currentEditor.getAttachment();
        fireEvent(new SubmitEvent(this, SubmitEvent.SUBMITTED, attachment));
        // Finally, close window
        close();
    } catch (InvalidValueException ive) {
    // Validation error, Editor UI will handle this.
    }
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) Attachment(org.activiti.engine.task.Attachment) SubmitEvent(org.activiti.explorer.ui.event.SubmitEvent)

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