@Override public void step1() { txt = content.getValue().toString(); txt = txt.trim(); if (txt.length() < 5) { Notification.show( "Card not played.", "Your message is too short to be useful.", Notification.Type.ERROR_MESSAGE); doNotAdvanceSteps(); // come into step1 again next time return; } if (txt.length() > 140) { Notification.show( "Card not played.", "Only 140 characters please.", Notification.Type.ERROR_MESSAGE); doNotAdvanceSteps(); // come into step1 again next time return; } // Admins get to add cards under other names author = Mmowgli2UI.getGlobals().getUserTL(); if (author.isAdministrator()) adminSwitchAuthorsTL(event.getButton(), this); else run(); // does not need to suspend, so "continues" and executes step2 // in the same clicklistener thread }
private Component buildFooter() { HorizontalLayout footer = new HorizontalLayout(); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); footer.setWidth(100.0f, Unit.PERCENTAGE); Button ok = new Button("OK"); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.addClickListener( event -> { try { fieldGroup.commit(); // Updated user should also be persisted to database. But // not in this demo. Notification success = new Notification("Profile updated successfully"); success.setDelayMsec(2000); success.setStyleName("bar success small"); success.setPosition(Position.BOTTOM_CENTER); success.show(Page.getCurrent()); // DashboardEventBus.post(new ProfileUpdatedEvent()); close(); } catch (CommitException e) { Notification.show("Error while updating profile", Type.ERROR_MESSAGE); } }); ok.focus(); footer.addComponent(ok); footer.setComponentAlignment(ok, Alignment.TOP_RIGHT); return footer; }
public void save(Button.ClickEvent event) { try { formFieldBindings.commit(); service.saveAsNewCoin(coin, crawlerResult); String msg = String.format("Saved '%s'.", coin.getName()); Notification.show(msg, Notification.Type.TRAY_NOTIFICATION); parentTable.refreshResults(); } catch (FieldGroup.CommitException e) { e.printStackTrace(); } }
private void login() { try { final Authentication authentication = vaadinSecurity.login(userName.getValue(), passwordField.getValue()); eventBus.publish(this, new SuccessfulLoginEvent(getUI(), authentication)); } catch (AuthenticationException ex) { userName.focus(); userName.selectAll(); passwordField.setValue(""); loginFailedLabel.setValue(String.format("Login failed: %s", ex.getMessage())); loginFailedLabel.setVisible(true); } catch (Exception ex) { Notification.show("An unexpected error occurred", ex.getMessage(), Notification.Type.ERROR_MESSAGE); LoggerFactory.getLogger(getClass()).error("Unexpected error while logging in", ex); } finally { login.setEnabled(true); } }
@Override public void uploadSucceeded(Upload.SucceededEvent succeededEvent) { loadKeys(); Notification.show("Upload", "File uploaded!", Notification.Type.TRAY_NOTIFICATION); }
private void showError(String text) { Notification.show(text, Notification.Type.ERROR_MESSAGE); }
private Component buildProfileTab() { HorizontalLayout root = new HorizontalLayout(); root.setCaption("Profile"); root.setIcon(FontAwesome.USER); root.setWidth(100.0f, Unit.PERCENTAGE); root.setSpacing(true); root.setMargin(true); root.addStyleName("profile-form"); VerticalLayout pic = new VerticalLayout(); pic.setSizeUndefined(); pic.setSpacing(true); Image profilePic = new Image(null, new ThemeResource("img/profile-pic-300px.jpg")); profilePic.setWidth(100.0f, Unit.PIXELS); pic.addComponent(profilePic); Button upload = new Button( "Change…", event -> { Notification.show("Not implemented in this demo"); }); upload.addStyleName(ValoTheme.BUTTON_TINY); pic.addComponent(upload); root.addComponent(pic); FormLayout details = new FormLayout(); details.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); root.addComponent(details); root.setExpandRatio(details, 1); firstNameField = new TextField("First Name"); details.addComponent(firstNameField); lastNameField = new TextField("Last Name"); details.addComponent(lastNameField); titleField = new ComboBox("Title"); titleField.setInputPrompt("Please specify"); titleField.addItem("Mr."); titleField.addItem("Mrs."); titleField.addItem("Ms."); titleField.setNewItemsAllowed(true); details.addComponent(titleField); sexField = new OptionGroup("Sex"); sexField.addItem(Boolean.FALSE); sexField.setItemCaption(Boolean.FALSE, "Female"); sexField.addItem(Boolean.TRUE); sexField.setItemCaption(Boolean.TRUE, "Male"); sexField.addStyleName("horizontal"); details.addComponent(sexField); Label section = new Label("Contact Info"); section.addStyleName(ValoTheme.LABEL_H4); section.addStyleName(ValoTheme.LABEL_COLORED); details.addComponent(section); emailField = new TextField("Email"); emailField.setWidth("100%"); emailField.setRequired(true); emailField.setNullRepresentation(""); details.addComponent(emailField); locationField = new TextField("Location"); locationField.setWidth("100%"); locationField.setNullRepresentation(""); locationField.setComponentError(new UserError("This address doesn't exist")); details.addComponent(locationField); phoneField = new TextField("Phone"); phoneField.setWidth("100%"); phoneField.setNullRepresentation(""); details.addComponent(phoneField); newsletterField = new OptionalSelect<>(); newsletterField.addOption(0, "Daily"); newsletterField.addOption(1, "Weekly"); newsletterField.addOption(2, "Monthly"); details.addComponent(newsletterField); section = new Label("Additional Info"); section.addStyleName(ValoTheme.LABEL_H4); section.addStyleName(ValoTheme.LABEL_COLORED); details.addComponent(section); websiteField = new TextField("Website"); websiteField.setInputPrompt("http://"); websiteField.setWidth("100%"); websiteField.setNullRepresentation(""); details.addComponent(websiteField); bioField = new TextArea("Bio"); bioField.setWidth("100%"); bioField.setRows(4); bioField.setNullRepresentation(""); details.addComponent(bioField); return root; }
@Override public void buttonClick(ClickEvent event) { String msg = "saved"; String update = "insert"; if (event.getButton() == save) { try { // Commit the fields from UI to DAO formFieldBindings.commit(); // go to the database and get the ID of the contact selected ContactService c = ContactService.createDemoService(); ArrayList<Contact> contacts = (ArrayList<Contact>) c.findAll(null); for (int i = 0; i < contacts.size(); i++) { if (contacts.get(i).getFirstName().equals(this.contact.getFirstName()) && contacts.get(i).getLastName().equals(this.contact.getLastName()) && (!contacts.get(i).getPhone().equals(this.contact.getPhone()) || !contacts.get(i).getEmail().equals(this.contact.getEmail()) || !contacts.get(i).getBirthDate().equals(this.contact.getBirthDate()))) { this.contact.setId(contacts.get(i).getId()); update = "update"; break; } else if (contacts.get(i).getFirstName().equals(this.contact.getFirstName()) && contacts.get(i).getLastName().equals(this.contact.getLastName()) && contacts.get(i).getPhone().equals(this.contact.getPhone()) && contacts.get(i).getEmail().equals(this.contact.getEmail())) { update = "duplicate"; break; } else if (!contacts.get(i).getFirstName().equals(this.contact.getFirstName()) && !contacts.get(i).getLastName().equals(this.contact.getLastName())) { update = "insert"; } } // Save DAO to backend with direct synchronous service API int status = getUI().service.save(this.contact, update); if (status == 1 || status == 0) { msg = String.format("Saved '%s %s'.", contact.getFirstName(), contact.getLastName()); } else msg = String.format( "Cannot Save Duplicate '%s %s'.", contact.getFirstName(), contact.getLastName()); Notification.show(msg, Type.TRAY_NOTIFICATION); getUI().refreshContacts(); } catch (FieldGroup.CommitException e) { // Validation exceptions could be shown here } } else if (event.getButton() == cancel) { // Place to call business logic. Notification.show("Cancelled", Type.TRAY_NOTIFICATION); getUI().contactList.select(null); } getUI().contactList.select(null); }
public void cancel(Button.ClickEvent event) { Notification.show("Cancelled", Notification.Type.TRAY_NOTIFICATION); removeAllComponents(); parentTable.unSelectResult(); }