Search in sources :

Example 1 with HideColumnPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent in project nebula.widgets.nattable by eclipse.

the class ColumnHideShowLayerTest2 method shouldFireTheCorrectEventOnColumnHide.

@Test
public void shouldFireTheCorrectEventOnColumnHide() throws Exception {
    NatTable natTable = new NatTableFixture();
    LayerListenerFixture listener = new LayerListenerFixture();
    natTable.addLayerListener(listener);
    // Grid coordinates
    natTable.doCommand(new ColumnHideCommand(natTable, 5));
    assertEquals(1, listener.getReceivedEvents().size());
    HideColumnPositionsEvent hideEvent = (HideColumnPositionsEvent) listener.getReceivedEvents().get(0);
    Range range = hideEvent.getColumnPositionRanges().iterator().next();
    assertEquals(5, range.start);
    assertEquals(6, range.end);
    // The range Before hide: 5 -> 6
    // The range After hide: 5 -> 5 (column is not there anymore)
    StructuralDiff columnDiff = hideEvent.getColumnDiffs().iterator().next();
    assertEquals(5, columnDiff.getBeforePositionRange().start);
    assertEquals(6, columnDiff.getBeforePositionRange().end);
    assertEquals(5, columnDiff.getAfterPositionRange().start);
    assertEquals(5, columnDiff.getAfterPositionRange().end);
}
Also used : ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) HideColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 2 with HideColumnPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent in project nebula.widgets.nattable by eclipse.

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionIfSelectedColumnIsHidden.

@Test
public void shouldClearSelectionIfSelectedColumnIsHidden() {
    this.selectionModel.addSelection(3, 4);
    List<Integer> columns = new ArrayList<Integer>();
    columns.add(3);
    this.selectionModel.handleLayerEvent(new HideColumnPositionsEvent(this.dataLayer, columns));
    Assert.assertTrue(this.selectionModel.isEmpty());
}
Also used : HideColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with HideColumnPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent in project nebula.widgets.nattable by eclipse.

the class SelectionModelStructuralChangeEventHandlerTest method shouldNotClearSelectionIfOtherColumnIsHidden.

@Test
public void shouldNotClearSelectionIfOtherColumnIsHidden() {
    this.selectionModel.addSelection(3, 4);
    List<Integer> columns = new ArrayList<Integer>();
    columns.add(2);
    this.selectionModel.handleLayerEvent(new HideColumnPositionsEvent(this.dataLayer, columns));
    Assert.assertTrue(this.selectionModel.isEmpty());
}
Also used : HideColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with HideColumnPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent in project nebula.widgets.nattable by eclipse.

the class ColumnHideShowLayerTest2 method scrollAndHideTheLastColumn.

/**
 * Integration test
 */
@Test
public void scrollAndHideTheLastColumn() throws Exception {
    // Total columns in fixture - 20 (index 0 - 19)
    NatTableFixture natTable = new NatTableFixture();
    LayerListenerFixture natTableListener = new LayerListenerFixture();
    natTable.addLayerListener(natTableListener);
    // Scroll to position 14 in grid/14 in body
    natTable.scrollToColumn(14);
    assertEquals(14, natTable.getColumnIndexByPosition(1));
    // Hide last column - position 6/index 19
    assertEquals(19, natTable.getColumnIndexByPosition(6));
    natTable.doCommand(new ColumnHideCommand(natTable, 6));
    // Assert event received
    assertNotNull(natTableListener.getReceivedEvent(HideColumnPositionsEvent.class));
    HideColumnPositionsEvent hideEvent = (HideColumnPositionsEvent) natTableListener.getReceivedEvent(HideColumnPositionsEvent.class);
    // When last column is hidden it is not carrying the following info
    assertEquals(1, hideEvent.getColumnPositionRanges().size());
    // View port adjusted origin to move an extra column in
    Range hiddenRange = hideEvent.getColumnPositionRanges().iterator().next();
    assertEquals(7, hiddenRange.start);
    assertEquals(8, hiddenRange.end);
}
Also used : ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) HideColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 5 with HideColumnPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent in project nebula.widgets.nattable by eclipse.

the class ColumnGroupExpandCollapseCommandHandler method doCommand.

@Override
protected boolean doCommand(ColumnGroupExpandCollapseCommand command) {
    int columnIndex = this.columnGroupExpandCollapseLayer.getColumnIndexByPosition(command.getColumnPosition());
    ColumnGroupModel model = this.columnGroupExpandCollapseLayer.getModel(command.getRowPosition());
    ColumnGroup columnGroup = model.getColumnGroupByIndex(columnIndex);
    // further operation ...
    if (columnGroup == null || !columnGroup.isCollapseable()) {
        return true;
    }
    List<Integer> columnIndexes = new ArrayList<Integer>(columnGroup.getMembers());
    columnIndexes.removeAll(columnGroup.getStaticColumnIndexes());
    boolean wasCollapsed = columnGroup.isCollapsed();
    if (wasCollapsed) {
        // we need to cleanup the column position list before we toggle
        // because the columns are hidden before the toggle and will be
        // visible afterwards
        cleanupColumnIndexes(columnIndexes);
    }
    columnGroup.toggleCollapsed();
    if (!wasCollapsed) {
        // we need to cleanup the column position list after we toggle
        // because the columns are hidden now
        cleanupColumnIndexes(columnIndexes);
    }
    ILayerEvent event;
    if (wasCollapsed) {
        event = new ShowColumnPositionsEvent(this.columnGroupExpandCollapseLayer, columnIndexes);
    } else {
        event = new HideColumnPositionsEvent(this.columnGroupExpandCollapseLayer, columnIndexes);
    }
    this.columnGroupExpandCollapseLayer.fireLayerEvent(event);
    return true;
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) HideColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent) ArrayList(java.util.ArrayList) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel) ShowColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowColumnPositionsEvent)

Aggregations

HideColumnPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 HashSet (java.util.HashSet)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 ColumnGroupModel (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)1 ColumnGroup (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)1 ShowColumnPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowColumnPositionsEvent)1 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)1 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)1