List of usage examples for com.vaadin.ui FormLayout addComponent
@Override public void addComponent(Component c)
From source file:management.limbr.ui.entity.EntityEditorViewImpl.java
License:Open Source License
@PostConstruct public void init() { FormLayout content = new FormLayout(); content.setWidthUndefined();/*from w w w . j a va2 s. c o m*/ for (java.lang.reflect.Field field : entityClass.getDeclaredFields()) { if ("id".equals(field.getName())) { continue; } Field uiField = getUIField(field); fieldMap.put(field.getName(), uiField); content.addComponent(uiField); } save = new Button(messages.get("saveButtonLabel"), FontAwesome.SAVE); Button cancel = new Button(messages.get("cancelButtonLabel")); delete = new Button(messages.get("deleteButtonLabel"), FontAwesome.TRASH_O); CssLayout actions = new CssLayout(save, cancel, delete); content.addComponent(actions); content.setMargin(true); setContent(content); setClosable(true); setResizable(false); setModal(true); save.addClickListener(event -> listeners.forEach(EntityEditorView.Listener::save)); delete.addClickListener(event -> listeners.forEach(EntityEditorView.Listener::deleteClicked)); cancel.addClickListener(event -> listeners.forEach(EntityEditorView.Listener::cancel)); }
From source file:my.vaadin.profile.Forms.java
public Forms() { setSpacing(true);/*from w w w . j a v a 2s . c o 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.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java
License:Apache License
private Component displaySetting(VmSetting s, boolean edit) { Panel form = new Panel(TRANSLATOR.translate("setting.detail")); FormLayout layout = new FormLayout(); form.setContent(layout);// w w w . j a v a 2 s . com form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(s.getClass()); binder.setItemDataSource(s); Field<?> id = (TextField) binder.buildAndBind(TRANSLATOR.translate("general.setting"), "setting"); layout.addComponent(id); Field bool = binder.buildAndBind(TRANSLATOR.translate("bool.value"), "boolVal"); bool.setSizeFull(); layout.addComponent(bool); Field integerVal = binder.buildAndBind(TRANSLATOR.translate("int.value"), "intVal"); integerVal.setSizeFull(); layout.addComponent(integerVal); Field longVal = binder.buildAndBind(TRANSLATOR.translate("long.val"), "longVal"); longVal.setSizeFull(); layout.addComponent(longVal); Field stringVal = binder.buildAndBind(TRANSLATOR.translate("string.val"), "stringVal", TextArea.class); stringVal.setSizeFull(); layout.addComponent(stringVal); Button cancel = new Button(TRANSLATOR.translate("general.cancel")); cancel.addClickListener((Button.ClickEvent event) -> { binder.discard(); }); //Editing existing one Button update = new Button(TRANSLATOR.translate("general.update")); update.addClickListener((Button.ClickEvent event) -> { try { binder.commit(); displaySetting(s); } catch (FieldGroup.CommitException ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate("general.error.record.update"), ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } }); boolean blocked = !s.getSetting().startsWith("version."); if (blocked) { HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(update); hl.addComponent(cancel); layout.addComponent(hl); } binder.setBuffered(true); binder.setReadOnly(edit); binder.bindMemberFields(form); //The version settigns are not modifiable from the GUI binder.setEnabled(blocked); //Id is always blocked. id.setEnabled(false); form.setSizeFull(); return form; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.BaselineComponent.java
License:Apache License
public BaselineComponent(Baseline baseline, boolean edit, RequirementSpec rs) { super(TRANSLATOR.translate("baseline.detail")); FormLayout layout = new FormLayout(); setContent(layout);/* ww w . j av a2 s. c om*/ addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(baseline.getClass()); binder.setItemDataSource(baseline); Field<?> id = binder.buildAndBind(TRANSLATOR.translate("general.name"), "baselineName"); layout.addComponent(id); Field desc = binder.buildAndBind(TRANSLATOR.translate("general.description"), "description", TextArea.class); desc.setSizeFull(); layout.addComponent(desc); Button cancel = new Button(TRANSLATOR.translate("general.cancel")); if (rs != null) { List<History> potential = new ArrayList<>(); Tool.extractRequirements(rs).forEach((r) -> { potential.add(r.getHistoryList().get(r.getHistoryList().size() - 1)); }); layout.addComponent(((ValidationManagerUI) UI.getCurrent()) .createRequirementHistoryTable(TRANSLATOR.translate("included.requirements"), potential, true)); } else { layout.addComponent(((ValidationManagerUI) UI.getCurrent()).createRequirementHistoryTable( TRANSLATOR.translate("included.requirements"), baseline.getHistoryList(), true)); } cancel.addClickListener((Button.ClickEvent event) -> { binder.discard(); ((ValidationManagerUI) UI.getCurrent()) .displayObject(((ValidationManagerUI) UI.getCurrent()).getTree().getValue()); }); if (edit) { if (baseline.getId() == null) { //Creating a new one Button save = new Button(TRANSLATOR.translate("general.save")); save.addClickListener((Button.ClickEvent event) -> { try { binder.commit(); if (rs != null) { MessageBox prompt = MessageBox.createQuestion() .withCaption(TRANSLATOR.translate("save.baseline.title")) .withMessage(TRANSLATOR.translate("save.baseine.message") + "requirements will be released to a new major version") .withYesButton(() -> { Baseline entity = BaselineServer.createBaseline(baseline.getBaselineName(), baseline.getDescription(), rs).getEntity(); ((ValidationManagerUI) UI.getCurrent()).updateProjectList(); ((ValidationManagerUI) UI.getCurrent()).buildProjectTree(entity); ((ValidationManagerUI) UI.getCurrent()).displayObject(entity, false); ((ValidationManagerUI) UI.getCurrent()).updateScreen(); }, ButtonOption.focus(), ButtonOption.icon(VaadinIcons.CHECK)) .withNoButton(() -> { ((ValidationManagerUI) UI.getCurrent()).displayObject( ((ValidationManagerUI) UI.getCurrent()).getTree().getValue()); }, ButtonOption.icon(VaadinIcons.CLOSE)); prompt.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); prompt.open(); } else { //Recreate the tree to show the addition ((ValidationManagerUI) UI.getCurrent()).displayObject(baseline, true); } ((ValidationManagerUI) UI.getCurrent()).updateProjectList(); ((ValidationManagerUI) UI.getCurrent()).updateScreen(); } catch (FieldGroup.CommitException ex) { LOG.log(Level.SEVERE, null, ex); } }); 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 { ((ValidationManagerUI) UI.getCurrent()).handleVersioning(baseline, () -> { try { new BaselineJpaController(DataBaseManager.getEntityManagerFactory()).edit(baseline); //Recreate the tree to show the addition ((ValidationManagerUI) UI.getCurrent()).buildProjectTree(baseline); ((ValidationManagerUI) UI.getCurrent()).displayBaseline(baseline, 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); } }); } catch (Exception 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); } } binder.setBuffered(true); binder.setReadOnly(!edit); binder.bindMemberFields(this); setSizeFull(); }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.DataEntryComponent.java
License:Apache License
@Override protected Component initContent() { Panel p = new Panel(); FormLayout layout = new FormLayout(); p.setContent(layout);// w ww . ja v a2 s . c o m getInternalValue().forEach(de -> { BeanFieldGroup binder = new BeanFieldGroup(de.getClass()); binder.setItemDataSource(de); TextField name = new TextField(TRANSLATOR.translate("general.name")); binder.bind(name, "entryName"); name.setConverter(new TranslationConverter()); layout.addComponent(name); TextField type = new TextField(TRANSLATOR.translate("general.type")); type.setConverter(new Converter<String, DataEntryType>() { @Override public DataEntryType convertToModel(String value, Class<? extends DataEntryType> targetType, Locale locale) throws Converter.ConversionException { for (DataEntryType det : DataEntryTypeServer.getTypes()) { if (TRANSLATOR.translate(det.getTypeName()).equals(value)) { return det; } } return null; } @Override public String convertToPresentation(DataEntryType value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException { return TRANSLATOR.translate(value.getTypeName()); } @Override public Class<DataEntryType> getModelType() { return DataEntryType.class; } @Override public Class<String> getPresentationType() { return String.class; } }); DataEntryPropertyComponent properties = new DataEntryPropertyComponent(edit); binder.bind(type, "dataEntryType"); layout.addComponent(type); binder.bind(properties, "dataEntryPropertyList"); layout.addComponent(properties); binder.setReadOnly(!edit); type.setReadOnly(true); }); return p; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.DataEntryPropertyComponent.java
License:Apache License
@Override protected Component initContent() { Panel p = new Panel(); FormLayout l = new FormLayout(); getInternalValue().forEach(prop -> { if (!prop.getPropertyName().equals("property.expected.result")) { HorizontalLayout hl = new HorizontalLayout(); TextField tf = new TextField(TRANSLATOR.translate(prop.getPropertyName()), prop.getPropertyValue()); hl.addComponent(tf);//from ww w . j ava 2s .c o m if (edit) { //Add button for deleting this property. Button delete = new Button(); delete.setIcon(VaadinIcons.MINUS); delete.addClickListener(listener -> { getInternalValue().remove(prop); l.removeComponent(hl); }); hl.addComponent(delete); } l.addComponent(hl); } }); p.setContent(l); return p; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.DataEntryTypeComponent.java
License:Apache License
@Override protected Component initContent() { Panel p = new Panel(); FormLayout l = new FormLayout(); p.setContent(l);/*from w w w . j a va 2s .c o m*/ BeanFieldGroup binder = new BeanFieldGroup(getInternalValue().getClass()); binder.setItemDataSource(getInternalValue()); l.addComponent(binder.buildAndBind(TRANSLATOR.translate("general.name"), "typeName")); l.addComponent(binder.buildAndBind(TRANSLATOR.translate("general.description"), "typeDescription")); binder.setReadOnly(!edit); return p; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.ExecutionStepComponent.java
License:Apache License
private void init() { FormLayout layout = new FormLayout(); setContent(layout);/*from w ww .ja v a 2 s . co 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.IssueResolutionComponent.java
License:Apache License
private void init() { FormLayout layout = new FormLayout(); setContent(layout);/* ww w . j ava 2 s . c om*/ addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(ir.getClass()); binder.setItemDataSource(ir); Field<?> name = binder.buildAndBind(TRANSLATOR.translate("general.name"), "name"); layout.addComponent(name); if (edit) { Button update = new Button(ir.getId() == null ? TRANSLATOR.translate("general.create") : TRANSLATOR.translate("general.update")); update.addClickListener((Button.ClickEvent event) -> { IssueResolutionJpaController c = new IssueResolutionJpaController( DataBaseManager.getEntityManagerFactory()); if (ir.getId() == null) { ir.setName((String) name.getValue()); c.create(ir); } else { try { binder.commit(); } catch (FieldGroup.CommitException ex) { LOG.log(Level.SEVERE, null, ex); } } }); Button cancel = new Button( Lookup.getDefault().lookup(InternationalizationProvider.class).translate("general.cancel")); cancel.addClickListener((Button.ClickEvent event) -> { binder.discard(); ((VMUI) UI.getCurrent()).updateScreen(); }); binder.setReadOnly(!edit); binder.setBuffered(true); HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(update); hl.addComponent(cancel); layout.addComponent(hl); } }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.IssueTypeComponent.java
License:Apache License
private void init() { FormLayout layout = new FormLayout(); setContent(layout);// w w w.java 2s . c om addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(it.getClass()); binder.setItemDataSource(it); Field<?> name = binder.buildAndBind(TRANSLATOR.translate("general.name"), "typeName"); layout.addComponent(name); Field<?> desc = binder.buildAndBind(TRANSLATOR.translate("general.description"), "description"); layout.addComponent(desc); if (edit) { Button update = new Button(it.getId() == null ? TRANSLATOR.translate("general.create") : TRANSLATOR.translate("general.update")); update.addClickListener((Button.ClickEvent event) -> { IssueTypeJpaController c = new IssueTypeJpaController(DataBaseManager.getEntityManagerFactory()); if (it.getId() == null) { it.setDescription((String) desc.getValue()); it.setTypeName((String) name.getValue()); c.create(it); } else { try { binder.commit(); } catch (FieldGroup.CommitException ex) { LOG.log(Level.SEVERE, null, ex); } } }); Button cancel = new Button( Lookup.getDefault().lookup(InternationalizationProvider.class).translate("general.cancel")); cancel.addClickListener((Button.ClickEvent event) -> { binder.discard(); ((VMUI) UI.getCurrent()).updateScreen(); }); binder.setReadOnly(!edit); binder.setBuffered(true); HorizontalLayout hl = new HorizontalLayout(); hl.addComponent(update); hl.addComponent(cancel); layout.addComponent(hl); } }