Search in sources :

Example 76 with Range

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

the class ColumnReorderLayerStructuralChangeEventTest method testHandleMultipleColumnDeleteEvent.

@Test
public void testHandleMultipleColumnDeleteEvent() {
    // test start order: 0 1 2 3
    assertEquals(0, this.columnReorderLayer.getColumnIndexByPosition(0));
    assertEquals(1, this.columnReorderLayer.getColumnIndexByPosition(1));
    assertEquals(2, this.columnReorderLayer.getColumnIndexByPosition(2));
    assertEquals(3, this.columnReorderLayer.getColumnIndexByPosition(3));
    assertEquals("one", this.columnReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.columnReorderLayer.getDataValueByPosition(1, 0));
    assertEquals("three", this.columnReorderLayer.getDataValueByPosition(2, 0));
    assertEquals("four", this.columnReorderLayer.getDataValueByPosition(3, 0));
    // reorder to inverse order: 3 2 1 0
    this.columnReorderLayer.reorderColumnPosition(3, 0);
    this.columnReorderLayer.reorderColumnPosition(3, 1);
    this.columnReorderLayer.reorderColumnPosition(3, 2);
    assertEquals(3, this.columnReorderLayer.getColumnIndexByPosition(0));
    assertEquals(2, this.columnReorderLayer.getColumnIndexByPosition(1));
    assertEquals(1, this.columnReorderLayer.getColumnIndexByPosition(2));
    assertEquals(0, this.columnReorderLayer.getColumnIndexByPosition(3));
    assertEquals("four", this.columnReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("three", this.columnReorderLayer.getDataValueByPosition(1, 0));
    assertEquals("two", this.columnReorderLayer.getDataValueByPosition(2, 0));
    assertEquals("one", this.columnReorderLayer.getDataValueByPosition(3, 0));
    // delete columns in the middle
    this.contents.get(0).remove(1);
    this.contents.get(0).remove(1);
    this.underlyingLayer.fireLayerEvent(new ColumnDeleteEvent(this.underlyingLayer, new Range(1, 3)));
    assertEquals(2, this.columnReorderLayer.getColumnCount());
    assertEquals(1, this.columnReorderLayer.getColumnIndexByPosition(0));
    assertEquals(0, this.columnReorderLayer.getColumnIndexByPosition(1));
    assertEquals(-1, this.columnReorderLayer.getColumnIndexByPosition(2));
    assertEquals("four", this.columnReorderLayer.getDataValueByPosition(0, 0));
    assertEquals("one", this.columnReorderLayer.getDataValueByPosition(1, 0));
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 77 with Range

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldOnlyRemoveSelectionForDeleted.

@Test
public void shouldOnlyRemoveSelectionForDeleted() {
    assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, new int[] { 1, 2 }, true, false, 1));
    assertEquals(2, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(2, this.selectionLayer.getSelectedRowCount());
    // Ford motor at top and selected
    assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
    boolean fordFound = false;
    boolean alphabetFound = false;
    for (Range selection : this.selectionLayer.getSelectedRowPositions()) {
        for (int i = selection.start; i < selection.end; i++) {
            if ("B Ford Motor".equals(this.listFixture.get(i).getSecurity_description())) {
                fordFound = true;
            }
            if ("A Alphabet Co.".equals(this.listFixture.get(i).getSecurity_description())) {
                alphabetFound = true;
            }
        }
    }
    assertTrue("B Ford Motor not found", fordFound);
    assertTrue("A Alphabet Co. not found", alphabetFound);
    this.listFixture.remove(0);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
    // another value on top now
    assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("A Alphabet Co.", getSelected().getSecurity_description());
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 78 with Range

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

the class RangeTest method getMembers.

@SuppressWarnings("boxing")
@Test
public void getMembers() throws Exception {
    Set<Integer> members = new Range(3, 10).getMembers();
    assertEquals(7, members.size());
    HashSet<Integer> expectedMembes = new HashSet<Integer>(Arrays.asList(3, 4, 5, 6, 7, 8, 9));
    assertEquals(expectedMembes, members);
}
Also used : Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 79 with Range

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

the class RangeTest method range.

@Test
public void range() throws Exception {
    // 1 cell
    Range range = new Range(2, 3);
    assertTrue(range.contains(2));
    assertFalse(range.contains(3));
}
Also used : Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 80 with Range

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

the class SelectionLayerStructuralChangeEventHandlerTest method shouldClearSelectionIfListIsCleared.

@Test
public void shouldClearSelectionIfListIsCleared() {
    this.selectionModel.addSelection(3, 4);
    SelectionLayerStructuralChangeEventHandler handler = new SelectionLayerStructuralChangeEventHandler(this.selectionLayer);
    handler.handleLayerEvent(new RowDeleteEvent(this.dataLayer, new Range(0, 9)));
    Assert.assertTrue(this.selectionModel.isEmpty());
}
Also used : SelectionLayerStructuralChangeEventHandler(org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) 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