Search in sources :

Example 6 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerTest method testUnderlyingToLocalColumnPositions.

@Test
public void testUnderlyingToLocalColumnPositions() {
    ArrayList<Range> positionRanges = new ArrayList<>();
    positionRanges.add(new Range(0, 2));
    positionRanges.add(new Range(2, 4));
    positionRanges.add(new Range(4, 6));
    Collection<Range> underlying = this.treeLayer.underlyingToLocalColumnPositions(this.selectionLayer, positionRanges);
    ArrayList<Range> list = new ArrayList<>(underlying);
    assertEquals(new Range(1, 3), list.get(0));
    assertEquals(new Range(4, 6), list.get(1));
    assertEquals(new Range(7, 9), list.get(2));
    this.treeLayer.setShowTreeLevelHeader(false);
    underlying = this.treeLayer.underlyingToLocalColumnPositions(this.selectionLayer, positionRanges);
    list = new ArrayList<>(underlying);
    assertEquals(new Range(0, 2), list.get(0));
    assertEquals(new Range(2, 4), list.get(1));
    assertEquals(new Range(4, 6), list.get(2));
}
Also used : ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 7 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class CompositeFreezeLayerHideShowTest method testFreezeDeleteRows.

@Test
public void testFreezeDeleteRows() {
    this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 3));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(4, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(3, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(1, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(4, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(80, this.viewportLayer.getMinimumOrigin().getY());
    // fake a multi row delete with no details on which rows are deleted
    // technically the same as collapsing or filtering a GlazedLists
    this.rowCount = 2;
    this.dataLayer.fireLayerEvent(new RowDeleteEvent(this.dataLayer, new ArrayList<Range>()));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(3, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(0, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(-1, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    // since the RowHideShowLayer is involved in the current composition
    // the number of rows is cached and we need to update this before reset
    this.rowCount = 5;
    this.dataLayer.fireLayerEvent(new RowInsertEvent(this.dataLayer, new Range(0, 2)));
    reset();
}
Also used : FreezeRowCommand(org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand) RowInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent) ArrayList(java.util.ArrayList) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 8 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class ColumnGroupHeaderLayerSelectionTest method shouldSelectAllCellsInGroup.

@Test
public void shouldSelectAllCellsInGroup() {
    this.gridLayer.doCommand(new ViewportSelectColumnGroupCommand(this.gridLayer, 2, 0, false, false));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(0));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(1));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(2));
    assertEquals(1, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(RowSelectionEvent.class));
    RowSelectionEvent event = (RowSelectionEvent) this.layerListener.getReceivedEvent(RowSelectionEvent.class);
    Collection<Range> rowPositionRanges = event.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(0, this.gridLayer.getBodyLayer().getSelectionLayer().getRowCount()), rowPositionRanges.iterator().next());
}
Also used : ViewportSelectColumnGroupCommand(org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommand) RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 9 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range 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 10 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayerTest method testHideShowDefaultSizedColumns.

// test hide with default only set columns
@Test
public void testHideShowDefaultSizedColumns() {
    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));
    assertEquals(2, this.hideShowLayer.getHiddenColumnIndexes().size());
    assertTrue("1 is not contained in hidden column indexes", this.hideShowLayer.getHiddenColumnIndexes().contains(Integer.valueOf(1)));
    assertTrue("4 is not contained in hidden column indexes", this.hideShowLayer.getHiddenColumnIndexes().contains(Integer.valueOf(4)));
    assertFalse(this.bodyDataLayer.isColumnPositionResizable(1));
    assertFalse(this.bodyDataLayer.isColumnPositionResizable(4));
    this.hideShowLayer.showAllColumns();
    assertEquals(4, this.listener.getReceivedEvents().size());
    assertEquals(new Range(1, 2), ((ColumnResizeEvent) this.listener.getReceivedEvents().get(2)).getColumnDiffs().iterator().next().getAfterPositionRange());
    assertEquals(new Range(4, 5), ((ColumnResizeEvent) this.listener.getReceivedEvents().get(3)).getColumnDiffs().iterator().next().getAfterPositionRange());
    assertEquals(500, this.hideShowLayer.getWidth());
    assertEquals(100, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(100, this.hideShowLayer.getColumnWidthByPosition(4));
    assertTrue("hidden column indexes are not empty", this.hideShowLayer.getHiddenColumnIndexes().isEmpty());
    assertTrue(this.bodyDataLayer.isColumnPositionResizable(1));
    assertTrue(this.bodyDataLayer.isColumnPositionResizable(4));
}
Also used : ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Aggregations

Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)115 Test (org.junit.Test)54 ArrayList (java.util.ArrayList)40 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)23 HashSet (java.util.HashSet)12 Rectangle (org.eclipse.swt.graphics.Rectangle)12 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)9 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)9 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)6 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)6 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)6 ColumnResizeEvent (org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)6 ShowRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)5 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)5 Point (org.eclipse.swt.graphics.Point)5 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4