List of usage examples for com.vaadin.data Binder Binder
public Binder(Class<BEAN> beanType)
From source file:org.jpos.qi.login.LoginView.java
License:Open Source License
private FormLayout createForm() { FormLayout formLayout = new FormLayout(); formLayout.setMargin(false);//w w w .j a v a2 s . c om formLayout.setSizeUndefined(); binder = new Binder<>(String.class); username = new TextField(app.getMessage("login.username")); username.setMaxLength(60); binder.forField(username) .withValidator(new RegexpValidator( app.getMessage("errorMessage.invalidField", username.getCaption()), USERNAME_PATTERN)) .bind(string -> string, null); binder.setBean(""); username.focus(); username.setReadOnly(false); password = new PasswordField(); password.setCaption(app.getMessage("login.password")); password.setMaxLength(64); binder.forField(password).asRequired(app.getMessage("errorMessage.req", password.getCaption())) .withValidator(new RegexpValidator( app.getMessage("errorMessage.invalidField", password.getCaption()), PASSWORD_PATTERN)) .bind(string -> string, null); password.setReadOnly(false); rememberMe = new CheckBox(app.getMessage("login.remember")); rememberMe.setDescription(app.getMessage("login.rememberDesc")); formLayout.addComponent(username); formLayout.addComponent(password); if (helper.isRememberEnabled()) formLayout.addComponent(rememberMe); return formLayout; }
From source file:org.jpos.qi.minigl.NewEntryForm.java
License:Open Source License
public NewEntryForm(GLTransaction transaction, TransactionsHelper helper, EntryGrid entryGrid) { super();/*from w w w .j a v a 2 s . c om*/ try { this.transaction = transaction.clone(); } catch (CloneNotSupportedException e) { // Log error and ignore. Clone should be supported. QI.getQI().getLog().error(e); } this.journal = transaction.getJournal(); this.helper = helper; this.app = QI.getQI(); this.entryGrid = entryGrid; setStyleName(ValoTheme.LAYOUT_HORIZONTAL_WRAPPING); setSpacing(true); setWidthUndefined(); GLEntry entry = new GLEntry(); binder = new Binder(GLEntry.class); createAndBindFields(binder); binder.setBean(entry); binder.setReadOnly(true); addEntryBtn = new Button(app.getMessage("addEntry")); addEntryBtn.addClickListener(addEntryClickListener(binder)); addEntryBtn.setEnabled(false); addEntryBtn.setStyleName(ValoTheme.BUTTON_FRIENDLY); addComponent(addEntryBtn); setComponentAlignment(addEntryBtn, Alignment.BOTTOM_CENTER); }
From source file:org.jpos.qi.QIEntityView.java
License:Open Source License
public Layout createForm(final Object entity, String[] params, boolean isNew) { VerticalLayout profileLayout = new VerticalLayout(); profileLayout.setMargin(true);//from w w w.j av a 2 s . c om profileLayout.setSpacing(true); //Add Back Button if (params.length <= 1 || !"profile".equals(params[1])) { Button back = new Button(getApp().getMessage("back")); back.addStyleName("borderless-colored"); back.setIcon(VaadinIcons.ARROW_LEFT); back.addClickListener(event -> app.getNavigator().navigateTo(getGeneralRoute())); profileLayout.addComponent(back); profileLayout.setComponentAlignment(back, Alignment.MIDDLE_LEFT); } binder = new Binder<T>(clazz) { @Override public void setReadOnly(boolean readOnly) { super.setReadOnly(readOnly); if (readOnlyFields != null) { for (String fieldId : readOnlyFields) { if (binder.getBinding(fieldId).isPresent()) { HasValue field = binder.getBinding(fieldId).get().getField(); if ((field != null && !field.isEmpty()) || !field.isRequiredIndicatorVisible()) { field.setReadOnly(true); binder.bind(field, fieldId); } } } } } }; bean = (T) entity; final Layout formLayout = createLayout(); getHelper().setOriginalEntity(bean); binder.readBean((T) entity); binder.setReadOnly(true); profileLayout.addComponent(formLayout); HorizontalLayout footer = new HorizontalLayout(); footer.addStyleName("footer"); footer.setMargin(new MarginInfo(true, false, false, false)); footer.setSpacing(true); formLayout.addComponent(footer); //Add Save, Remove & Cancel Buttons editBtn = new Button(app.getMessage("edit")); removeBtn = new Button(app.getMessage("remove")); saveBtn = new Button(app.getMessage("save")); cancelBtn = new Button(app.getMessage("cancel")); editBtn.addClickListener(event -> editClick(event, formLayout)); editBtn.addStyleName("icon-edit"); saveBtn.addClickListener(event -> saveClick(event, formLayout)); saveBtn.setVisible(false); saveBtn.setStyleName("icon-ok"); saveBtn.setClickShortcut(ShortcutAction.KeyCode.ENTER); removeBtn.addClickListener(event -> app.addWindow(new ConfirmDialog(app.getMessage("confirmTitle"), app.getMessage("removeConfirmationMessage"), confirm -> { if (confirm) { removeEntity(); } }))); removeBtn.addStyleName("icon-trash"); cancelBtn.addClickListener(event -> { if (isNew) { app.getNavigator().navigateTo(getGeneralRoute()); } else { cancelClick(event, formLayout); } }); cancelBtn.setClickShortcut(ShortcutAction.KeyCode.ESCAPE); cancelBtn.setVisible(false); cancelBtn.addStyleName("icon-cancel"); if (canEdit()) { footer.addComponent(editBtn); footer.addComponent(saveBtn); footer.addComponent(cancelBtn); footer.setComponentAlignment(editBtn, Alignment.MIDDLE_RIGHT); footer.setComponentAlignment(saveBtn, Alignment.MIDDLE_RIGHT); footer.setComponentAlignment(cancelBtn, Alignment.MIDDLE_RIGHT); } if (canRemove()) { footer.addComponent(removeBtn); footer.setComponentAlignment(removeBtn, Alignment.MIDDLE_RIGHT); } if (isNew) { editBtn.click(); } errorLabel = new Label(); errorLabel.setVisible(false); errorLabel.setStyleName(ValoTheme.LABEL_FAILURE); profileLayout.addComponent(errorLabel); return profileLayout; }