Example usage for com.vaadin.ui Button addClickListener

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

Introduction

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

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Adds the button click listener.

Usage

From source file:com.whymenu.MainUI.java

private void updateLocations() {
    locations.forEach((key, value) -> {
        Location location = value;
        if (!buttons.containsKey(key)) {
            Button button = new Button(location != null ? location.getDescription() : key);
            button.addClickListener((Button.ClickEvent event) -> {
                System.out.println("test");
            });//  w  w  w  .  jav  a 2s. c o m
            mainLayout.addComponent(button);
            buttons.put(key, button);
        } else {
            Button button = buttons.get(key);
            if (!button.getCaption().equals(location.getDescription())) {
                button.setCaption(location.getDescription());
            }
        }
    });
    buttons.forEach((key, value) -> {
        if (!locations.containsKey(key)) {
            mainLayout.removeComponent(value);
            value = null;
        }
    });
}

From source file:com.wintindustries.pfserver.interfaces.view.dashboard.LoginView.java

private Component buildFields() {
    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);//from   ww  w . j  ava2  s.  c  o m
    fields.addStyleName("fields");

    final TextField username = new TextField("Username");
    username.setIcon(FontAwesome.USER);
    username.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    final PasswordField password = new PasswordField("Password");
    password.setIcon(FontAwesome.LOCK);
    password.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    final Button signin = new Button("Sign In");
    signin.addStyleName(ValoTheme.BUTTON_PRIMARY);
    signin.setClickShortcut(KeyCode.ENTER);
    signin.focus();

    fields.addComponents(username, password, signin);
    fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);

    signin.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {

            System.out.println("TRIGGER LOGIN");
            DashboardEventBus.post(new UserLoginRequestedEvent(username.getValue(), password.getValue()));
        }
    });
    return fields;
}

From source file:com.yoncabt.ebr.ui.ReportStatusWindow.java

@PostConstruct
private void init() {
    grid = makeGrid();//from  ww  w.java  2 s  .  co  m
    Button btnReload = new Button(FontAwesome.REFRESH);
    btnReload.addClickListener((Button.ClickEvent event) -> {
        fillTheGrid();
    });
    Button btnExport = YoncaGridXLSExporter.createDownloadButton(grid, "raporlar.xls");

    setContent(new VerticalLayout(new HorizontalLayout(btnExport, btnReload), grid));

    fillTheGrid();
    setWidth(100, Unit.PERCENTAGE);
}

From source file:com.yoncabt.ebr.ui.ReportWindow.java

@Override
protected void init(VaadinRequest request) {
    reportType.setNullSelectionAllowed(false);

    reportLocale.setNullSelectionAllowed(false);

    reportLocale.addItem("tr_TR");
    reportLocale.setItemCaption("tr_TR", "Trke");

    reportLocale.addItem("en_US");
    reportLocale.setItemCaption("en_US", "English");

    email.setEnabled(mailSender.isConfigured());

    grid = new Grid();

    try {//w  w w .ja va2  s .com
        MenuBar mb = createMenuBar();
        HorizontalLayout hl = new HorizontalLayout(mb);
        setContent(hl);
    } catch (IOException | JRException ex) {
        Notification.show("Hata", Notification.Type.ERROR_MESSAGE);
        Logger.getLogger(ReportWindow.class.getName()).log(Level.SEVERE, null, ex);
    }

    Button btnReload = new Button(FontAwesome.LIST_ALT);
    btnReload.setDisableOnClick(true);
    btnReload.addClickListener((Button.ClickEvent event) -> {
        try {
            fillTheGrid();
        } catch (Exception ex) {
            Notification.show("Hata", Notification.Type.ERROR_MESSAGE);
            Logger.getLogger(ReportWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
        event.getButton().setEnabled(true);
    });
    gridLayout = new HorizontalLayout();
    if (report instanceof SQLReport) {
        createGrid();
    }
    btnExport = YoncaGridXLSExporter.createDownloadButton(grid, "raporlar.xls");

    gridLayout.setSizeFull();

    window.setSizeUndefined();
    window.setContent(new VerticalLayout(formLayout, new HorizontalLayout(btnExport, btnReload), gridLayout));
    window.setClosable(false);
    addWindow(window);
    window.center();

    getPage().addUriFragmentChangedListener((Page.UriFragmentChangedEvent event) -> {
        String frag = event.getUriFragment();
        ReportWindow.this.uriFragmentChanged(frag);
    });
    if (StringUtils.isNotEmpty(getPage().getUriFragment())) {
        ReportWindow.this.uriFragmentChanged(getPage().getUriFragment());
    }
}

From source file:control.BarcodeController.java

License:Open Source License

/**
 * Initializes all listeners/*from www. j a v a  2 s.c om*/
 */
@SuppressWarnings("serial")
public void init(WizardBarcodeView bw) {
    view = bw;

    /**
     * Button listeners
     */
    Button.ClickListener cl = new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            String src = event.getButton().getCaption();
            if (src.startsWith("Print Barcodes")) {
                view.enablePrint(false);
                String project = view.getProjectCode();
                logger.info("Sending print command for project " + project + " barcodes");
                Printer p = view.getPrinter();
                creator.printBarcodeFolderForProject(project, p.getHostname(), p.getName(),
                        new PrintReadyRunnable(view));
                Styles.notification("Barcodes printing", "Barcodes have been sent to the printer.",
                        NotificationType.DEFAULT);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                view.enablePrint(true);
            }
            if (src.equals("Prepare Barcodes")) {
                if (expSelected()) {
                    view.creationPressed();
                    Iterator<Extension> it = view.getDownloadButton().getExtensions().iterator();
                    if (it.hasNext())
                        view.getDownloadButton().removeExtension(it.next());
                    barcodeBeans = getBarcodeInfoFromSelections(view.getSelectedExperiments(),
                            view.getSelectedSamples());
                    // boolean overwrite = view.getOverwrite();
                    String project = view.getProjectCode();
                    ProgressBar bar = view.getProgressBar();
                    bar.setVisible(true);
                    sortBeans(barcodeBeans);
                    if (view.getTabs().getSelectedTab() instanceof BarcodePreviewComponent) {
                        logger.info("Preparing barcodes (tubes) for project " + project);
                        creator.findOrCreateTubeBarcodesWithProgress(barcodeBeans, bar, view.getProgressInfo(),
                                new TubeBarcodesReadyRunnable(view, creator, barcodeBeans));
                    } else {
                        logger.info("Preparing barcodes (sheet) for project " + project);
                        String projectID = "/" + view.getSpaceCode() + "/" + project;
                        String name = dbManager.getProjectName(projectID);
                        creator.findOrCreateSheetBarcodesWithProgress(barcodeBeans, bar, view.getProgressInfo(),
                                new SheetBarcodesReadyRunnable(project, name,
                                        dbManager.getPersonForProject(projectID, "PI"),
                                        dbManager.getPersonForProject(projectID, "Contact"), view, creator,
                                        barcodeBeans));
                    }
                } else
                    Styles.notification("Can't create Barcodes",
                            "Please select at least one group of Sampes from the table!",
                            NotificationType.DEFAULT);
            }
        }
    };
    for (Button b : view.getButtons())
        b.addClickListener(cl);

    /**
     * Space selection listener
     */
    ValueChangeListener spaceSelectListener = new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            view.resetProjects();
            String space = view.getSpaceCode();
            if (space != null) {
                List<String> projects = new ArrayList<String>();
                for (Project p : openbis.getProjectsOfSpace(space)) {
                    String code = p.getCode();
                    String name = dbManager.getProjectName("/" + space + "/" + code);
                    if (name != null && name.length() > 0) {
                        if (name.length() >= 80)
                            name = name.substring(0, 80) + "...";
                        code += " (" + name + ")";
                    }
                    projects.add(code);
                }
                view.setProjectCodes(projects);
            }
        }

    };
    ComboBox space = view.getSpaceBox();
    if (space != null)
        space.addValueChangeListener(spaceSelectListener);

    /**
     * Project selection listener
     */

    ValueChangeListener projectSelectListener = new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            view.resetExperiments();
            String project = view.getProjectCode();
            view.setAvailableTubes(0);
            view.resetPrinters();
            view.enablePrep(projSelected());
            if (project != null) {
                if (project.contains(" "))
                    project = project.split(" ")[0];
                reactToProjectSelection(project);
            }
        }

    };
    ComboBox project = view.getProjectBox();
    if (project != null)
        project.addValueChangeListener(projectSelectListener);

    /**
     * Experiment selection listener
     */

    ValueChangeListener expSelectListener = new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            barcodeBeans = null;
            view.resetOptions();
            view.resetSamples();
            view.enablePrep(projSelected());// && optionSelected());
            if (expSelected()) {
                List<Sample> sampleList = new ArrayList<Sample>();
                Map<Sample, String> types = new HashMap<Sample, String>();
                for (ExperimentBarcodeSummary exp : view.getSelectedExperiments()) {
                    String type = exp.getBio_Type();
                    for (Sample s : exp.getSamples()) {
                        sampleList.add(s);
                        types.put(s, type);
                    }
                }
                view.setSamples(sampleList, types);
                if (tubesSelected())
                    view.enableTubeLabelPreview(getUsefulSample());
            } else
                view.disablePreview();
        }
    };
    view.getExperimentTable().addValueChangeListener(expSelectListener);

    ValueChangeListener sampSelectListener = new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            barcodeBeans = null;
            view.resetOptions();
            view.enablePrep(expSelected());
            if (expSelected() && tubesSelected())
                view.enableTubeLabelPreview(getUsefulSample());
        }
    };
    view.getSampleTable().addValueChangeListener(sampSelectListener);

    SelectedTabChangeListener tabListener = new SelectedTabChangeListener() {
        @Override
        public void selectedTabChange(SelectedTabChangeEvent event) {
            view.resetOptions();
            view.enablePrep(projSelected());
            if (tubesSelected() && expSelected())
                view.enableTubeLabelPreview(getUsefulSample());
            else
                view.disablePreview();
        }
    };
    view.getTabs().addSelectedTabChangeListener(tabListener);
}

From source file:cz.zcu.pia.social.network.frontend.components.login.ComponentLogin.java

/**
 * Creates register button/*from www. ja v a 2 s . c  o  m*/
 * @return register button
 */
private Button createRegisterButton() {
    Button register = new Button(msgs.getMessage(INFO_REGISTER));
    register.setStyleName(STYLE_BUTTON_LABEL);
    register.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {

            ((MyUI) UI.getCurrent().getUI()).getNavigator().navigateTo(ViewRegister.NAME);
        }
    });

    return register;
}

From source file:cz.zcu.pia.social.network.frontend.components.login.ComponentLogin.java

/**
 * Creates login button/*from ww w  . j  a  v  a  2  s  .  c  o  m*/
 * @return login button
 */
private Button createLoginButton() {
    Button login = new Button(msgs.getMessage(INFO_LOG_IN_BUTTON));
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    login.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (securityHelper.isAuthenticated()) {
                ((MyUI) UI.getCurrent().getUI()).getNavigator().navigateTo(ViewHome.NAME);
                return;
            }
            Users user = usersService.getUserByUsername(nickname.getValue());
            if (user == null) {
                Notification.show(msgs.getMessage(ERROR_NOT_CORRECT_LOGIN), Notification.Type.ERROR_MESSAGE);
                return;
            }
            StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();
            if (passwordEncryptor.checkPassword(password.getValue(), user.getPassword())) {
                securityHelper.setLogedInUser(user);
                ((MyUI) UI.getCurrent().getUI()).getHeader()
                        .setUsersFullName(user.getName() + " " + user.getSurname());
                ((MyUI) UI.getCurrent().getUI()).getHeader().setLoginButtonCaption();
                ((MyUI) UI.getCurrent().getUI()).getHeader()
                        .setSelectedMenuItem(msgs.getMessage("header.home"));
                ((MyUI) UI.getCurrent().getUI()).getHeader().addLogedInMenu();
                password.setValue("");
                nickname.setValue("");

                ((MyUI) UI.getCurrent().getUI()).getNavigator().navigateTo(ViewHome.NAME);
                return;
            } else {
                Notification.show(msgs.getMessage(ERROR_NOT_CORRECT_LOGIN), Notification.Type.ERROR_MESSAGE);
                return;
            }

        }
    });

    return login;
}

From source file:cz.zcu.pia.social.network.frontend.components.posts.ComponentPostAdd.java

/**
 * Constructor/*ww  w.  j  a  va 2 s. c  o m*/
 */
public ComponentPostAdd() {

    this.setSpacing(true);

    message.setWidth(100, Unit.PERCENTAGE);
    message.setHeight(100, Unit.PIXELS);
    message.setMaxLength(1000);

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

    newTag = new TextField();
    newTag.setImmediate(true);
    OnEnterKeyHandler onEnterHandler = new OnEnterKeyHandler() {
        @Override
        public void onEnterKeyPressed() {
            CustomLayout tag = new CustomLayout("tag");
            Button tagsButton = new Button(newTag.getValue());
            taglist.add(tagsButton);
            newTag.setValue("");
            newTag.focus();
            tagsButton.addClickListener(new Button.ClickListener() {

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    tags.removeComponent(event.getButton().getParent());
                    taglist.remove(event.getButton());
                }
            });

            tag.addComponent(tagsButton, "button");

            tags.addComponent(tag);
        }
    };
    onEnterHandler.installOn(newTag);

}

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//from w  w  w .  j a  v  a  2s  .co  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 ww  . ja  va 2s  .  com
 * @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());
        }
    }
}