List of usage examples for com.vaadin.ui Button addListener
@Override
public Registration addListener(Component.Listener listener)
From source file:com.trivago.mail.pigeon.web.components.groups.ActionButtonColumnGenerator.java
License:Apache License
@Override public Object generateCell(final Table source, final Object itemId, final Object columnId) { HorizontalLayout hl = new HorizontalLayout(); final Button showMembersButton = new Button(); showMembersButton.setIcon(new ThemeResource("../runo/icons/16/users.png")); showMembersButton.setDescription("Show recipients in this group"); showMembersButton.setImmediate(true); final Button deleteButton = new Button(); deleteButton.setIcon(new ThemeResource("../runo/icons/16/trash.png")); deleteButton.setDescription("Delete group and all users in it."); deleteButton.setImmediate(true);//from w ww . j a va 2s. c o m final Button csvImportButton = new Button(); csvImportButton.setIcon(new ThemeResource("../runo/icons/16/folder.png")); csvImportButton.setDescription("Import CSV file of users into this group"); csvImportButton.setImmediate(true); final Button refreshButton = new Button(); refreshButton.setIcon(new ThemeResource("../runo/icons/16/reload.png")); refreshButton.setDescription("Refresh the recipient count in this group (e.g. after an import)"); refreshButton.setImmediate(true); showMembersButton.setData(itemId); deleteButton.setData(itemId); csvImportButton.setData(itemId); refreshButton.setData(itemId); csvImportButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { ModalRecipientImportCsv modalNewWindow = new ModalRecipientImportCsv( (Long) event.getButton().getData()); event.getButton().getWindow().addWindow(modalNewWindow); modalNewWindow.setVisible(true); } }); refreshButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { source.removeGeneratedColumn("memberNumber"); source.addGeneratedColumn("memberNumber", new GroupColumnGenerator()); source.removeGeneratedColumn("Actions"); source.addGeneratedColumn("Actions", new ActionButtonColumnGenerator()); } }); showMembersButton.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { long itemId = (Long) event.getButton().getData(); ModalRecipientList rlist = new ModalRecipientList(itemId); source.getWindow().addWindow(rlist); rlist.setVisible(true); } }); deleteButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Transaction tx = ConnectionFactory.getDatabase().beginTx(); try { RecipientGroup r = new RecipientGroup((Long) itemId); ConnectionFactory.getGroupIndex().remove(r.getDataNode()); for (Relationship rs : r.getDataNode().getRelationships()) { rs.delete(); } r.getDataNode().delete(); source.removeItem(itemId); source.getWindow().showNotification("Successfully deleted."); tx.success(); } catch (Exception e) { source.getWindow().showNotification("Error while deleting entry: " + e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); log.error(e); tx.failure(); } finally { tx.finish(); } } }); hl.addComponent(showMembersButton); hl.addComponent(csvImportButton); hl.addComponent(refreshButton); hl.addComponent(deleteButton); hl.setSpacing(true); return hl; }
From source file:com.trivago.mail.pigeon.web.components.groups.GroupList.java
License:Apache License
public GroupList() { final GroupList gl = this; final Panel rootPanel = new Panel("Groups"); rootPanel.setWidth("800px"); Button groupListNewButton = new Button("Add group"); groupListNewButton.setImmediate(true); groupListNewButton.setIcon(new ThemeResource("../runo/icons/16/document-add.png")); groupListNewButton.addListener(new Button.ClickListener() { @Override/* ww w. j a v a 2s . c om*/ public void buttonClick(Button.ClickEvent event) { Window modalNewWindow = new ModalAddNewGroup(gl); event.getButton().getWindow().addWindow(modalNewWindow); modalNewWindow.setVisible(true); } }); viewTable = new Table(); viewTable.setWidth("100%"); final Button editButton = new Button("Edit"); editButton.setImmediate(true); editButton.setIcon(new ThemeResource("../runo/icons/16/document-txt.png")); editButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (viewTable.isEditable()) { viewTable.setEditable(false); editButton.setCaption("Edit"); viewTable.requestRepaintAll(); editButton.getWindow().showNotification("Save successful", Window.Notification.TYPE_HUMANIZED_MESSAGE); } else { viewTable.setEditable(true); editButton.setCaption("Save"); viewTable.requestRepaintAll(); } } }); viewTable.setImmediate(true); beanContainer = new BeanContainer<>(RecipientGroup.class); List<RecipientGroup> groupList = getGroupList(); for (RecipientGroup group : groupList) { beanContainer.addItem(group.getId(), group); } viewTable.setContainerDataSource(beanContainer); viewTable.addGeneratedColumn("memberNumber", new GroupColumnGenerator()); viewTable.addGeneratedColumn("Actions", new ActionButtonColumnGenerator()); // First set the vis. cols, then the headlines (the other way round leads to an exception) viewTable.setVisibleColumns(new String[] { "id", "name", "memberNumber", "Actions" }); viewTable.setColumnHeaders(new String[] { "ID", "Name", "Member #", "Actions" }); viewTable.setColumnExpandRatio(3, 2); viewTable.setColumnExpandRatio(4, 2); HorizontalLayout topButtonLayout = new HorizontalLayout(); topButtonLayout.setSpacing(true); topButtonLayout.setMargin(false, false, true, false); topButtonLayout.addComponent(groupListNewButton); topButtonLayout.addComponent(editButton); rootPanel.addComponent(topButtonLayout); rootPanel.addComponent(viewTable); setCompositionRoot(rootPanel); }
From source file:com.trivago.mail.pigeon.web.components.groups.ModalAddNewGroup.java
License:Apache License
public ModalAddNewGroup(final GroupList gl) { super();//from www . j ava 2s.co m setModal(true); setWidth("300px"); setClosable(false); Panel rootPanel = new Panel("Add new group"); VerticalLayout verticalLayout = new VerticalLayout(); VerticalLayout formLayout = new VerticalLayout(); final TextField tfName = new TextField("Name"); verticalLayout.addComponent(tfName); HorizontalLayout buttonLayout = new HorizontalLayout(); Button saveButton = new Button("Save"); Button cancelButton = new Button("Cancel"); saveButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (tfName.getValue().equals("")) { tfName.setComponentError(new UserError("Name must not be empty")); } else { tfName.setComponentError(null); } /* TODO XXX check for existing group: no duplicates! */ if (!tfName.getValue().equals("")) { tfName.setComponentError(null); long groupId = Util.generateId(); try { RecipientGroup g = new RecipientGroup(groupId, tfName.getValue().toString()); event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); event.getButton().getWindow().getParent().showNotification("Saved successfully", Notification.TYPE_HUMANIZED_MESSAGE); gl.getBeanContainer().addItem(g.getId(), g); // The group select could be placed anywhere but must be reloaded to reflect the changes. GroupSelectBox.reloadSelect(); } catch (RuntimeException e) { // Should never happen ... hopefully :D } } event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } }); cancelButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } }); buttonLayout.addComponent(saveButton); buttonLayout.addComponent(cancelButton); verticalLayout.addComponent(formLayout); verticalLayout.addComponent(buttonLayout); rootPanel.addComponent(verticalLayout); this.addComponent(rootPanel); }
From source file:com.trivago.mail.pigeon.web.components.groups.ModalRecipientImportCsv.java
License:Apache License
public ModalRecipientImportCsv(final long groupId) { super();/* w ww. java 2 s . co m*/ setModal(true); setClosable(false); setWidth("600px"); Panel rootPanel = new Panel("Import Recipients via CSV"); VerticalLayout vl = new VerticalLayout(); Label infoText = new Label( "You can upload a bunch of users into a group. Create a CSV file with no! headers. \n" + "You can leave out the user_id by just setting the column empty => ,\"Firstname Lastname\",\"first.last@trivago.com\"."); Label formatInfoText = new Label("Please format you CSV like: user_id,\"user_full_name\",\"email\""); final CheckBox forceUpdate = new CheckBox("Force update of existing recipients?"); Button cancelButton = new Button("Cancel"); vl.addComponent(infoText); vl.addComponent(formatInfoText); final UploadCsvFileComponent ucsv = new UploadCsvFileComponent(); vl.addComponent(ucsv); Button importButton = new Button("Import"); importButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (!ucsv.isUploadFinished()) { ucsv.setComponentError(new UserError("Please upload a csv first!")); } else { ucsv.setComponentError(null); try { File uploadedFile = ucsv.getCsvFile(); Csv importer = new Csv(uploadedFile, groupId); importer.importData(forceUpdate.booleanValue()); event.getButton().getApplication().getMainWindow().showNotification("Import done", Notification.TYPE_HUMANIZED_MESSAGE); event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } catch (Exception e) { log.error("Error while importing csv", e); event.getButton().getWindow().showNotification("The import failed.", e.getLocalizedMessage(), Notification.TYPE_ERROR_MESSAGE); } } } }); cancelButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } }); HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.addComponent(importButton); buttonLayout.addComponent(cancelButton); vl.addComponent(buttonLayout); rootPanel.addComponent(vl); addComponent(rootPanel); }
From source file:com.trivago.mail.pigeon.web.components.mail.ActionButtonColumnGenerator.java
License:Apache License
@Override public Object generateCell(final Table source, final Object itemId, final Object columnId) { HorizontalLayout hl = new HorizontalLayout(); Button showNlConentButton = new Button(); showNlConentButton.setDescription("View"); showNlConentButton.setImmediate(true); showNlConentButton.setIcon(new ThemeResource("../runo/icons/16/document-txt.png")); showNlConentButton.addListener(new Button.ClickListener() { @Override//from www .ja v a2 s . c o m public void buttonClick(Button.ClickEvent event) { Mail m = new Mail((Long) itemId); Window nlConentView = new Window("Newsletter Contents of ID " + itemId); // Create an empty tab sheet. TabSheet tabsheet = new TabSheet(); Panel pText = new Panel("Text Content"); Panel pHtml = new Panel("Text Content"); RichTextArea textArea = new RichTextArea(); textArea.setValue(m.getText()); textArea.setReadOnly(true); RichTextArea richTextArea = new RichTextArea(); richTextArea.setValue(m.getHtml()); richTextArea.setReadOnly(true); pText.addComponent(textArea); pHtml.addComponent(richTextArea); richTextArea.setHeight("50%"); richTextArea.setWidth("100%"); textArea.setHeight("50%"); textArea.setWidth("100%"); nlConentView.setResizable(true); nlConentView.setWidth("800px"); nlConentView.setHeight("600px"); tabsheet.addTab(pText); tabsheet.getTab(pText).setCaption("Text Version"); tabsheet.addTab(pHtml); tabsheet.getTab(pHtml).setCaption("Html Version"); nlConentView.addComponent(tabsheet); source.getWindow().addWindow(nlConentView); nlConentView.setVisible(true); } }); final Button showOpenendMails = new Button(); showOpenendMails.setDescription("Show recipients of this mailling"); showOpenendMails.setIcon(new ThemeResource("../runo/icons/16/users.png")); showOpenendMails.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Mail m = new Mail((Long) itemId); ModalRecipientListByMail modalRecipientListByMail = new ModalRecipientListByMail(m); source.getWindow().addWindow(modalRecipientListByMail); modalRecipientListByMail.setVisible(true); } }); hl.addComponent(showNlConentButton); hl.addComponent(showOpenendMails); return hl; }
From source file:com.trivago.mail.pigeon.web.components.mail.ModalAddNewsletter.java
License:Apache License
public ModalAddNewsletter(final NewsletterList nl) { super();// ww w . j av a 2s. co m setModal(true); setWidth("600px"); setClosable(false); Panel rootPanel = new Panel("Add new Newsletter"); final VerticalLayout verticalLayout = new VerticalLayout(); final SenderSelectBox senderSelectBox = new SenderSelectBox(); final HorizontalLayout buttonLayout = new HorizontalLayout(); final GroupSelectBox groupSelectBox = new GroupSelectBox(); final UploadTextFileComponent uploadTextfile = new UploadTextFileComponent(); final UploadHtmlFileComponent uploadHtmlfile = new UploadHtmlFileComponent(); final TemplateSelectBox templateSelectBox = new TemplateSelectBox(); final TextField tfSubject = new TextField("Subject"); final DateField tfSendDate = new DateField("Send Date"); final Button cancelButton = new Button("Cancel"); final Button saveButton = new Button("Send"); tfSendDate.setInvalidAllowed(false); tfSendDate.setResolution(DateField.RESOLUTION_MIN); tfSendDate.setValue(new Date()); cancelButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } }); saveButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { boolean hasError = false; // Validation if (tfSubject.getValue().equals("") && templateSelectBox.getSelectedTemplate() == null) { hasError = true; tfSubject.setComponentError( new UserError("Subject cannot be empty if you do not choose a template.")); } else { tfSubject.setComponentError(null); } if (tfSendDate.getValue() == null) { hasError = true; tfSendDate.setComponentError(new UserError("Date cannot be empty")); } else { tfSendDate.setComponentError(null); } if (templateSelectBox.getSelectedTemplate() == null) { if (!uploadTextfile.isUploadFinished()) { hasError = true; uploadTextfile.setComponentError( new UserError("You must provide a text file if you do not choose a template")); } else { uploadTextfile.setComponentError(null); } if (!uploadHtmlfile.isUploadFinished()) { hasError = true; uploadHtmlfile.setComponentError( new UserError("You must provide a html file if you do not choose a template")); } else { uploadHtmlfile.setComponentError(null); } } if (senderSelectBox.getSelectedSender() == 0) { hasError = true; senderSelectBox.setComponentError(new UserError("You must select a sender")); } else { senderSelectBox.setComponentError(null); } if (groupSelectBox.getSelectedGroup() == 0) { hasError = true; groupSelectBox.setComponentError(new UserError("You must select a recipient group")); } else { groupSelectBox.setComponentError(null); } log.debug("Has Error: " + hasError); if (!hasError) { log.info("No validation errors found, processing request"); long mailId = Util.generateId(); try { Sender s = new Sender(senderSelectBox.getSelectedSender()); String text; String html; String subject; if (templateSelectBox.getSelectedTemplate() == null) { text = uploadTextfile.getTextData(); html = uploadHtmlfile.getHtmlData(); subject = tfSubject.getValue().toString(); } else { MailTemplate mt = new MailTemplate(templateSelectBox.getSelectedTemplate()); text = mt.getText(); html = mt.getHtml(); subject = mt.getSubject(); } Mail m = new Mail(mailId, text, html, (Date) tfSendDate.getValue(), subject, s); QueueNewsletter queueNewsletter = new QueueNewsletter(); queueNewsletter.queueNewsletter(m, s, new RecipientGroup(groupSelectBox.getSelectedGroup())); event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); event.getButton().getWindow().getParent().showNotification("Queued successfully", Notification.TYPE_HUMANIZED_MESSAGE); nl.getBeanContainer().addItem(m.getId(), m); } catch (RuntimeException e) { log.error("RuntimeException", e); event.getButton().getApplication().getMainWindow().showNotification( "An error occured: " + e.getLocalizedMessage(), Notification.TYPE_ERROR_MESSAGE); } } } }); buttonLayout.setSpacing(true); buttonLayout.addComponent(saveButton); buttonLayout.addComponent(cancelButton); Panel metaData = new Panel("Basic Data"); metaData.addComponent(tfSendDate); verticalLayout.addComponent(metaData); verticalLayout.addComponent(senderSelectBox); verticalLayout.addComponent(groupSelectBox); verticalLayout.addComponent(templateSelectBox); verticalLayout.addComponent(tfSubject); verticalLayout.addComponent(uploadTextfile); verticalLayout.addComponent(uploadHtmlfile); verticalLayout.addComponent(buttonLayout); rootPanel.addComponent(verticalLayout); this.addComponent(rootPanel); }
From source file:com.trivago.mail.pigeon.web.components.mail.NewsletterList.java
License:Apache License
public NewsletterList() { final NewsletterList nl = this; final Panel rootPanel = new Panel("Newsletter"); rootPanel.setWidth("800px"); viewTable = new Table(); viewTable.setWidth("100%"); beanContainer = new BeanContainer<>(Mail.class); Button senderListNewButton = new Button("New Newsletter"); senderListNewButton.setImmediate(true); senderListNewButton.setIcon(new ThemeResource("../runo/icons/16/document-add.png")); senderListNewButton.addListener(new Button.ClickListener() { @Override// w w w . java 2 s. co m public void buttonClick(Button.ClickEvent event) { Window modalNewWindow = new ModalAddNewsletter(nl); event.getButton().getWindow().addWindow(modalNewWindow); modalNewWindow.setVisible(true); } }); Button statusPopup = new Button("Show delivery status"); statusPopup.setImmediate(true); statusPopup.setIcon(new ThemeResource("../runo/icons/16/globe.png")); statusPopup.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Window modalNewWindow = new PopupActiveNewsletters(); event.getButton().getWindow().addWindow(modalNewWindow); modalNewWindow.setVisible(true); } }); List<Mail> mailList = getMailList(); for (Mail mail : mailList) { beanContainer.addItem(mail.getId(), mail); } viewTable.setContainerDataSource(beanContainer); viewTable.addGeneratedColumn("Sender", new SenderColumnGenerator()); viewTable.addGeneratedColumn("Actions", new ActionButtonColumnGenerator()); // First set the vis. cols, then the headlines (the other way round leads to an exception) viewTable.setVisibleColumns(new String[] { "id", "subject", "sendDate", "Sender", "done", "Actions" }); viewTable.setColumnHeaders(new String[] { "ID", "Subject", "Send Date", "Sender", "Finished", "Actions" }); viewTable.setColumnExpandRatio(6, 2); HorizontalLayout topButtonLayout = new HorizontalLayout(); topButtonLayout.addComponent(senderListNewButton); // topButtonLayout.addComponent(statusPopup); topButtonLayout.setMargin(false, false, true, false); rootPanel.addComponent(topButtonLayout); rootPanel.addComponent(viewTable); setCompositionRoot(rootPanel); }
From source file:com.trivago.mail.pigeon.web.components.mail.NewsletterProgressComponent.java
License:Apache License
public NewsletterProgressComponent(final Mail mail) { Panel rootPanel = new Panel("Progress for Mail with Suject " + mail.getSubject()); VerticalLayout vl = new VerticalLayout(); vl.setSpacing(true);/*from w w w. j a v a 2 s. c om*/ DateField df = new DateField("Send Date"); df.setValue(mail.getSendDate()); df.setReadOnly(true); df.setResolution(DateField.RESOLUTION_MIN); indicator = new ProgressIndicator(new Float(0.0)); indicator.setPollingInterval(500); int cnt = 0; Iterable<Relationship> recipients = mail.getRecipients(); for (Relationship rec : recipients) { ++cnt; } final int recpCount = cnt; class WorkerThread extends Thread { int current = 0; public volatile int stop = 0; public void run() { while (true) { if (stop > 0) { break; } try { QueueNewsletter qn = new QueueNewsletter(); int progress = qn.getProgress(mail.getId()); current = recpCount - progress; if (current == recpCount) { mail.setDone(); break; } double result = (recpCount / 100.00) * current; indicator.setValue(new Float(result / 100.00)); sleep(500); } catch (InterruptedException e) { } } } } final WorkerThread workerThread = new WorkerThread(); final Button startButton = new Button("Poll status"); final Button stopButton = new Button("Stop polling"); startButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { workerThread.start(); event.getButton().setVisible(false); stopButton.setVisible(true); } }); stopButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { workerThread.stop = 1; workerThread.interrupt(); event.getButton().setVisible(false); startButton.setVisible(true); } }); stopButton.setVisible(false); vl.addComponent(df); vl.addComponent(indicator); vl.addComponent(startButton); vl.addComponent(stopButton); rootPanel.addComponent(vl); setCompositionRoot(rootPanel); }
From source file:com.trivago.mail.pigeon.web.components.mail.PopupActiveNewsletters.java
License:Apache License
public PopupActiveNewsletters() { setClosable(false);/* w w w . j av a2s. com*/ setWidth("400px"); VerticalLayout vl = new VerticalLayout(); vl.setSpacing(true); Button closeButton = new Button("Close"); vl.addComponent(closeButton); IndexHits<Node> all = Mail.getAll(); for (Node mailNode : all) { Mail mail = new Mail(mailNode); if (!mail.isDone()) { NewsletterProgressComponent pc = new NewsletterProgressComponent(mail); vl.addComponent(pc); } } closeButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } }); addComponent(vl); }
From source file:com.trivago.mail.pigeon.web.components.recipients.ActionButtonColumnGenerator.java
License:Apache License
@Override public Object generateCell(final Table source, final Object itemId, final Object columnId) { HorizontalLayout hl = new HorizontalLayout(); Button deleteButton = new Button(); deleteButton.setImmediate(true);//from w ww .ja v a2 s . com deleteButton.setIcon(new ThemeResource("../runo/icons/16/trash.png")); deleteButton.setDescription("Delete recipient"); deleteButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Transaction tx = ConnectionFactory.getDatabase().beginTx(); try { Recipient s = new Recipient((Long) itemId); ConnectionFactory.getUserIndex().remove(s.getDataNode()); for (Relationship r : s.getDataNode().getRelationships()) { r.delete(); } s.getDataNode().delete(); source.removeItem(itemId); source.getWindow().showNotification("Successfully deleted."); tx.success(); } catch (Exception e) { log.error("Error while deleting entry", e); source.getWindow().showNotification("Error while deleting entry: " + e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); tx.failure(); } finally { tx.finish(); } } }); hl.addComponent(deleteButton); return hl; }