Example usage for com.vaadin.ui Image addClickListener

List of usage examples for com.vaadin.ui Image addClickListener

Introduction

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

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Add a click listener to the component.

Usage

From source file:org.vaadin.presentation.views.NewsView.java

private Table createTable(IndexedContainer container) {
    Table table = new Table("Image Table", container);
    table.setSizeFull();/*from w w w.j  a  v a2  s .  co m*/
    table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);

    table.addGeneratedColumn("image1", new Table.ColumnGenerator() {
        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            Item item = source.getItem(itemId);
            Resource url = (Resource) item.getItemProperty("url1").getValue();
            String tags = (String) item.getItemProperty("tags1").getValue();
            int height = (Integer) item.getItemProperty("height").getValue();
            int width = (Integer) item.getItemProperty("width").getValue();
            Image enb = new Image("", url);
            enb.setWidth("320px");
            //                enb.setWidth(width, Unit.PIXELS);
            //                enb.setHeight(height, Unit.PIXELS);
            enb.addClickListener(new MouseEvents.ClickListener() {

                @Override
                public void click(MouseEvents.ClickEvent event) {
                    showNotify(url, tags);
                }
            });
            return enb;

        }

    });
    table.addGeneratedColumn("image2", new Table.ColumnGenerator() {
        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            Item item = source.getItem(itemId);
            Resource url = (Resource) item.getItemProperty("url2").getValue();
            String tags = (String) item.getItemProperty("tags2").getValue();
            int height = (Integer) item.getItemProperty("height").getValue();
            int width = (Integer) item.getItemProperty("width").getValue();
            Image enb = new Image("", url);
            enb.setWidth("320px");
            //                enb.setHeight(height, Unit.PIXELS);
            enb.addClickListener(new MouseEvents.ClickListener() {

                @Override
                public void click(MouseEvents.ClickEvent event) {
                    showNotify(url, tags);
                }
            });
            return enb;

        }

    });
    table.addGeneratedColumn("image3", new Table.ColumnGenerator() {
        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            Item item = source.getItem(itemId);
            Resource url = (Resource) item.getItemProperty("url3").getValue();
            String tags = (String) item.getItemProperty("tags3").getValue();
            int height = (Integer) item.getItemProperty("height").getValue();
            int width = (Integer) item.getItemProperty("width").getValue();
            Image enb = new Image("", url);
            enb.setWidth("320px");
            //                enb.setWidth(width, Unit.PIXELS);
            //                enb.setHeight(height, Unit.PIXELS);
            enb.addClickListener(new MouseEvents.ClickListener() {

                @Override
                public void click(MouseEvents.ClickEvent event) {
                    showNotify(url, tags);
                }
            });
            return enb;

        }

    });
    table.setColumnAlignment("image1", Table.Align.CENTER);
    table.setColumnAlignment("image2", Table.Align.CENTER);
    table.setColumnAlignment("image3", Table.Align.CENTER);

    table.setVisibleColumns(new Object[] { "image1", "image2", "image3" });
    //        table.setColumnExpandRatio("title", 1f);
    return table;
}