Search in sources :

Example 1 with UngroupByColumnIndexCommand

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.command.UngroupByColumnIndexCommand in project nebula.widgets.nattable by eclipse.

the class GroupByHeaderMenuConfiguration method createGroupByHeaderMenu.

/**
 * Creates the {@link PopupMenuBuilder} for the groupBy header menu with the
 * menu items to ungroup.
 *
 * @param natTable
 *            The NatTable where the menu should be attached.
 * @return The {@link PopupMenuBuilder} that is used to build the groupBy
 *         header menu.
 */
protected PopupMenuBuilder createGroupByHeaderMenu(NatTable natTable) {
    return new PopupMenuBuilder(natTable).withMenuItemProvider(UNGROUP_BY_MENU_ITEM_ID, new IMenuItemProvider() {

        @Override
        public void addMenuItem(final NatTable natTable, Menu popupMenu) {
            MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
            // $NON-NLS-1$
            menuItem.setText(Messages.getLocalizedMessage("%GroupByHeaderMenuConfiguration.ungroupBy"));
            menuItem.setEnabled(true);
            menuItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    NatEventData natEventData = MenuItemProviders.getNatEventData(event);
                    MouseEvent originalEvent = natEventData.getOriginalEvent();
                    int groupByColumnIndex = GroupByHeaderMenuConfiguration.this.groupByHeaderLayer.getGroupByColumnIndexAtXY(originalEvent.x, originalEvent.y);
                    natTable.doCommand(new UngroupByColumnIndexCommand(groupByColumnIndex));
                }
            });
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) UngroupByColumnIndexCommand(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.command.UngroupByColumnIndexCommand) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) MenuItem(org.eclipse.swt.widgets.MenuItem) NatEventData(org.eclipse.nebula.widgets.nattable.ui.NatEventData) Menu(org.eclipse.swt.widgets.Menu) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)

Aggregations

NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 UngroupByColumnIndexCommand (org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.command.UngroupByColumnIndexCommand)1 NatEventData (org.eclipse.nebula.widgets.nattable.ui.NatEventData)1 IMenuItemProvider (org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider)1 PopupMenuBuilder (org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Menu (org.eclipse.swt.widgets.Menu)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1