Example usage for com.vaadin.ui Button Button

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

Introduction

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

Prototype

public Button(Resource icon) 

Source Link

Document

Creates a new push button with the given icon.

Usage

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void jpaContTable(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);/* w  w w .  j a va  2 s  . c  o  m*/
    show(layout, "Please notice table rows are selectable, column order movable, column sort order adjustable");

    // Create a persistent person container
    JPAContainer<Trip> trips = JPAContainerFactory.make(Trip.class, "source.jpa");
    // You can add entities to the container as well
    trips.addEntity(new Trip("Riga", "Brussels", 5.0F));
    trips.addEntity(new Trip("London", "Riga", 101.0F));

    // Bind it to a component
    Table personTable = new Table("Past Trips", trips);

    personTable.setSizeUndefined();
    personTable.setSelectable(true);
    personTable.setMultiSelect(false);
    personTable.setImmediate(true);
    personTable.setColumnReorderingAllowed(true);
    personTable.setColumnCollapsingAllowed(true);

    personTable.setVisibleColumns(new String[] { "id", "price", "startLocation", "finishLocation" });
    layout.addComponent(personTable);

    Button button = new Button("Clear");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            //layout.addComponent(new Label("Thank you for clicking"));
            layout.removeAllComponents();
        }
    });
    layout.addComponent(button);
}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void jpaContTable2(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);/*from  w  w  w .  j a va2  s .  c o  m*/
    show(layout, "This is same as above but EntityManager is created explicitly");

    EntityManager em = JPAContainerFactory.createEntityManagerForPersistenceUnit("source.jpa");
    /*
            
       Notice that if you use update the persistent data with an entity manager outside a JPAContainer bound to the 
       data, you need to refresh the container as described in Section 19.4.2, Creating and Accessing Entities?.
            
    Refreshing JPAContainer
            
    In cases where you change JPAContainer items outside the container, for example by through an EntityManager, 
    or when they change in the database, you need to refresh the container.
    The EntityContainer interface implemented by JPAContainer provides two methods to refresh a container. The 
    refresh() discards all container caches and buffers and refreshes all loaded items in the container. All 
    changes made to items provided by the container are discarded. The refreshItem() refreshes a single item.
            
    */
    // Create a persistent person container
    JPAContainer<Trip> trips = JPAContainerFactory.make(Trip.class, em);

    // You can add entities to the container as well
    trips.addEntity(new Trip("Riga", "Brussels", 5.0F));
    trips.addEntity(new Trip("London", "Riga", 101.0F));

    // Bind it to a component
    Table personTable = new Table("Past Trips", trips);

    personTable.setSizeUndefined();
    personTable.setSelectable(true);
    personTable.setMultiSelect(false);
    personTable.setImmediate(true);
    personTable.setColumnReorderingAllowed(true);
    personTable.setColumnCollapsingAllowed(true);

    personTable.setVisibleColumns(new String[] { "id", "price", "startLocation", "finishLocation" });
    layout.addComponent(personTable);

    Button button = new Button("Clear");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            //layout.addComponent(new Label("Thank you for clicking"));
            layout.removeAllComponents();
        }
    });
    layout.addComponent(button);
}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void jpaContForm1(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);/*from  ww w.  java2  s . com*/
    show(layout, "JPAContainer Form Example enterd!");

    // Have a persistent container
    final JPAContainer<Trip> trips = JPAContainerFactory.make(Trip.class, "source.jpa");
    // For selecting an item to edit
    // Country Editor
    final Form tripForm = new Form();
    tripForm.setCaption("Trip form");

    tripForm.setWidth("420px");
    tripForm.setBuffered(true);
    tripForm.setEnabled(false);
    Object itemId = trips.getIdByIndex(0);
    if (itemId == null)
        show(layout, "Sorry no item retrieved!");
    else {
        show(layout, " choosen item: " + itemId); //+" class: "+itemId.getClass().getName());
        Item tripItem = trips.getItem(itemId);
        show(layout, " Item found :" + tripItem);
        layout.addComponent(tripForm);

        // Use a JPAContainer field factory
        //  - no configuration is needed here
        final FieldFactory fieldFactory = new FieldFactory();
        //fieldFactory.
        tripForm.setFormFieldFactory(fieldFactory);
        // Edit the item in the form
        tripForm.setItemDataSource(tripItem);
        tripForm.setEnabled(true);

        tripForm.setVisibleItemProperties(new String[] { "startLocation", "finishLocation", "status" });
        //tripForm.getField("name").setCaption("name new caption");

        // Handle saves on the form
        final Button save = new Button("Save");
        tripForm.getFooter().addComponent(save);
        save.addClickListener(new ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                try {
                    tripForm.commit();
                    tripForm.setEnabled(false);
                } catch (InvalidValueException e) {
                    e.printStackTrace();
                }
            }
        });

    }

}

From source file:com.bsb.common.vaadin.embed.component.DevApplicationHeader.java

License:Apache License

/**
 * Creates an new instance with the specified {@link EmbedVaadinServer}
 * to manage./* w  ww. jav a 2s .  c  o  m*/
 *
 * @param server the server to manage
 */
public DevApplicationHeader(final EmbedVaadinServer server) {
    final Button shutdown = new Button("shutdown");
    shutdown.setStyleName(BaseTheme.BUTTON_LINK);
    shutdown.setDescription("Shutdown the embed server and close this tab");
    addComponent(shutdown);
    setComponentAlignment(shutdown, Alignment.MIDDLE_CENTER);

    shutdown.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            // Stop the server in a separate thread.
            final Thread thread = new Thread(new Runnable() {
                public void run() {
                    server.stop();
                }
            });
            // avoid that catalina's WebappClassLoader.clearReferencesThreads warns about the thread because it is
            // part of the web application being stopped.
            thread.setContextClassLoader(null);

            thread.start();

            // Close the browser tab
            getWindow().executeJavaScript("close();");
        }
    });
}

From source file:com.bsb.common.vaadin.embed.SampleMain.java

License:Apache License

public static void main(String[] args) {
    EmbedVaadin.forComponent(new Button("Hello")).withDevelopmentHeader(true).openBrowser(true).start();
}

From source file:com.cavisson.gui.dashboard.components.calender.HiddenFwdBackButtons.java

License:Apache License

@SuppressWarnings("deprecation")
@Override//from w  ww.  j  a  v  a  2s .  c om
protected void init(VaadinRequest request) {
    GridLayout content = new GridLayout(1, 2);
    content.setSizeFull();
    setContent(content);

    final Calendar calendar = new Calendar();
    calendar.setLocale(new Locale("fi", "FI"));

    calendar.setSizeFull();
    calendar.setStartDate(new Date(100, 1, 1));
    calendar.setEndDate(new Date(100, 1, 7));
    content.addComponent(calendar);
    Button button = new Button("Hide forward and back buttons");
    button.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            // This should hide the forward and back navigation buttons
            calendar.setHandler((BackwardHandler) null);
            calendar.setHandler((ForwardHandler) null);
        }
    });
    content.addComponent(button);

    content.setRowExpandRatio(0, 1);

}

From source file:com.cavisson.gui.dashboard.components.charts.Impl.ResizeInsideVaadinComponent.java

@Override
protected Component getChart() {

    VerticalSplitPanel verticalSplitPanel = new VerticalSplitPanel();
    HorizontalSplitPanel horizontalSplitPanel = new HorizontalSplitPanel();
    horizontalSplitPanel.setSecondComponent(verticalSplitPanel);
    verticalSplitPanel.setFirstComponent(createChart());

    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setMargin(true);//from  w w  w.j  ava 2s .  c  om
    verticalLayout.setSpacing(true);
    verticalLayout.addComponent(
            new Label("Relatively sized components resize themselves automatically when in Vaadin component."));

    Button button = new Button("Open in a window");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Window window = new Window("Chart windodw");
            window.setContent(createChart());
            window.setWidth("50%");
            window.setHeight("50%");

            getUI().addWindow(window);

        }
    });

    verticalLayout.addComponent(button);
    horizontalSplitPanel.setFirstComponent(verticalLayout);

    return horizontalSplitPanel;
}

From source file:com.cavisson.gui.dashboard.components.controls.ButtonsAndLinks.java

License:Apache License

/**
* 
*///w w w .  ja  va2  s . c o m
public ButtonsAndLinks() {
    setMargin(true);

    Label h1 = new Label("Buttons");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    Button button = new Button("Normal");
    row.addComponent(button);

    button = new Button("Disabled");
    button.setEnabled(false);
    row.addComponent(button);

    button = new Button("Primary");
    button.addStyleName("primary");
    row.addComponent(button);

    button = new Button("Friendly");
    button.addStyleName("friendly");
    row.addComponent(button);

    button = new Button("Danger");
    button.addStyleName("danger");
    row.addComponent(button);

    TestIcon testIcon = new TestIcon(10);
    button = new Button("Small");
    button.addStyleName("small");
    button.setIcon(testIcon.get());
    row.addComponent(button);

    button = new Button("Large");
    button.addStyleName("large");
    button.setIcon(testIcon.get());
    row.addComponent(button);

    button = new Button("Top");
    button.addStyleName("icon-align-top");
    button.setIcon(testIcon.get());
    row.addComponent(button);

    button = new Button("Image icon");
    button.setIcon(testIcon.get(true, 16));
    row.addComponent(button);

    button = new Button("Image icon");
    button.addStyleName("icon-align-right");
    button.setIcon(testIcon.get(true));
    row.addComponent(button);

    button = new Button("Photos");
    button.setIcon(testIcon.get());
    row.addComponent(button);

    button = new Button();
    button.setIcon(testIcon.get());
    button.addStyleName("icon-only");
    row.addComponent(button);

    button = new Button("Borderless");
    button.setIcon(testIcon.get());
    button.addStyleName("borderless");
    row.addComponent(button);

    button = new Button("Borderless, colored");
    button.setIcon(testIcon.get());
    button.addStyleName("borderless-colored");
    row.addComponent(button);

    button = new Button("Quiet");
    button.setIcon(testIcon.get());
    button.addStyleName("quiet");
    row.addComponent(button);

    button = new Button("Link style");
    button.setIcon(testIcon.get());
    button.addStyleName("link");
    row.addComponent(button);

    button = new Button("Icon on right");
    button.setIcon(testIcon.get());
    button.addStyleName("icon-align-right");
    row.addComponent(button);

    CssLayout group = new CssLayout();
    group.addStyleName("v-component-group");
    row.addComponent(group);

    button = new Button("One");
    group.addComponent(button);
    button = new Button("Two");
    group.addComponent(button);
    button = new Button("Three");
    group.addComponent(button);

    button = new Button("Tiny");
    button.addStyleName("tiny");
    row.addComponent(button);

    button = new Button("Huge");
    button.addStyleName("huge");
    row.addComponent(button);

    NativeButton nbutton = new NativeButton("Native");
    row.addComponent(nbutton);

    h1 = new Label("Links");
    h1.addStyleName("h1");
    addComponent(h1);

    row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    Link link = new Link("vaadin.com", new ExternalResource("https://vaadin.com"));
    row.addComponent(link);

    link = new Link("Link with icon", new ExternalResource("https://vaadin.com"));
    link.addStyleName("color3");
    link.setIcon(testIcon.get());
    row.addComponent(link);

    link = new Link("Small", new ExternalResource("https://vaadin.com"));
    link.addStyleName("small");
    row.addComponent(link);

    link = new Link("Large", new ExternalResource("https://vaadin.com"));
    link.addStyleName("large");
    row.addComponent(link);

    link = new Link(null, new ExternalResource("https://vaadin.com"));
    link.setIcon(testIcon.get());
    link.addStyleName("large");
    row.addComponent(link);
}

From source file:com.cavisson.gui.dashboard.components.controls.ComboBoxes.java

License:Apache License

public ComboBoxes() {
    setMargin(true);// ww  w.jav  a2 s  .  co  m

    Label h1 = new Label("Combo Boxes");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    ComboBox combo = new ComboBox("Normal");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.setItemIcon(combo.getItemIds().iterator().next(), new ThemeResource("../runo/icons/16/document.png"));
    row.addComponent(combo);

    CssLayout group = new CssLayout();
    group.setCaption("Grouped with a Button");
    group.addStyleName("v-component-group");
    row.addComponent(group);

    combo = new ComboBox();
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.setWidth("240px");
    group.addComponent(combo);
    Button today = new Button("Do It");
    group.addComponent(today);

    combo = new ComboBox("Explicit size");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setWidth("260px");
    combo.setHeight("60px");
    row.addComponent(combo);

    combo = new ComboBox("No text input allowed");
    combo.setInputPrompt("You can click here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setTextInputAllowed(false);
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    row.addComponent(combo);

    combo = new ComboBox("Error");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    combo.setComponentError(new UserError("Fix it, now!"));
    row.addComponent(combo);

    combo = new ComboBox("Error, borderless");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    combo.setComponentError(new UserError("Fix it, now!"));
    combo.addStyleName("borderless");
    row.addComponent(combo);

    combo = new ComboBox("Disabled");
    combo.setInputPrompt("You can't type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setEnabled(false);
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("color1");
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("color2");
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("color3");
    row.addComponent(combo);

    combo = new ComboBox("Small");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("small");
    row.addComponent(combo);

    combo = new ComboBox("Large");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("large");
    row.addComponent(combo);

    combo = new ComboBox("Borderless");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.addStyleName("borderless");
    row.addComponent(combo);

    combo = new ComboBox("Tiny");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("tiny");
    row.addComponent(combo);

    combo = new ComboBox("Huge");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("huge");
    row.addComponent(combo);
}

From source file:com.cavisson.gui.dashboard.components.controls.CommonParts.java

License:Apache License

Panel loadingIndicators() {
    Panel p = new Panel("Loading Indicator");
    final VerticalLayout content = new VerticalLayout();
    p.setContent(content);/*from  w ww  . ja  v  a2 s  . c o  m*/
    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 (!ValoThemeUI.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;
}