Search in sources :

Example 1 with HeaderClickListener

use of com.vaadin.ui.Table.HeaderClickListener in project VaadinUtils by rlsutton1.

the class TableContextMenu method setAsTableContextMenu.

/**
 * Assigns this as the context menu of given table. Allows context menu to
 * appear only on certain parts of the table.
 *
 * @param table
 * @param onRow
 *            show context menu when row is clicked
 * @param onHeader
 *            show context menu when header is clicked
 * @param onFooter
 *            show context menu when footer is clicked
 */
public void setAsTableContextMenu(final Table table, final boolean onRow, final boolean onHeader, final boolean onFooter) {
    extend(table);
    setOpenAutomatically(false);
    if (onRow) {
        table.addItemClickListener(new ItemClickEvent.ItemClickListener() {

            private static final long serialVersionUID = -348059189217149508L;

            @Override
            public void itemClick(ItemClickEvent event) {
                if (event.getButton() == MouseButton.RIGHT) {
                    for (TableContextMenuEvents events : eventsList) events.preContextMenuOpen();
                    fireEvent(new ContextMenuOpenedOnTableRowEvent(TableContextMenu.this, table, event.getItemId(), event.getPropertyId()));
                    open(event.getClientX(), event.getClientY());
                }
            }
        });
    }
    if (onHeader) {
        table.addHeaderClickListener(new HeaderClickListener() {

            private static final long serialVersionUID = -5880755689414670581L;

            @Override
            public void headerClick(HeaderClickEvent event) {
                if (event.getButton() == MouseButton.RIGHT) {
                    for (TableContextMenuEvents events : eventsList) events.preContextMenuOpen();
                    fireEvent(new ContextMenuOpenedOnTableHeaderEvent(TableContextMenu.this, table, event.getPropertyId()));
                    open(event.getClientX(), event.getClientY());
                }
            }
        });
    }
    if (onFooter) {
        table.addFooterClickListener(new FooterClickListener() {

            private static final long serialVersionUID = 2884227013964132482L;

            @Override
            public void footerClick(FooterClickEvent event) {
                if (event.getButton() == MouseButton.RIGHT) {
                    for (TableContextMenuEvents events : eventsList) events.preContextMenuOpen();
                    fireEvent(new ContextMenuOpenedOnTableHeaderEvent(TableContextMenu.this, table, event.getPropertyId()));
                    open(event.getClientX(), event.getClientY());
                }
            }
        });
    }
}
Also used : HeaderClickListener(com.vaadin.ui.Table.HeaderClickListener) ItemClickEvent(com.vaadin.event.ItemClickEvent) HeaderClickEvent(com.vaadin.ui.Table.HeaderClickEvent) FooterClickListener(com.vaadin.ui.Table.FooterClickListener) FooterClickEvent(com.vaadin.ui.Table.FooterClickEvent)

Aggregations

ItemClickEvent (com.vaadin.event.ItemClickEvent)1 FooterClickEvent (com.vaadin.ui.Table.FooterClickEvent)1 FooterClickListener (com.vaadin.ui.Table.FooterClickListener)1 HeaderClickEvent (com.vaadin.ui.Table.HeaderClickEvent)1 HeaderClickListener (com.vaadin.ui.Table.HeaderClickListener)1