Example usage for com.vaadin.ui TextField setValue

List of usage examples for com.vaadin.ui TextField setValue

Introduction

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

Prototype

@Override
public void setValue(String value) 

Source Link

Document

Sets the value of this text field.

Usage

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

License:Open Source License

private static Layout getSystemErrorTester() {
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);/*  ww  w  .  jav a  2 s .  co m*/

    Button button = new Button("click me to show error", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            throw new Error("badabum");
        }
    });
    layout.addComponent(button);

    final TextField txtCaption = new TextField("caption");
    txtCaption.setValue("Notification Caption");

    final TextField txtMessage = new TextField("message");
    txtMessage.setValue("Notification Message");

    final TextField txtDelay = new TextField("delay (msec)");
    txtDelay.setValue("2000");

    final Select position = new Select("Position");
    position.setNullSelectionAllowed(false);

    final int[] positions = { Window.Notification.POSITION_BOTTOM_LEFT,
            Window.Notification.POSITION_BOTTOM_RIGHT, Window.Notification.POSITION_CENTERED,
            Window.Notification.POSITION_CENTERED_BOTTOM, Window.Notification.POSITION_CENTERED_TOP,
            Window.Notification.POSITION_TOP_LEFT, Window.Notification.POSITION_TOP_RIGHT };

    final String[] posLabels = { "BOTTOM_LEFT", " BOTTOM_RIGHT", "CENTERED", "CENTERED_BOTTOM", "CENTERED_TOP",
            "TOP_LEFT", "TOP_RIGHT" };

    for (int i = 0; i < positions.length; i++) {
        int pos = positions[i];
        position.addItem(pos);
        position.setItemCaption(pos, posLabels[i]);
    }

    position.select(position.getContainerDataSource().getItem(0));

    layout.addComponent(txtCaption);
    layout.addComponent(txtMessage);
    layout.addComponent(txtDelay);
    layout.addComponent(position);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);

    final int[] types = { Window.Notification.TYPE_ERROR_MESSAGE, Window.Notification.TYPE_HUMANIZED_MESSAGE,
            Window.Notification.TYPE_TRAY_NOTIFICATION, Window.Notification.TYPE_WARNING_MESSAGE };
    final String[] labels = { "error", "humanized", "tray", "warning" };
    for (int i = 0; i < types.length; i++) {
        final int type = types[i];
        Button btNotif = new Button(labels[i], new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                Window.Notification notif = new Window.Notification((String) txtCaption.getValue(),
                        (String) txtMessage.getValue(), type);
                notif.setPosition((Integer) position.getValue());
                notif.setDelayMsec(Integer.parseInt((String) txtDelay.getValue()));
                event.getButton().getApplication().getMainWindow().showNotification(notif);
            }
        });
        hl.addComponent(btNotif);
    }

    layout.addComponent(hl);
    return layout;
}

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

License:Open Source License

private Layout getTextFieldPreviews() {
    Layout grid = getPreviewLayout("Text fields");

    TextField tf = new TextField();
    tf.setValue("Text field");
    grid.addComponent(tf);//from www  .  java  2s. co m

    tf = new TextField();
    tf.setValue("Small field");
    tf.setStyleName("small");
    grid.addComponent(tf);

    tf = new TextField();
    tf.setValue("Big field");
    tf.setStyleName("big");
    tf.setComponentError(new UserError("Test error"));
    grid.addComponent(tf);

    tf = new TextField();
    tf.setInputPrompt("Search field");
    tf.setStyleName("search");
    grid.addComponent(tf);

    tf = new TextField();
    tf.setInputPrompt("Small search");
    tf.setStyleName("search small");
    grid.addComponent(tf);

    tf = new TextField();
    tf.setInputPrompt("Big search");
    tf.setStyleName("search big");
    grid.addComponent(tf);

    tf = new TextField("Error");
    tf.setComponentError(new UserError("Test error"));
    grid.addComponent(tf);

    tf = new TextField();
    tf.setInputPrompt("Error");
    tf.setComponentError(new UserError("Test error"));
    grid.addComponent(tf);

    tf = new TextField();
    tf.setInputPrompt("Small error");
    tf.setStyleName("small");
    tf.setComponentError(new UserError("Test error"));
    grid.addComponent(tf);

    TextArea ta = new TextArea();
    ta.setInputPrompt("Multiline");
    ta.setRows(4);
    grid.addComponent(ta);

    ta = new TextArea();
    ta.setInputPrompt("Small multiline");
    ta.setStyleName("small");
    ta.setRows(4);
    grid.addComponent(ta);

    ta = new TextArea();
    ta.setInputPrompt("Big multiline");
    ta.setStyleName("big");
    ta.setRows(4);
    grid.addComponent(ta);

    return grid;
}

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

public Forms() {
    setSpacing(true);/*from w  w w.  ja  v a  2  s.  co  m*/
    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.larbig.ScriptRunnerApplication.java

License:Apache License

@Override
public void init() {
    window = new Window("Scriptrunner");
    setMainWindow(window);//from w w  w. j a  v  a 2s  .  com

    VerticalLayout layout = new VerticalLayout();
    final TextField tfDriver = new TextField("Driver");
    tfDriver.setWidth(300, Sizeable.UNITS_PIXELS);
    tfDriver.setValue("com.mysql.jdbc.Driver");
    final TextField tfURL = new TextField("URL");
    tfURL.setWidth(300, Sizeable.UNITS_PIXELS);
    tfURL.setValue("jdbc:mysql://mysql.host.net:3306/datenbank");
    final TextField tfUser = new TextField("User");
    tfUser.setWidth(300, Sizeable.UNITS_PIXELS);
    final TextField tfPasswort = new TextField("Password");
    tfPasswort.setWidth(300, Sizeable.UNITS_PIXELS);
    final TextArea taSQL = new TextArea("SQL");
    taSQL.setWidth(300, Sizeable.UNITS_PIXELS);
    taSQL.setHeight(150, Sizeable.UNITS_PIXELS);

    Button button = new Button("Execute");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {

            try {
                Class.forName((String) tfDriver.getValue()).newInstance();
                Connection con = DriverManager.getConnection(tfURL.getValue().toString(),
                        tfUser.getValue().toString(), tfPasswort.getValue().toString());
                ScriptRunner runner = new ScriptRunner(con, false, true);
                Reader r = new StringReader(taSQL.getValue().toString());
                runner.runScript(r);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });

    layout.addComponent(tfDriver);
    layout.addComponent(tfURL);
    layout.addComponent(tfUser);
    layout.addComponent(tfPasswort);
    layout.addComponent(taSQL);
    layout.addComponent(button);
    window.addComponent(layout);

}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.about.AboutProvider.java

License:Apache License

@Override
public Component getContent() {
    VerticalLayout vl = new VerticalLayout();
    vl.addComponent(new Image("", LOGO));
    TextField version = new TextField(TRANSLATOR.translate("general.version"));
    version.setValue(((ValidationManagerUI) UI.getCurrent()).getVersion());
    version.setReadOnly(true);/*from   ww  w  . j  av  a2 s  .c om*/
    vl.addComponent(version);
    TextField build = new TextField(TRANSLATOR.translate("general.build"));
    build.setValue(((ValidationManagerUI) UI.getCurrent()).getBuild());
    build.setReadOnly(true);
    vl.addComponent(build);
    TextArea desc = new TextArea();
    desc.setValue("Validation Manager is a tool to handle all the "
            + "cumbersome paperwork of regulated environment validations. "
            + "Including Validation Plans, protocols, "
            + "executions and exceptions. Keeping everything in one " + "place and best of all paperless. ");
    desc.setReadOnly(true);
    desc.setWidth(100, Unit.PERCENTAGE);
    Link link = new Link("Get more information here",
            new ExternalResource("https://github.com/javydreamercsw/validation-manager"));
    vl.addComponent(desc);
    vl.addComponent(link);
    vl.setId(getComponentCaption());
    return vl;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.ExecutionStepComponent.java

License:Apache License

private void init() {
    FormLayout layout = new FormLayout();
    setContent(layout);/* w w  w  . j av  a 2s .c  o m*/
    addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(es.getClass());
    binder.setItemDataSource(es);
    FieldGroupFieldFactory defaultFactory = binder.getFieldFactory();
    binder.setFieldFactory(new FieldGroupFieldFactory() {

        @Override
        public <T extends Field> T createField(Class<?> dataType, Class<T> fieldType) {
            if (dataType.isAssignableFrom(VmUser.class)) {
                BeanItemContainer<VmUser> userEntityContainer = new BeanItemContainer<>(VmUser.class);
                userEntityContainer.addBean(es.getAssignee());
                Field field = new TextField(
                        es.getAssignee() == null ? TRANSLATOR.translate("general.not.applicable")
                                : es.getAssignee().getFirstName() + " " + es.getAssignee().getLastName());
                return fieldType.cast(field);
            }

            return defaultFactory.createField(dataType, fieldType);
        }
    });
    layout.addComponent(((VMUI) UI.getCurrent()).createStepHistoryTable(TRANSLATOR.translate("step.detail"),
            Arrays.asList(es.getStepHistory()), false));
    if (es.getResultId() != null) {
        Field<?> result = binder.buildAndBind(TRANSLATOR.translate("general.result"), "resultId.resultName");
        layout.addComponent(result);
    }
    if (es.getComment() != null) {
        TextArea comment = new TextArea(TRANSLATOR.translate("general.comment"));
        binder.bind(comment, "comment");
        layout.addComponent(comment);
    }
    if (es.getAssignee() != null) {
        TextField assignee = new TextField(TRANSLATOR.translate("general.assignee"));
        VmUser u = es.getAssignee();
        assignee.setValue(u.toString());
        assignee.setReadOnly(true);
        layout.addComponent(assignee);
    }
    if (es.getExecutionStart() != null) {
        Field<?> start = binder.buildAndBind(TRANSLATOR.translate("execution.start"), "executionStart");
        layout.addComponent(start);
    }
    if (es.getExecutionEnd() != null) {
        Field<?> end = binder.buildAndBind(TRANSLATOR.translate("execution.end"), "executionEnd");
        layout.addComponent(end);
    }
    if (es.getExecutionTime() != null && es.getExecutionTime() > 0) {
        Field<?> time = binder.buildAndBind(TRANSLATOR.translate("execution.time"), "executionTime");
        layout.addComponent(time);
    }
    if (!es.getHistoryList().isEmpty()) {
        layout.addComponent(((VMUI) UI.getCurrent()).createRequirementHistoryTable(
                TRANSLATOR.translate("related.requirements"), es.getHistoryList(), true));
    }
    Button cancel = new Button(TRANSLATOR.translate("general.cancel"));
    cancel.addClickListener((Button.ClickEvent event) -> {
        binder.discard();
        if (es.getExecutionStepPK() == null) {
            ((VMUI) UI.getCurrent()).displayObject(((VMUI) UI.getCurrent()).getSelectdValue());
        } else {
            ((VMUI) UI.getCurrent()).displayObject(es, false);
        }
    });
    binder.setReadOnly(true);
    binder.bindMemberFields(this);
    layout.setSizeFull();
    setSizeFull();
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.RequirementComponent.java

License:Apache License

private void init() {
    FormLayout layout = new FormLayout();
    setContent(layout);//from  w w w.jav  a2s  .  com
    addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(req.getClass());
    binder.setItemDataSource(req);
    TextField id = (TextField) binder.buildAndBind(TRANSLATOR.translate("requirement.id"), "uniqueId",
            TextField.class);
    id.setNullRepresentation("");
    layout.addComponent(id);
    TextArea desc = (TextArea) binder.buildAndBind(TRANSLATOR.translate("general.description"), "description",
            TextArea.class);
    desc.setNullRepresentation("");
    desc.setSizeFull();
    layout.addComponent(desc);
    TextArea notes = (TextArea) binder.buildAndBind(TRANSLATOR.translate("general.notes"), "notes",
            TextArea.class);
    notes.setNullRepresentation("");
    notes.setSizeFull();
    layout.addComponent(notes);
    if (req.getParentRequirementId() != null) {
        TextField tf = new TextField(TRANSLATOR.translate("general.parent"));
        tf.setValue(req.getParentRequirementId().getUniqueId());
        tf.setReadOnly(true);
        layout.addComponent(tf);
    }
    if (req.getRequirementList() == null) {
        req.setRequirementList(new ArrayList<>());
    }
    if (!req.getRequirementList().isEmpty() && !edit) {
        layout.addComponent(((VMUI) UI.getCurrent()).getDisplayRequirementList(
                TRANSLATOR.translate("related.requirements"), req.getRequirementList()));
    } else if (edit) {
        //Allow user to add children
        AbstractSelect as = ((VMUI) UI.getCurrent()).getRequirementSelectionComponent();
        req.getRequirementList().forEach(sub -> {
            as.select(sub);
        });
        as.addValueChangeListener(event -> {
            Set<Requirement> selected = (Set<Requirement>) event.getProperty().getValue();
            req.getRequirementList().clear();
            selected.forEach(r -> {
                req.getRequirementList().add(r);
            });
        });
        layout.addComponent(as);
    }
    Button cancel = new Button(TRANSLATOR.translate("general.cancel"));
    cancel.addClickListener((Button.ClickEvent event) -> {
        binder.discard();
        if (req.getId() == null) {
            ((VMUI) UI.getCurrent()).displayObject(req.getRequirementSpecNode());
        } else {
            ((VMUI) UI.getCurrent()).displayObject(req, false);
        }
    });
    if (edit) {
        if (req.getId() == null) {
            //Creating a new one
            Button save = new Button(TRANSLATOR.translate("general.save"));
            save.addClickListener((Button.ClickEvent event) -> {
                req.setUniqueId(id.getValue().toString());
                req.setNotes(notes.getValue().toString());
                req.setDescription(desc.getValue().toString());
                req.setRequirementSpecNode((RequirementSpecNode) ((VMUI) UI.getCurrent()).getSelectdValue());
                new RequirementJpaController(DataBaseManager.getEntityManagerFactory()).create(req);
                setVisible(false);
                //Recreate the tree to show the addition
                ((VMUI) UI.getCurrent()).buildProjectTree(req);
                ((VMUI) UI.getCurrent()).displayObject(req, true);
            });
            HorizontalLayout hl = new HorizontalLayout();
            hl.addComponent(save);
            hl.addComponent(cancel);
            layout.addComponent(hl);
        } else {
            //Editing existing one
            Button update = new Button(TRANSLATOR.translate("general.update"));
            update.addClickListener((Button.ClickEvent event) -> {
                try {
                    RequirementServer rs = new RequirementServer(req);
                    rs.setDescription(((TextArea) desc).getValue());
                    rs.setNotes(((TextArea) notes).getValue());
                    rs.setUniqueId(((TextField) id).getValue());
                    ((VMUI) UI.getCurrent()).handleVersioning(rs, () -> {
                        try {
                            rs.write2DB();
                            //Recreate the tree to show the addition
                            ((VMUI) UI.getCurrent()).buildProjectTree(rs.getEntity());
                            ((VMUI) UI.getCurrent()).displayObject(rs.getEntity(), false);
                        } catch (NonexistentEntityException ex) {
                            LOG.log(Level.SEVERE, null, ex);
                            Notification.show(TRANSLATOR.translate("general.error.record.update"),
                                    ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                        } catch (Exception ex) {
                            LOG.log(Level.SEVERE, null, ex);
                            Notification.show(TRANSLATOR.translate("general.error.record.update"),
                                    ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                        }
                    });
                    setVisible(false);
                } catch (VMException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                    Notification.show(TRANSLATOR.translate("general.error.record.update"),
                            ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                }
            });
            HorizontalLayout hl = new HorizontalLayout();
            hl.addComponent(update);
            hl.addComponent(cancel);
            layout.addComponent(hl);
        }
    }
    try {
        //Add a history section
        if (req.getId() != null) {
            List<History> versions = new RequirementServer(req).getHistoryList();
            if (!versions.isEmpty()) {
                layout.addComponent(((VMUI) UI.getCurrent()).createRequirementHistoryTable(
                        TRANSLATOR.translate("general.history"), versions, true));
            }
        }
    } catch (VMException ex) {
        LOG.log(Level.SEVERE, null, ex);
    }
    binder.setBuffered(true);
    binder.setReadOnly(!edit);
    binder.bindMemberFields(this);
    setSizeFull();
}

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());
    }//w ww . j  a v a2  s.c  om
    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.activiti.explorer.ui.process.simple.editor.table.TaskTable.java

License:Apache License

protected Object addTaskRow(Object previousTaskItemId, String taskName, String taskAssignee, String taskGroups,
        String taskDescription, Boolean startWithPrevious) {

    Object newItemId = null;// w  w  w  .ja v  a2s.c  o  m
    if (previousTaskItemId == null) { // add at the end of list
        newItemId = addItem();
    } else {
        newItemId = addItemAfter(previousTaskItemId);
    }
    Item newItem = getItem(newItemId);

    // name
    newItem.getItemProperty(ID_NAME).setValue(taskName == null ? "my task" : taskName);

    // assignee
    ComboBox assigneeComboBox = new ComboBox();
    assigneeComboBox.setNullSelectionAllowed(true);

    try {
        for (User user : ProcessEngines.getDefaultProcessEngine().getIdentityService().createUserQuery()
                .orderByUserFirstName().asc().list()) {
            assigneeComboBox.addItem(user.getId());
            assigneeComboBox.setItemCaption(user.getId(), user.getFirstName() + " " + user.getLastName());
        }
    } catch (Exception e) {
        // Don't do anything. Will be an empty dropdown.
    }

    if (taskAssignee != null) {
        assigneeComboBox.select(taskAssignee);
    }

    newItem.getItemProperty(ID_ASSIGNEE).setValue(assigneeComboBox);

    // groups
    ComboBox groupComboBox = new ComboBox();
    groupComboBox.setNullSelectionAllowed(true);

    try {
        for (Group group : ProcessEngines.getDefaultProcessEngine().getIdentityService().createGroupQuery()
                .orderByGroupName().asc().list()) {
            groupComboBox.addItem(group.getId());
            groupComboBox.setItemCaption(group.getId(), group.getName());
        }
    } catch (Exception e) {
        // Don't do anything. Will be an empty dropdown.
    }

    if (taskGroups != null) {
        groupComboBox.select(taskGroups);
    }

    newItem.getItemProperty(ID_GROUPS).setValue(groupComboBox);

    // description
    TextField descriptionTextField = new TextField();
    descriptionTextField.setColumns(16);
    descriptionTextField.setRows(1);
    if (taskDescription != null) {
        descriptionTextField.setValue(taskDescription);
    }
    newItem.getItemProperty(ID_DESCRIPTION).setValue(descriptionTextField);

    // concurrency
    CheckBox startWithPreviousCheckBox = new CheckBox(
            i18nManager.getMessage(Messages.PROCESS_EDITOR_TASK_START_WITH_PREVIOUS));
    startWithPreviousCheckBox.setValue(startWithPrevious == null ? false : startWithPrevious);
    newItem.getItemProperty(ID_START_WITH_PREVIOUS).setValue(startWithPreviousCheckBox);

    // actions
    newItem.getItemProperty(ID_ACTIONS).setValue(generateActionButtons(newItemId));

    return newItemId;
}

From source file:org.activiti.explorer.ui.profile.AccountSelectionPopup.java

License:Apache License

protected void initImapComponent() {
    imapForm = new Form();
    imapForm.setDescription(i18nManager.getMessage(Messages.IMAP_DESCRIPTION));

    final TextField imapServer = new TextField(i18nManager.getMessage(Messages.IMAP_SERVER));
    imapForm.getLayout().addComponent(imapServer);

    final TextField imapPort = new TextField(i18nManager.getMessage(Messages.IMAP_PORT));
    imapPort.setWidth(30, UNITS_PIXELS);
    imapPort.setValue(143); // Default imap port (non-ssl)
    imapForm.getLayout().addComponent(imapPort);

    final CheckBox useSSL = new CheckBox(i18nManager.getMessage(Messages.IMAP_SSL));
    useSSL.setValue(false);/*from  ww w. j  av a2 s .c o m*/
    useSSL.setImmediate(true);
    imapForm.getLayout().addComponent(useSSL);
    useSSL.addListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            imapPort.setValue(((Boolean) useSSL.getValue()) ? 993 : 143);
        }
    });

    final TextField imapUserName = new TextField(i18nManager.getMessage(Messages.IMAP_USERNAME));
    imapForm.getLayout().addComponent(imapUserName);

    final PasswordField imapPassword = new PasswordField(i18nManager.getMessage(Messages.IMAP_PASSWORD));
    imapForm.getLayout().addComponent(imapPassword);

    // Matching listener
    imapClickListener = new ClickListener() {
        public void buttonClick(ClickEvent event) {
            Map<String, Object> accountDetails = createAccountDetails("imap",
                    imapUserName.getValue().toString(), imapPassword.getValue().toString(), "server",
                    imapServer.getValue().toString(), "port", imapPort.getValue().toString(), "ssl",
                    imapPort.getValue().toString());
            fireEvent(new SubmitEvent(AccountSelectionPopup.this, SubmitEvent.SUBMITTED, accountDetails));
        }
    };
}