Example usage for com.vaadin.ui Button setData

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

Introduction

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

Prototype

public void setData(Object data) 

Source Link

Document

Sets the data object, that can be used for any application specific data.

Usage

From source file:com.skysql.manager.ui.MonitorsLayout.java

License:Open Source License

/**
 * Adds a new monitor row.//from w  ww .j  a va2s  .c o  m
 *
 * @param monitorID the monitor id
 * @return the component
 */
private Component addRow(String monitorID) {
    HorizontalLayout row = new HorizontalLayout();
    ComboBox selectMonitor = new ComboBox();
    for (MonitorRecord availMonitor : availableMonitors.values()) {
        selectMonitor.addItem(availMonitor.getID());
        selectMonitor.setItemCaption(availMonitor.getID(), availMonitor.getName());
    }
    row.addComponent(selectMonitor);
    selectMonitorList.add(selectMonitor);

    selectMonitor.setValue(monitorID);
    selectMonitor.setNullSelectionAllowed(false);
    selectMonitor.setImmediate(true);
    selectMonitor.addValueChangeListener(monitorSelectListener);

    if (getComponentCount() > componentIndex) {
        Button deleteButton = new Button("X");
        row.addComponent(deleteButton);
        deleteButton.setData(selectMonitor);
        deleteButton.addClickListener(new Button.ClickListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            public void buttonClick(ClickEvent event) {
                // remove combobox from list
                Button button = event.getButton();
                ComboBox select = (ComboBox) button.getData();
                selectMonitorList.remove(select);

                // remove layout from dialog
                int layoutIndex = getComponentIndex(button.getParent());
                HorizontalLayout layout = (HorizontalLayout) getComponent(layoutIndex);
                removeComponent(layout);

                refreshMonitors();
            }
        });
    }

    focus();

    return (row);

}

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

@SuppressWarnings("unchecked")
private void addLinksTable() {

    container.addContainerProperty("S/N", Integer.class, 0);
    container.addContainerProperty("Username", String.class, null);
    container.addContainerProperty("MSISDN", String.class, null);
    container.addContainerProperty("Email", String.class, null);
    container.addContainerProperty("Action", Button.class, null);

    StringBuilder sb = new StringBuilder();

    sb.append(/*from   w w w. j ava  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' ");
    sb.append(" and ah.accountholderdetailid = ahd.accountdetailsid ");
    sb.append(" and pl.childuserresourceid = ah.accountholderid ");
    sb.append(" and parentuserresourceid in (select accountholderid from accountholders ");
    sb.append(" where (username = '" + curUser + "'))");

    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());

        int x = 0;
        Property<String> pUn;
        Property<String> pMsisdn;
        Property<String> pEmail;
        Property<Integer> pSn;
        Property<Button> pBtn;

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

        while (rs.next()) {

            x++;

            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);
        if (x > 30)
            x = 30;
        tb.setPageLength(x);

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

        errorHandler(e);
    }

}

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

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

    sb.append(//from  ww  w  . jav a  2 s .com
            " 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.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  2  s.c om*/

    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:cz.zcu.pia.social.network.frontend.components.posts.ComponentPostPaginator.java

/**
 * Add buttons, based on number of pages
 *
 * @param numberOfPages number Of Pages//  w w w  . j a  v  a2s . c o  m
 */
public void addButtons(int numberOfPages) {
    this.removeAllComponents();
    buttonList.clear();
    for (int i = 0; i <= numberOfPages; i++) {
        Button b = new Button("" + i);
        b.setData(i);
        b.setStyleName("button-paginator button-label-simple");
        b.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                int page = (int) event.getButton().getData();
                if (curentPage != page) {
                    filterReference.setPageAndReload(page);
                    removeActiveStyle();
                    curentPage = page;
                    buttonList.get(curentPage).addStyleName("paginator-active");
                }
            }

        });
        if (i == 0) {
            b.addStyleName("paginator-active");
        }
        buttonList.add(b);
        this.addComponent(b);
    }

}

From source file:cz.zcu.pia.social.network.frontend.components.profile.friends.ComponentFriends.java

/**
 * Adds friends to table/*from   w w  w. j av a  2 s . c  o  m*/
 * @param friendsList  friends List
 */
private void addFriendsToTable(List<Friends> friendsList) {
    for (Friends f : friendsList) {
        Button removeFriend = new Button(msgs.getMessage("profile.remove.friend"));
        removeFriend.setData(f);
        removeFriend.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                Friends f = (Friends) event.getButton().getData();
                friendsService.delete(f);
                table.removeItem(f.getId());
            }
        });
        if (f.getFriend().getId().equals(securityHelper.getLogedInUser().getId())) {
            table.addItem(new Object[] { f.getUser().getName(), f.getUser().getSurname(),
                    getTimeStamp(f.getFriendsSince()), removeFriend }, f.getId());
        } else {
            table.addItem(new Object[] { f.getFriend().getName(), f.getFriend().getSurname(),
                    getTimeStamp(f.getFriendsSince()), removeFriend }, f.getId());
        }
    }
}

From source file:cz.zcu.pia.social.network.frontend.components.profile.friends.ComponentFriends.java

/**
 * Adds following to table//from   ww  w  .ja va2 s .c  o  m
 * @param followingList  following List
 */
private void addFollowingToTable(List<Following> followingList) {
    for (Following f : followingList) {
        Button removeFollow = new Button(msgs.getMessage("component.friends.remove.following"));
        removeFollow.setData(f);
        removeFollow.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                Following f = (Following) event.getButton().getData();
                table.removeItem(f.getId());
                followingService.removeFollow(f);
            }
        });
        table.addItem(new Object[] { f.getFeeder().getName(), f.getFeeder().getSurname(),
                getTimeStamp(f.getFollowingSince()), removeFollow }, f.getId());
    }
}

From source file:cz.zcu.pia.social.network.frontend.components.profile.friends.ComponentManageFriendRequest.java

/**
 * Adds content/*from ww  w.j  av a2s.  c  om*/
 */
private void addContent() {
    Long userId = securityHelper.getLogedInUser().getId();
    List<FriendRequest> friendRequestList = friendRequestService.getFriendRequests(userId);
    for (FriendRequest fr : friendRequestList) {
        Button accept = new Button(msgs.getMessage("request.accept"));
        accept.setData(fr);
        accept.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                FriendRequest fr = (FriendRequest) event.getButton().getData();
                friendRequestService.confirmFriendRequest(fr);
                table.removeItem(fr.getId());
                parentReference.reload();
            }
        });
        Button deny = new Button(msgs.getMessage("request.deny"));
        HorizontalLayout wrapper = new HorizontalLayout();
        wrapper.setSpacing(true);
        wrapper.addComponent(accept);
        wrapper.addComponent(deny);
        if (fr.isDenyed()) {
            deny.setEnabled(false);
        } else {
            deny.setData(fr);
            deny.addClickListener(new Button.ClickListener() {

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    FriendRequest fr = (FriendRequest) event.getButton().getData();
                    friendRequestService.denyFriendRequest(fr);
                    event.getButton().setEnabled(false);
                }
            });
        }
        table.addItem(new Object[] { fr.getUserSender().getName(), fr.getUserSender().getSurname(),
                getTimeStamp(fr.getDateSent()), wrapper }, fr.getId());
    }

}

From source file:cz.zcu.pia.social.network.frontend.components.profile.profile.ComponentProfilePost.java

/**
 * Gets add friend button/*from ww w  . j a  v  a 2 s.  com*/
 * @return add friend button
 */
private Button getAddFriendButton() {
    Button addFriend;

    Friends friends = friendsService.getFriend(securityHelper.getLogedInUser(), user);
    if (friends == null) {
        addFriend = new Button(msgs.getMessage("profile.add.friend"));

    } else {

        addFriend = new Button(msgs.getMessage("profile.remove.friend"));
        addFriend.setData(friends);
    }

    addFriend.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (event.getButton().getCaption().equals(msgs.getMessage("profile.add.friend"))) {
                FriendRequest request = friendRequestService.getFriendRequest(securityHelper.getLogedInUser(),
                        user);
                if (request != null && !request.isDenyed()) {
                    Notification.show(msgs.getMessage("request.sent"), Notification.Type.HUMANIZED_MESSAGE);
                    return;
                }
                FriendRequest fr = new FriendRequest(securityHelper.getLogedInUser(), user);
                friendRequestService.persist(fr);
                event.getButton().setEnabled(false);
            } else {
                Friends friends = (Friends) event.getButton().getData();
                friendsService.delete(friends);
            }
        }
    });
    return addFriend;
}

From source file:de.metas.ui.web.vaadin.window.components.ATabToolbar.java

License:Open Source License

private void addToolbarButton(final ActionInfo actionInfo) {
    final String action = actionInfo.getAction();

    final Button button = new Button();
    button.setCaption(action);/*  www .j av a2  s .  com*/
    button.setData(actionInfo);
    button.setEnabled(model.isActionEnabled(action));
    button.addClickListener(actionButtonListener);

    action2button.put(action, button);

    addComponent(button);
}