Example usage for com.vaadin.ui Button setIcon

List of usage examples for com.vaadin.ui Button setIcon

Introduction

In this page you can find the example usage for com.vaadin.ui Button setIcon.

Prototype

@Override
public void setIcon(Resource icon) 

Source Link

Document

Sets the component's icon.

Usage

From source file:com.swifta.mats.web.usermanagement.UserDetailsModule.java

private void addLinkUserContainer() {

    VerticalLayout cDeletePrompt = new VerticalLayout();
    cPlaceholder.addComponent(cDeletePrompt);
    cPlaceholder.setComponentAlignment(cDeletePrompt, Alignment.MIDDLE_CENTER);
    // cDeletePrompt.setWidth("100%");
    cDeletePrompt.setStyleName("c_link");
    cDeletePrompt.setSpacing(true);/* w  ww.j  av  a2  s.  c o m*/
    String username = curUser;

    Label lbActivationPrompt = new Label(
            "<span style='text-align: center;'>Please enter Child Username to link to " + username
                    + "'s Account</span>");
    lbActivationPrompt.setContentMode(ContentMode.HTML);
    lbActivationPrompt.setWidth("300px");
    lbActivationPrompt.setStyleName("lb_link_user");

    cDeletePrompt.addComponent(lbActivationPrompt);
    cDeletePrompt.setComponentAlignment(lbActivationPrompt, Alignment.TOP_LEFT);

    VerticalLayout frmDeleteReason = new VerticalLayout();
    frmDeleteReason.setSizeUndefined();
    frmDeleteReason.setSpacing(true);
    frmDeleteReason.setMargin(true);
    cDeletePrompt.addComponent(frmDeleteReason);
    cDeletePrompt.setComponentAlignment(frmDeleteReason, Alignment.TOP_CENTER);

    tFU = new TextField("Child Username");
    tFU.setRequired(true);

    final ComboBox comboUProf = new ComboBox("Select Profile");
    comboUProf.setNullSelectionAllowed(false);
    comboUProf.setRequired(true);
    comboUProf.addItem(8);
    comboUProf.setItemCaption(8, "DEPOSIT_ONLY");

    comboUProf.addItem(9);
    comboUProf.setItemCaption(9, "DEPOSIT_AND_WITHDRAWAL");

    comboUProf.select(8);

    final TextField tFP = new TextField("Parent Account ID");
    tFP.setValue(username);
    tFP.setEnabled(false);

    final TextField tFInitUser = new TextField("Initiating User");
    tFInitUser.setValue(UI.getCurrent().getSession().getAttribute("user").toString());
    tFInitUser.focus();
    tFInitUser.setEnabled(false);

    frmDeleteReason.addComponent(tFU);
    frmDeleteReason.addComponent(comboUProf);
    frmDeleteReason.addComponent(tFP);
    frmDeleteReason.addComponent(tFInitUser);

    HorizontalLayout cPopupBtns = new HorizontalLayout();
    cPopupBtns.setSizeUndefined();
    cPopupBtns.setSpacing(true);

    final Button btnCancel = new Button();
    btnCancel.setIcon(FontAwesome.UNDO);
    btnCancel.setStyleName("btn_link");
    btnCancel.setDescription("Cancel");

    final Button btnSet = new Button("Link");
    btnSet.setDescription("Link specified account.");
    btnSet.setIcon(FontAwesome.LINK);
    cPopupBtns.addComponent(btnSet);
    cPopupBtns.addComponent(btnCancel);
    frmDeleteReason.addComponent(cPopupBtns);

    cDeletePrompt.setComponentAlignment(frmDeleteReason, Alignment.MIDDLE_CENTER);
    btnSet.setClickShortcut(KeyCode.ENTER, null);

    btnSet.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = -6318666715385643538L;

        @Override
        public void buttonClick(ClickEvent event) {

            tFU.validate();
            btnSet.setEnabled(false);
            btnCancel.setEnabled(false);

            Button btn = event.getButton();

            if (ums == null)
                ums = new UserManagementService();
            btn.setEnabled(false);

            String strResponse = null;
            try {

                strResponse = UserManagementService.linkUser(tFP.getValue(),
                        new Integer(comboUProf.getValue().toString()), tFInitUser.getValue(), tFU.getValue());

                if (strResponse.equals("The operation was successful and completed")) {

                    updateLinksTable(tFU.getValue());
                    cPlaceholder.setVisible(false);
                    tFU.setValue("");
                    btnLink.setVisible(true);

                    NotifCustom.show("Link", strResponse);

                } else {
                    NotifCustom.show("Link", strResponse);
                }

            } catch (RemoteException e) {

                e.printStackTrace();

            }

            btnSet.setEnabled(true);
            btnCancel.setEnabled(true);

        }
    });

    btnCancel.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 7161821652386306043L;

        @Override
        public void buttonClick(ClickEvent event) {
            btnLink.setVisible(true);
            cPlaceholder.setVisible(false);

        }

    });

}

From source file:com.swifta.mats.web.usermanagement.UserDetailsModule.java

@SuppressWarnings("unchecked")
private void updateLinksTable(String un) {
    StringBuilder sb = new StringBuilder();

    sb.append(//w  ww  .  j  a v a  2  s  .c  om
            " SELECT concat(ahd.firstname,' ',ahd.lastname) as Name, ah.username as 'username', ah.msisdn as msisdn, ah.email as email ");
    sb.append(" FROM linkaccountrelations pl, accountholders ah, accountholderdetails ahd ");
    sb.append(" where linkstatus = 'LINKED' and username = '" + un + "'");
    sb.append(" and ah.accountholderdetailid = ahd.accountdetailsid ");
    sb.append(" and pl.childuserresourceid = ah.accountholderid");

    String drivers = "com.mysql.jdbc.Driver";
    try {
        Class<?> driver_class = Class.forName(drivers);
        Driver driver = (Driver) driver_class.newInstance();
        DriverManager.registerDriver(driver);

        Connection conn = DriverManager.getConnection(MatsWebPortalUI.conf.DB, MatsWebPortalUI.conf.UN,
                MatsWebPortalUI.conf.PW);

        Statement stmt = conn.createStatement();

        ResultSet rs = stmt.executeQuery(sb.toString());

        Property<String> pUn;
        Property<String> pMsisdn;
        Property<String> pEmail;
        Property<Integer> pSn;
        Property<Button> pBtn;

        String msisdn;
        String email;
        Object rid;
        Button btnLink;
        Item r;

        while (rs.next()) {
            int x = container.size() + 1;
            un = rs.getString("username");
            msisdn = rs.getString("msisdn");
            email = rs.getString("email");

            rid = container.addItem();
            r = container.getItem(rid);

            pSn = r.getItemProperty("S/N");
            pUn = r.getItemProperty("Username");
            pMsisdn = r.getItemProperty("MSISDN");
            pEmail = r.getItemProperty("Email");
            pBtn = r.getItemProperty("Action");
            btnLink = new Button();
            btnLink.setIcon(FontAwesome.UNLINK);
            btnLink.setStyleName("btn_link");
            btnLink.setDescription("Unlink this account.");
            btnLink.addClickListener(new UNLinkClickHandler());
            btnLink.setId(un);
            btnLink.setData(rid);

            pSn.setValue(x);
            pUn.setValue(un);
            pMsisdn.setValue(msisdn);
            pEmail.setValue(email);
            pBtn.setValue(btnLink);

        }

        tb.setContainerDataSource(container);
        int t = container.size();
        if (t > 30)
            t = 30;
        tb.setPageLength(t);

    } catch (SQLException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {

        errorHandler(e);
    }

}

From source file:com.swifta.mats.web.usermanagement.UserDetailsModule.java

private HorizontalLayout getPC() {

    VerticalLayout cAgentInfo = new VerticalLayout();
    final HorizontalLayout cPlaceholder = new HorizontalLayout();
    cAgentInfo.setMargin(new MarginInfo(true, true, true, true));
    cAgentInfo.setStyleName("c_details_test");

    final VerticalLayout cLBody = new VerticalLayout();

    cLBody.setStyleName("c_body_visible");
    tb = new Table("Linked child accounts");
    // addLinksTable();

    final VerticalLayout cAllProf = new VerticalLayout();

    HorizontalLayout cProfActions = new HorizontalLayout();
    final FormLayout cProfName = new FormLayout();

    cProfName.setStyleName("frm_profile_name");
    cProfName.setSizeUndefined();/*w w  w  .j  av a2 s .  c om*/

    final Label lbProf = new Label();
    final TextField tFProf = new TextField();

    lbProf.setCaption("Profile Name: ");
    lbProf.setValue("Certified Authorized User.");

    tFProf.setCaption(lbProf.getCaption());
    cProfName.addComponent(lbProf);

    final Button btnEdit = new Button();
    btnEdit.setIcon(FontAwesome.EDIT);
    btnEdit.setStyleName("btn_link");
    btnEdit.setDescription("Edit profile name");

    final Button btnCancel = new Button();
    btnCancel.setIcon(FontAwesome.UNDO);
    btnCancel.setStyleName("btn_link");
    btnCancel.setDescription("Cancel Profile name editting.");

    Button btnAdd = new Button("+");
    // btnAdd.setIcon(FontAwesome.EDIT);
    btnAdd.setStyleName("btn_link");
    btnAdd.setDescription("Set new profile");

    Button btnRemove = new Button("-");
    // btnRemove.setIcon(FontAwesome.EDIT);
    btnRemove.setStyleName("btn_link");
    btnRemove.setDescription("Remove current profile");

    // cProf.addComponent(cProfName);
    cProfActions.addComponent(btnEdit);
    cProfActions.addComponent(btnCancel);
    cProfActions.addComponent(btnAdd);
    cProfActions.addComponent(btnRemove);

    btnCancel.setVisible(false);

    cAllProf.addComponent(cProfName);
    cAllProf.addComponent(cProfActions);
    cAllProf.setComponentAlignment(cProfActions, Alignment.TOP_CENTER);

    cLBody.addComponent(cAllProf);

    // cLBody.addComponent(tb);

    tb.setSelectable(true);

    cAgentInfo.addComponent(cLBody);

    btnLink = new Button("Add New Link");
    btnLink.setIcon(FontAwesome.LINK);
    btnLink.setDescription("Link new account.");

    // cLBody.addComponent(btnLink);
    // cLBody.setComponentAlignment(btnLink, Alignment.TOP_LEFT);
    btnLink.addClickListener(new LinkClickHandler());

    cPlaceholder.setVisible(false);
    addLinkUserContainer();
    cPlaceholder.setWidth("100%");

    cLBody.addComponent(cPlaceholder);
    cLBody.setComponentAlignment(cPlaceholder, Alignment.TOP_CENTER);
    HorizontalLayout c = new HorizontalLayout();
    c.addComponent(cAgentInfo);

    btnEdit.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = -8427226211153164650L;

        @Override
        public void buttonClick(ClickEvent event) {

            if (btnEdit.getIcon().equals(FontAwesome.EDIT)) {

                tFProf.setValue(lbProf.getValue());
                tFProf.selectAll();
                cProfName.replaceComponent(lbProf, tFProf);
                btnEdit.setIcon(FontAwesome.SAVE);
                btnCancel.setVisible(true);
                return;

            } else if (btnEdit.getIcon().equals(FontAwesome.SAVE)) {

                lbProf.setValue(tFProf.getValue());
                cProfName.replaceComponent(tFProf, lbProf);
                btnEdit.setIcon(FontAwesome.EDIT);
                btnCancel.setVisible(false);

                return;
            }
            lbProf.setValue(tFProf.getValue());
            cProfName.replaceComponent(tFProf, lbProf);
            btnEdit.setIcon(FontAwesome.EDIT);
            btnCancel.setVisible(false);

        }
    });

    btnCancel.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = -2870045546205986347L;

        @Override
        public void buttonClick(ClickEvent event) {
            cProfName.replaceComponent(tFProf, lbProf);
            btnEdit.setIcon(FontAwesome.EDIT);
            btnCancel.setVisible(false);

        }
    });

    btnAdd.addClickListener(new AddProfileHandler(cAllProf, cPlaceholder));

    btnRemove.addClickListener(new RemoveProfileHandler(pop));

    return c;

}

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   ww w  . j a  v  a2  s.  com*/

    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//from   ww  w. j a  v a  2 s  . c  o  m
        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.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//  www . j a va 2  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.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/*from   w  w w  .  j  a v  a  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.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.  j av  a 2s. co  m
    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;
}

From source file:com.trivago.mail.pigeon.web.components.recipients.RecipientList.java

License:Apache License

private void init() {
    final Panel rootPanel = new Panel("Recipients");
    rootPanel.setWidth("800px");

    //      Button senderListNewButton = new Button("Add Sender");
    //      senderListNewButton.setImmediate(true);
    //      senderListNewButton.setIcon(new ThemeResource("../runo/icons/16/document-add.png"));
    //      senderListNewButton.addListener(new Button.ClickListener()
    //      {/*  w  ww.  j a  v  a2 s .co m*/
    //         @Override
    //         public void buttonClick(Button.ClickEvent event)
    //         {
    //            Window modalNewWindow = new ModalAddNewSender(sl);
    //            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();
            }
        }
    });

    Button exportTable = new Button("Export");
    exportTable.setImmediate(true);
    exportTable.setIcon(new ThemeResource("../runo/icons/16/document-xsl.png"));
    exportTable.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            log.debug("Starting export");
            TableExport te = new ExcelExport(viewTable, "Recipient list", "Recipient list",
                    "Recipient_list.xls", false);
            log.debug("Converting table");
            te.convertTable();
            log.debug("Sending converted table...");
            boolean success = te.sendConverted();
            if (success) {
                log.debug("Sending should be successful");
            } else {
                log.warn("Sending not successfull, maybe IOException occured?");
            }
        }
    });

    viewTable.setImmediate(true);
    beanContainer = new BeanContainer<>(Recipient.class);

    List<Recipient> recipientList = getRecipientList();
    for (Recipient recipient : recipientList) {
        beanContainer.addItem(recipient.getId(), recipient);
    }

    viewTable.setContainerDataSource(beanContainer);
    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", "title", "firstname", "lastname", "email", "active",
            "gender", "birthday", "city", "country", "language", "Actions" });

    viewTable.setColumnHeaders(new String[] { "ID", "Title", "Firstname", "Lastname", "E-Mail", "Active",
            "Gender", "Birthday", "City", "Country", "Language", "Actions" });

    viewTable.setColumnCollapsingAllowed(true);

    viewTable.setColumnCollapsed("gender", true);
    viewTable.setColumnCollapsed("title", true);
    viewTable.setColumnCollapsed("birthday", true);
    viewTable.setColumnCollapsed("city", true);
    viewTable.setColumnCollapsed("country", true);
    viewTable.setColumnCollapsed("language", true);

    viewTable.setColumnExpandRatio(3, 2);
    viewTable.setColumnExpandRatio(4, 2);

    HorizontalLayout topButtonLayout = new HorizontalLayout();
    topButtonLayout.setSpacing(true);
    topButtonLayout.setMargin(false, false, true, false);
    topButtonLayout.addComponent(editButton);
    topButtonLayout.addComponent(exportTable);

    rootPanel.addComponent(topButtonLayout);
    rootPanel.addComponent(viewTable);

    setCompositionRoot(rootPanel);
}

From source file:com.trivago.mail.pigeon.web.components.sender.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 .  jav  a 2s  . co  m*/
    deleteButton.setIcon(new ThemeResource("../runo/icons/16/trash.png"));
    deleteButton.setDescription("Delete sender");
    deleteButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            Transaction tx = ConnectionFactory.getDatabase().beginTx();
            try {
                Sender s = new Sender((Long) itemId);
                ConnectionFactory.getSenderIndex().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) {
                source.getWindow().showNotification("Error while deleting entry: " + e.getMessage(),
                        Window.Notification.TYPE_ERROR_MESSAGE);
                log.error(e);
                tx.failure();
            } finally {
                tx.finish();
            }
        }
    });

    hl.addComponent(deleteButton);
    return hl;
}