Search in sources :

Example 6 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayerTest method setup.

@Before
public void setup() {
    this.hideShowLayer = new ResizeColumnHideShowLayer(this.bodyDataLayer, this.bodyDataLayer);
    this.listener = new LayerListenerFixture();
    this.hideShowLayer.addLayerListener(this.listener);
}
Also used : LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Before(org.junit.Before)

Example 7 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture in project nebula.widgets.nattable by eclipse.

the class DataLayerPersistenceTest method testLoadState.

@Test
public void testLoadState() {
    LayerListenerFixture listener = new LayerListenerFixture();
    this.dataLayer.addLayerListener(listener);
    Properties properties = new Properties();
    properties.setProperty("prefix.columnWidth.defaultSize", "80");
    properties.setProperty("prefix.columnWidth.resizableByDefault", "false");
    properties.setProperty("prefix.columnWidth.percentageSizing", "true");
    properties.setProperty("prefix.rowHeight.defaultSize", "70");
    properties.setProperty("prefix.rowHeight.resizableByDefault", "true");
    this.dataLayer.loadState("prefix", properties);
    assertEquals(80, this.dataLayer.getColumnWidthByPosition(0));
    assertEquals(80, this.dataLayer.getColumnWidthByPosition(1));
    assertFalse(this.dataLayer.isColumnPositionResizable(0));
    assertFalse(this.dataLayer.isColumnPositionResizable(1));
    assertEquals(70, this.dataLayer.getRowHeightByPosition(0));
    assertEquals(70, this.dataLayer.getRowHeightByPosition(1));
    assertTrue(this.dataLayer.isRowPositionResizable(0));
    assertTrue(this.dataLayer.isRowPositionResizable(1));
    assertTrue(this.dataLayer.isColumnPercentageSizing());
    assertFalse(this.dataLayer.isRowPercentageSizing());
}
Also used : LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture 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)

Example 9 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture in project nebula.widgets.nattable by eclipse.

the class RowHideShowLayerTest2 method scrollAndHideTheLastRow.

/**
 * Integration test
 */
@Test
public void scrollAndHideTheLastRow() throws Exception {
    // Total rows in fixture - 20 (index 0 - 19)
    NatTableFixture 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);
        }
    }, 600, 120);
    LayerListenerFixture natTableListener = new LayerListenerFixture();
    natTable.addLayerListener(natTableListener);
    // Scroll to position 15 in grid/15 in body
    natTable.scrollToRow(15);
    assertEquals(15, natTable.getRowIndexByPosition(1));
    // Hide last row - position 5/index 19
    assertEquals(19, natTable.getRowIndexByPosition(5));
    natTable.doCommand(new RowHideCommand(natTable, 5));
    // Assert event received
    assertNotNull(natTableListener.getReceivedEvent(HideRowPositionsEvent.class));
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) natTableListener.getReceivedEvent(HideRowPositionsEvent.class);
    // When last row is hidden it is not carrying the following info
    assertEquals(1, hideEvent.getRowPositionRanges().size());
    // View port adjusted origin to move an extra row in
    Range hiddenRange = hideEvent.getRowPositionRanges().iterator().next();
    assertEquals(6, hiddenRange.start);
    assertEquals(7, hiddenRange.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) 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)

Example 10 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture in project nebula.widgets.nattable by eclipse.

the class HideShowColumnEventTest method setUp.

@Before
public void setUp() {
    this.hideShowLayer = new BaseColumnHideShowLayerFixture(new DataLayerFixture(100, 40));
    this.layerListener = new LayerListenerFixture();
}
Also used : BaseColumnHideShowLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseColumnHideShowLayerFixture) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Before(org.junit.Before)

Aggregations

LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)37 Test (org.junit.Test)21 Before (org.junit.Before)16 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)11 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)7 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 Shell (org.eclipse.swt.widgets.Shell)4 Properties (java.util.Properties)3 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)3 CellVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent)3 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)3 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)3 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)2 DummyBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)2 RowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand)2 HideColumnPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent)2 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)2