Search in sources :

Example 16 with ColumnHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand in project nebula.widgets.nattable by eclipse.

the class MenuItemProviders method hideColumnMenuItemProvider.

/**
 * Will create and return the {@link IMenuItemProvider} that adds the action
 * for executing the {@link ColumnHideCommand} to a popup menu. This command
 * is intended to hide the current selected column immediately.
 * <p>
 * The {@link MenuItem} will be shown with the given menu label.
 *
 * @param menuLabel
 *            The text that will be showed for the generated
 *            {@link MenuItem}
 * @return The {@link IMenuItemProvider} for the {@link MenuItem} that
 *         executes the {@link ColumnHideCommand}.
 */
public static IMenuItemProvider hideColumnMenuItemProvider(final String menuLabel) {
    return new IMenuItemProvider() {

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

                @Override
                public void widgetSelected(SelectionEvent event) {
                    int columnPosition = getNatEventData(event).getColumnPosition();
                    natTable.doCommand(new ColumnHideCommand(natTable, columnPosition));
                }
            });
        }
    };
}
Also used : ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Aggregations

ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)16 Test (org.junit.Test)13 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)7 ShowAllColumnsCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand)6 FreezeColumnCommand (org.eclipse.nebula.widgets.nattable.freeze.command.FreezeColumnCommand)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)2 HideColumnPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent)2 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)2 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)2 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)1