use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class ResizeColumnHideShowLayerTest method testShowSpecificColumnsFixedWidth.
// test showing specific columns again
@Test
public void testShowSpecificColumnsFixedWidth() {
assertEquals(500, this.hideShowLayer.getWidth());
assertTrue(this.bodyDataLayer.isColumnPositionResizable(1));
assertTrue(this.bodyDataLayer.isColumnPositionResizable(4));
this.hideShowLayer.hideColumnPositions(1, 4);
assertEquals(2, this.listener.getReceivedEvents().size());
assertEquals(new Range(1, 2), ((ColumnResizeEvent) this.listener.getReceivedEvents().get(0)).getColumnDiffs().iterator().next().getAfterPositionRange());
assertEquals(new Range(4, 5), ((ColumnResizeEvent) this.listener.getReceivedEvents().get(1)).getColumnDiffs().iterator().next().getAfterPositionRange());
assertEquals(300, this.hideShowLayer.getWidth());
assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(1));
assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(4));
assertFalse(this.bodyDataLayer.isColumnPositionResizable(1));
assertFalse(this.bodyDataLayer.isColumnPositionResizable(4));
this.hideShowLayer.showColumnIndexes(1);
assertEquals(3, this.listener.getReceivedEvents().size());
assertEquals(new Range(1, 2), ((ColumnResizeEvent) this.listener.getReceivedEvents().get(2)).getColumnDiffs().iterator().next().getAfterPositionRange());
assertEquals(400, this.hideShowLayer.getWidth());
assertEquals(100, this.hideShowLayer.getColumnWidthByPosition(1));
assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(4));
assertTrue(this.bodyDataLayer.isColumnPositionResizable(1));
assertFalse(this.bodyDataLayer.isColumnPositionResizable(4));
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class RowHideShowLayerStructuralChangeEventTest method testHandleMultipleRowDeleteEvent.
@Test
public void testHandleMultipleRowDeleteEvent() {
// test start order: 0 1 2 3 4
assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
assertEquals(2, this.rowHideShowLayer.getRowIndexByPosition(2));
assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(3));
assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(4));
assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
assertEquals("two", this.rowHideShowLayer.getDataValueByPosition(0, 1));
assertEquals("three", this.rowHideShowLayer.getDataValueByPosition(0, 2));
assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 3));
assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 4));
// hide row at position 2: 0 1 3 4
List<Integer> rowsToHide = new ArrayList<Integer>();
rowsToHide.add(2);
this.rowHideShowLayer.hideRowPositions(rowsToHide);
assertEquals(4, this.rowHideShowLayer.getRowCount());
assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(2));
assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(3));
assertEquals(-1, this.rowHideShowLayer.getRowIndexByPosition(4));
assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
assertEquals("two", this.rowHideShowLayer.getDataValueByPosition(0, 1));
assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 2));
assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 3));
// delete rows in the middle
this.contents.remove(1);
this.contents.remove(1);
this.contents.remove(1);
this.underlyingLayer.fireLayerEvent(new RowDeleteEvent(this.underlyingLayer, new Range(1, 4)));
assertEquals(2, this.rowHideShowLayer.getRowCount());
assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
assertEquals(-1, this.rowHideShowLayer.getRowIndexByPosition(2));
assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 1));
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range 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);
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range 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);
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionIfListIsCleared.
@Test
public void shouldClearSelectionIfListIsCleared() {
this.selectionModel.addSelection(3, 4);
this.selectionModel.handleLayerEvent(new RowDeleteEvent(this.dataLayer, new Range(0, 9)));
Assert.assertTrue(this.selectionModel.isEmpty());
}
Aggregations