List of usage examples for com.vaadin.ui Button setComponentError
public void setComponentError(ErrorMessage componentError)
From source file:com.snowy.NewUserSubWindow.java
public void build() { //setClosable(false); setModal(true);//from ww w . ja v a 2s .co 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:it.vige.greenarea.bpm.custom.ui.form.GreenareaAbstractFormPropertyRenderer.java
License:Apache License
protected void addButton(String operation, HorizontalLayout buttons, final String item, final Table table) { final String finalOperation = operation; final Button button = new Button(); if (operation.equals(MODIFICA.name())) button.setIcon(new ThemeResource("img/edit.png")); else if (operation.equals(CANCELLAZIONE.name())) button.setIcon(new ThemeResource("img/delete.png")); else//w ww . j a v a2 s . c o m button.setIcon(new ThemeResource("img/task-16.png")); button.addStyleName(BUTTON_LINK); I18nManager i18nManager = get().getI18nManager(); button.setDescription(i18nManager.getMessage(operation)); buttons.addComponent(button); buttons.setComponentAlignment(button, BOTTOM_RIGHT); button.addListener(new ClickListener() { private static final long serialVersionUID = -6091586145870618870L; public void buttonClick(ClickEvent event) { // Extract the submitted values from the form. Throws // exception // when validation fails. try { table.select(item); Map<String, String> formProperties = greenareaFormPropertiesForm .getGreenareaFormPropertiesComponent().getFormPropertyValues(); setOperation(formProperties, finalOperation); greenareaFormPropertiesForm.getMainTitle() .setPropertyDataSource(new ObjectProperty<String>( greenareaFormPropertiesForm.getMainTitle().getValue() + " > " + finalOperation, String.class)); FormPropertiesEvent formPropertiesEvent = greenareaFormPropertiesForm.new FormPropertiesEvent( greenareaFormPropertiesForm, TYPE_SUBMIT, formProperties); greenareaFormPropertiesForm.fireEvent(formPropertiesEvent); button.setComponentError(null); } catch (InvalidValueException ive) { // Error is presented to user by the form component } } }); }
From source file:it.vige.greenarea.bpm.custom.ui.form.GreenareaFormPropertiesForm.java
License:Apache License
private void addButtons() { GreenareaFormPropertiesComponent greenareaFormPropertiesComponent = (GreenareaFormPropertiesComponent) formPropertiesComponent; List<String> operationsFromRenderers = getOperationsFromRenderers(greenareaFormPropertiesComponent); FormProperty operations = greenareaFormPropertiesComponent.getOperations(); if (operations != null) { @SuppressWarnings("unchecked") Map<String, String> mapOperations = (Map<String, String>) operations.getType().getInformation("values"); buttons = new HorizontalLayout(); buttons.setSpacing(true);// www . ja v a2 s.c om buttons.setWidth(100, UNITS_PERCENTAGE); buttons.addStyleName(STYLE_DETAIL_BLOCK); for (String operation : mapOperations.keySet()) { if (!operationsFromRenderers.contains(operation)) { final String finalOperation = operation; final Button button = new Button(); button.setCaption(i18nManager.getMessage(operation)); buttons.addComponent(button); buttons.setComponentAlignment(button, BOTTOM_RIGHT); button.addListener(new ClickListener() { private static final long serialVersionUID = -6091586145870618870L; public void buttonClick(ClickEvent event) { // Extract the submitted values from the form. // Throws // exception // when validation fails. try { Map<String, String> formProperties = formPropertiesComponent .getFormPropertyValues(); setOperation(formProperties, finalOperation); mainTitle.setPropertyDataSource(new ObjectProperty<String>( mainTitle.getValue() + " > " + finalOperation, String.class)); fireEvent(new FormPropertiesEvent(GreenareaFormPropertiesForm.this, TYPE_SUBMIT, formProperties)); button.setComponentError(null); } catch (InvalidValueException ive) { // Error is presented to user by the form // component } } }); } } Label buttonSpacer = new Label(); buttons.addComponent(buttonSpacer); buttons.setExpandRatio(buttonSpacer, 1.0f); addComponent(buttons); } else { submitFormButton = new Button(); cancelFormButton = new Button(); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.setWidth(100, UNITS_PERCENTAGE); buttons.addStyleName(STYLE_DETAIL_BLOCK); buttons.addComponent(submitFormButton); buttons.setComponentAlignment(submitFormButton, BOTTOM_RIGHT); // buttons.addComponent(cancelFormButton); // buttons.setComponentAlignment(cancelFormButton, BOTTOM_RIGHT); Label buttonSpacer = new Label(); buttons.addComponent(buttonSpacer); buttons.setExpandRatio(buttonSpacer, 1.0f); addComponent(buttons); setSubmitButtonCaption(i18nManager.getMessage(TASK_COMPLETE)); // setCancelButtonCaption(i18nManager.getMessage(TASK_RESET_FORM)); } }