use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionIntegrationTest method testColumnSelectionProcessing.
@SuppressWarnings("rawtypes")
@Test
public void testColumnSelectionProcessing() {
final List selectedObjects = new ArrayList();
// add a listener to see how many rows are selected
this.selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {
@SuppressWarnings("unchecked")
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
selectedObjects.addAll(selection.toList());
}
});
// first execute column selection with default configuration to see that
// all rows get selected
this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 1, 0, false, false));
assertEquals(10, selectedObjects.size());
// now clear set the flag for column selection processing to false and
// fire the event again
selectedObjects.clear();
this.selectionProvider.setProcessColumnSelection(false);
this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 1, 0, false, false));
assertEquals(0, selectedObjects.size());
// now select a cell to verify that other selections are still processed
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 1, false, false));
assertEquals(1, selectedObjects.size());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class MultiRowResizeCommandTest method testMultiResizeWithoutDownscaleOnSelection.
@Test
public void testMultiResizeWithoutDownscaleOnSelection() {
DummyGridLayerStack gridLayer = new DummyGridLayerStack();
IDpiConverter dpiConverter = new AbstractDpiConverter() {
@Override
protected void readDpiFromDisplay() {
this.dpi = 120;
}
};
gridLayer.doCommand(new ConfigureScalingCommand(dpiConverter, dpiConverter));
setClientAreaProvider(gridLayer);
// scaling enabled, therefore default height of 20 pixels is up scaled
// to 25
assertEquals(25, gridLayer.getRowHeightByPosition(2));
assertEquals(25, gridLayer.getRowHeightByPosition(3));
assertEquals(25, gridLayer.getRowHeightByPosition(4));
assertEquals(25, gridLayer.getRowHeightByPosition(5));
assertEquals(25, gridLayer.getRowHeightByPosition(6));
// select rows
gridLayer.doCommand(new SelectRowsCommand(gridLayer, 1, new int[] { 3, 4, 5 }, false, true, -1));
// resize one of the selected columns
RowResizeCommand columnResizeCommand = new RowResizeCommand(gridLayer, 3, 50);
gridLayer.doCommand(columnResizeCommand);
// command executed with down scaling disabled, therefore set height 50
// is up scaled to 63
assertEquals(25, gridLayer.getRowHeightByPosition(2));
assertEquals(63, gridLayer.getRowHeightByPosition(3));
assertEquals(63, gridLayer.getRowHeightByPosition(4));
assertEquals(63, gridLayer.getRowHeightByPosition(5));
assertEquals(25, gridLayer.getRowHeightByPosition(6));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand 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.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRetainRowSelectionOnMove.
@Test
public void shouldRetainRowSelectionOnMove() throws Exception {
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
// Ford motor at top and selected
assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("B Ford Motor", getSelected().getSecurity_description());
RowDataFixture ford = getSelected();
// move selected to the bottom
this.listFixture.remove(ford);
this.listFixture.add(ford);
// fire event to trigger structural refresh
this.bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(this.bodyDataLayer));
// Tata motors at top but Ford motors still selected
assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("B Ford Motor", getSelected().getSecurity_description());
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
assertEquals(this.listFixture.size() - 1, this.selectionLayer.getFullySelectedRowPositions()[0]);
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveSelectionOnDelete.
@Test
public void shouldRemoveSelectionOnDelete() {
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
// Ford motor at top and selected
assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("B Ford Motor", getSelected().getSecurity_description());
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());
// selection should be empty since the selected row was deleted
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
assertEquals(0, this.selectionLayer.getSelectedRowCount());
}
Aggregations