Search in sources :

Example 1 with ContextClickEvent

use of com.vaadin.event.ContextClickEvent 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)

Example 2 with ContextClickEvent

use of com.vaadin.event.ContextClickEvent in project VaadinUtils by rlsutton1.

the class TreeContextMenu method setAsTreeContextMenu.

@Override
public void setAsTreeContextMenu(final Tree tree) {
    this.tree = tree;
    extend(tree);
    setOpenAutomatically(false);
    tree.addContextClickListener(new ContextClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void contextClick(ContextClickEvent event) {
            if (event.getButton() == MouseButton.RIGHT) {
                openContext((TreeContextClickEvent) event);
                open(event.getClientX(), event.getClientY());
            }
        }
    });
}
Also used : TreeContextClickEvent(com.vaadin.ui.Tree.TreeContextClickEvent) ContextClickListener(com.vaadin.event.ContextClickEvent.ContextClickListener) TreeContextClickEvent(com.vaadin.ui.Tree.TreeContextClickEvent) ContextClickEvent(com.vaadin.event.ContextClickEvent)

Example 3 with ContextClickEvent

use of com.vaadin.event.ContextClickEvent in project VaadinUtils by rlsutton1.

the class ButtonContextMenu method setAsButtonContextMenu.

/**
 * Assigns this as the context menu of a button.
 */
public void setAsButtonContextMenu(final Button button, final E targetEntity) {
    this.targetEntity = targetEntity;
    extend(button);
    setOpenAutomatically(false);
    button.addContextClickListener(new ContextClickListener() {

        private static final long serialVersionUID = 4777762727944373063L;

        @Override
        public void contextClick(ContextClickEvent event) {
            openContext(event.getClientX(), event.getClientY());
        }
    });
}
Also used : ContextClickListener(com.vaadin.event.ContextClickEvent.ContextClickListener) ContextClickEvent(com.vaadin.event.ContextClickEvent)

Aggregations

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