Example usage for com.vaadin.ui Button addListener

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

Introduction

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

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

Usage

From source file:org.vaadin.hene.splitbutton.SplitButton.java

License:Apache License

/**
 * This is not a part of the official API of SplitButton, just for testing
 * purposes./*from  w  w w .  j av a2s  .c  o  m*/
 */
protected SplitButton(Button button, PopupButton popupButton) {
    this.button = button;
    button.setParent(this);
    button.addListener(this);

    this.popupButton = popupButton;
    popupButton.setHeight("100%");
    // TODO
    // popupButton.setPopupPositionPaintable(this);
    popupButton.setParent(this);
    popupButton.addPopupVisibilityListener(this);
}

From source file:org.vaadin.johannesh.jfokus2012.touchkit.view.EditContactView.java

License:Open Source License

private void buildView() {
    Button undoButton = new Button("Undo");
    undoButton.addListener(new Button.ClickListener() {
        @Override/*from  ww  w .j  ava 2s. c o m*/
        public void buttonClick(ClickEvent event) {
            form.discard();
            getNavigationManager().navigateBack();
        }
    });

    Button readyButton = new Button("Ready");
    readyButton.addStyleName("blue");
    readyButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            form.commit();
            JPAContainer<Person> persons = App.getPersonsContainer();
            persons.addEntity(editedItem.getEntity());
            getNavigationManager().navigateBack();
        }
    });

    form = new ViewBoundForm(new ContactEntityView());
    form.getLayout().setWidth("100%");
    form.setSizeUndefined();
    form.setWidth("100%");

    getNavigationBar().setLeftComponent(undoButton);
    getNavigationBar().setRightComponent(readyButton);

    content = new CssLayout();
    content.setSizeUndefined();
    content.setWidth("100%");

    form.setItemDataSource(editedItem.asItem());
    content.addComponent(form);

    setContent(content);
}

From source file:org.vaadin.johannesh.jfokus2012.touchkit.view.ShowContactView.java

License:Open Source License

private void buildLayout() {
    layout = new CssLayout();
    layout.addStyleName("show-contact-view");
    layout.setWidth("100%");

    VerticalComponentGroup infoGroup = new VerticalComponentGroup("");
    infoGroup.setWidth("100%");

    Component label;//  w w w.  j  av a2  s.c o m
    Property p;

    p = item.getItemProperty(ContactUtils.PROPERTY_COMPANY);
    label = new Label(new ContactUtils.CompanyPropertyFormatter(p));
    label.setCaption(ContactUtils.formatFieldCaption(ContactUtils.PROPERTY_COMPANY));
    infoGroup.addComponent(label);

    p = item.getItemProperty(ContactUtils.PROPERTY_MOBILE);
    label = new Label(p);
    label.setCaption(ContactUtils.formatFieldCaption(ContactUtils.PROPERTY_MOBILE));
    infoGroup.addComponent(label);

    p = item.getItemProperty(ContactUtils.PROPERTY_EMAIL);
    label = new Label(p);
    label.setCaption(ContactUtils.formatFieldCaption(ContactUtils.PROPERTY_EMAIL));
    infoGroup.addComponent(label);

    Embedded picture = new Embedded("", new ThemeResource("icon/picture.png"));
    picture.setWidth("57px");
    picture.setHeight("57px");

    Label firstName = new Label(item.getItemProperty(ContactUtils.PROPERTY_FIRST_NAME));
    firstName.addStyleName("strong-name");

    Label lastName = new Label(item.getItemProperty(ContactUtils.PROPERTY_LAST_NAME));
    lastName.addStyleName("strong-name");

    GridLayout nameLayout = new GridLayout(2, 2);
    nameLayout.setWidth("100%");
    nameLayout.setSpacing(true);
    nameLayout.setMargin(true, true, false, true);
    nameLayout.setColumnExpandRatio(1, 1.0f);
    nameLayout.addComponent(picture, 0, 0, 0, 1);
    nameLayout.addComponent(firstName, 1, 0);
    nameLayout.addComponent(lastName, 1, 1);
    nameLayout.setComponentAlignment(firstName, Alignment.MIDDLE_LEFT);
    nameLayout.setComponentAlignment(lastName, Alignment.MIDDLE_LEFT);

    final Favourite favourite = new Favourite();
    favourite.setImmediate(true);
    favourite.setReadOnly(true);
    favourite.setIcon(new ThemeResource("icon/favourite.png"));
    favourite.setPropertyDataSource(item.getItemProperty(ContactUtils.PROPERTY_FAVOURITE));

    layout.addComponent(nameLayout);
    layout.addComponent(favourite);
    layout.addComponent(infoGroup);

    Button editButton = new Button("Edit");
    editButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            getNavigationManager().navigateTo(new EditContactView(item));
        }
    });
    setRightComponent(editButton);
    setContent(layout);
}

From source file:org.vaadin.notifique.Notifique.java

License:Apache License

/**
 * Create a close button for a message./* w w w  .j  a  va  2  s.  c  o m*/
 */
protected Button createCloseButtonFor(final Message i) {
    Button b = new Button();
    b.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = -1932127150282887613L;

        public void buttonClick(ClickEvent event) {
            i.hide();

        }
    });
    b.setStyleName(Reindeer.BUTTON_LINK);
    b.addStyleName(STYLE_CLOSE);
    return b;
}

From source file:org.vaadin.training.fundamentals.happening.ui.viewimpl.EditHappeningViewImpl.java

License:Apache License

@SuppressWarnings("serial")
@Override//from   w w w  .  jav a  2 s .  co  m
public boolean showUserPrompt(PendingNavigationCallback callback) {
    if (form.isModified()) {
        currentCallback = callback;
        final Window confirmWindow = new Window("Are you sure?");
        Button okButton = new Button("Ok");
        okButton.addListener(new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getWindow().removeWindow(confirmWindow);
                if (currentCallback != null) {
                    currentCallback.commit();
                }
            }
        });
        Button cancelButton = new Button("Cancel");
        cancelButton.addListener(new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getWindow().removeWindow(confirmWindow);
                if (currentCallback != null) {
                    currentCallback.discard();
                }
            }
        });
        confirmWindow.addComponent(okButton);
        confirmWindow.addComponent(cancelButton);
        getWindow().addWindow(confirmWindow);
        return true;
    }
    return false;
}

From source file:org.vaadin.training.fundamentals.happening.ui.viewimpl.ShowHappeningViewImpl.java

License:Apache License

@SuppressWarnings("serial")
private void rebuildLayout() {
    removeAllComponents();//  www.  j a v  a  2s .  c  o  m
    ResourceBundle tr = AppData.getTr(AppData.getLocale());
    Button editButton = new Button(tr.getString("Button.Edit"));
    editButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            eventRouter.fireEvent(new EditSelectedEvent(event.getButton()));
        }
    });
    addComponent(editButton, 0, 0, 1, 0);
    setComponentAlignment(editButton, Alignment.TOP_RIGHT);
}

From source file:pl.skawanna.webapp.MyVaadinApplication.java

License:Apache License

@Override
public void init() {
    SpringContextHelper helper = new SpringContextHelper(this);
    final AnnaService service = (AnnaService) helper.getBean("service");

    window = new Window("My Vaadin Application");
    setMainWindow(window);//w  ww  .  j a  v  a2 s .co  m
    Button button = new Button("Click Me");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            window.addComponent(new Label("Thank you for clicking"));
            window.addComponent(new Label(service.hello()));
        }
    });
    window.addComponent(button);

}

From source file:pt.ist.vaadinframework.ui.fields.ContainerEditor.java

License:Open Source License

public ContainerEditor(TableFieldFactory factory, String bundlename, Class<? extends PC> type) {
    super(new ContainerEditorTable(factory, bundlename), null, type);

    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);/*from  www .j  a  v  a  2 s. co m*/
    layout.addComponent(getWrappedField());
    Button add = new Button(VaadinResources.getString(VaadinResourceConstants.COMMONS_ACTION_ADD));
    add.addStyleName(BaseTheme.BUTTON_LINK);
    layout.addComponent(add);
    add.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (getWrappedField().getContainerDataSource() instanceof AbstractBufferedContainer) {
                AbstractBufferedContainer<PC, ?, ?> container = (AbstractBufferedContainer<PC, ?, ?>) getWrappedField()
                        .getContainerDataSource();
                container.addItem(container.getElementType());
            } else {
                getWrappedField().getContainerDataSource().addItem();
            }
        }
    });
    setCompositionRoot(layout);
}

From source file:ramo.klevis.main.MyVaadinApplication.java

License:Apache License

@Override
public void init() {
    window = new Window("My Vaadin Application");
    setMainWindow(window);//from  www . jav  a2  s .c om

    // binding form example
    BeanController<Bean> beanController = new BeanController<Bean>();

    final ArmatimeForm<Bean> bindingFormWithvalidation = beanController.createBindingForm(new Bean(),
            new BeanView());

    window.addComponent(bindingFormWithvalidation);
    // end of binding form example

    Button button = new Button("Show me some values of form");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {

            bindingFormWithvalidation.commit();
            System.out.println("Values of your form are " + bindingFormWithvalidation.getBean());

        }
    });

    Button button2 = new Button("Clear all from form");
    button2.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub

            bindingFormWithvalidation.clearForm();

            System.out.println("Form cleaned " + bindingFormWithvalidation.getBean());
        }
    });
    window.addComponent(button);
    window.addComponent(button2);

    // annotation table example
    final AnnotationTable<BeanTable> annotationTable = new AnnotationTable<BeanTable>(BeanTable.class);

    window.addComponent(annotationTable);
    // end of annotation table example

    Button button3 = new Button("Add some values to table");

    button3.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub

            ArrayList<BeanTable> arrayList = new ArrayList<BeanTable>();

            BeanTable beanTable = new BeanTable();
            beanTable.setAge(8);
            Document document = new Document();
            document.setId("56-iso 9");
            document.setContent("Example of table");
            beanTable.setDocument(document);
            beanTable.setFather("Kali");
            beanTable.setName("Demi");
            beanTable.setSurname("Dragoi ");
            arrayList.add(beanTable);

            annotationTable.addToContainer(arrayList);

        }
    });

    Button button4 = new Button("Clear the table");

    button4.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub

            annotationTable.clearContainer();
        }
    });

    window.addComponent(button3);
    window.addComponent(button4);
}

From source file:ro.zg.netcell.vaadin.action.application.CreateEntityHandler.java

License:Apache License

private void displaySuccessfulMessage(final Entity entity, final UserAction ua, final OpenGroupsApplication app,
        final ComponentContainer targetComponent, final long entityId, final ActionContext ac) {
    /* store current target component */
    // final ComponentContainer targetComponent = app.getTargetComponent();
    String entityTypeLowerCase = ua.getTargetEntityType().toLowerCase();
    String createdSuccessfullyMessage = app.getMessage(entityTypeLowerCase + ".created.successfully");
    String createNewMessage = app.getMessage("create.new." + entityTypeLowerCase);
    String openCreatedMessage = app.getMessage("open.created." + entityTypeLowerCase);

    VerticalLayout container = new VerticalLayout();
    container.setSizeFull();//from www  .j  a v  a 2  s .c om

    Label success = new Label(createdSuccessfullyMessage);
    container.addComponent(success);

    HorizontalLayout linksContainer = new HorizontalLayout();
    linksContainer.setSpacing(true);
    Button openCreated = new Button(openCreatedMessage);
    linksContainer.addComponent(openCreated);
    openCreated.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            List<String> subtypesList = app.getAppConfigManager()
                    .getSubtypesForComplexType(ua.getTargetEntityComplexType());
            if (subtypesList != null) {
                Entity entity = new Entity(entityId);
                //          getActionsManager().executeAction(ActionsManager.REFRESH_SELECTED_ENTITY, entity, app, null, false,ac);
                //          getActionsManager().executeAction(ActionsManager.OPEN_ENTITY_IN_TAB, entity, app, null, false,ac);
                app.openInActiveWindow(entity);
            }
            /* if no subtypes open the parent entity */
            else {
                Entity parentEntity = ac.getMainEntity();
                parentEntity.getState().setEntityTypeVisible(true);
                String complexEntityType = ua.getTargetEntityComplexType();
                parentEntity.getState().setDesiredActionsPath(
                        complexEntityType + Defaults.getDefaultActionForEntityType(complexEntityType));
                //          app.getTemporaryTab(parentEntity).setRefreshOn(true);
                //          getActionsManager().executeAction(ActionsManager.OPEN_ENTITY_IN_TAB, parentEntity, app, null, false,ac);
                app.openInActiveWindow(parentEntity);
            }
        }
    });

    Button createNew = new Button(createNewMessage);
    linksContainer.addComponent(createNew);
    createNew.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            /* recall the handle method on this handler */
            // app.setTargetComponent(targetComponent);
            ua.executeHandler(entity, app, targetComponent, ac);
        }
    });

    container.addComponent(linksContainer);

    targetComponent.removeAllComponents();
    targetComponent.addComponent(container);

    /* refresh hierarchy tree */
    ActionsManager.getInstance().executeAction(ActionsManager.REFRESH_CAUSAL_HIERARCHY, ac);
}