Search in sources :

Example 71 with Range

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

the class ColumnGroupHeaderLayerSelectionTest method shouldSelectAllCellsInGroupWithCtrl.

@Test
public void shouldSelectAllCellsInGroupWithCtrl() {
    this.gridLayer.doCommand(new ViewportSelectColumnGroupCommand(this.gridLayer, 2, 0, false, false));
    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());
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(0));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(1));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(2));
    this.gridLayer.doCommand(new ViewportSelectColumnGroupCommand(this.gridLayer, 6, 0, false, true));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(0));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(1));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(2));
    assertFalse(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(3));
    assertFalse(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(4));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(5));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(6));
}
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 72 with Range

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

the class ColumnGroupHeaderLayerSelectionTest method shouldSelectAllCellsInGroupsToRightWithShift.

@Test
public void shouldSelectAllCellsInGroupsToRightWithShift() {
    this.gridLayer.doCommand(new ViewportSelectColumnGroupCommand(this.gridLayer, 2, 0, false, false));
    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());
    this.layerListener.clearReceivedEvents();
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(0));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(1));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(2));
    assertFalse(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(3));
    assertFalse(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(4));
    assertFalse(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(5));
    assertFalse(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(6));
    this.gridLayer.doCommand(new ViewportSelectColumnGroupCommand(this.gridLayer, 6, 0, true, false));
    assertEquals(1, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(RowSelectionEvent.class));
    event = (RowSelectionEvent) this.layerListener.getReceivedEvent(RowSelectionEvent.class);
    rowPositionRanges = event.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(0, this.gridLayer.getBodyLayer().getSelectionLayer().getRowCount()), rowPositionRanges.iterator().next());
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(0));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(1));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(2));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(3));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(4));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(5));
    assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(6));
}
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 73 with Range

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

the class RowReorderLayerStructuralChangeEventTest method testHandleMultipleRowDeleteEvent.

@Test
public void testHandleMultipleRowDeleteEvent() {
    // test start order: 0 1 2 3
    assertEquals(0, this.rowReorderLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowReorderLayer.getRowIndexByPosition(1));
    assertEquals(2, this.rowReorderLayer.getRowIndexByPosition(2));
    assertEquals(3, this.rowReorderLayer.getRowIndexByPosition(3));
    assertEquals("one", this.rowReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.rowReorderLayer.getDataValueByPosition(0, 1));
    assertEquals("three", this.rowReorderLayer.getDataValueByPosition(0, 2));
    assertEquals("four", this.rowReorderLayer.getDataValueByPosition(0, 3));
    // reorder to inverse order: 3 2 1 0
    this.rowReorderLayer.reorderRowPosition(3, 0);
    this.rowReorderLayer.reorderRowPosition(3, 1);
    this.rowReorderLayer.reorderRowPosition(3, 2);
    assertEquals(3, this.rowReorderLayer.getRowIndexByPosition(0));
    assertEquals(2, this.rowReorderLayer.getRowIndexByPosition(1));
    assertEquals(1, this.rowReorderLayer.getRowIndexByPosition(2));
    assertEquals(0, this.rowReorderLayer.getRowIndexByPosition(3));
    assertEquals("four", this.rowReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("three", this.rowReorderLayer.getDataValueByPosition(0, 1));
    assertEquals("two", this.rowReorderLayer.getDataValueByPosition(0, 2));
    assertEquals("one", this.rowReorderLayer.getDataValueByPosition(0, 3));
    // delete rows in the middle
    this.contents.remove(1);
    this.contents.remove(1);
    this.underlyingLayer.fireLayerEvent(new RowDeleteEvent(this.underlyingLayer, new Range(1, 3)));
    assertEquals(2, this.rowReorderLayer.getRowCount());
    assertEquals(1, this.rowReorderLayer.getRowIndexByPosition(0));
    assertEquals(0, this.rowReorderLayer.getRowIndexByPosition(1));
    assertEquals(-1, this.rowReorderLayer.getRowIndexByPosition(2));
    assertEquals("four", this.rowReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("one", this.rowReorderLayer.getDataValueByPosition(0, 1));
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 74 with Range

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

the class MultiColumnReorderEventDiffTest method testReorderLeftConvertToLocal.

/**
 * + - - - before: 0 1 2 3 4 5 6 7 8 9 10 after: 0 1 7 8 9 2 3 4 5 6 10 + +
 * + -
 */
@Test
public void testReorderLeftConvertToLocal() {
    this.event = new ColumnReorderEvent(this.dataLayer, Arrays.asList(new Integer[] { 7, 8, 9 }), 2, true);
    this.event.convertToLocal(this.viewportLayer);
    Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
    Assert.assertNotNull(columnDiffs);
    Assert.assertEquals(2, columnDiffs.size());
    Iterator<StructuralDiff> iterator = columnDiffs.iterator();
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.DELETE, new Range(5, 8), new Range(8, 8)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(0, 0), new Range(0, 3)), iterator.next());
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 75 with Range

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

the class MultiColumnReorderEventDiffTest method testReorderRightConvertToLocal.

/**
 * - - - + before: 0 1 2 3 4 5 6 7 8 after: 0 1 5 6 2 3 4 7 8 - + + +
 */
@Test
public void testReorderRightConvertToLocal() {
    this.event = new ColumnReorderEvent(this.dataLayer, Arrays.asList(new Integer[] { 2, 3, 4 }), 7, true);
    this.event.convertToLocal(this.viewportLayer);
    Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
    Assert.assertNotNull(columnDiffs);
    Assert.assertEquals(2, columnDiffs.size());
    Iterator<StructuralDiff> iterator = columnDiffs.iterator();
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.DELETE, new Range(0, 3), new Range(0, 0)), iterator.next());
    Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(5, 5), new Range(2, 5)), iterator.next());
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent) 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