Example usage for com.vaadin.ui Button click

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

Introduction

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

Prototype

public void click() 

Source Link

Document

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

Usage

From source file:com.peergreen.webconsole.core.vaadin7.BaseUI.java

License:Open Source License

/**
 * Build login view/*from  w  ww . j a v  a  2 s  .c  o m*/
 *
 * @param exit
 */
private void buildLoginView(final boolean exit) {
    if (exit) {
        root.removeAllComponents();
    }
    notifierService.closeAll();

    addStyleName("login");

    VerticalLayout loginLayout = new VerticalLayout();
    loginLayout.setId("webconsole_loginlayout_id");
    loginLayout.setSizeFull();
    loginLayout.addStyleName("login-layout");
    root.addComponent(loginLayout);

    final CssLayout loginPanel = new CssLayout();
    loginPanel.addStyleName("login-panel");

    HorizontalLayout labels = new HorizontalLayout();
    labels.setWidth(MAX_WIDTH);
    labels.setMargin(true);
    loginPanel.addComponent(labels);

    Label welcome = new Label("Welcome");
    welcome.addStyleName("h4");
    labels.addComponent(welcome);
    labels.setComponentAlignment(welcome, Alignment.MIDDLE_LEFT);

    Label title = new Label(consoleName);
    //title.setSizeUndefined();
    title.addStyleName("h2");
    title.addStyleName("light");
    labels.addComponent(title);
    labels.setComponentAlignment(title, Alignment.MIDDLE_RIGHT);

    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);
    fields.setMargin(true);
    fields.addStyleName("fields");

    final TextField username = new TextField("Username");
    username.focus();
    username.setId("webconsole_login_username");
    fields.addComponent(username);

    final PasswordField password = new PasswordField("Password");
    password.setId("webconsole_login_password");
    fields.addComponent(password);

    final Button signin = new Button("Sign In");
    signin.setId("webconsole_login_signin");
    signin.addStyleName("default");
    fields.addComponent(signin);
    fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);

    final ShortcutListener enter = new ShortcutListener("Sign In", ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            signin.click();
        }
    };

    signin.addShortcutListener(enter);
    loginPanel.addComponent(fields);

    HorizontalLayout bottomRow = new HorizontalLayout();
    bottomRow.setWidth(MAX_WIDTH);
    bottomRow.setMargin(new MarginInfo(false, true, false, true));
    final CheckBox keepLoggedIn = new CheckBox("Keep me logged in");
    bottomRow.addComponent(keepLoggedIn);
    bottomRow.setComponentAlignment(keepLoggedIn, Alignment.MIDDLE_LEFT);
    // Add new error message
    final Label error = new Label("Wrong username or password.", ContentMode.HTML);
    error.setId("webconsole_login_error");
    error.addStyleName("error");
    error.setSizeUndefined();
    error.addStyleName("light");
    // Add animation
    error.addStyleName("v-animate-reveal");
    error.setVisible(false);
    bottomRow.addComponent(error);
    bottomRow.setComponentAlignment(error, Alignment.MIDDLE_RIGHT);
    loginPanel.addComponent(bottomRow);

    signin.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (authenticate(username.getValue(), password.getValue())) {
                //                    if (keepLoggedIn.getValue()) {
                //                        //Cookie userCookie = getCookieByName(PEERGREEN_USER_COOKIE_NAME);
                //                       if (getCookieByName(PEERGREEN_USER_COOKIE_NAME) == null) {
                //                            // Get a token for this user and create a cooki
                //                            Page.getCurrent().getJavaScript().execute( String.format("document.cookie = '%s=%s; path=%s'",
                //                                    PEERGREEN_USER_COOKIE_NAME, token, VaadinService.getCurrentRequest().getContextPath()));
                //                        } else {
                //                            // update token
                //                            userCookie.setValue(token);
                //                            userCookie.setPath(VaadinService.getCurrentRequest().getContextPath());
                //                        }
                //                    }

                buildMainView();
            } else {
                error.setVisible(true);
            }
        }
    });

    loginLayout.addComponent(loginPanel);
    loginLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
}

From source file:de.catma.ui.CatmaApplication.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    backgroundService = new UIBackgroundService(true);

    storeParameters(request.getParameterMap());

    Page.getCurrent().setTitle("CATMA 5.0 " + MINORVERSION);

    mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();/*from   ww  w.  j  ava2  s  .  c om*/

    menuPanel = new Panel();
    menuPanel.addStyleName("menuPanel");
    mainLayout.addComponent(menuPanel);

    contentPanel = new Panel();
    contentPanel.setHeight("100%");
    contentPanel.addStyleName("contentPanel");

    defaultContentPanelLabel = new Label("Please log in to get started");
    defaultContentPanelLabel.addStyleName("defaultContentPanelLabel");
    contentPanel.setContent(defaultContentPanelLabel);

    mainLayout.addComponent(contentPanel);
    mainLayout.setExpandRatio(contentPanel, 1.0f);

    menuLayout = new HorizontalLayout();
    menuLayout.setMargin(true);
    menuLayout.setSpacing(true);

    logoResource = new ThemeResource("catma-logo.png");
    Link logoImage = new Link(null, new ExternalResource("http://www.catma.de"));
    logoImage.setIcon(logoResource);
    logoImage.setTargetName("_blank");
    menuLayout.addComponent(logoImage);

    MenuFactory menuFactory = new MenuFactory();
    try {

        initTempDirectory();
        tagManager = new TagManager();

        repositoryManagerView = new RepositoryManagerView(
                new RepositoryManager(this, tagManager, RepositoryProperties.INSTANCE.getProperties()));

        tagManagerView = new TagManagerView(tagManager);

        taggerManagerView = new TaggerManagerView();

        analyzerManagerView = new AnalyzerManagerView();

        visualizationManagerView = new VisualizationManagerView();

        menu = menuFactory.createMenu(menuLayout, contentPanel,
                new MenuFactory.MenuEntryDefinition("Repository Manager", repositoryManagerView),
                new MenuFactory.MenuEntryDefinition("Tag Type Manager", tagManagerView),
                new MenuFactory.MenuEntryDefinition("Tagger", taggerManagerView),
                new MenuFactory.MenuEntryDefinition("Analyzer", analyzerManagerView),
                new MenuFactory.MenuEntryDefinition("Visualizer", visualizationManagerView));
        addPropertyChangeListener(CatmaApplicationEvent.userChange, menu.userChangeListener);

        Link latestFeaturesLink = new Link("Latest Features",
                new ExternalResource("http://www.catma.de/latestfeatures"));
        latestFeaturesLink.setTargetName("_blank");
        menuLayout.addComponent(latestFeaturesLink);
        menuLayout.setComponentAlignment(latestFeaturesLink, Alignment.TOP_RIGHT);
        menuLayout.setExpandRatio(latestFeaturesLink, 1.0f);

        Link aboutLink = new Link("About", new ExternalResource("http://www.catma.de"));
        aboutLink.setTargetName("_blank");
        menuLayout.addComponent(aboutLink);
        menuLayout.setComponentAlignment(aboutLink, Alignment.TOP_RIGHT);

        Link termsOfUseLink = new Link("Terms of Use", new ExternalResource("http://www.catma.de/termsofuse"));
        termsOfUseLink.setTargetName("_blank");
        menuLayout.addComponent(termsOfUseLink);
        menuLayout.setComponentAlignment(termsOfUseLink, Alignment.TOP_RIGHT);

        Link manualLink = new Link("Manual", new ExternalResource(request.getContextPath() + "/manual/"));
        manualLink.setTargetName("_blank");
        menuLayout.addComponent(manualLink);
        menuLayout.setComponentAlignment(manualLink, Alignment.TOP_RIGHT);

        Link helpLink = new Link("Helpdesk", new ExternalResource("http://www.catma.de/helpdesk/"));
        helpLink.setTargetName("_blank");
        menuLayout.addComponent(helpLink);
        menuLayout.setComponentAlignment(helpLink, Alignment.TOP_RIGHT);
        helpLink.setVisible(false);

        btHelp = new Button(FontAwesome.QUESTION_CIRCLE);
        btHelp.addStyleName("help-button");
        btHelp.addStyleName("application-help-button");

        menuLayout.addComponent(btHelp);

        btHelp.addClickListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {

                if (uiHelpWindow.getParent() == null) {
                    UI.getCurrent().addWindow(uiHelpWindow);
                } else {
                    UI.getCurrent().removeWindow(uiHelpWindow);
                }

            }
        });

        LoginLogoutCommand loginLogoutCommand = new LoginLogoutCommand(menu, repositoryManagerView);
        Button btloginLogout = new Button("Sign in", event -> loginLogoutCommand.menuSelected(null));
        btloginLogout.setStyleName(BaseTheme.BUTTON_LINK);
        btloginLogout.addStyleName("application-loginlink");

        loginLogoutCommand.setLoginLogoutButton(btloginLogout);

        menuLayout.addComponent(btloginLogout);
        menuLayout.setComponentAlignment(btloginLogout, Alignment.TOP_RIGHT);
        menuLayout.setWidth("100%");

        menuPanel.setContent(menuLayout);

        setContent(mainLayout);

        if (getParameter(Parameter.USER_IDENTIFIER) != null) {
            btloginLogout.click();
        }

        setPollInterval(10000);

        if ((getParameter(Parameter.AUTOLOGIN) != null) && (getUser() == null)) {
            getPage().setLocation(repositoryManagerView.createAuthenticationDialog().createLogInClick(this,
                    RepositoryPropertyKey.CATMA_oauthAuthorizationCodeRequestURL.getValue(),
                    RepositoryPropertyKey.CATMA_oauthAccessTokenRequestURL.getValue(),
                    RepositoryPropertyKey.CATMA_oauthClientId.getValue(),
                    RepositoryPropertyKey.CATMA_oauthClientSecret.getValue(), URLEncoder.encode("/", "UTF-8")));
        }

    } catch (Exception e) {
        showAndLogError("The system could not be initialized!", e);
    }

}

From source file:de.symeda.sormas.ui.dashboard.surveillance.SurveillanceOverviewLayout.java

License:Open Source License

private void addDiseaseBurdenView() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setMargin(false);/* w w  w.ja  v a 2s.c om*/

    layout.addComponent(diseaseTileViewLayout);
    layout.setExpandRatio(diseaseTileViewLayout, 1);

    // "Expand" and "Collapse" buttons
    Button showTableViewButton = new Button("", VaadinIcons.TABLE);
    CssStyles.style(showTableViewButton, CssStyles.BUTTON_SUBTLE);
    showTableViewButton.addStyleName(CssStyles.VSPACE_NONE);

    Button showTileViewButton = new Button("", VaadinIcons.SQUARE_SHADOW);
    CssStyles.style(showTileViewButton, CssStyles.BUTTON_SUBTLE);
    showTileViewButton.addStyleName(CssStyles.VSPACE_NONE);

    showTableViewButton.addClickListener(e -> {
        layout.removeComponent(diseaseTileViewLayout);
        layout.addComponent(diseaseBurdenComponent);
        layout.setExpandRatio(diseaseBurdenComponent, 1);

        layout.removeComponent(showTableViewButton);
        layout.addComponent(showTileViewButton);
        layout.setComponentAlignment(showTileViewButton, Alignment.TOP_RIGHT);
    });
    showTileViewButton.addClickListener(e -> {
        layout.removeComponent(diseaseBurdenComponent);
        layout.addComponent(diseaseTileViewLayout);
        layout.setExpandRatio(diseaseTileViewLayout, 1);

        layout.removeComponent(showTileViewButton);
        layout.addComponent(showTableViewButton);
        layout.setComponentAlignment(showTableViewButton, Alignment.TOP_RIGHT);
    });

    layout.addComponent(showTableViewButton);
    layout.setComponentAlignment(showTableViewButton, Alignment.TOP_RIGHT);

    diseaseBurdenView = layout;
    addComponent(diseaseBurdenView, BURDEN_LOC);

    if (UserRole.isSupervisor(UserProvider.getCurrent().getUser().getUserRoles()))
        showTableViewButton.click();
}

From source file:fr.univlorraine.mondossierweb.uicomponents.AutoComplete.java

License:Apache License

public void showChoices(List<ResultatDeRecherche> text, Layout layout, Button btnRecherche,
        boolean touchkitMobileDisplay) {

    //Si du texte est saisi
    if (text.size() > 0) {

        //Si la popup est dj instancie, on la masque
        if (choicesPopup != null) {
            choicesPopup.setPopupVisible(false);

        }//  ww  w.  ja  va 2  s . c o m

        //Si c'est la premire fois que l'on affiche la popup
        if (choices == null) {
            //On cr la table contenant les propositions
            choices = new Table();
            //Ajout du libell dans la table
            choices.addContainerProperty("lib", String.class, "");
            //Si on est en affichage bureau, on ajoute le type
            if (!touchkitMobileDisplay) {
                choices.addContainerProperty("type", String.class, "");
            }
            //On cache les headers des colonnes
            choices.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
            //la table fait la mme largeur que le composant textfield de saisie
            choices.setWidth(getWidth(), getWidthUnits());
            //Ajout du style css googletable
            choices.setStyleName("googletable");
            //Si on est en affichage bureau, on dtermine  la main la taille des colonnes
            if (!touchkitMobileDisplay) {
                choices.setColumnWidth("lib", 596);
                choices.setColumnWidth("type", 100);
            }

            choices.setImmediate(true);

            //Gestion du clic sur une ligne de la table -> on met la valeut de la ligne dans le textField de saisie
            choices.addItemClickListener(new ItemClickListener() {
                @Override
                public void itemClick(ItemClickEvent event) {
                    Item i = event.getItem();
                    setValue(i.getItemProperty("lib").getValue().toString());
                    btnRecherche.click();
                }

            });

        } else {
            //On vide simplement la table de son contenu prcdent
            choices.removeAllItems();
        }

        //On parcourt les rsultats pour les ajouter  la table
        int i = 1;
        for (ResultatDeRecherche r : text) {
            Item item = choices.addItem(i);
            item.getItemProperty("lib").setValue(r.getLib());
            //Si on est en affichage bureau, on ajoute le type
            if (!touchkitMobileDisplay) {
                item.getItemProperty("type").setValue(transcodeType(r.getType()));
            }
            i++;
        }
        selectedItem = 0;
        //On fixe la hauteur de la table en fonction du nombre de rsultats affichs
        choices.setHeight(38 * text.size() + 1, Unit.PIXELS);
        //la table fait la mme largeur que le composant textfield de saisie
        choices.setWidth(getWidth(), getWidthUnits());

        // Si on n'a encore jamais affich la popup
        if (choicesPopup == null) {
            //on cr la popup
            choicesPopup = new PopupView(new PopupTextFieldContent());
            //On lui ajoute le style css googlepopupview
            choicesPopup.setStyleName("googlepopupview");
            //On ajoute la popup au layout
            layout.addComponent(choicesPopup);
            //la popup fait la mme largeur que le composant textfield de saisie
            choicesPopup.setWidth(getWidth(), getWidthUnits());
            choices.setSelectable(true);
            choices.setImmediate(true);
            choicesPopup.addPopupVisibilityListener(new PopupVisibilityListener() {
                @Override
                public void popupVisibilityChange(PopupVisibilityEvent event) {
                    if (!event.isPopupVisible()) {
                        //On masque la popup quand on perd le focus sur le champ texte
                        choicesPopup.setVisible(false);
                    }
                }
            });

        }

        //On affiche la popup
        choicesPopup.setVisible(true);
        choicesPopup.setPopupVisible(true);
        //La popup fait la mme hauteur que la table qu'elle contient
        choicesPopup.setHeight(choices.getHeight(), choices.getHeightUnits());

    } else {
        //Aucun texte n'ai saisi
        if (choicesPopup != null) {
            //On masque la popup si elle est dj instancie
            choicesPopup.setVisible(false);
            choicesPopup.setPopupVisible(false);
        }
    }

}

From source file:io.subutai.plugin.accumulo.ui.manager.Manager.java

private void checkNodesStatus(final Table nodesTable) {
    if (nodesTable != null) {
        for (Object o : nodesTable.getItemIds()) {
            int rowId = (Integer) o;
            Item row = nodesTable.getItem(rowId);
            HorizontalLayout availableOperationsLayout = (HorizontalLayout) (row
                    .getItemProperty(AVAILABLE_OPERATIONS_COLUMN_CAPTION).getValue());
            if (availableOperationsLayout != null) {
                Button checkBtn = getButton(availableOperationsLayout, CHECK_BUTTON_CAPTION);
                if (checkBtn != null) {
                    checkBtn.click();
                }// w w  w. ja  v a2s  . c  o m
            }
        }
    }
}

From source file:no.uib.probe.csf.pr.touch.view.core.SearchingField.java

/**
 * Default constructor to initialize the main attributes.
 *//*from w  ww.  j  av a 2  s . co m*/
public SearchingField() {
    this.setSpacing(true);
    this.setHeightUndefined();

    HorizontalLayout searchFieldContainerLayout = new HorizontalLayout();
    searchFieldContainerLayout.setWidthUndefined();
    searchFieldContainerLayout.setHeight(100, Unit.PERCENTAGE);
    searchFieldContainerLayout.setSpacing(true);
    TextField searchField = new TextField();
    searchField.setDescription("Search proteins by name or accession");
    searchField.setImmediate(true);
    searchField.setWidth(100, Unit.PIXELS);
    searchField.setHeight(18, Unit.PIXELS);
    searchField.setInputPrompt("Search...");
    searchFieldContainerLayout.addComponent(searchField);
    searchField.setTextChangeTimeout(1500);
    searchField.setStyleName(ValoTheme.TEXTFIELD_SMALL);
    searchField.addStyleName(ValoTheme.TEXTFIELD_TINY);
    final Button b = new Button();
    searchField.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.LAZY);

    searchField.addShortcutListener(new Button.ClickShortcut(b, ShortcutListener.KeyCode.ENTER));

    VerticalLayout searchingBtn = new VerticalLayout();
    searchingBtn.setWidth(22, Unit.PIXELS);
    searchingBtn.setHeight(18, Unit.PIXELS);
    searchingBtn.setStyleName("tablesearchingbtn");
    searchFieldContainerLayout.addComponent(searchingBtn);
    searchFieldContainerLayout.setComponentAlignment(searchingBtn, Alignment.TOP_CENTER);
    this.addComponent(searchFieldContainerLayout);
    this.setComponentAlignment(searchFieldContainerLayout, Alignment.TOP_CENTER);
    searchingCommentLabel = new Label();
    searchingCommentLabel.setWidth(100, Unit.PERCENTAGE);
    searchingCommentLabel.setHeight(23, Unit.PIXELS);
    searchingCommentLabel.addStyleName(ValoTheme.LABEL_BOLD);
    searchingCommentLabel.addStyleName(ValoTheme.LABEL_SMALL);
    searchingCommentLabel.addStyleName(ValoTheme.LABEL_TINY);
    this.addComponent(searchingCommentLabel);
    this.setComponentAlignment(searchingCommentLabel, Alignment.TOP_CENTER);

    searchingBtn.addLayoutClickListener((LayoutEvents.LayoutClickEvent event) -> {
        b.click();
    });
    searchField.addTextChangeListener((FieldEvents.TextChangeEvent event) -> {
        SearchingField.this.textChanged(event.getText());
    });
    b.addClickListener((Button.ClickEvent event) -> {
        SearchingField.this.textChanged(searchField.getValue());
    });

}

From source file:org.eclipse.hawkbit.ui.common.ConfirmationDialog.java

License:Open Source License

/**
 * Constructor for configuring confirmation dialog.
 * /* www.j  av  a2  s.  c  o  m*/
 * @param caption
 *            the dialog caption.
 * @param question
 *            the question.
 * @param okLabel
 *            the Ok button label.
 * @param cancelLabel
 *            the cancel button label.
 * @param callback
 *            the callback.
 * @param icon
 *            the icon of the dialog
 * @param id
 *            the id of the confirmation dialog
 * @param tab
 *            ConfirmationTab which contains more information about the
 *            action which has to be confirmed, e.g. maintenance window
 * @param mapCloseToCancel
 *            Flag indicating whether or not the close event on the
 *            enclosing window should be mapped to a cancel event.
 */
public ConfirmationDialog(final String caption, final String question, final String okLabel,
        final String cancelLabel, final ConfirmationDialogCallback callback, final Resource icon,
        final String id, final ConfirmationTab tab, final boolean mapCloseToCancel) {
    window = new Window(caption);
    if (!StringUtils.isEmpty(id)) {
        window.setId(id);
    }
    window.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION);

    if (icon != null) {
        window.setIcon(icon);
    }

    okButton = createOkButton(okLabel);

    final Button cancelButton = createCancelButton(cancelLabel);
    if (mapCloseToCancel) {
        window.addCloseListener(e -> {
            if (!isImplicitClose) {
                cancelButton.click();
            }
        });
    }
    window.setModal(true);
    window.addStyleName(SPUIStyleDefinitions.CONFIRMBOX_WINDOW_STYLE);
    if (this.callback == null) {
        this.callback = callback;
    }
    final VerticalLayout vLayout = new VerticalLayout();
    if (question != null) {
        vLayout.addComponent(createConfirmationQuestion(question));
    }
    if (tab != null) {
        vLayout.addComponent(tab);
    }

    final HorizontalLayout hButtonLayout = createButtonLayout(cancelButton);
    hButtonLayout.addStyleName("marginTop");
    vLayout.addComponent(hButtonLayout);
    vLayout.setComponentAlignment(hButtonLayout, Alignment.BOTTOM_CENTER);

    window.setContent(vLayout);
    window.setResizable(false);
}

From source file:org.groom.review.ui.flows.LogFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout gridLayout = new GridLayout(1, 3);
    gridLayout.setSizeFull();/*from w  w  w  .  j  a va  2 s  .  com*/
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(2, 1f);
    setViewContent(gridLayout);

    final HorizontalLayout filterLayout = new HorizontalLayout();
    filterLayout.setSpacing(true);
    filterLayout.setSizeUndefined();
    gridLayout.addComponent(filterLayout, 0, 0);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setSizeUndefined();
    gridLayout.addComponent(buttonLayout, 0, 1);

    final Validator validator = new Validator() {
        @Override
        public void validate(Object o) throws InvalidValueException {
            final String value = (String) o;
            if (value.indexOf("..") != -1) {
                throw new InvalidValueException("..");
            }
            for (int i = 0; i < value.length(); i++) {
                final char c = value.charAt(i);
                if (!(Character.isLetter(c) || Character.isDigit(c) || "-./".indexOf(c) != -1)) {
                    throw new InvalidValueException("" + c);
                }
            }
        }
    };

    repositoryField = new ComboBox(getSite().localize("field-repository"));
    repositoryField.setNullSelectionAllowed(false);
    repositoryField.setTextInputAllowed(true);
    repositoryField.setNewItemsAllowed(false);
    repositoryField.setInvalidAllowed(false);
    final List<Repository> repositories = ReviewDao.getRepositories(entityManager,
            (Company) getSite().getSiteContext().getObject(Company.class));

    for (final Repository repository : repositories) {
        repositoryField.addItem(repository);
        repositoryField.setItemCaption(repository, repository.getPath());
        if (repositoryField.getItemIds().size() == 1) {
            repositoryField.setValue(repository);
        }
    }
    filterLayout.addComponent(repositoryField);

    sinceField = new TextField(getSite().localize("field-since"));
    sinceField.setValue("master");
    sinceField.setValidationVisible(true);
    sinceField.addValidator(validator);
    filterLayout.addComponent(sinceField);

    untilField = new TextField(getSite().localize("field-until"));
    untilField.setValidationVisible(true);
    untilField.addValidator(validator);
    filterLayout.addComponent(untilField);

    final BeanQueryFactory<CommitBeanQuery> beanQueryFactory = new BeanQueryFactory<CommitBeanQuery>(
            CommitBeanQuery.class);
    queryConfiguration = new HashMap<String, Object>();
    beanQueryFactory.setQueryConfiguration(queryConfiguration);

    final LazyQueryContainer container = new LazyQueryContainer(beanQueryFactory, "hash", 200, false);

    container.addContainerFilter(new Compare.Equal("branch", sinceField.getValue()));
    container.addContainerProperty("hash", String.class, null, true, false);
    container.addContainerProperty("committerDate", Date.class, null, true, false);
    container.addContainerProperty("committer", String.class, null, true, false);
    container.addContainerProperty("authorDate", Date.class, null, true, false);
    container.addContainerProperty("author", String.class, null, true, false);
    container.addContainerProperty("tags", String.class, null, true, false);
    container.addContainerProperty("subject", String.class, null, true, false);

    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    final Table table = new Table() {

        @Override
        protected String formatPropertyValue(Object rowId, Object colId, Property property) {
            Object v = property.getValue();
            if (v instanceof Date) {
                Date dateValue = (Date) v;
                return format.format(v);
            }
            return super.formatPropertyValue(rowId, colId, property);
        }

    };

    table.setWidth(100, Unit.PERCENTAGE);
    table.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight() - 350, Unit.PIXELS);
    table.setContainerDataSource(container);
    table.setVisibleColumns(
            new Object[] { "hash", "committerDate", "committer", "authorDate", "author", "tags", "subject" });

    table.setColumnWidth("hash", 50);
    table.setColumnWidth("committerDate", 120);
    table.setColumnWidth("committer", 100);
    table.setColumnWidth("authorDate", 120);
    table.setColumnWidth("author", 100);
    table.setColumnWidth("tags", 100);

    table.setColumnHeaders(new String[] { getSite().localize("field-hash"),
            getSite().localize("field-committer-date"), getSite().localize("field-committer"),
            getSite().localize("field-author-date"), getSite().localize("field-author"),
            getSite().localize("field-tags"), getSite().localize("field-subject") });

    table.setColumnCollapsingAllowed(true);
    table.setColumnCollapsed("authorDate", true);
    table.setColumnCollapsed("author", true);
    table.setSelectable(true);
    table.setMultiSelect(true);
    table.setImmediate(true);

    gridLayout.addComponent(table, 0, 2);

    final Button refreshButton = new Button(getSite().localize("button-refresh"));
    buttonLayout.addComponent(refreshButton);
    refreshButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    refreshButton.addStyleName("default");
    refreshButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            repository = (Repository) repositoryField.getValue();

            if (repository != null && sinceField.isValid() && untilField.isValid()) {
                queryConfiguration.put("repository", repository);
                final StringBuilder range = new StringBuilder(sinceField.getValue());
                if (untilField.getValue().length() > 0) {
                    range.append("..");
                    range.append(untilField);
                }
                container.removeAllContainerFilters();
                container.addContainerFilter(new Compare.Equal("range", range.toString()));
                container.refresh();
            }
        }
    });

    final Button fetchButton = new Button("Fetch");
    buttonLayout.addComponent(fetchButton);
    fetchButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Repository repository = (Repository) repositoryField.getValue();
            Notification.show("Executed fetch. " + Shell.execute("git fetch", repository.getPath()));
            refreshButton.click();
        }
    });

    final Button addReviewButton = getSite().getButton("add-review");
    addReviewButton.setEnabled(false);
    buttonLayout.addComponent(addReviewButton);
    addReviewButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Object[] selection = ((Set) table.getValue()).toArray();
            if (selection != null && selection.length == 2) {
                final String hashOne = (String) selection[0];
                final String hashTwo = (String) selection[1];
                final Commit commitOne = ((NestingBeanItem<Commit>) container.getItem(hashOne)).getBean();
                final Commit commitTwo = ((NestingBeanItem<Commit>) container.getItem(hashTwo)).getBean();

                final Commit sinceCommit;
                final Commit untilCommit;
                if (commitOne.getCommitterDate().getTime() > commitTwo.getCommitterDate().getTime()) {
                    sinceCommit = commitTwo;
                    untilCommit = commitOne;
                } else {
                    sinceCommit = commitOne;
                    untilCommit = commitTwo;
                }
                createReview(sinceCommit.getHash(), untilCommit.getHash());
            } else {
                final ReviewRangeDialog dialog = new ReviewRangeDialog(new ReviewRangeDialog.DialogListener() {
                    @Override
                    public void onOk(String sinceHash, String untilHash) {
                        if (sinceHash.length() > 0 && untilHash.length() > 0) {
                            createReview(sinceHash, untilHash);
                        }
                    }

                    @Override
                    public void onCancel() {
                    }
                }, ((selection != null && selection.length == 1) ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
                        : ""), ((selection != null && selection.length == 1) ? (String) selection[0] : ""));
                dialog.setCaption("Please enter final comment.");
                UI.getCurrent().addWindow(dialog);
                dialog.getSinceField().focus();
            }

        }
    });

    table.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            final Set selection = (Set) table.getValue();
            addReviewButton.setEnabled(selection != null && (selection.size() == 1 || selection.size() == 2));
        }
    });

}

From source file:org.jdal.vaadin.ui.ButtonBar.java

License:Apache License

/**
 * Simulates a button click on first button with provided caption
 * @param caption caption to search./*  w ww. j a  va 2s.  c  o  m*/
 */
public void click(String caption) {
    if (caption == null && buttons.size() > 0) {
        Button button = buttons.get(0);
        button.click();
        return;
    }

    Button button = getButtonByCaption(caption);
    if (button != null)
        button.click();
}

From source file:org.lunifera.runtime.web.vaadin.databinding.component.internal.ButtonClickProperty.java

License:Open Source License

protected void doSetValue(Object source, Object value) {
    Button component = (Button) source;
    component.click();
}