Search in sources :

Example 81 with Range

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

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnDataUpdates.

@Test
public void shouldClearSelectionOnDataUpdates() throws Exception {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    GridLayerFixture gridLayer = new GridLayerFixture(bodyDataProvider);
    NatTable nattable = new NatTableFixture(gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    SelectionLayer selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
    // test SelectionModel updates
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
    nattable.doCommand(new SelectRowsCommand(nattable, 1, 1, false, false));
    assertEquals(1, selectionLayer.getFullySelectedRowPositions().length);
    // Ford motor at top and selected
    assertEquals("B Ford Motor", nattable.getDataValueByPosition(2, 1).toString());
    Range selection = selectionLayer.getSelectedRowPositions().iterator().next();
    assertEquals("B Ford Motor", listFixture.get(selection.start).getSecurity_description());
    listFixture.add(0, RowDataFixture.getInstance("Tata motors", "A"));
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(bodyDataLayer));
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 82 with Range

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

the class SelectionModelTest method getSelectedRowsForOverlapingSelections.

@Test
public void getSelectedRowsForOverlapingSelections() {
    this.model.addSelection(new Rectangle(10, 3, 5, 2));
    this.model.addSelection(new Rectangle(10, 4, 5, 10));
    this.model.addSelection(new Rectangle(10, 20, 5, 10));
    List<Range> selectedRows = ObjectUtils.asList(this.model.getSelectedRowPositions());
    assertEquals(2, selectedRows.size());
    assertTrue(selectedRows.contains(new Range(3, 14)));
    assertTrue(selectedRows.contains(new Range(20, 30)));
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 83 with Range

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

the class SelectionModelTest method getSelectedRowsForLargeNumberOfSelections.

@Test
public void getSelectedRowsForLargeNumberOfSelections() {
    this.model.addSelection(1, 10);
    this.model.addSelection(new Rectangle(5, 1, 1, 100));
    List<Range> selectedRows = ObjectUtils.asList(this.model.getSelectedRowPositions());
    assertEquals(1, selectedRows.size());
    assertTrue(selectedRows.contains(new Range(1, 100)));
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 84 with Range

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

the class PreserveSelectionModelTest method getSelectedRowPositions.

@Test
public void getSelectedRowPositions() {
    this.testee.addSelection(1, 1);
    this.testee.addSelection(0, 0);
    this.testee.addSelection(2, 2);
    HashSet<Range> actualSelectedRowPositions = new HashSet<Range>(this.testee.getSelectedRowPositions());
    HashSet<Range> expectedSelectedRowPositions = new HashSet<Range>();
    expectedSelectedRowPositions.add(new Range(0, 1));
    expectedSelectedRowPositions.add(new Range(1, 2));
    expectedSelectedRowPositions.add(new Range(2, 3));
    assertEquals(expectedSelectedRowPositions, actualSelectedRowPositions);
}
Also used : Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 85 with Range

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

the class RenameColumnIntegrationTest method shouldRenameColumnHeaderForReorderedColumn.

@Test
public void shouldRenameColumnHeaderForReorderedColumn() {
    String originalColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
    assertEquals("Column 2", originalColumnHeader);
    this.natTableFixture.doCommand(new ColumnReorderCommand(this.natTableFixture, 1, 5));
    originalColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
    assertEquals("Column 3", originalColumnHeader);
    this.natTableFixture.doCommand(new RenameColumnHeaderCommand(this.natTableFixture, 2, TEST_COLUMN_NAME));
    String renamedColumnHeader = this.natTableFixture.getDataValueByPosition(2, 0).toString();
    assertEquals(TEST_COLUMN_NAME, renamedColumnHeader);
    assertEquals(2, this.listener.getEventsCount());
    RenameColumnHeaderEvent event = (RenameColumnHeaderEvent) this.listener.getReceivedEvent(RenameColumnHeaderEvent.class);
    assertEquals(new Range(2, 3), event.getColumnPositionRanges().iterator().next());
}
Also used : RenameColumnHeaderEvent(org.eclipse.nebula.widgets.nattable.columnRename.event.RenameColumnHeaderEvent) RenameColumnHeaderCommand(org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) 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