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.peergreen.example.webconsole.extensions.CssContributionExtension.java

License:Open Source License

@PostConstruct
public void init() {
    String css = ".custom_button_style {\n" + "   color : red !important;\n"
            + "   border : 1px green dashed !important;\n" + "}";
    final TextArea textArea = new TextArea("Css : ", css);
    textArea.setWidth("500px");
    addComponent(textArea);//from  www .j  ava2s .  c om
    Button button = new Button("Change my style !");
    button.setWidth("500px");
    button.addStyleName("custom_button_style");
    button.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            String newCss = textArea.getValue();
            cssInjectorService.inject(newCss);
        }
    });
    addComponent(button);
    setExpandRatio(button, 1.5f);
}

From source file:com.peergreen.example.webconsole.extensions.DefaultWindowExtension.java

License:Open Source License

public DefaultWindowExtension() {
    setSizeFull();//from   w ww.  j  a  va 2 s  .  c om
    setSpacing(true);
    setMargin(true);

    Link showCodeSource = new Link("Show code source",
            new ExternalResource(GitHubClassURL.getURL(DefaultWindowExtension.class)));
    showCodeSource.setTargetName("_blank");
    addComponent(showCodeSource);
    setComponentAlignment(showCodeSource, Alignment.TOP_RIGHT);

    Button simpleButton = new Button("Click to open a Window");
    simpleButton.setWidth("400px");
    simpleButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            final UI ui = clickEvent.getConnector().getUI();
            String caption = "Default window";
            Label content = new Label("This is a simple window");
            Button close = new Button("Close");
            close.addStyleName("wide");
            close.addStyleName("default");
            final DefaultWindow window = new DefaultWindow(caption, content, close);
            window.center();
            ui.addWindow(window);
            close.addClickListener(new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent clickEvent) {
                    window.close();
                }
            });
        }
    });
    addComponent(simpleButton);

    setExpandRatio(simpleButton, 1.5f);
}

From source file:com.peergreen.example.webconsole.extensions.NavigatorExtension.java

License:Open Source License

@PostConstruct
public void init() {
    Label guide = new Label(
            "The path of a navigable extension is the path of its parent concatenated with the string "
                    + "inside the class annotation @Navigable(\"alias\")");
    guide.addStyleName("h2");
    addComponent(guide);//from  www.jav a2  s  .  co m

    HorizontalLayout row = new HorizontalLayout();
    row.setSpacing(true);
    row.setMargin(true);
    row.setCaption("Type the alias of an extension you want to navigate to");
    final ComboBox comboBox = new ComboBox();
    comboBox.setWidth("400px");
    comboBox.setNullSelectionAllowed(false);
    comboBox.addItem("/example/simple");
    comboBox.addItem("/example/notifier");
    comboBox.addItem("/example/window");
    comboBox.addItem("/example/confirm");
    row.addComponent(comboBox);
    Button navigate = new Button("Navigate");
    navigate.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            if (comboBox.getValue() != null && !"".equals(comboBox.getValue())) {
                uiContext.getViewNavigator().navigateTo(comboBox.getValue().toString());
            }
        }
    });
    row.addComponent(navigate);
    addComponent(row);
    setExpandRatio(row, 1.5f);
}

From source file:com.peergreen.example.webconsole.extensions.NotifierExtension.java

License:Open Source License

@PostConstruct
public void init() {
    HorizontalLayout row = new HorizontalLayout();
    row.setWidth("100%");
    Button simpleButton = new Button("Click to create a notification !");
    final Random random = new Random();
    simpleButton.addClickListener(new Button.ClickListener() {
        @Override/*from   ww  w.  j av a  2 s. co  m*/
        public void buttonClick(Button.ClickEvent clickEvent) {
            notifierService.addNotification(MESSAGES[random.nextInt(MESSAGES.length)]);
        }
    });
    simpleButton.setWidth("400px");
    row.addComponent(simpleButton);
    row.setComponentAlignment(simpleButton, Alignment.BOTTOM_LEFT);

    final TextField customNotification = new TextField();
    customNotification.setCaption("Write something and type enter");
    final ShortcutListener addNotification = new ShortcutListener("Execute", ShortcutAction.KeyCode.ENTER,
            null) {
        @Override
        public void handleAction(Object o, Object o2) {
            notifierService.addNotification(customNotification.getValue());
            customNotification.setValue("");
        }
    };
    customNotification.addFocusListener(new FieldEvents.FocusListener() {
        @Override
        public void focus(FieldEvents.FocusEvent focusEvent) {
            customNotification.addShortcutListener(addNotification);
        }
    });
    customNotification.addBlurListener(new FieldEvents.BlurListener() {
        @Override
        public void blur(FieldEvents.BlurEvent blurEvent) {
            customNotification.removeShortcutListener(addNotification);
        }
    });
    customNotification.setWidth("400px");
    row.addComponent(customNotification);
    addComponent(row);
    setExpandRatio(row, 1.5f);
}

From source file:com.peergreen.webconsole.core.notifier.NotifierService.java

License:Open Source License

/**
 * {@inheritDoc}//from  w  w  w.  jav  a 2 s. c om
 */
@Override
public void addNotificationsButton(Button button, final Window window, final UI ui) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    window.setContent(layout);

    notificationButtons.put(ui, new NotificationButton(button, 0));

    button.addClickListener(new NotificationClickListener(layout));
}

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

License:Open Source License

/**
 * Build login view//from  w  w  w  . j ava 2s  .  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:com.peergreen.webconsole.core.vaadin7.BaseUI.java

License:Open Source License

/**
 * Add scope button in menu//from   w  w  w .jav  a  2 s .c o  m
 *
 * @param scope scope
 * @param notify for notifierService to show badge
 */
private void addScopeButtonInMenu(final Scope scope, boolean notify) {
    if (menu != null) {
        final Button b = new NativeButton(scope.getScopeName().toUpperCase());

        b.addStyleName(scope.getScopeIconClass());

        b.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                //clearMenuSelection();
                notifierService.removeBadge(scope.getScopeView());
                viewNavigator.navigateTo(scope.getScopeAlias());
            }
        });

        sortButtonsInMenu(scope.getScopeAlias(), b);

        notifierService.addScopeButton(scope.getScopeView(), b, this, notify);

        scopes.get(scope.getScopeAlias()).setScopeMenuButton(b);

        if (nbScopesToBind > 0) {
            Float progressIndicatorValue = progressIndicator.getValue();
            progressIndicatorValue += (float) (1.0 / nbScopesToBind);
            progressIndicator.setValue(progressIndicatorValue);
        }
    }
}

From source file:com.peergreen.webconsole.scope.deployment.internal.components.DeployableWindow.java

License:Open Source License

public DefaultWindow getWindow() {
    Button close = new Button("Close");
    close.addStyleName("wide");
    close.addStyleName("default");
    final DefaultWindow w = new DefaultWindow(deployableEntry.getName(), getContent(), close);
    close.addClickListener(new Button.ClickListener() {
        @Override/*  ww w.  j  a  va  2  s.c o m*/
        public void buttonClick(Button.ClickEvent event) {
            w.close();
        }
    });
    w.center();
    return w;
}

From source file:com.peergreen.webconsole.scope.deployment.internal.components.ExceptionView.java

License:Open Source License

private void showDefaultView() {
    if (messageView == null) {
        messageView = new HorizontalLayout();
        messageView.setWidth("100%");
        StringBuilder sb = new StringBuilder();
        sb.append("<span style=\"color:red\">");
        sb.append(artifactErrorDetail.getMessage());
        sb.append("</span>");
        Label message = new Label(sb.toString(), ContentMode.HTML);
        messageView.addComponent(message);
        messageView.setComponentAlignment(message, Alignment.TOP_LEFT);
        Button details = new Button("Details");
        details.addStyleName("link");
        details.addClickListener(new Button.ClickListener() {
            @Override//w w  w  .  j  a  va  2  s .  com
            public void buttonClick(Button.ClickEvent event) {
                showDetailsView();
            }
        });
        messageView.addComponent(details);
        messageView.setComponentAlignment(details, Alignment.TOP_RIGHT);
    }

    removeAllComponents();
    addComponent(messageView);
}

From source file:com.peergreen.webconsole.scope.deployment.internal.components.ExceptionView.java

License:Open Source License

private void showDetailsView() {
    if (stackTraceView == null) {
        stackTraceView = new VerticalLayout();
        stackTraceView.setWidth("100%");

        StringBuilder sb = new StringBuilder();
        sb.append("<span style=\"color:red\"> Message : ");
        sb.append(artifactErrorDetail.getMessage());
        sb.append("<br />");
        for (StackTraceElement element : artifactErrorDetail.getStackTrace()) {
            sb.append("&nbsp;&nbsp;&nbsp;");
            sb.append(" |- ");
            sb.append(element.getClassName());
            sb.append('.');
            sb.append(element.getMethodName());
            sb.append('(');
            sb.append(element.getFileName());
            sb.append(':');
            sb.append(element.getLineNumber());
            sb.append(')');
            sb.append("<br />");
        }/*from   w  w w .  jav  a  2  s. c  o  m*/
        sb.append("</span>");
        Label stackTrace = new Label(sb.toString(), ContentMode.HTML);
        stackTraceView.addComponent(stackTrace);
        stackTraceView.setComponentAlignment(stackTrace, Alignment.TOP_LEFT);

        Button hideDetails = new Button("Hide");
        hideDetails.addStyleName("link");
        hideDetails.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                showDefaultView();
            }
        });
        stackTraceView.addComponent(hideDetails);
        stackTraceView.setComponentAlignment(hideDetails, Alignment.TOP_RIGHT);
    }

    removeAllComponents();
    addComponent(stackTraceView);
}