List of usage examples for com.vaadin.ui FormLayout removeAllComponents
@Override public void removeAllComponents()
From source file:com.snowy.NewUserSubWindow.java
public void build() { //setClosable(false); setModal(true);//from w w w . j a v a 2 s. c o m setResizable(false); setResponsive(true); setDraggable(false); FormLayout fl = new FormLayout(); fl.setMargin(true); //fl.setSizeFull(); fl.setSizeUndefined(); fl.setSpacing(true); TextField uname = new TextField("Username"); uname.setRequired(true); //uname.addValidator(null); fl.addComponent(uname); TextField email = new TextField("Email"); email.setRequired(true); email.addValidator(new EmailValidator("A Valid Email is Required")); fl.addComponent(email); PasswordField pf1 = new PasswordField("Password"); pf1.setRequired(true); pf1.addValidator(new StringLengthValidator("Password must be between 8 and 60 characters", 8, 60, false)); fl.addComponent(pf1); PasswordField pf2 = new PasswordField("Confirm Password"); pf2.setRequired(true); pf2.addValidator((Object value) -> { if (!pf2.getValue().equals(pf1.getValue())) { throw new InvalidValueException("Passwords Must Match"); } }); //pf2.setImmediate(true); fl.addComponent(pf2); Button b = new Button("Submit"); b.addClickListener((Button.ClickEvent e) -> { if (uname.isValid() && email.isValid() && pf1.isValid() && pf2.isValid()) { String result = d.createUser(uname.getValue(), pf2.getValue(), email.getValue()); if (result.equals("Creation Sucess")) { fl.removeAllComponents(); fl.addComponent(new Label("User Created Sucessfully")); fl.addComponent(new Button("Close", (ee) -> { this.close(); })); } else { Notification.show(result); } } else { b.setComponentError(new UserError("Issues with required fields")); } //d.close(); }); fl.addComponent(b); setContent(fl); }
From source file:com.yoncabt.ebr.ui.ReportWindow.java
private void showFields(ReportDefinition definition, final Window w, final FormLayout fl) throws AssertionError, JSONException { fl.removeAllComponents(); w.setCaption(definition.getCaption()); for (ReportParam param : definition.getReportParams()) { AbstractField comp = null;/*from w w w . j a v a2 s. c o m*/ if (param.getInputType() == InputType.COMBO) { ComboBox f = new ComboBox(param.getLabel()); param.getLovData().forEach((k, v) -> { f.addItem(k); f.setItemCaption(k, (String) v); }); comp = f; } else { switch (param.getFieldType()) { case STRING: { TextField f = new TextField(param.getLabel()); comp = f; break; } case INTEGER: { TextField f = new TextField(param.getLabel()); f.addValidator(new IntegerRangeValidator("Say kontrol", (Integer) param.getMin(), (Integer) param.getMax())); comp = f; break; } case LONG: { TextField f = new TextField(param.getLabel()); f.addValidator(new LongRangeValidator("Say kontrol", (Long) param.getMin(), (Long) param.getMax())); comp = f; break; } case DOUBLE: { TextField f = new TextField(param.getLabel()); f.addValidator(new DoubleRangeValidator("Say kontrol", (Double) param.getMin(), (Double) param.getMax())); comp = f; break; } case DATE: { DateField f = new DateField(param.getLabel()); f.setDateFormat(param.getFormat()); comp = f; break; } default: { throw new AssertionError(param.getName() + " in tipi tannmyor :" + param.getJavaType()); } } } if (param.getDefaultValue() != null) { comp.setValue(param.getDefaultValue()); } comp.setImmediate(true); comp.setValidationVisible(false); comp.setId(param.getName()); fl.addComponent(comp); } if (report instanceof SQLReport) { reportType.addItem(ReportOutputFormat.xls); reportType.setItemCaption(ReportOutputFormat.xls, ReportOutputFormat.xls.getTypeName()); } else { for (ReportOutputFormat value : ReportOutputFormat.values()) { reportType.addItem(value); reportType.setItemCaption(value, value.getTypeName()); } } reportType.setValue(ReportOutputFormat.xls); fl.addComponent(reportType); fl.addComponent(reportLocale); fl.addComponent(email); }
From source file:pl.exsio.frameset.vaadin.ui.support.component.data.form.SecurityPermissionsForm.java
License:Open Source License
private void handleRoleSelectionChange(ComboBox roleSelect, final FormLayout permissionsLayout, final JPAContainer<? extends Role> roles, final Map<String, Permission> permissionsMap) { roleSelect.addValueChangeListener(new Property.ValueChangeListener() { private Map<CheckBox, Permission> permissionCbsMap; @Override//from www .j a v a2 s.c om public void valueChange(Property.ValueChangeEvent event) { if (event.getProperty().getValue() != null) { this.createRolePermissionsForm(event); } } private void createRolePermissionsForm(Property.ValueChangeEvent event) throws NumberFormatException { this.permissionCbsMap = new HashMap<>(); permissionsLayout.removeAllComponents(); Long itemId = Long.parseLong(event.getProperty().getValue().toString()); Role selectedRole = roles.getItem(itemId).getEntity(); final GrantedAuthoritySid sid = new GrantedAuthoritySid(selectedRole.getName()); for (String permissionName : permissionsMap.keySet()) { CheckBox permissionCb = this.createPermissionCheckbox(permissionName, sid); permissionsLayout.addComponent(permissionCb); } Button savePermissions = this.createSaveButton(sid); permissionsLayout.addComponent(savePermissions); } private CheckBox createPermissionCheckbox(String permissionName, final GrantedAuthoritySid sid) { CheckBox permissionCb = new CheckBox(permissionName, acl.isGranted(subject, permissionsMap.get(permissionName), sid)); this.permissionCbsMap.put(permissionCb, permissionsMap.get(permissionName)); return permissionCb; } private Button createSaveButton(final GrantedAuthoritySid sid) { Button savePermissions = new Button(t("core.save"), FontAwesome.FLOPPY_O); savePermissions.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { for (CheckBox permissionCb : permissionCbsMap.keySet()) { if (permissionCb.getValue()) { acl.grant(subject, permissionCbsMap.get(permissionCb), sid); } else { acl.revoke(subject, permissionCbsMap.get(permissionCb), sid); } } Notification.show(t("core.security.management.permision.update.success")); } }); return savePermissions; } }); }