List of usage examples for com.vaadin.ui TextArea TextArea
public TextArea(ValueChangeListener<String> valueChangeListener)
From source file:module.pandabox.presentation.PandaBox.java
License:Open Source License
private Component getBennuInterface() { GridSystemLayout gsl = new GridSystemLayout(); gsl.setMargin(false);/*from ww w.java 2 s. c om*/ 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:net.larbig.ScriptRunnerApplication.java
License:Apache License
@Override public void init() { window = new Window("Scriptrunner"); setMainWindow(window);/* w w w . j ava 2s. c o m*/ 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.admin.AdminScreenProvider.java
License:Apache License
private Component getEmailSettingTab() { VerticalLayout s2 = new VerticalLayout(); HorizontalSplitPanel split2 = new HorizontalSplitPanel(); s2.addComponent(split2);//from w w w . j av a 2 s.com Tree sTree2 = new Tree(TRANSLATOR.translate("general.email.settings")); sTree2.addValueChangeListener((Property.ValueChangeEvent event) -> { if (sTree2.getValue() instanceof VmSetting) { VmSetting vmSetting = (VmSetting) sTree2.getValue(); split2.setSecondComponent(displaySetting(vmSetting, !vmSetting.getSetting().equals("mail.enable"))); } }); split2.setFirstComponent(sTree2); VMSettingServer.getSettings().forEach(s -> { if (s.getSetting().startsWith("mail")) { sTree2.addItem(s); sTree2.setChildrenAllowed(s, false); sTree2.setItemCaption(s, TRANSLATOR.translate(s.getSetting())); } }); Button testEmail = new Button(TRANSLATOR.translate("general.email.settings.test"), listener -> { //Show a window to test email settings VMWindow w = new VMWindow(TRANSLATOR.translate("general.email.settings.test")); VerticalLayout vl = new VerticalLayout(); TextField to = new TextField(TRANSLATOR.translate("general.email.to")); TextField from = new TextField(TRANSLATOR.translate("general.email.from")); TextField subject = new TextField(TRANSLATOR.translate("general.email.subject")); TextArea mess = new TextArea(TRANSLATOR.translate("general.email.message")); mess.setSizeFull(); TextArea output = new TextArea(TRANSLATOR.translate("general.output")); output.setReadOnly(true); output.setSizeFull(); Button send = new Button(TRANSLATOR.translate("general.email.send"), l -> { try { Lookup.getDefault().lookup(IEmailManager.class).sendEmail(to.getValue(), null, from.getValue(), subject.getValue(), mess.getValue()); output.setValue(TRANSLATOR.translate("general.email.settings.test.success")); //Successful, update the enable setting. VMSettingServer enable = new VMSettingServer("mail.enable"); enable.setBoolVal(true); enable.write2DB(); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); output.setReadOnly(false); output.setValue(sw.toString()); output.setReadOnly(true); } }); vl.addComponent(to); vl.addComponent(from); vl.addComponent(subject); vl.addComponent(mess); vl.addComponent(send); vl.addComponent(output); w.setContent(vl); w.setHeight(75, Sizeable.Unit.PERCENTAGE); w.setWidth(75, Sizeable.Unit.PERCENTAGE); ValidationManagerUI.getInstance().addWindow(w); }); s2.addComponent(testEmail); return s2; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.ExecutionStepComponent.java
License:Apache License
private void init() { FormLayout layout = new FormLayout(); setContent(layout);/*www .j a va 2 s .c om*/ 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.StepComponent.java
License:Apache License
private void init() { FormLayout layout = new FormLayout(); setContent(layout);/*from ww w .j av a 2s . co m*/ addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(s.getClass()); binder.setItemDataSource(s); Field<?> sequence = binder.buildAndBind(TRANSLATOR.translate("general.sequence"), "stepSequence"); layout.addComponent(sequence); TextArea text = new TextArea(TRANSLATOR.translate("general.text")); text.setConverter(new ByteToStringConverter()); binder.bind(text, "text"); layout.addComponent(text); TextArea result = new TextArea(TRANSLATOR.translate("expected.result")); result.setConverter(new ByteToStringConverter()); binder.bind(result, "expectedResult"); layout.addComponent(result); Field notes = binder.buildAndBind(TRANSLATOR.translate("general.notes"), "notes", TextArea.class); notes.setSizeFull(); layout.addComponent(notes); if (!s.getRequirementList().isEmpty() && !edit) { layout.addComponent(((ValidationManagerUI) UI.getCurrent()).getDisplayRequirementList( TRANSLATOR.translate("related.requirements"), s.getRequirementList())); } else { AbstractSelect requirements = ((ValidationManagerUI) UI.getCurrent()) .getRequirementSelectionComponent(); //Select the exisitng ones. if (s.getRequirementList() != null) { s.getRequirementList().forEach((r) -> { requirements.select(r); }); } requirements.addValueChangeListener(event -> { Set<Requirement> selected = (Set<Requirement>) event.getProperty().getValue(); s.getRequirementList().clear(); selected.forEach(r -> { s.getRequirementList().add(r); }); }); layout.addComponent(requirements); } DataEntryComponent fields = new DataEntryComponent(edit); binder.bind(fields, "dataEntryList"); layout.addComponent(fields); binder.setReadOnly(edit); Button cancel = new Button(TRANSLATOR.translate("general.cancel")); cancel.addClickListener((Button.ClickEvent event) -> { binder.discard(); if (s.getStepPK() == null) { ((ValidationManagerUI) UI.getCurrent()) .displayObject(((ValidationManagerUI) UI.getCurrent()).getTree().getValue()); } else { ((ValidationManagerUI) UI.getCurrent()).displayObject(s, false); } }); if (edit) { Button add = new Button(TRANSLATOR.translate("add.field")); add.addClickListener(listener -> { VMWindow w = new VMWindow(); FormLayout fl = new FormLayout(); ComboBox newType = new ComboBox(TRANSLATOR.translate("general.type")); newType.setNewItemsAllowed(false); newType.setTextInputAllowed(false); newType.addValidator(new NullValidator(TRANSLATOR.translate("message.required.field.missing") .replaceAll("%f", TRANSLATOR.translate("general.type")), false)); BeanItemContainer<DataEntryType> container = new BeanItemContainer<>(DataEntryType.class, new DataEntryTypeJpaController(DataBaseManager.getEntityManagerFactory()) .findDataEntryTypeEntities()); newType.setContainerDataSource(container); newType.getItemIds().forEach(id -> { DataEntryType temp = ((DataEntryType) id); newType.setItemCaption(id, TRANSLATOR.translate(temp.getTypeName())); }); fl.addComponent(newType); TextField tf = new TextField(TRANSLATOR.translate("general.name")); fl.addComponent(tf); HorizontalLayout hl = new HorizontalLayout(); Button a = new Button(TRANSLATOR.translate("general.add")); a.addClickListener(l -> { DataEntryType det = (DataEntryType) newType.getValue(); DataEntry de = null; switch (det.getId()) { case 1: de = DataEntryServer.getStringField(tf.getValue()); break; case 2: de = DataEntryServer.getNumericField(tf.getValue(), null, null); break; case 3: de = DataEntryServer.getBooleanField(tf.getValue()); break; case 4: de = DataEntryServer.getAttachmentField(tf.getValue()); break; } if (de != null) { s.getDataEntryList().add(de); ((ValidationManagerUI) UI.getCurrent()).displayObject(s); } UI.getCurrent().removeWindow(w); }); hl.addComponent(a); Button c = new Button(TRANSLATOR.translate("general.cancel")); c.addClickListener(l -> { UI.getCurrent().removeWindow(w); }); hl.addComponent(c); fl.addComponent(hl); w.setContent(fl); UI.getCurrent().addWindow(w); }); if (s.getStepPK() == null) { //Creating a new one Button save = new Button(TRANSLATOR.translate("general.save")); save.addClickListener(listener -> { try { s.setExpectedResult(((TextArea) result).getValue().getBytes(encoding)); s.setNotes(notes.getValue() == null ? "" : notes.getValue().toString()); s.setStepSequence(Integer.parseInt(sequence.getValue().toString())); s.setTestCase((TestCase) ((ValidationManagerUI) UI.getCurrent()).getTree().getValue()); s.setText(text.getValue().getBytes(encoding)); if (s.getRequirementList() == null) { s.setRequirementList(new ArrayList<>()); } new StepJpaController(DataBaseManager.getEntityManagerFactory()).create(s); setVisible(false); //Recreate the tree to show the addition ((ValidationManagerUI) UI.getCurrent()).updateProjectList(); ((ValidationManagerUI) UI.getCurrent()).updateScreen(); ((ValidationManagerUI) UI.getCurrent()).displayObject(s); ((ValidationManagerUI) UI.getCurrent()).buildProjectTree(s); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.creation"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } }); HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(save); hl.addComponent(add); hl.addComponent(cancel); layout.addComponent(hl); } else { //Editing existing one Button update = new Button(TRANSLATOR.translate("general.update")); update.addClickListener((Button.ClickEvent event) -> { try { s.setExpectedResult(((TextArea) result).getValue().getBytes(encoding)); s.setNotes(notes.getValue().toString()); s.setStepSequence(Integer.parseInt(sequence.getValue().toString())); s.setText(text.getValue().getBytes(encoding)); if (s.getRequirementList() == null) { s.setRequirementList(new ArrayList<>()); } ((ValidationManagerUI) UI.getCurrent()).handleVersioning(s, () -> { try { new StepJpaController(DataBaseManager.getEntityManagerFactory()).edit(s); } 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); } }); ((ValidationManagerUI) UI.getCurrent()).displayObject(s); } catch (UnsupportedEncodingException | NumberFormatException ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.creation"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } }); HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(update); hl.addComponent(add); hl.addComponent(cancel); layout.addComponent(hl); } } binder.setReadOnly(!edit); binder.bindMemberFields(this); layout.setSizeFull(); 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()); }//from ww w . j av a 2 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:net.sourceforge.javydreamercsw.validation.manager.web.notification.NotificationScreenProvider.java
License:Apache License
@Override public Component getContent() { VerticalLayout vs = new VerticalLayout(); //On top put a list of notifications BeanItemContainer<Notification> container = new BeanItemContainer<>(Notification.class); ValidationManagerUI.getInstance().getUser().getNotificationList().forEach(n -> { container.addBean(n);/*from w w w . j a va 2s . c o m*/ }); // Unable to use VerticalSplitPanel as I hoped. // See: https://github.com/vaadin/framework/issues/9460 // VerticalSplitPanel vs = new VerticalSplitPanel(); // vs.setSplitPosition(25, Sizeable.Unit.PERCENTAGE); TextArea text = new TextArea(TRANSLATOR.translate("general.text")); text.setWordwrap(true); text.setReadOnly(true); text.setSizeFull(); Grid grid = new Grid(TRANSLATOR.translate("general.notifications"), container); grid.setColumns("notificationType", "author", "creationDate", "archieved"); if (container.size() > 0) { grid.setHeightMode(HeightMode.ROW); grid.setHeightByRows(container.size() > 5 ? 5 : container.size()); } GridCellFilter filter = new GridCellFilter(grid); filter.setBooleanFilter("archieved", new GridCellFilter.BooleanRepresentation(VaadinIcons.CHECK, TRANSLATOR.translate("general.yes")), new GridCellFilter.BooleanRepresentation(VaadinIcons.CLOSE, TRANSLATOR.translate("general.no"))); filter.setDateFilter("creationDate", new SimpleDateFormat(VMSettingServer.getSetting("date.format").getStringVal()), true); grid.sort("creationDate"); Column nt = grid.getColumn("notificationType"); nt.setHeaderCaption(TRANSLATOR.translate("notification.type")); nt.setConverter(new Converter<String, NotificationType>() { @Override public NotificationType convertToModel(String value, Class<? extends NotificationType> targetType, Locale locale) throws Converter.ConversionException { for (NotificationType n : new NotificationTypeJpaController( DataBaseManager.getEntityManagerFactory()).findNotificationTypeEntities()) { if (Lookup.getDefault().lookup(InternationalizationProvider.class).translate(n.getTypeName()) .equals(value)) { return n; } } return null; } @Override public String convertToPresentation(NotificationType value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException { return Lookup.getDefault().lookup(InternationalizationProvider.class) .translate(value.getTypeName()); } @Override public Class<NotificationType> getModelType() { return NotificationType.class; } @Override public Class<String> getPresentationType() { return String.class; } }); Column author = grid.getColumn("author"); author.setConverter(new UserToStringConverter()); author.setHeaderCaption(TRANSLATOR.translate("notification.author")); Column creation = grid.getColumn("creationDate"); creation.setHeaderCaption(TRANSLATOR.translate("creation.time")); Column archive = grid.getColumn("archieved"); archive.setHeaderCaption(TRANSLATOR.translate("general.archived")); archive.setConverter(new Converter<String, Boolean>() { @Override public Boolean convertToModel(String value, Class<? extends Boolean> targetType, Locale locale) throws Converter.ConversionException { return value.equals(TRANSLATOR.translate("general.yes")); } @Override public String convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException { return value ? TRANSLATOR.translate("general.yes") : TRANSLATOR.translate("general.no"); } @Override public Class<Boolean> getModelType() { return Boolean.class; } @Override public Class<String> getPresentationType() { return String.class; } }); grid.setSelectionMode(SelectionMode.SINGLE); grid.setSizeFull(); ContextMenu menu = new ContextMenu(grid, true); menu.addItem(TRANSLATOR.translate("notification.mark.unread"), (MenuItem selectedItem) -> { Object selected = ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow(); if (selected != null) { NotificationServer ns = new NotificationServer((Notification) selected); ns.setAcknowledgeDate(null); try { ns.write2DB(); ((VMUI) UI.getCurrent()).updateScreen(); ((VMUI) UI.getCurrent()).showTab(getComponentCaption()); } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } }); menu.addItem(TRANSLATOR.translate("notification.archive"), (MenuItem selectedItem) -> { Object selected = ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow(); if (selected != null) { NotificationServer ns = new NotificationServer((Notification) selected); ns.setArchieved(true); try { ns.write2DB(); ((VMUI) UI.getCurrent()).updateScreen(); ((VMUI) UI.getCurrent()).showTab(getComponentCaption()); } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } }); grid.addSelectionListener(selectionEvent -> { // Get selection from the selection model Object selected = ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow(); if (selected != null) { text.setReadOnly(false); Notification n = (Notification) selected; text.setValue(n.getContent()); text.setReadOnly(true); if (n.getAcknowledgeDate() != null) { try { //Mark as read NotificationServer ns = new NotificationServer((Notification) n); ns.setAcknowledgeDate(new Date()); ns.write2DB(); } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } } }); vs.addComponent(grid); vs.addComponent(text); vs.setSizeFull(); vs.setId(getComponentCaption()); return vs; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.wizard.plan.DetailStep.java
License:Apache License
@Override public Component getContent() { Panel form = new Panel("execution.detail"); FormLayout layout = new FormLayout(); form.setContent(layout);/*from w w w . j a v a 2 s.c om*/ form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(TestCaseExecution.class); binder.setItemDataSource(tce); TextArea name = new TextArea("general.name"); name.setConverter(new ByteToStringConverter()); binder.bind(name, "name"); layout.addComponent(name); TextArea scope = new TextArea("general.scope"); scope.setConverter(new ByteToStringConverter()); binder.bind(scope, "scope"); layout.addComponent(scope); if (tce.getId() != null) { TextArea conclusion = new TextArea("general.conclusion"); conclusion.setConverter(new ByteToStringConverter()); binder.bind(conclusion, "conclusion"); layout.addComponent(conclusion); conclusion.setSizeFull(); layout.addComponent(conclusion); } binder.setBuffered(false); binder.bindMemberFields(form); form.setSizeFull(); return form; }
From source file:nl.kpmg.lcm.ui.view.metadata.MetadataCreateWindow.java
License:Apache License
private FormLayout initSectionPanel() { nameField = new TextField("Name"); nameField.setWidth("100%"); sectionPanel.addComponent(nameField); dataView = new TextArea("Data"); dataView.setWidth("100%"); dataView.setHeight(TEXT_AREA_HEIGHT); sectionPanel.addComponent(dataView); expirationTimesView = new TextArea("Expiration times"); expirationTimesView.setWidth("100%"); expirationTimesView.setHeight(TEXT_AREA_HEIGHT); sectionPanel.addComponent(expirationTimesView); generalInfoView = new TextArea("General Info"); generalInfoView.setWidth("100%"); generalInfoView.setHeight(TEXT_AREA_HEIGHT); sectionPanel.addComponent(generalInfoView); enrichmentPropertiesView = new TextArea("Enrichment Properties"); enrichmentPropertiesView.setWidth("100%"); enrichmentPropertiesView.setHeight(TEXT_AREA_HEIGHT); sectionPanel.addComponent(enrichmentPropertiesView); dynamicDataView = new TextArea("Dynamic data"); dynamicDataView.setWidth("100%"); dynamicDataView.setHeight(TEXT_AREA_HEIGHT); sectionPanel.addComponent(dynamicDataView); sectionPanel.setMargin(true);/*w w w . j a v a 2 s . co m*/ sectionPanel.setHeight(PANEL_HEIGHT); return sectionPanel; }
From source file:nl.kpmg.lcm.ui.view.metadata.MetadataCreateWindow.java
License:Apache License
private VerticalLayout initRawPanel() { rawView = new TextArea("Raw metadata"); rawView.setWidth("100%"); rawView.setHeight("100%"); rawPanel.setMargin(true);//w ww. ja v a 2 s . c o m rawPanel.addComponent(rawView); rawPanel.setHeight(PANEL_HEIGHT); return rawPanel; }