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.webconsole.scope.home.extensions.PeergreenNewsFeedFrame.java

License:Open Source License

@PostConstruct
public void init() throws MalformedURLException, RssServiceException {
    Rss rss = null;/*from   ww w .  j  av a2 s .  c om*/
    rss = rssService.parse(new URL(PEERGREEN_RSS_FLOW_URL));
    int i = 0;
    for (final FeedMessage feedMessage : rss.getItems()) {
        Button news = new NativeButton(feedMessage.getTitle());
        news.addStyleName("link");
        news.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                Window w = getNewsDescription(feedMessage);
                UI.getCurrent().addWindow(w);
                w.focus();
            }
        });

        addItem(new Object[] { news }, i++);
    }
}

From source file:com.peergreen.webconsole.scope.home.extensions.PeergreenNewsFeedFrame.java

License:Open Source License

/**
 * News popup//  www  . j a  v  a  2s . c  om
 *
 * @param feedMessage
 * @return
 */
private Window getNewsDescription(FeedMessage feedMessage) {
    FormLayout fields = new FormLayout();
    fields.setWidth("35em");
    fields.setSpacing(true);
    fields.setMargin(true);

    Label label = new Label("<a href=\"" + feedMessage.getLink() + "\">"
            + feedMessage.getLink().substring(0, 50) + "..." + "</a>");
    label.setContentMode(ContentMode.HTML);
    label.setSizeUndefined();
    label.setCaption("URL");
    fields.addComponent(label);

    String description = feedMessage.getDescription();
    if (description.length() > 1000) {
        description = description.substring(0, 999) + "...";
    }

    Label desc = new Label(description);
    desc.setContentMode(ContentMode.HTML);
    desc.setCaption("Description");
    fields.addComponent(desc);

    Button ok = new Button("Close");
    ok.addStyleName("wide");
    ok.addStyleName("default");

    final Window w = new DefaultWindow(feedMessage.getTitle(), fields, ok);
    w.center();
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            w.close();
        }
    });
    return w;
}

From source file:com.peergreen.webconsole.scope.logs.LogsScope.java

License:Open Source License

public LogsScope() {
    setMargin(true);//from  w w w  .ja va  2s.c om
    setSpacing(true);
    setSizeFull();

    HorizontalLayout topBar = new HorizontalLayout();
    topBar.setWidth("100%");
    addComponent(topBar);
    FormLayout form = new FormLayout();
    form.setWidth("40%");
    topBar.addComponent(form);

    TextField textFieldFilter = new TextField();
    textFieldFilter.setCaption("Filter:");
    textFieldFilter.setInputPrompt("filter");
    textFieldFilter.setWidth("60%");
    textFieldFilter.addTextChangeListener(new TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            container.removeAllContainerFilters();
            Container.Filter or = new Or(new SimpleStringFilter("caller", event.getText().trim(), true, false),
                    new SimpleStringFilter("text", event.getText().trim(), true, false));
            Filter and = new And(or, filter);

            container.addContainerFilter(and);
        }
    });

    topBar.addComponent(textFieldFilter);

    //form.setWidth("100%");
    form.setSpacing(true);
    form.setMargin(true);
    HorizontalLayout systemLayout = new HorizontalLayout();
    systemLayout.setCaption("JVM System streams:");
    form.addComponent(systemLayout);
    HorizontalLayout loggerLayout = new HorizontalLayout();
    loggerLayout.setCaption("Loggers:");
    form.addComponent(loggerLayout);

    final CheckBox systemOut = new CheckBox("out");
    systemOut.setValue(true);
    systemLayout.addComponent(systemOut);

    this.container = new BeanItemContainer<TableEntry>(TableEntry.class);
    filter = new TypeFilter();
    container.addContainerFilter(filter);

    systemOut.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptSystemOut(value);
            container.addContainerFilter(filter);
        }
    });

    CheckBox systemErr = new CheckBox("err");
    systemLayout.addComponent(systemErr);
    systemErr.setValue(true);
    systemErr.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptSystemErr(value);
            container.addContainerFilter(filter);
        }
    });

    CheckBox loggerInfo = new CheckBox("Info");
    loggerLayout.addComponent(loggerInfo);
    loggerInfo.setValue(true);
    loggerInfo.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptLoggerInfo(value);
            container.addContainerFilter(filter);
        }
    });

    CheckBox loggerWarning = new CheckBox("Warning");
    loggerLayout.addComponent(loggerWarning);
    loggerWarning.setValue(true);
    loggerWarning.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptLoggerWarning(value);
            container.addContainerFilter(filter);
        }
    });

    CheckBox loggerError = new CheckBox("Error");
    loggerLayout.addComponent(loggerError);
    loggerError.setValue(true);
    loggerError.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptLoggerError(value);
            container.addContainerFilter(filter);
        }
    });

    Button clearButton = new Button("clear");
    //horizontalLayout.addComponent(clearButton);
    clearButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            container.removeAllItems();

        }
    });

    this.table = new Table();
    table.setSizeFull();
    table.setImmediate(true);

    // Define the names and data types of columns.
    table.addContainerProperty("date", Date.class, null);
    table.addContainerProperty("type", String.class, null);
    table.addContainerProperty("caller", String.class, null);
    table.addContainerProperty("text", String.class, "empty");

    table.setContainerDataSource(container);
    table.addGeneratedColumn("text", new TextColumnGenerator());

    table.setItemDescriptionGenerator(new ItemDescriptionGenerator() {
        @Override
        public String generateDescription(Component source, Object itemId, Object propertyId) {
            TableEntry tableEntry = (TableEntry) itemId;

            return simpleDateFormat.format(tableEntry.getDate()).concat(" : ").concat(tableEntry.getType())
                    .concat(" : ").concat(tableEntry.getCaller());

        }
    });

    table.setVisibleColumns(new Object[] { "text" });
    table.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
    table.setSortEnabled(true);
    addComponent(table);
    setExpandRatio(table, 1.5f);
}

From source file:com.peergreen.webconsole.scope.system.internal.bundle.BundleTab.java

License:Open Source License

private void init() {

    setMargin(true);//from  w w  w . j  a v a  2s . c  o m
    setSpacing(true);

    // ----------------------------------------------------
    // Title
    // ----------------------------------------------------

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

    Label title = new Label(format("Bundle %d: %s (%s)", bundle.getBundleId(),
            getHeader(bundle, Constants.BUNDLE_NAME), bundle.getVersion()));
    title.addStyleName("h1");
    header.addComponent(title);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);

    addComponent(header);

    // ----------------------------------------------------
    // Action(s) Bar
    // ----------------------------------------------------

    HorizontalLayout actions = new HorizontalLayout();
    if (BundleHelper.isState(bundle, Bundle.INSTALLED) || BundleHelper.isState(bundle, Bundle.RESOLVED)) {
        Button changeState = new Button();
        changeState.addClickListener(new StartBundleClickListener(bundle, notifierService));
        //changeState.addStyleName("no-padding");
        changeState.setCaption("Start");
        changeState.setIcon(new ClassResource(getClass(), "/images/32x32/go-next.png"));
        actions.addComponent(changeState);
    }
    if (BundleHelper.isState(bundle, Bundle.ACTIVE)) {
        Button changeState = new Button();
        changeState.addClickListener(new StopBundleClickListener(bundle, notifierService));
        //changeState.addStyleName("no-padding");
        changeState.setCaption("Stop");
        changeState.setIcon(new ClassResource(getClass(), "/images/32x32/media-record.png"));
        actions.addComponent(changeState);
    }

    // Update
    Button update = new Button();
    update.addClickListener(new UpdateBundleClickListener(bundle, notifierService));
    //update.addStyleName("no-padding");
    update.setCaption("Update");
    update.setIcon(new ClassResource(getClass(), "/images/32x32/view-refresh.png"));
    actions.addComponent(update);

    // Trash
    Button trash = new Button();
    trash.addClickListener(new UninstallBundleClickListener(bundle, notifierService));
    //trash.addStyleName("no-padding");
    trash.setCaption("Remove");
    trash.setIcon(new ClassResource(getClass(), "/images/32x32/user-trash-full.png"));
    actions.addComponent(trash);
    addComponent(actions);
    setComponentAlignment(actions, Alignment.MIDDLE_RIGHT);

    // ----------------------------------------------------
    // Standard Section
    // ----------------------------------------------------

    Table table = new Table();
    table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    table.setWidth("100%");

    Section mainSection = new Section("Standard", table);
    addComponent(mainSection);

    table.addContainerProperty("label", Label.class, null);
    table.addContainerProperty("value", Label.class, null);

    table.addItem(new Object[] { label("Bundle ID"), label(String.valueOf(bundle.getBundleId())) },
            "bundle.id");
    for (Map.Entry<String, String> entry : HEADERS.entrySet()) {
        String value = getHeader(bundle, entry.getKey());
        if (value != null) {
            table.addItem(new Object[] { label(entry.getValue()), label(value) }, entry.getKey());
        }
    }
    table.addItem(new Object[] { label("Location"), label(bundle.getLocation()) }, "bundle.location");
    Date date = new Date(bundle.getLastModified());
    table.addItem(new Object[] { label("Last Modified"), label(date.toString()) }, "last.modified");

    // ----------------------------------------------------
    // Packages Section
    // ----------------------------------------------------

    FilteredPackageTable exported = new FilteredPackageTable("Exported");

    FilteredPackageTable imported = new FilteredPackageTable("Imported");

    GridLayout packages = new GridLayout(2, 1);
    packages.addComponent(exported);
    packages.addComponent(imported);
    packages.setSpacing(true);
    packages.setWidth("100%");

    Section packagesSection = new Section("Packages", packages);
    addComponent(packagesSection);

    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    if (wiring != null) {
        for (BundleCapability capability : wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
            String name = (String) capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
            Version version = (Version) capability.getAttributes()
                    .get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            exported.addPackage(format("%s (%s)", name, version));
        }
        for (BundleRequirement requirement : wiring.getRequirements(PackageNamespace.PACKAGE_NAMESPACE)) {
            String filter = requirement.getDirectives().get(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE);
            imported.addPackage(filter);
        }
    }

    // ----------------------------------------------------
    // Services Section
    // ----------------------------------------------------

    FilteredServiceTable registered = new FilteredServiceTable("Registered");

    FilteredServiceTable used = new FilteredServiceTable("Used Services");

    VerticalLayout services = new VerticalLayout(registered, used);
    services.setSpacing(true);
    services.setWidth("100%");

    ServiceReference<?>[] registeredServices = bundle.getRegisteredServices();
    if (registeredServices != null) {
        for (ServiceReference<?> reference : registeredServices) {
            registered.addService(reference);
        }
    }

    ServiceReference<?>[] inUseServices = bundle.getServicesInUse();
    if (inUseServices != null) {
        for (ServiceReference<?> reference : inUseServices) {
            used.addService(reference);
        }
    }

    if (!registered.isEmpty() || !used.isEmpty()) {
        Section servicesSection = new Section("Services", services);
        addComponent(servicesSection);
    }

    // ----------------------------------------------------
    // Raw Manifest Section
    // ----------------------------------------------------

    Page.Styles styles = Page.getCurrent().getStyles();
    styles.add(".monospaced-font {font-family: monospace !important; }");

    Table manifest = new Table();
    manifest.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    manifest.setWidth("100%");
    manifest.addStyleName("monospaced-font");
    manifest.setPageLength(15);
    manifest.addContainerProperty("name", String.class, null);
    manifest.addContainerProperty("value", String.class, null);

    Dictionary<String, String> headers = bundle.getHeaders();
    for (String key : Collections.list(headers.keys())) {
        manifest.addItem(new Object[] { key, headers.get(key) }, null);
    }

    Section manifestSection = new Section("Manifest", manifest);
    addComponent(manifestSection);

}

From source file:com.peergreen.webconsole.scope.system.internal.bundle.BundleView.java

License:Open Source License

@PostConstruct
public void createView() {
    setMargin(true);//ww w .  j  a  v  a 2  s  . c  om
    setSpacing(true);

    /*
    Page.Styles styles = Page.getCurrent().getStyles();
    styles.add(".no-padding {padding: 0em 0em 0em 0em !important; }");
    */

    HorizontalLayout header = new HorizontalLayout();
    //        header.setWidth("100%");
    header.setSpacing(true);
    header.setMargin(true);

    Label title = new Label("OSGi Bundles");
    title.addStyleName("h1");
    //        title.setSizeUndefined();
    header.addComponent(title);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);

    final TextField filter = new TextField();
    filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            data.removeAllContainerFilters();
            String trimmed = event.getText().trim();
            Container.Filter or = new Or(new SimpleStringFilter(BUNDLE_ID_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(BUNDLE_NAME_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(BUNDLE_SYMBOLICNAME_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(VERSION_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(PRETTY_STATE_COLUMN, trimmed, true, false));

            data.addContainerFilter(or);
        }
    });

    filter.setInputPrompt("Filter");
    filter.addShortcutListener(new ShortcutListener("Clear", ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            filter.setValue("");
            data.removeAllContainerFilters();
        }
    });
    header.addComponent(filter);
    header.setExpandRatio(filter, 1);
    header.setComponentAlignment(filter, Alignment.MIDDLE_LEFT);

    // Store the header in the vertical layout (this)
    addComponent(header);

    addComponent(tabSheet);

    table = new Table();
    table.setContainerDataSource(data);
    table.setSizeFull();
    table.setSortContainerPropertyId(BUNDLE_ID_COLUMN);
    table.setSortAscending(true);
    table.setImmediate(true);
    table.setColumnHeader(BUNDLE_ID_COLUMN, "Bundle ID");
    table.setColumnHeader(PRETTY_NAME_COLUMN, "Bundle Name");
    table.setColumnHeader(VERSION_COLUMN, "Version");
    table.setColumnHeader(PRETTY_STATE_COLUMN, "State");
    table.setColumnHeader("actions", "Actions");

    table.setColumnWidth(BUNDLE_ID_COLUMN, 100);

    table.setColumnAlignment(BUNDLE_ID_COLUMN, Table.Align.CENTER);
    table.setColumnAlignment(PRETTY_STATE_COLUMN, Table.Align.CENTER);
    table.setColumnAlignment(VERSION_COLUMN, Table.Align.CENTER);

    table.addGeneratedColumn("actions", new Table.ColumnGenerator() {
        @Override
        public Object generateCell(final Table source, final Object itemId, final Object columnId) {
            HorizontalLayout layout = new HorizontalLayout();
            BeanItem<BundleItem> item = (BeanItem<BundleItem>) source.getContainerDataSource().getItem(itemId);
            Bundle bundle = item.getBean().getBundle();
            if (BundleHelper.isState(bundle, Bundle.INSTALLED)
                    || BundleHelper.isState(bundle, Bundle.RESOLVED)) {
                Button changeState = new Button();
                changeState.addClickListener(new StartBundleClickListener(bundle, notifierService));
                //changeState.addStyleName("no-padding");
                changeState.setCaption("Start");
                //changeState.setIcon(new ClassResource(BundleViewer.class, "/images/go-next.png"));
                if (!securityManager.isUserInRole("admin")) {
                    changeState.setDisableOnClick(true);
                }
                layout.addComponent(changeState);
            }
            if (BundleHelper.isState(bundle, Bundle.ACTIVE)) {
                Button changeState = new Button();
                changeState.addClickListener(new StopBundleClickListener(bundle, notifierService));
                //changeState.addStyleName("no-padding");
                changeState.setCaption("Stop");
                if (!securityManager.isUserInRole("admin")) {
                    changeState.setDisableOnClick(true);
                }
                //changeState.setIcon(new ClassResource(BundleViewer.class, "/images/media-record.png"));
                layout.addComponent(changeState);
            }

            // Update
            Button update = new Button();
            update.addClickListener(new UpdateBundleClickListener(bundle, notifierService));
            //update.addStyleName("no-padding");
            update.setCaption("Update");
            if (!securityManager.isUserInRole("admin")) {
                update.setDisableOnClick(true);
            }
            //update.setIcon(new ClassResource(BundleViewer.class, "/images/view-refresh.png"));
            layout.addComponent(update);

            // Trash
            Button trash = new Button();
            trash.addClickListener(new UninstallBundleClickListener(bundle, notifierService));
            //trash.addStyleName("no-padding");
            trash.setCaption("Delete");
            if (!securityManager.isUserInRole("admin")) {
                trash.setDisableOnClick(true);
            }
            //trash.setIcon(new ClassResource(BundleViewer.class, "/images/user-trash-full.png"));
            layout.addComponent(trash);

            return layout;
        }
    });

    table.setVisibleColumns(BUNDLE_ID_COLUMN, PRETTY_NAME_COLUMN, VERSION_COLUMN, PRETTY_STATE_COLUMN,
            "actions");

    table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(final ItemClickEvent event) {
            if (event.isDoubleClick()) {
                BeanItem<BundleItem> item = (BeanItem<BundleItem>) table.getContainerDataSource()
                        .getItem(event.getItemId());
                Bundle bundle = item.getBean().getBundle();
                showBundle(bundle);
            }
        }
    });

    createBundleTracker();

    tabSheet.setSizeFull();
    selectedTabListener = new SelectedTabListener(uiContext.getViewNavigator());
    selectedTabListener.addLocation(table, uiContext.getViewNavigator().getLocation(this.getClass().getName()));
    tabSheet.addSelectedTabChangeListener(selectedTabListener);
    tabSheet.addTab(table, "Bundles", new ClassResource(BundleView.class, "/images/22x22/user-home.png"));
    setExpandRatio(tabSheet, 1.5f);

    tabSheet.setCloseHandler(new TabSheet.CloseHandler() {
        @Override
        public void onTabClose(TabSheet tabsheet, Component tabContent) {
            for (Map.Entry<Long, Component> tab : openTabs.entrySet()) {
                if (tabContent.equals(tab.getValue())) {
                    openTabs.remove(tab.getKey());
                }
            }
            tabsheet.removeComponent(tabContent);
            selectedTabListener.removeLocation(tabContent);
        }
    });
}

From source file:com.philippefichet.vaadincdipush.view.FirstView.java

@PostConstruct
public void init() {
    setHeight("100%");
    loginLayout = new HorizontalLayout();
    Label loginLabel = new Label("Login");
    loginChoose = new TextField();
    attach = new Button("Connect");
    attach.addClickListener((Button.ClickEvent event) -> {
        if (chat.loginFree(loginChoose.getValue())) {
            if (login == null) {
                login = loginChoose.getValue();
                chat.getUsernameConnected().forEach((l) -> {
                    newUser(l);/*from   w  w  w. j  a  v a2s  .  co  m*/
                });
                chat.attach(this);
            } else {
                chat.rename(loginChoose.getValue(), this);
                login = loginChoose.getValue();
            }
            attach.setStyleName(ValoTheme.BUTTON_FRIENDLY);
            Notification.show("Login \"" + loginChoose.getValue() + "\" valid.", null,
                    Notification.Type.HUMANIZED_MESSAGE);

            messagePanel.setVisible(true);
            sendLayout.setVisible(true);

        } else {
            Notification.show("Login \"" + loginChoose.getValue() + "\" already exist.", null,
                    Notification.Type.ERROR_MESSAGE);
        }
    });

    chatMessage.setWidth("100%");
    sendLayout.setWidth("100%");
    sendMessage.setWidthUndefined();
    sendLayout.addComponent(chatMessage);
    sendLayout.addComponent(sendMessage);
    sendLayout.setExpandRatio(chatMessage, 100);
    sendMessage.addClickListener((event) -> {
        chat.sendMessage(this, chatMessage.getValue());
        chatMessage.setValue("");
    });

    Button next = new Button("next");
    next.addClickListener((eventClick) -> {
        getUI().getNavigator().navigateTo("next");
    });

    loginLayout.addComponent(loginLabel);
    loginLayout.addComponent(loginChoose);
    loginLayout.addComponent(attach);
    loginLayout.setComponentAlignment(loginLabel, Alignment.MIDDLE_RIGHT);
    loginLayout.setComponentAlignment(loginChoose, Alignment.MIDDLE_CENTER);
    loginLayout.setComponentAlignment(attach, Alignment.MIDDLE_LEFT);

    loginLayout.setWidth("100%");
    loginLabel.setWidthUndefined();
    loginChoose.setWidth("100%");
    attach.setWidthUndefined();
    messagePanel.setHeight("100%");
    listUserPanel.setStyleName(ValoTheme.PANEL_WELL);
    listUserPanel.setContent(listUserLayout);
    listUserPanel.setHeight("100%");
    centerLayout.setHeight("100%");
    centerLayout.addComponent(listUserPanel);
    centerLayout.addComponent(messageLayout);
    centerLayout.setExpandRatio(messageLayout, 100);
    messagePanel.setContent(centerLayout);
    addComponent(loginLayout);
    addComponent(messagePanel);
    addComponent(sendLayout);

    messagePanel.setVisible(false);
    sendLayout.setVisible(false);

    setExpandRatio(messagePanel, 100);
}

From source file:com.philippefichet.vaadincdipush.view.SecondView.java

@PostConstruct
public void init() {
    Button prev = new Button("prev");
    prev.addClickListener((eventClick) -> {
        getUI().getNavigator().navigateTo("");
    });/*  ww  w .  ja v a 2s. c  o m*/
    addComponent(prev);
}

From source file:com.piccritic.website.Home.java

/**
 * Sets up menu based on auth//  w ww  .  j  a va2s  . co m
 */
private void setupMenu() {
    Button home = new Button("Home", e -> {
        navigator.navigateTo(DefaultView.NAME);
    });
    menu.addComponent(home);
    LoginStatus loginStatus = getLoginStatus();
    if (loginStatus == LoginStatus.LOGGED_IN) {
        Button logout = new Button("Log out");
        logout.addClickListener(e -> {
            logoutUser();
            Page.getCurrent().reload();
        });
        menu.addComponent(logout);

        Button button = new Button("Create Post");
        button.addClickListener(e -> {
            Window createPost = new CreatePost(getHandle());
            UI.getCurrent().addWindow(createPost);
        });

        menu.addComponent(button);
    } else {
        Button loginUser = new Button("Login");
        loginUser.addClickListener(e -> {
            Window login = new LoginWindow();
            addWindow(login);
        });
        menu.addComponent(loginUser);
    }

    Button createUser = new Button(((loginStatus == LoginStatus.LOGGED_IN) ? "Update" : "Create") + "User");
    createUser.addClickListener(e -> {
        Window userForm = new Window();
        userForm.setModal(true);
        userForm.setContent(new VerticalLayout(new UserForm(getHandle())));
        addWindow(userForm);
    });

    menu.addComponent(createUser);
    menu.setMargin(true);
    menu.setSpacing(true);

}

From source file:com.rex.components.valo.CommonParts.java

License:Apache License

Panel loadingIndicators() {
    Panel p = new Panel("Loading Indicator");
    final VerticalLayout content = new VerticalLayout();
    p.setContent(content);//from ww  w .  j a v a2s .com
    content.setSpacing(true);
    content.setMargin(true);
    content.addComponent(new Label("You can test the loading indicator by pressing the buttons."));

    CssLayout group = new CssLayout();
    group.setCaption("Show the loading indicator for");
    group.addStyleName("v-component-group");
    content.addComponent(group);
    Button loading = new Button("0.8");
    loading.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                Thread.sleep(800);
            } catch (InterruptedException e) {
            }
        }
    });
    group.addComponent(loading);

    Button delay = new Button("3");
    delay.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
            }
        }
    });
    group.addComponent(delay);

    Button wait = new Button("15");
    wait.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                Thread.sleep(15000);
            } catch (InterruptedException e) {
            }
        }
    });
    wait.addStyleName("last");
    group.addComponent(wait);
    Label label = new Label("&nbsp;&nbsp; seconds", ContentMode.HTML);
    label.setSizeUndefined();
    group.addComponent(label);

    Label spinnerDesc = new Label(
            "The theme also provides a mixin that you can use to include a spinner anywhere in your application. The button below reveals a Label with a custom style name, for which the spinner mixin is added.");
    spinnerDesc.addStyleName("small");
    spinnerDesc.setCaption("Spinner");
    content.addComponent(spinnerDesc);

    if (!ReportEngineUI.isTestMode()) {
        final Label spinner = new Label();
        spinner.addStyleName("spinner");

        Button showSpinnerButton = new Button("Show spinner", new ClickListener() {
            @Override
            public void buttonClick(final ClickEvent event) {
                content.replaceComponent(event.getComponent(), spinner);
            }
        });
        content.addComponent(showSpinnerButton);
    }

    return p;
}

From source file:com.salsaw.msalsa.HomePageView.java

License:Apache License

/**
 * The constructor should first build the main layout, set the
 * composition root and then do any custom initialization.
 *
 * The constructor will not be automatically regenerated by the
 * visual editor.//  w ww.ja v  a  2s  . c o  m
 * @param navigator 
 */
public HomePageView(SalsaParameters salsaParameters) {
    if (salsaParameters == null) {
        throw new IllegalArgumentException("salsaParameters");
    }

    buildMainLayout();

    // Create form with salsa parameters
    BeanItem<SalsaParameters> salsaParametersBeanItem = new BeanItem<SalsaParameters>(salsaParameters);
    SalsaParametersForm salsaParametersForm = new SalsaParametersForm(salsaParametersBeanItem);

    Button toogleSalsaParametersButton = new Button("Show/Hide M-SALSA Parameters");
    toogleSalsaParametersButton.addClickListener(new Button.ClickListener() {
        /**
        * 
        */
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            salsaParametersForm.setVisible(!salsaParametersForm.isVisible());
        }
    });

    toogleSalsaParametersButton.setWidth("-1px");
    toogleSalsaParametersButton.setHeight("-1px");
    mainLayout.addComponent(toogleSalsaParametersButton);
    mainLayout.setComponentAlignment(toogleSalsaParametersButton, new Alignment(48));

    salsaParametersForm.setWidth("-1px");
    salsaParametersForm.setHeight("-1px");
    mainLayout.addComponent(salsaParametersForm);
    mainLayout.setComponentAlignment(salsaParametersForm, new Alignment(48));

    setCompositionRoot(mainLayout);

    // TODO add user code here      

    // Implement both receiver that saves upload in a file and
    // listener for successful upload
    class AligmentUploader implements Receiver, SucceededListener {
        /**
        * 
        */
        private static final long serialVersionUID = 1L;

        public File file;

        public OutputStream receiveUpload(String filename, String mimeType) {
            // Create upload stream
            FileOutputStream fos = null; // Stream to write to
            try {
                // Load server configuration
                String tmpFolder = ConfigurationManager.getInstance().getServerConfiguration()
                        .getTemporaryFilePath();

                // Open the file for writing.
                file = Paths.get(tmpFolder, filename).toFile();
                fos = new FileOutputStream(file);
            } catch (final java.io.FileNotFoundException e) {
                new Notification("Could not open file<br/>", e.getMessage(), Notification.Type.ERROR_MESSAGE)
                        .show(Page.getCurrent());
                return null;
            }
            return fos; // Return the output stream to write to
        }

        public void uploadSucceeded(SucceededEvent event) {
            try {
                for (IHomePageListener listener : listeners) {
                    listener.buttonClick(file);
                }

            } catch (SALSAException | IOException | InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

                new Notification("ERROR: ", e.getMessage(), Notification.Type.ERROR_MESSAGE)
                        .show(Page.getCurrent());
            }
        }
    }
    ;

    AligmentUploader receiver = new AligmentUploader();

    uploadInput.setReceiver(receiver);
    uploadInput.addSucceededListener(receiver);

}