Search in sources :

Example 61 with Range

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

the class DataChangeLayerTest method shouldUpdateOnMultiRowDelete.

@Test
public void shouldUpdateOnMultiRowDelete() {
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 1, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 3, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 5, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 7, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 9, "Lovejoy"));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 0));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 1));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 3));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 4));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 5));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 6));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 7));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 8));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 9));
    // delete all the Simpsons
    this.dataModel.remove(8);
    this.dataModel.remove(6);
    this.dataModel.remove(4);
    this.dataModel.remove(2);
    this.dataModel.remove(0);
    this.dataLayer.fireLayerEvent(new RowDeleteEvent(this.dataLayer, new Range(0, 1), new Range(2, 3), new Range(4, 5), new Range(6, 7), new Range(8, 9)));
    assertEquals(13, this.dataModel.size());
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 0));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 1));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 2));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 3));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 4));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 0));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 1));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 2));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 3));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 4));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 0).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 1).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 3).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 4).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 5).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 6).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 7).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 8).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 9).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 10).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 11).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 12).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertTrue("Row 0 is not dirty", this.dataChangeLayer.isRowDirty(0));
    assertTrue("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(1));
    assertTrue("Row 2 is not dirty", this.dataChangeLayer.isRowDirty(2));
    assertTrue("Row 3 is not dirty", this.dataChangeLayer.isRowDirty(3));
    assertTrue("Row 4 is not dirty", this.dataChangeLayer.isRowDirty(4));
    assertFalse("Row 5 is dirty", this.dataChangeLayer.isRowDirty(5));
    assertFalse("Row 6 is dirty", this.dataChangeLayer.isRowDirty(6));
    assertFalse("Row 7 is dirty", this.dataChangeLayer.isRowDirty(7));
    assertFalse("Row 8 is dirty", this.dataChangeLayer.isRowDirty(8));
    assertFalse("Row 9 is dirty", this.dataChangeLayer.isRowDirty(9));
    assertFalse("Row 10 is dirty", this.dataChangeLayer.isRowDirty(10));
    assertFalse("Row 11 is dirty", this.dataChangeLayer.isRowDirty(11));
    assertFalse("Row 12 is dirty", this.dataChangeLayer.isRowDirty(12));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 0));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 1));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 2));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 3));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 4));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 5));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(0, 2));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(2, 3));
    assertFalse("changed columns are empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertFalse("changed rows are empty", this.dataChangeLayer.changedRows.isEmpty());
    assertFalse("changes are empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 62 with Range

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

the class CopyDataCommandHandlerTest method checkBodyCells.

private void checkBodyCells(ILayerCell[][] copiedGrid) {
    int cellWithDataCounter = 0;
    int[] selectedColumns = this.selectionLayer.getSelectedColumnPositions();
    Set<Range> selectedRowRanges = this.selectionLayer.getSelectedRowPositions();
    Set<Integer> selectedRows = new HashSet<Integer>();
    for (Range range : selectedRowRanges) {
        selectedRows.addAll(range.getMembers());
    }
    Iterator<Integer> rowsIterator = selectedRows.iterator();
    // Row zero is for column headers
    for (int rowPosition = 1; rowPosition < copiedGrid.length; rowPosition++) {
        ILayerCell[] cells = copiedGrid[rowPosition];
        assertEquals(this.rowHeaderLayer.getDataValueByPosition(0, rowPosition - 1), cells[0].getDataValue());
        // Check body data
        int selectedRowPosition = rowsIterator.next().intValue();
        for (int columnPosition = 1; columnPosition < cells.length; columnPosition++) {
            final ILayerCell cell = cells[columnPosition];
            if (cell != null) {
                cellWithDataCounter++;
                assertEquals(this.selectionLayer.getDataValueByPosition(selectedColumns[columnPosition - 1], selectedRowPosition), cell.getDataValue());
            }
        }
    }
    assertEquals(this.selectionLayer.getSelectedCellPositions().length, cellWithDataCounter);
}
Also used : Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) HashSet(java.util.HashSet)

Example 63 with Range

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

the class ResizeEventDiffTest method testColumnDiffs.

@Test
public void testColumnDiffs() {
    Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
    Assert.assertNotNull(columnDiffs);
    Assert.assertEquals(1, columnDiffs.size());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.CHANGE, new Range(2, 3), new Range(2, 3)), columnDiffs.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 64 with Range

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

the class ShowColumnPositionsEventDiffTest 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> 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());
    this.event.convertToLocal(this.viewportLayer);
    columnDiffs = this.event.getColumnDiffs();
    Assert.assertNotNull(columnDiffs);
    Assert.assertEquals(3, columnDiffs.size());
    iterator = columnDiffs.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 65 with Range

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

the class HierarchicalTreeLayerTest method testCollapseMultipleExpandSingleToLevel.

// collapse second - collapse first - expand first to level 1 - second also
// expanded
@Test
public void testCollapseMultipleExpandSingleToLevel() {
    // collapse first node in second level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 2));
    // collapse first node in first level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(7, this.treeLayer.getRowCount());
    assertEquals(2, this.treeLayer.collapsedNodes.size());
    assertTrue(this.treeLayer.collapsedNodes.contains(new HierarchicalTreeNode(2, 0, null)));
    assertTrue(this.treeLayer.collapsedNodes.contains(new HierarchicalTreeNode(0, 0, null)));
    assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
    // expand first node in first level to level 1
    this.treeLayer.doCommand(new TreeExpandToLevelCommand(0, 1));
    assertEquals(11, this.treeLayer.getRowCount());
    assertTrue(this.treeLayer.collapsedNodes.isEmpty());
    assertTrue(this.treeLayer.getHiddenRowIndexes().isEmpty());
    assertEquals(3, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(ShowRowPositionsEvent.class));
    ShowRowPositionsEvent showEvent = (ShowRowPositionsEvent) this.layerListener.getReceivedEvent(ShowRowPositionsEvent.class);
    Collection<Range> rowPositionRanges = showEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 5), rowPositionRanges.iterator().next());
}
Also used : HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) TreeExpandToLevelCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandToLevelCommand) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent) 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