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));
}
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());
}
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);
}
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));
}
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());
}
Aggregations