Search in sources :

Example 1 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.

the class ShowColumnPositionsEventDiffTest method testColumnDiffs.

/**
 * + + + before: 0 1 3 5 6 8 9 10 11 12 after: 0 1 2 3 4 5 6 7 8 9 + + + + +
 */
@Test
public void testColumnDiffs() {
    Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
    Assert.assertNotNull(columnDiffs);
    Assert.assertEquals(3, columnDiffs.size());
    Iterator<StructuralDiff> iterator = columnDiffs.iterator();
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(2, 2), new Range(2, 3)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(3, 3), new Range(4, 5)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(5, 5), new Range(7, 10)), iterator.next());
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 2 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.

the class ShowRowPositionsEventDiffTest method testConvertToLocal.

/**
 * + + + before: 0 1 3 5 6 8 9 10 11 12 after: 0 1 2 3 4 5 6 7 8 9 + + + + +
 */
@Test
public void testConvertToLocal() {
    this.event.convertToLocal(this.hideShowLayer);
    Collection<StructuralDiff> rowDiffs = this.event.getRowDiffs();
    Assert.assertNotNull(rowDiffs);
    Assert.assertEquals(3, rowDiffs.size());
    Iterator<StructuralDiff> iterator = rowDiffs.iterator();
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(2, 2), new Range(2, 3)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(3, 3), new Range(4, 5)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(5, 5), new Range(7, 10)), iterator.next());
    this.event.convertToLocal(this.viewportLayer);
    rowDiffs = this.event.getRowDiffs();
    Assert.assertNotNull(rowDiffs);
    Assert.assertEquals(3, rowDiffs.size());
    iterator = rowDiffs.iterator();
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(0, 0), new Range(0, 1)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(1, 1), new Range(2, 3)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(3, 3), new Range(5, 8)), iterator.next());
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 3 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.

the class ShowRowPositionsEventDiffTest method testColumnDiffs.

/**
 * + + + before: 0 1 3 5 6 8 9 10 11 12 after: 0 1 2 3 4 5 6 7 8 9 + + + + +
 */
@Test
public void testColumnDiffs() {
    Collection<StructuralDiff> rowDiffs = this.event.getRowDiffs();
    Assert.assertNotNull(rowDiffs);
    Assert.assertEquals(3, rowDiffs.size());
    Iterator<StructuralDiff> iterator = rowDiffs.iterator();
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(2, 2), new Range(2, 3)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(3, 3), new Range(4, 5)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(5, 5), new Range(7, 10)), iterator.next());
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 4 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff 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 5 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.

the class RowHideShowLayerTest2 method shouldFireTheCorrectEventOnRowHide.

@Test
public void shouldFireTheCorrectEventOnRowHide() throws Exception {
    NatTable natTable = new NatTableFixture(new Shell(), new DummyGridLayerStack() {

        @Override
        protected void init(IUniqueIndexLayer bodyDataLayer, IUniqueIndexLayer columnHeaderDataLayer, IUniqueIndexLayer rowHeaderDataLayer, IUniqueIndexLayer cornerDataLayer) {
            RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(bodyDataLayer);
            super.init(rowHideShowLayer, columnHeaderDataLayer, rowHeaderDataLayer, cornerDataLayer);
        }
    });
    LayerListenerFixture listener = new LayerListenerFixture();
    natTable.addLayerListener(listener);
    // Grid coordinates
    natTable.doCommand(new RowHideCommand(natTable, 5));
    assertEquals(1, listener.getReceivedEvents().size());
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) listener.getReceivedEvents().get(0);
    Range range = hideEvent.getRowPositionRanges().iterator().next();
    assertEquals(5, range.start);
    assertEquals(6, range.end);
    // The range Before hide: 5 -> 6
    // The range After hide: 5 -> 5 (row is not there anymore)
    StructuralDiff rowDiff = hideEvent.getRowDiffs().iterator().next();
    assertEquals(5, rowDiff.getBeforePositionRange().start);
    assertEquals(6, rowDiff.getBeforePositionRange().end);
    assertEquals(5, rowDiff.getAfterPositionRange().start);
    assertEquals(5, rowDiff.getAfterPositionRange().end);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) 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) IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand) Test(org.junit.Test)

Aggregations

StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)28 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)23 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 IStructuralChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent)5 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)4 Serializable (java.io.Serializable)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)1 DataUpdateEvent (org.eclipse.nebula.widgets.nattable.edit.event.DataUpdateEvent)1 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)1