Search in sources :

Example 11 with ColumnHideCommand

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

the class DefaultBodyLayerStackTest method hideColumnsAndReorder.

/*
     * Data Layer: 0 1 2 3 4 5 6 7 8 9
     * -----------------------------------------------------
     */
@Test
public void hideColumnsAndReorder() throws Exception {
    // Hide 3, 4
    this.layerStack.doCommand(new ColumnHideCommand(this.layerStack, 3));
    this.layerStack.doCommand(new ColumnHideCommand(this.layerStack, 3));
    assertEquals(0, this.layerStack.getColumnIndexByPosition(0));
    assertEquals(1, this.layerStack.getColumnIndexByPosition(1));
    assertEquals(2, this.layerStack.getColumnIndexByPosition(2));
    assertEquals(5, this.layerStack.getColumnIndexByPosition(3));
    assertEquals(6, this.layerStack.getColumnIndexByPosition(4));
    assertEquals(7, this.layerStack.getColumnIndexByPosition(5));
    assertEquals(8, this.layerStack.getColumnIndexByPosition(6));
    assertEquals(9, this.layerStack.getColumnIndexByPosition(7));
    assertEquals(-1, this.layerStack.getColumnIndexByPosition(8));
    // Reorder 0 -> 4
    this.layerStack.doCommand(new ColumnReorderCommand(this.layerStack, 0, 4));
    assertEquals(1, this.layerStack.getColumnIndexByPosition(0));
    assertEquals(2, this.layerStack.getColumnIndexByPosition(1));
    assertEquals(5, this.layerStack.getColumnIndexByPosition(2));
    assertEquals(0, this.layerStack.getColumnIndexByPosition(3));
    assertEquals(6, this.layerStack.getColumnIndexByPosition(4));
    assertEquals(7, this.layerStack.getColumnIndexByPosition(5));
    assertEquals(8, this.layerStack.getColumnIndexByPosition(6));
    assertEquals(9, this.layerStack.getColumnIndexByPosition(7));
    assertEquals(-1, this.layerStack.getColumnIndexByPosition(8));
}
Also used : ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) Test(org.junit.Test)

Example 12 with ColumnHideCommand

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

the class DefaultBodyLayerStackTest method resizeAColumnAndHideIt.

@Test
public void resizeAColumnAndHideIt() throws Exception {
    assertEquals(10, this.layerStack.getColumnCount());
    assertEquals(1000, this.layerStack.getWidth());
    // Resize 2
    this.layerStack.doCommand(new ColumnResizeCommand(this.layerStack, 2, 500));
    assertEquals(1400, this.layerStack.getWidth());
    assertEquals(1, this.layerStack.getColumnIndexByPosition(1));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(1));
    assertEquals(100, this.layerStack.getStartXOfColumnPosition(1));
    assertEquals(2, this.layerStack.getColumnIndexByPosition(2));
    assertEquals(500, this.layerStack.getColumnWidthByPosition(2));
    assertEquals(200, this.layerStack.getStartXOfColumnPosition(2));
    assertEquals(3, this.layerStack.getColumnIndexByPosition(3));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(3));
    assertEquals(700, this.layerStack.getStartXOfColumnPosition(3));
    // Hide 2
    this.layerStack.doCommand(new ColumnHideCommand(this.layerStack, 2));
    assertEquals(9, this.layerStack.getColumnCount());
    assertEquals(1, this.layerStack.getColumnIndexByPosition(1));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(1));
    assertEquals(100, this.layerStack.getStartXOfColumnPosition(1));
    assertEquals(3, this.layerStack.getColumnIndexByPosition(2));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(2));
    assertEquals(200, this.layerStack.getStartXOfColumnPosition(2));
    assertEquals(4, this.layerStack.getColumnIndexByPosition(3));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(3));
    assertEquals(300, this.layerStack.getStartXOfColumnPosition(3));
    assertEquals(9, this.layerStack.getColumnIndexByPosition(8));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(8));
    assertEquals(800, this.layerStack.getStartXOfColumnPosition(8));
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) Test(org.junit.Test)

Example 13 with ColumnHideCommand

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

the class HideSelectedColumnsTest method shouldHideColumnForSelectedCell.

@Test
public void shouldHideColumnForSelectedCell() {
    // Select cell in column we want to hide
    this.selectionLayer.setSelectedCell(3, 0);
    // Hide selection
    this.selectionLayer.doCommand(new ColumnHideCommand(this.selectionLayer, 3));
    // The previously selected column should be hidden
    Assert.assertTrue(this.columnHideShowLayer.isColumnIndexHidden(3));
    Assert.assertEquals(4, this.selectionLayer.getColumnCount());
}
Also used : MultiColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand) ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) Test(org.junit.Test)

Example 14 with ColumnHideCommand

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveCellSelectionOnColumnDelete.

@Test
public void shouldRemoveCellSelectionOnColumnDelete() {
    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));
    assertEquals(2, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new ColumnHideCommand(this.nattable, 1));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(0, selectedCells.size());
}
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) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 15 with ColumnHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand 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)

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