Search in sources :

Example 1 with GridContextClickEvent

use of com.vaadin.ui.Grid.GridContextClickEvent in project VaadinUtils by rlsutton1.

the class GridContextMenu method setAsGridContextMenu.

/**
 * 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 setAsGridContextMenu(final Grid grid, final boolean onRow, final boolean onHeader, final boolean onFooter) {
    this.grid = grid;
    extend(grid);
    setOpenAutomatically(false);
    grid.addContextClickListener(new ContextClickListener() {

        private static final long serialVersionUID = -2197393292360426242L;

        @Override
        public void contextClick(ContextClickEvent event) {
            if (!(event instanceof GridContextClickEvent)) {
                return;
            }
            final GridContextClickEvent e = (GridContextClickEvent) event;
            switch(e.getSection()) {
                case BODY:
                    if (onRow) {
                        openContext(e);
                    }
                    break;
                case FOOTER:
                    if (onFooter) {
                        openContext(e);
                    }
                    break;
                case HEADER:
                    if (onHeader) {
                        openContext(e);
                    }
                    break;
                default:
                    break;
            }
        }
    });
}
Also used : ContextClickListener(com.vaadin.event.ContextClickEvent.ContextClickListener) GridContextClickEvent(com.vaadin.ui.Grid.GridContextClickEvent) ContextClickEvent(com.vaadin.event.ContextClickEvent) GridContextClickEvent(com.vaadin.ui.Grid.GridContextClickEvent)

Aggregations

ContextClickEvent (com.vaadin.event.ContextClickEvent)1 ContextClickListener (com.vaadin.event.ContextClickEvent.ContextClickListener)1 GridContextClickEvent (com.vaadin.ui.Grid.GridContextClickEvent)1