Example usage for com.vaadin.ui NativeButton click

List of usage examples for com.vaadin.ui NativeButton click

Introduction

In this page you can find the example usage for com.vaadin.ui NativeButton click.

Prototype

public void click() 

Source Link

Document

Simulates a button click, notifying all server-side listeners.

Usage

From source file:at.peppol.webgui.app.MainWindow.java

License:Mozilla Public License

@SuppressWarnings("serial")
private void initUI() {

    final VerticalLayout root = new VerticalLayout();
    root.setMargin(false);/*from   w ww  .jav a  2 s  . com*/
    setContent(root);

    // createTopBar();
    // Changed with menuBar -- under testing
    createMenuBar();
    // Changed with custom layout using bootstrap -- under testing
    // createHeaderMenu();

    final UserFolder<File> userFolder = new UserFolder<File>();
    final long polling = 20000;
    int draftInvoicesNum = um.countItemsInSpace(um.getDrafts());
    int inboxInvoicesNum = um.countItemsInSpace(um.getInbox());
    int outboxInvoicesNum = um.countItemsInSpace(um.getOutbox());
    //Buttons
    final NativeButton inboxInvoices = new NativeButton("Invoices (" + inboxInvoicesNum + ")");
    final NativeButton outboxInvoices = new NativeButton("Invoices (" + outboxInvoicesNum + ")");
    final NativeButton draftInvoices = new NativeButton("Invoices (" + draftInvoicesNum + ")");

    //thread
    final Thread tFolderCount = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                while (true) {
                    int countDrafts = um.countItemsInSpace(um.getDrafts());
                    int countInbox = um.countItemsInSpace(um.getInbox());
                    int countOutbox = um.countItemsInSpace(um.getOutbox());
                    synchronized (MainWindow.this.getApplication()) {
                        String labelD = draftInvoices.getCaption();
                        labelD = labelD.replaceFirst("[\\d]+", "" + countDrafts);
                        draftInvoices.setCaption(labelD);

                        String labelI = inboxInvoices.getCaption();
                        labelI = labelI.replaceFirst("[\\d]+", "" + countInbox);
                        inboxInvoices.setCaption(labelI);

                        String labelO = outboxInvoices.getCaption();
                        labelO = labelO.replaceFirst("[\\d]+", "" + countOutbox);
                        outboxInvoices.setCaption(labelO);

                        itemsPanel.reloadTable(userFolder);
                    }
                    Thread.sleep(polling);
                }
            } catch (InterruptedException e) {
                System.out.println("Thread folders interrupted!!!");
            }
        }
    });

    // ------ START: Left NavBar -------
    final CssLayout leftNavBar = new CssLayout();
    leftNavBar.setStyleName("sidebar-menu");
    leftNavBar.setSizeFull();
    leftNavBar.setWidth("220px");

    // User theUser = (User) getApplication().getUser();
    final Label homeLbl = new Label("HOME");
    homeLbl.addStyleName("blue");
    leftNavBar.addComponent(homeLbl);

    leftNavBar.addComponent(new Label("INBOX"));
    final NativeButton catalogueBtn = new NativeButton("Catalogue");
    leftNavBar.addComponent(catalogueBtn);
    leftNavBar.addComponent(new NativeButton("Orders"));
    //leftNavBar.addComponent (new NativeButton ("Invoices"));
    //int inboxInvoicesNum = um.countItemsInSpace(um.getInbox());
    //inboxInvoices = new NativeButton ("Invoices ("+inboxInvoicesNum+")");
    inboxInvoices.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            inboxInvoices.setCaption("Invoices (" + um.countItemsInSpace(um.getInbox()) + ")");
            userFolder.setFolder(um.getInbox().getFolder());
            userFolder.setName(um.getInbox().getName());
            showInitialMainContent(userFolder);
            draftInvoices.removeStyleName("v-bold-nativebuttoncaption");
        }
    });
    leftNavBar.addComponent(inboxInvoices);

    leftNavBar.addComponent(new Label("DRAFTS"));
    leftNavBar.addComponent(new NativeButton("Catalogue"));
    leftNavBar.addComponent(new NativeButton("Orders"));
    //int draftInvoicesNum = um.countItemsInSpace(um.getDrafts());
    //draftInvoices = new NativeButton ("Invoices ("+draftInvoicesNum+")");
    draftInvoices.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            draftInvoices.setCaption("Invoices (" + um.countItemsInSpace(um.getDrafts()) + ")");
            userFolder.setFolder(um.getDrafts().getFolder());
            userFolder.setName(um.getDrafts().getName());
            showInitialMainContent(userFolder);
            draftInvoices.removeStyleName("v-bold-nativebuttoncaption");
        }
    });
    leftNavBar.addComponent(draftInvoices);

    leftNavBar.addComponent(new Label("OUTBOX"));
    leftNavBar.addComponent(new NativeButton("Catalogue"));
    leftNavBar.addComponent(new NativeButton("Orders"));
    //leftNavBar.addComponent (new NativeButton ("Invoices"));
    //int outboxInvoicesNum = um.countItemsInSpace(um.getOutbox());
    //outboxInvoices = new NativeButton ("Invoices ("+outboxInvoicesNum+")");
    outboxInvoices.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            outboxInvoices.setCaption("Invoices (" + um.countItemsInSpace(um.getOutbox()) + ")");
            userFolder.setFolder(um.getOutbox().getFolder());
            userFolder.setName(um.getOutbox().getName());
            showInitialMainContent(userFolder);
            draftInvoices.removeStyleName("v-bold-nativebuttoncaption");
        }
    });
    leftNavBar.addComponent(outboxInvoices);

    leftNavBar.addComponent(new Label("SETTINGS"));
    leftNavBar.addComponent(new NativeButton("My Profile"));
    leftNavBar.addComponent(new NativeButton("Customers"));
    leftNavBar.addComponent(new NativeButton("Suppliers"));

    final Embedded peppolLogoImg = new Embedded(null, new ExternalResource("img/peppol_logo.png"));

    peppolLogoImg.setStyleName("logo");
    leftNavBar.addComponent(peppolLogoImg);

    middleContentLayout.addComponent(leftNavBar);

    /*Button refreshButton = new Button("Refresh");
    refreshButton.addListener(new Button.ClickListener() {
      @Override
      public void buttonClick(ClickEvent event) {
         int draftInvoices = um.countItemsInSpace(um.getDrafts());
         invoices.setCaption("Invoices ("+draftInvoices+")");
      }
    });
    leftNavBar.addComponent(refreshButton);*/

    //workaround so that thread refreshes UI. It seems that when a ProgressIndicator is present,
    //all components receive server side refreshes
    ProgressIndicator p = new ProgressIndicator();
    p.setPollingInterval((int) polling);
    p.setWidth("0px");
    p.setHeight("0px");
    leftNavBar.addComponent(p);

    showInitialMainContent(null);
    draftInvoices.click();
    tFolderCount.start();
    draftInvoices.addStyleName("v-bold-nativebuttoncaption");
}

From source file:com.foc.web.unitTesting.FocUnitTestingCommand.java

License:Apache License

/**
 * Simulates a click on the "Log Out" button in the application.
 *///from   w  w  w  .j a  va2  s  .c  o  m
public void logout() throws Exception {
    if (Globals.isValo()) {

        getDictionary().incrementTestIndexes();
        getMainWindow().logout();
        FocUnitDictionary.getInstance().setExitTesting(true);
        /*
        MenuItem logoutMenuItem = getMainWindow() != null ? getMainWindow().getLogoutMenuItem() : null;
        if(logoutMenuItem != null && logoutMenuItem.getCommand() != null){
           logoutMenuItem.getCommand().menuSelected(logoutMenuItem);
           getMainWindow().setMenuBarFilled(false); //To Fix Logout Bug  06-01-2016 //
        }else{
           getLogger().addFailure("Log Out button not found.");
        }
        */

    } else {
        NativeButton logout = getMainWindow().getLogoutButton();
        if (logout != null) {
            logout.click();
        } else {
            getLogger().addFailure("Log Out button not found.");
        }
    }
}

From source file:com.foc.web.unitTesting.FocUnitTestingCommand.java

License:Apache License

/**
 * Simulates a click on the "Navigation" button in the application.
 * /*from  w  w  w .j  a v  a 2s  . c om*/
 */
public void button_ClickNavigate() throws Exception {
    NativeButton navigation = getMainWindow().getNavigationButton();
    if (navigation != null) {
        navigation.click();
    } else {
        getLogger().addFailure("Navigation button not found.");
    }
}

From source file:com.foc.web.unitTesting.FocUnitTestingCommand.java

License:Apache License

/**
 * Simulates a click on the "Home" button in the application.
 *//*from  w ww  . ja va 2s . com*/
public void button_ClickHome() throws Exception {
    NativeButton home = getMainWindow().getHomeButton();
    if (home != null) {
        home.click();
    } else {
        getLogger().addFailure("Home button not found.");
    }
}

From source file:com.foc.web.unitTesting.FocUnitTestingCommand.java

License:Apache License

/**
 * Simulates a click on the "Admin" button in the application.
 * //  ww w .ja  v a  2s .c  o m
 */
protected void button_ClickAdmin() throws Exception {
    NativeButton admin = getMainWindow().getAdminButton();
    if (admin != null) {
        admin.click();
    } else {
        getLogger().addFailure("Admin button not found.");
    }
}

From source file:com.foc.web.unitTesting.FocUnitTestingCommand.java

License:Apache License

public void login() throws Exception {
    NativeButton loginButton = getMainWindow().getLoginButton();
    if (loginButton != null) {
        loginButton.click();
    } else {//from ww w . j a  v a 2  s  .  co  m
        getLogger().addFailure("Login button not found.");
    }
}