Search in sources :

Example 16 with ShowAllColumnsCommand

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemovePartialCellSelectionOnColumnDelete.

@Test
public void shouldRemovePartialCellSelectionOnColumnDelete() {
    assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 2, false, true));
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 1, false, true));
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 2, false, true));
    assertEquals(4, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new ColumnHideCommand(this.nattable, 1));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(2, selectedCells.size());
    // moved to the left
    for (ILayerCell cell : selectedCells) {
        assertEquals(0, cell.getColumnPosition());
    }
    // insert again to verify the column position shift
    this.nattable.doCommand(new ShowAllColumnsCommand());
    // the deselected cells shouldn't get automatically selected again
    selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(2, selectedCells.size());
    // moved to the right
    for (ILayerCell cell : selectedCells) {
        assertEquals(1, cell.getColumnPosition());
    }
}
Also used : MultiColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand) ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ShowAllColumnsCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 17 with ShowAllColumnsCommand

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

the class MenuItemProviders method showAllColumnsMenuItemProvider.

/**
 * Will create and return the {@link IMenuItemProvider} that adds the action
 * for executing the {@link ShowAllColumnsCommand} to a popup menu. This
 * command is intended to show all columns of the NatTable and is used to
 * unhide previous hidden columns.
 * <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 ShowAllColumnsCommand}.
 */
public static IMenuItemProvider showAllColumnsMenuItemProvider(final String menuLabel) {
    return new IMenuItemProvider() {

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

                @Override
                public void widgetSelected(SelectionEvent e) {
                    natTable.doCommand(new ShowAllColumnsCommand());
                }
            });
        }
    };
}
Also used : 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) ShowAllColumnsCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand) Menu(org.eclipse.swt.widgets.Menu)

Aggregations

ShowAllColumnsCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand)17 Test (org.junit.Test)16 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)14 FreezeColumnCommand (org.eclipse.nebula.widgets.nattable.freeze.command.FreezeColumnCommand)12 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)6 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)2 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)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