Example usage for com.vaadin.ui DateField DateField

List of usage examples for com.vaadin.ui DateField DateField

Introduction

In this page you can find the example usage for com.vaadin.ui DateField DateField.

Prototype

public DateField(ValueChangeListener<LocalDate> valueChangeListener) 

Source Link

Document

Constructs a new DateField with a value change listener.

Usage

From source file:lifetime.component.welcome.register.RegistrationForm.java

License:Apache License

public RegistrationForm(String language) {
    super();/*w w w  .j a v  a2s  .  c  o  m*/
    setSizeUndefined();
    setMargin(true);
    setSpacing(true);
    Label text = new Label("Register");
    setSpacing(true);
    text.setStyleName("login");

    defaultLanguage = new LocalesComboBox(language);
    /* Creates the firstname text field and registers a validator */
    firstname = new LifetimeTextField("Firstname"); // Creates text field
    firstname.addValidator(new NameValidator()); // Register Validator
    firstname.setValidationVisible(true); // Automatic validation
    firstname.setId(StyleClassName.REGISTRATION_FORM_FIRSTNAME.getId());

    /* Creates lastnames text field and registers a validator */
    lastname = new LifetimeTextField("Lastname");
    lastname.addValidator(new NameValidator());
    lastname.setValidationVisible(true);
    lastname.setRequired(true);
    lastname.setId(StyleClassName.REGISTRATION_FORM_LASTNAME.getId());

    /* Creates email text field and registers a validator */
    email = new LifetimeTextField("Email / Username");
    email.addValidator(new EmailValidator("Invalid email address"));
    email.setValidationVisible(true);
    email.setId(StyleClassName.REGISTRATION_FORM_EMAIL.getId());

    /* Creates password text field and registers a validator */
    password = new PasswordField("Password");
    password.addValidator(new PasswordValidator());
    password.setId(StyleClassName.REGISTRATION_FORM_ENCRYPTED.getId());

    passwordRepeat = new PasswordField("Repeat password");
    passwordRepeat.setId(StyleClassName.REGISTRATION_FORM_ENCRYPTED_REPEAT.getId());

    birthDate = new DateField("Birthdate");
    birthDate.setLocale(new Locale(language));
    birthDate.setId(StyleClassName.REGISTRATION_FORM_BIRTHDATE.getId());

    //
    birthPlace = new LifetimeTextField("Birth place");
    birthPlace.setId(StyleClassName.REGISTRATION_FORM_BIRTHPLACE.getId());

    VerticalLayout personalData = new VerticalLayout(defaultLanguage, firstname, lastname, email, password,
            passwordRepeat);
    VerticalLayout birthData = new VerticalLayout(birthDate, birthPlace);
    birthData.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
    addComponents(personalData, birthData);
    setStyleName(StyleClassName.REGISTRATION_FORM.getStyleName());
    setId(StyleClassName.REGISTRATION_FORM.getId());
}

From source file:me.uni.emuseo.view.common.helpers.BeanFieldGroupFixed.java

License:Open Source License

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public <F extends Field> F buildAndBind(String caption, Object propertyId, Class<F> fieldType)
        throws BindException {
    final Class<?> type = getPropertyType(propertyId);

    F field;/* w  ww.ja  v a 2s. c  om*/
    if (Enum.class.isAssignableFrom(type)) {
        field = (F) super.buildAndBind(caption, propertyId, ComboBox.class);
    } else if (Date.class.isAssignableFrom(type)) {
        field = getFieldFactory().createField(type, (Class<F>) DateField.class);
        if (field == null)
            field = (F) new DateField(caption);
        else
            field.setCaption(caption);

        bind(field, propertyId);
    } else {
        field = super.buildAndBind(caption, propertyId, fieldType);
    }
    return field;
}

From source file:module.pandabox.presentation.PandaBox.java

License:Open Source License

private Component getBennuInterface() {
    GridSystemLayout gsl = new GridSystemLayout();
    gsl.setMargin(false);// w ww  . j  a v a  2 s.c  o  m

    Label lblBigTitle = new Label("A Big Title (H1)", Label.CONTENT_TEXT);
    lblBigTitle.setStyleName(BennuTheme.LABEL_H1);

    Label lblBigText = new Label(LOREM_TEXT_LARGE, Label.CONTENT_TEXT);

    gsl.setCell("big_title", 16, lblBigTitle);
    gsl.setCell("big_text", 16, lblBigText);

    Label lblOneLink = new Label(
            "<a href='http://www.google.com'>Label Link : One link a day keeps the doctor away</a>",
            Label.CONTENT_XHTML);
    gsl.setCell("label_one_link", 16, lblOneLink);

    Button btOneLink = new Button("Button Link: One link a day keeps the doctor away", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            event.getButton().getWindow().showNotification("You just clicked a button link!");
        }
    });

    btOneLink.setStyleName(BaseTheme.BUTTON_LINK);
    gsl.setCell("button_one_link", 16, btOneLink);

    Label lblTitleH2 = new Label("A Not So Big Title (H2)", Label.CONTENT_TEXT);
    lblTitleH2.setStyleName(BennuTheme.LABEL_H2);
    gsl.setCell("not_so_big_title", 16, lblTitleH2);

    Label lblSmallText = new Label(LOREM_TEXT_SMALL, Label.CONTENT_TEXT);
    gsl.setCell("small_text", 16, lblSmallText);

    Table table = new Table();
    table.setSizeFull();
    table.setPageLength(0);
    table.addContainerProperty("Name", String.class, "");
    table.addContainerProperty("Age", Integer.class, "");
    table.addContainerProperty("Nickname", String.class, "");

    table.addItem(new Object[] { "Giacomo Guilizzoni", 34, "Peidi" }, 1);
    table.addItem(new Object[] { "Giodp Jack Guilizzoni", 4, "The Guids" }, 2);
    table.addItem(new Object[] { "Marco Botton", 31, "" }, 3);
    table.addItem(new Object[] { "Mariah Maciachlan", 35, "Patata" }, 4);
    table.addItem(new Object[] { "Valerie Libery WOW! Division", 23, "Val" }, 5);
    table.addItem(new Object[] { "Guido Master lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum", 99,
            "Booya Master" }, 6);

    gsl.setCell("table", 16, table);

    Label lblTitleH3 = new Label("A Getting Smaller Title (H3)", Label.CONTENT_TEXT);
    lblTitleH3.setStyleName(BennuTheme.LABEL_H3);
    gsl.setCell("getting_smaller_title", 16, lblTitleH3);

    Panel panelLeft = new Panel();
    panelLeft.setScrollable(true);
    panelLeft.setSizeFull();
    panelLeft.setHeight("145px");
    panelLeft.addComponent(new Label(LOREM_TEXT_ALL));

    Panel panelRight = new Panel();
    panelRight.addComponent(new Label(LOREM_TEXT_LARGE));

    gsl.setCell("panel_left", 8, panelLeft);
    gsl.setCell("panel_right", 8, panelRight);

    Label lblTitleH4 = new Label("A Smaller Title (H4)", Label.CONTENT_TEXT);
    lblTitleH4.setStyleName(BennuTheme.LABEL_H4);
    gsl.setCell("smaller_title", 16, lblTitleH4);

    Label lblTextb4Form = new Label(LOREM_TEXT_SMALL, Label.CONTENT_TEXT);
    gsl.setCell("txtB4Form", 0, 8, 8, lblTextb4Form);

    Form form = new Form();
    form.setSizeFull();
    form.addField("form_label", new TextField("Form Label"));
    form.addField("large_form_label", new DateField("Large Form Label"));
    form.addField("much_larger_form_label", new Select("Much Larger Form Label"));
    form.addField("something_diff", new TextArea("And now for something completely different"));

    final OptionGroup checkboxes = new OptionGroup("Checkboxes fun");
    checkboxes.setMultiSelect(true);
    checkboxes.addItem("not selected");
    checkboxes.addItem("selected");
    checkboxes.select("selected");
    checkboxes.addItem("disabled");
    checkboxes.setItemEnabled("disabled", false);
    checkboxes.addItem("disabled selected");
    checkboxes.select("disabled selected");
    checkboxes.setItemEnabled("disabled selected", false);

    form.addField("checkboxes", checkboxes);

    final OptionGroup radiobuttons = new OptionGroup("Radio on/off");
    radiobuttons.addItem("option 1(selected)");
    radiobuttons.select("option 1(selected)");
    radiobuttons.addItem("option 2");
    radiobuttons.addItem("option 3 (disabled)");
    radiobuttons.setItemEnabled("option 3 (disabled)", false);

    radiobuttons.addItem("option 4 (disabled and selected)");
    radiobuttons.select("option 4 (disabled and selected)");
    radiobuttons.setItemEnabled("option 4 (disabled and selected)", false);

    form.addField("radiobuttons", radiobuttons);

    form.getFooter().addComponent(new Button("Submit the info"));
    form.getFooter().addComponent(new Button("Cancel the info"));

    final Panel rightFormPanel = new Panel();
    rightFormPanel.setScrollable(true);
    rightFormPanel.setSizeFull();
    rightFormPanel.setHeight("400px");
    rightFormPanel.addComponent(new Label(LOREM_TEXT_ALL, Label.CONTENT_TEXT));

    gsl.setCell("form", 12, form);
    gsl.setCell("rightFormPanel", 4, rightFormPanel);

    return gsl;
}

From source file:my.vaadin.profile.Forms.java

public Forms() {
    setSpacing(true);//from  www.  ja  v  a  2 s  .com
    setMargin(true);

    Label title = new Label("Signup Form");
    title.addStyleName("h1");
    addComponent(title);

    final FormLayout form = new FormLayout();
    form.setMargin(false);
    form.setWidth("900px");
    form.addStyleName("light");
    addComponent(form);

    Label section = new Label("Personal Info");
    section.addStyleName("h2");
    section.addStyleName("colored");
    form.addComponent(section);
    //StringGenerator sg = new StringGenerator();

    TextField zID = new TextField("zID");
    zID.setValue("z123456");
    zID.setRequired(true);
    form.addComponent(zID);

    TextField name = new TextField("Name");
    name.setValue("loreum");
    //name.setWidth("50%");
    form.addComponent(name);

    PasswordField pw = new PasswordField("Set Password");
    pw.setRequired(true);
    form.addComponent(pw);

    DateField birthday = new DateField("Birthday");
    birthday.setDateFormat("dd-MM-yyyy");
    birthday.setValue(new java.util.Date());
    form.addComponent(birthday);

    OptionGroup gender = new OptionGroup("Gender");
    gender.addItem("Male");
    gender.addItem("Female");
    //sex.select("Male");
    gender.addStyleName("horizontal");
    form.addComponent(gender);

    section = new Label("Class Info");
    section.addStyleName("h2");
    section.addStyleName("colored");
    form.addComponent(section);

    TextField classID = new TextField("Class ID");
    classID.setValue("INFS2605");
    classID.setRequired(true);
    //classID.setWidth("50%");
    form.addComponent(classID);

    TextField groupID = new TextField("Group ID");
    groupID.setValue("1");
    //groupID.setWidth("50%");
    groupID.setRequired(true);
    form.addComponent(groupID);

    Button confirm = new Button("Confirm");
    confirm.addStyleName("primary");
    form.addComponent(confirm);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setMargin(new MarginInfo(true, false, true, false));
    footer.setSpacing(true);
    footer.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    form.addComponent(footer);
    footer.addComponent(confirm);

}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.execution.ExecutionWizardStep.java

License:Apache License

@Override
public Component getContent() {
    Panel form = new Panel(TRANSLATOR.translate("step.detail"));
    if (getExecutionStep().getExecutionStart() == null) {
        //Set the start date.
        getExecutionStep().setExecutionStart(new Date());
    }//  ww  w  . j av a 2s.  c  o m
    FormLayout layout = new FormLayout();
    form.setContent(layout);
    form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(getExecutionStep().getStep().getClass());
    binder.setItemDataSource(getExecutionStep().getStep());
    TextArea text = new TextArea(TRANSLATOR.translate("general.text"));
    text.setConverter(new ByteToStringConverter());
    binder.bind(text, "text");
    text.setSizeFull();
    layout.addComponent(text);
    Field notes = binder.buildAndBind(TRANSLATOR.translate("general.notes"), "notes", TextArea.class);
    notes.setSizeFull();
    layout.addComponent(notes);
    if (getExecutionStep().getExecutionStart() != null) {
        start = new DateField(TRANSLATOR.translate("start.date"));
        start.setResolution(Resolution.SECOND);
        start.setDateFormat(VMSettingServer.getSetting("date.format").getStringVal());
        start.setValue(getExecutionStep().getExecutionStart());
        start.setReadOnly(true);
        layout.addComponent(start);
    }
    if (getExecutionStep().getExecutionEnd() != null) {
        end = new DateField(TRANSLATOR.translate("end.date"));
        end.setDateFormat(VMSettingServer.getSetting("date.format").getStringVal());
        end.setResolution(Resolution.SECOND);
        end.setValue(getExecutionStep().getExecutionEnd());
        end.setReadOnly(true);
        layout.addComponent(end);
    }
    binder.setReadOnly(true);
    //Space to record result
    if (getExecutionStep().getResultId() != null) {
        result.setValue(getExecutionStep().getResultId().getResultName());
    }
    layout.addComponent(result);
    if (reviewer) {//Space to record review
        if (getExecutionStep().getReviewResultId() != null) {
            review.setValue(getExecutionStep().getReviewResultId().getReviewName());
        }
        layout.addComponent(review);
    }
    //Add Reviewer name
    if (getExecutionStep().getReviewer() != null) {
        TextField reviewerField = new TextField(TRANSLATOR.translate("general.reviewer"));
        reviewerField.setValue(getExecutionStep().getReviewer().getFirstName() + " "
                + getExecutionStep().getReviewer().getLastName());
        reviewerField.setReadOnly(true);
        layout.addComponent(reviewerField);
    }
    if (getExecutionStep().getReviewDate() != null) {
        reviewDate = new DateField(TRANSLATOR.translate("review.date"));
        reviewDate.setDateFormat(VMSettingServer.getSetting("date.format").getStringVal());
        reviewDate.setResolution(Resolution.SECOND);
        reviewDate.setValue(getExecutionStep().getReviewDate());
        reviewDate.setReadOnly(true);
        layout.addComponent(reviewDate);
    }
    if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) {
        TextArea expectedResult = new TextArea(TRANSLATOR.translate("expected.result"));
        expectedResult.setConverter(new ByteToStringConverter());
        binder.bind(expectedResult, "expectedResult");
        expectedResult.setSizeFull();
        layout.addComponent(expectedResult);
    }
    //Add the fields
    fields.clear();
    getExecutionStep().getStep().getDataEntryList().forEach(de -> {
        switch (de.getDataEntryType().getId()) {
        case 1://String
            TextField tf = new TextField(TRANSLATOR.translate(de.getEntryName()));
            tf.setRequired(true);
            tf.setData(de.getEntryName());
            if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) {
                //Add expected result
                DataEntryProperty stringCase = DataEntryServer.getProperty(de, "property.match.case");
                DataEntryProperty r = DataEntryServer.getProperty(de, "property.expected.result");
                if (r != null && !r.getPropertyValue().equals("null")) {
                    String error = TRANSLATOR.translate("expected.result") + ": " + r.getPropertyValue();
                    tf.setRequiredError(error);
                    tf.setRequired(DataEntryServer.getProperty(de, "property.required").getPropertyValue()
                            .equals("true"));
                    tf.addValidator((Object val) -> {
                        //We have an expected result and a match case requirement
                        if (stringCase != null && stringCase.getPropertyValue().equals("true")
                                ? !((String) val).equals(r.getPropertyValue())
                                : !((String) val).equalsIgnoreCase(r.getPropertyValue())) {
                            throw new InvalidValueException(error);
                        }
                    });
                }
            }
            fields.add(tf);
            //Set value if already recorded
            updateValue(tf);
            layout.addComponent(tf);
            break;
        case 2://Numeric
            NumberField field = new NumberField(TRANSLATOR.translate(de.getEntryName()));
            field.setSigned(true);
            field.setUseGrouping(true);
            field.setGroupingSeparator(',');
            field.setDecimalSeparator('.');
            field.setConverter(new StringToDoubleConverter());
            field.setRequired(
                    DataEntryServer.getProperty(de, "property.required").getPropertyValue().equals("true"));
            field.setData(de.getEntryName());
            Double min = null, max = null;
            for (DataEntryProperty prop : de.getDataEntryPropertyList()) {
                String value = prop.getPropertyValue();
                if (prop.getPropertyName().equals("property.max")) {
                    try {
                        max = Double.parseDouble(value);
                    } catch (NumberFormatException ex) {
                        //Leave as null
                    }
                } else if (prop.getPropertyName().equals("property.min")) {
                    try {
                        min = Double.parseDouble(value);
                    } catch (NumberFormatException ex) {
                        //Leave as null
                    }
                }
            }
            //Add expected result
            if (VMSettingServer.getSetting("show.expected.result").getBoolVal()
                    && (min != null || max != null)) {
                String error = TRANSLATOR.translate("error.out.of.range") + " "
                        + (min == null ? " " : (TRANSLATOR.translate("property.min") + ": " + min)) + " "
                        + (max == null ? "" : (TRANSLATOR.translate("property.max") + ": " + max));
                field.setRequiredError(error);
                field.addValidator(new DoubleRangeValidator(error, min, max));
            }
            fields.add(field);
            //Set value if already recorded
            updateValue(field);
            layout.addComponent(field);
            break;
        case 3://Boolean
            CheckBox cb = new CheckBox(TRANSLATOR.translate(de.getEntryName()));
            cb.setData(de.getEntryName());
            cb.setRequired(
                    DataEntryServer.getProperty(de, "property.required").getPropertyValue().equals("true"));
            if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) {
                DataEntryProperty r = DataEntryServer.getProperty(de, "property.expected.result");
                if (r != null) {
                    //Add expected result
                    String error = TRANSLATOR.translate("expected.result") + ": " + r.getPropertyValue();
                    cb.addValidator((Object val) -> {
                        if (!val.toString().equals(r.getPropertyValue())) {
                            throw new InvalidValueException(error);
                        }
                    });
                }
            }
            fields.add(cb);
            //Set value if already recorded
            updateValue(cb);
            layout.addComponent(cb);
            break;
        case 4://Attachment
            Label l = new Label(TRANSLATOR.translate(de.getEntryName()));
            layout.addComponent(l);
            break;
        default:
            LOG.log(Level.SEVERE, "Unexpected field type: {0}", de.getDataEntryType().getId());
        }
    });
    //Add the Attachments
    HorizontalLayout attachments = new HorizontalLayout();
    attachments.setCaption(TRANSLATOR.translate("general.attachment"));
    HorizontalLayout comments = new HorizontalLayout();
    comments.setCaption(TRANSLATOR.translate("general.comments"));
    HorizontalLayout issues = new HorizontalLayout();
    issues.setCaption(TRANSLATOR.translate("general.issue"));
    int commentCounter = 0;
    int issueCounter = 0;
    for (ExecutionStepHasIssue ei : getExecutionStep().getExecutionStepHasIssueList()) {
        issueCounter++;
        Button a = new Button("Issue #" + issueCounter);
        a.setIcon(VaadinIcons.BUG);
        a.addClickListener((Button.ClickEvent event) -> {
            displayIssue(new IssueServer(ei.getIssue()));
        });
        a.setEnabled(!step.getLocked());
        issues.addComponent(a);
    }
    for (ExecutionStepHasAttachment attachment : getExecutionStep().getExecutionStepHasAttachmentList()) {
        switch (attachment.getAttachment().getAttachmentType().getType()) {
        case "comment": {
            //Comments go in a different section
            commentCounter++;
            Button a = new Button("Comment #" + commentCounter);
            a.setIcon(VaadinIcons.CLIPBOARD_TEXT);
            a.addClickListener((Button.ClickEvent event) -> {
                if (!step.getLocked()) {
                    //Prompt if user wants this removed
                    MessageBox mb = getDeletionPrompt(attachment);
                    mb.open();
                } else {
                    displayComment(new AttachmentServer(attachment.getAttachment().getAttachmentPK()));
                }
            });
            a.setEnabled(!step.getLocked());
            comments.addComponent(a);
            break;
        }
        default: {
            Button a = new Button(attachment.getAttachment().getFileName());
            a.setEnabled(!step.getLocked());
            a.setIcon(VaadinIcons.PAPERCLIP);
            a.addClickListener((Button.ClickEvent event) -> {
                if (!step.getLocked()) {
                    //Prompt if user wants this removed
                    MessageBox mb = getDeletionPrompt(attachment);
                    mb.open();
                } else {
                    displayAttachment(new AttachmentServer(attachment.getAttachment().getAttachmentPK()));
                }
            });
            attachments.addComponent(a);
            break;
        }
        }
    }
    if (attachments.getComponentCount() > 0) {
        layout.addComponent(attachments);
    }
    if (comments.getComponentCount() > 0) {
        layout.addComponent(comments);
    }
    if (issues.getComponentCount() > 0) {
        layout.addComponent(issues);
    }
    //Add the menu
    HorizontalLayout hl = new HorizontalLayout();
    attach = new Button(TRANSLATOR.translate("add.attachment"));
    attach.setIcon(VaadinIcons.PAPERCLIP);
    attach.addClickListener((Button.ClickEvent event) -> {
        //Show dialog to upload file.
        Window dialog = new VMWindow(TRANSLATOR.translate("attach.file"));
        VerticalLayout vl = new VerticalLayout();
        MultiFileUpload multiFileUpload = new MultiFileUpload() {
            @Override
            protected void handleFile(File file, String fileName, String mimeType, long length) {
                try {
                    LOG.log(Level.FINE, "Received file {1} at: {0}",
                            new Object[] { file.getAbsolutePath(), fileName });
                    //Process the file
                    //Create the attachment
                    AttachmentServer a = new AttachmentServer();
                    a.addFile(file, fileName);
                    //Overwrite the default file name set in addFile. It'll be a temporary file name
                    a.setFileName(fileName);
                    a.write2DB();
                    //Now add it to this Execution Step
                    if (getExecutionStep().getExecutionStepHasAttachmentList() == null) {
                        getExecutionStep().setExecutionStepHasAttachmentList(new ArrayList<>());
                    }
                    getExecutionStep().addAttachment(a);
                    getExecutionStep().write2DB();
                    w.updateCurrentStep();
                } catch (Exception ex) {
                    LOG.log(Level.SEVERE, "Error creating attachment!", ex);
                }
            }
        };
        multiFileUpload.setCaption(TRANSLATOR.translate("select.files.attach"));
        vl.addComponent(multiFileUpload);
        dialog.setContent(vl);
        dialog.setHeight(25, Sizeable.Unit.PERCENTAGE);
        dialog.setWidth(25, Sizeable.Unit.PERCENTAGE);
        ValidationManagerUI.getInstance().addWindow(dialog);
    });
    hl.addComponent(attach);
    bug = new Button(TRANSLATOR.translate("create.issue"));
    bug.setIcon(VaadinIcons.BUG);
    bug.addClickListener((Button.ClickEvent event) -> {
        displayIssue(new IssueServer());
    });
    hl.addComponent(bug);
    comment = new Button(TRANSLATOR.translate("add.comment"));
    comment.setIcon(VaadinIcons.CLIPBOARD_TEXT);
    comment.addClickListener((Button.ClickEvent event) -> {
        AttachmentServer as = new AttachmentServer();
        //Get comment type
        AttachmentType type = AttachmentTypeServer.getTypeForExtension("comment");
        as.setAttachmentType(type);
        displayComment(as);
    });
    hl.addComponent(comment);
    step.update();
    attach.setEnabled(!step.getLocked());
    bug.setEnabled(!step.getLocked());
    comment.setEnabled(!step.getLocked());
    result.setEnabled(!step.getLocked());
    layout.addComponent(hl);
    return layout;
}

From source file:org.abstractform.vaadin.VaadinFormToolkit.java

License:Apache License

protected AbstractComponent internalBuildField(Field field, Map<String, Object> extraObjects) {
    AbstractComponent ret = null;//from   www.ja  v  a  2  s  .  c o m
    if (field.getType().equals(Field.TYPE_BOOL)) {
        CheckBox cb = new CheckBox(field.getName());
        cb.setImmediate(true);
        ret = cb;
    } else if (field.getType().equals(Field.TYPE_DATETIME)) {
        DateField dt = new DateField(field.getName());
        dt.setResolution(DateField.RESOLUTION_DAY);
        dt.setDescription(field.getDescription());
        dt.setRequired(field.isRequired());
        dt.setImmediate(true);
        dt.setReadOnly(field.isReadOnly());
        ret = dt;
    } else if (field.getType().equals(Field.TYPE_TEXT) || field.getType().equals(Field.TYPE_NUMERIC)
            || field.getType().equals(Field.TYPE_PASSWORD)) {
        AbstractTextField textField;
        if (field.getType().equals(Field.TYPE_PASSWORD)) {
            textField = new PasswordField(field.getName());
        } else {
            textField = new TextField(field.getName());
        }
        //textField.setColumns(field.getDisplayWidth());
        if (field.getMaxLength() != 0) {
            textField.setMaxLength(field.getMaxLength());
        }
        textField.setDescription(field.getDescription());
        textField.setReadOnly(field.isReadOnly());
        textField.setNullRepresentation("".intern());
        textField.setNullSettingAllowed(true);
        textField.setRequired(field.isRequired());
        textField.setImmediate(true);
        textField.setWidth("100%");
        ret = textField;
    } else if (field.getType().equals(SelectorConstants.TYPE_SELECTOR)) {
        ComboBox comboBox = new ComboBox(field.getName());
        comboBox.setTextInputAllowed(false);
        comboBox.setNullSelectionAllowed(!field.isRequired());
        comboBox.setDescription(field.getDescription());
        comboBox.setReadOnly(field.isReadOnly());
        comboBox.setRequired(field.isRequired());
        comboBox.setImmediate(true);
        comboBox.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
        comboBox.setItemCaptionPropertyId(VaadinSelectorContainer.PROPERTY_CAPTION);
        comboBox.setWidth("100%");
        ret = comboBox;
    } else if (field.getType().equals(TableConstants.TYPE_TABLE)) {
        ret = buildTableField(field, extraObjects);
    }
    return ret;
}

From source file:org.activiti.explorer.ui.task.NewCasePopupWindow.java

License:Apache License

protected void initForm() {
    form = new Form();
    form.setValidationVisibleOnCommit(true);
    form.setImmediate(true);/* w w  w  .j  av a 2  s . c o  m*/
    addComponent(form);

    // name
    nameField = new TextField(i18nManager.getMessage(Messages.TASK_NAME));
    nameField.focus();
    nameField.setRequired(true);
    nameField.setRequiredError(i18nManager.getMessage(Messages.TASK_NAME_REQUIRED));
    form.addField("name", nameField);

    // description
    descriptionArea = new TextArea(i18nManager.getMessage(Messages.TASK_DESCRIPTION));
    descriptionArea.setColumns(25);
    form.addField("description", descriptionArea);

    // duedate
    dueDateField = new DateField(i18nManager.getMessage(Messages.TASK_DUEDATE));
    dueDateField.setResolution(DateField.RESOLUTION_DAY);
    form.addField("duedate", dueDateField);

    // priority
    priorityComboBox = new PriorityComboBox(i18nManager);
    form.addField("priority", priorityComboBox);
}

From source file:org.casbah.ui.MainCAView.java

License:Open Source License

public void init() throws CAProviderException {

    final X509Certificate caCert = provider.getCACertificate();
    Panel panel = new Panel("CA Details");
    VerticalLayout mainLayout = new VerticalLayout();
    panel.setContent(mainLayout);//from w  w w.j av a2  s  .  c  o  m
    mainLayout.setSizeFull();
    VerticalLayout caInfo = new VerticalLayout();
    TextField name = new TextField("Distinguished Name");
    String nameValue = caCert.getSubjectX500Principal().getName();
    name.setValue(nameValue);
    name.setColumns(50);
    name.setReadOnly(true);

    TextField issuer = new TextField("Issuer");
    issuer.setColumns(50);
    issuer.setValue(caCert.getIssuerX500Principal().getName());
    issuer.setReadOnly(true);

    DateField expDate = new DateField("Expiration Date");
    expDate.setResolution(DateField.RESOLUTION_SEC);
    expDate.setValue(caCert.getNotAfter());
    expDate.setReadOnly(true);

    TextField serial = new TextField("Serial");
    serial.setValue(caCert.getSerialNumber().toString(16));
    serial.setReadOnly(true);

    caInfo.addComponent(name);
    caInfo.addComponent(issuer);
    caInfo.addComponent(expDate);
    caInfo.addComponent(serial);
    caInfo.setSizeFull();

    HorizontalLayout caButtons = new HorizontalLayout();
    caButtons.addComponent(new Button("View Certificate", new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            try {
                showEncodedCertificate(caCert, caCert.getSerialNumber().toString(16));
            } catch (CAProviderException e) {
                e.printStackTrace();
            }

        }
    }));
    caButtons.addComponent(new Button("Download Certificate", new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            try {
                downloadEncodedCertificate(caCert, caCert.getSerialNumber().toString(16));
            } catch (CAProviderException e) {
                e.printStackTrace();
            }
        }
    }));

    caButtons.addComponent(new Button("Sign a CSR", new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            try {
                uploadAndSignCsr();
            } catch (CAProviderException pe) {
                pe.printStackTrace();
            }

        }

    }));

    caButtons.addComponent(new Button("Get CRL", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                downloadCrlList(provider.getLatestCrl(false));
            } catch (CAProviderException pe) {
                logger.log(Level.SEVERE, "Could not retrieve CRL", pe);
                getWindow().showNotification("An error occurred while retrieving the CRL",
                        Notification.TYPE_ERROR_MESSAGE);
            }

        }

    }));

    panel.addComponent(caInfo);
    panel.addComponent(caButtons);
    panel.setSizeFull();
    setSizeFull();
    setCompositionRoot(panel);

}

From source file:org.jpos.qi.QIEntityView.java

License:Open Source License

protected DateField buildAndBindDateField(String id) {
    DateField dateField = new DateField(getCaptionFromId("field." + id));
    List<Validator> v = getValidators(id);
    Binder.BindingBuilder builder = getBinder().forField(dateField);
    for (Validator val : v) {
        builder.withValidator(val);
    }//from  www .jav  a  2s  . c  o  m
    if (isRequired(id)) {
        builder.asRequired(getApp().getMessage("errorMessage.req",
                StringUtils.capitalize(getCaptionFromId("field." + id))));
    }
    ;
    builder.withConverter(new LocalDateToDateConverter()).bind(id);
    return dateField;
}

From source file:org.jpos.util.FieldFactory.java

License:Open Source License

public DateField buildAndBindDateField(String id) {
    DateField dateField = new DateField(getCaptionFromId("field." + id));
    Binder.BindingBuilder builder = getBinder().forField(dateField);
    builder.withConverter(new LocalDateToDateConverter()).bind(id);
    if (viewConfig == null)
        return dateField;
    List<Validator> v = getValidators(id);
    for (Validator val : v)
        builder.withValidator(val);
    if (isRequired(id))
        builder.asRequired(getApp().getMessage("errorMessage.req",
                StringUtils.capitalize(getCaptionFromId("field." + id))));
    if ("endDate".equals(id))
        dateField.addValueChangeListener(
                (HasValue.ValueChangeListener<LocalDate>) event -> dateField.addStyleName("expired-date"));
    return dateField;
}