use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class SelectionUtilsTest method testGetBottomRightSelectDifferentRows.
@Test
public void testGetBottomRightSelectDifferentRows() {
DataLayer dataLayer = new DataLayer(new DataProviderFixture(10, 10));
SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
// select cells for same columns in non consecutive rows
selectionLayer.selectRegion(2, 2, 3, 1);
selectionLayer.selectRegion(4, 4, 3, 1);
assertEquals(6, selectionLayer.getSelectedCells().size());
ILayerCell bottomRight = SelectionUtils.getBottomRightCellInSelection(selectionLayer);
assertNull(bottomRight);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class SelectionUtilsTest method testGetBottomRightSelectRegionDeselectTopEdge.
@Test
public void testGetBottomRightSelectRegionDeselectTopEdge() {
DataLayer dataLayer = new DataLayer(new DataProviderFixture(10, 10));
SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
// select region
selectionLayer.selectRegion(2, 2, 3, 3);
// deselect a cell
selectionLayer.clearSelection(2, 2);
ILayerCell bottomRight = SelectionUtils.getBottomRightCellInSelection(selectionLayer);
assertNull(bottomRight);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveCellSelectionOnRowDelete.
@Test
public void shouldRemoveCellSelectionOnRowDelete() {
assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getSelectedCells().size());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 1, true, false));
assertEquals(2, this.selectionLayer.getSelectedCells().size());
this.listFixture.remove(0);
// fire event to trigger structural refresh
this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(0, selectedCells.size());
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemovePartialSplitCellSelectionOnColumnDelete.
@Test
public void shouldRemovePartialSplitCellSelectionOnColumnDelete() {
assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getSelectedCells().size());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 5, 2, true, false));
Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(10, selectedCells.size());
boolean[] found = new boolean[5];
for (ILayerCell cell : selectedCells) {
if (cell.getColumnPosition() >= 5) {
fail("wrong column position selected");
} else {
found[cell.getColumnPosition()] = true;
}
}
for (int i = 0; i < found.length; i++) {
assertTrue("columnPosition " + i + " not selected", found[i]);
}
this.nattable.doCommand(new MultiColumnHideCommand(this.nattable, new int[] { 2, 4 }));
selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(6, selectedCells.size());
found = new boolean[3];
for (ILayerCell cell : selectedCells) {
if (cell.getColumnPosition() >= 3) {
fail("wrong column position selected");
} else {
found[cell.getColumnPosition()] = true;
}
}
for (int i = 0; i < found.length; i++) {
assertTrue("columnPosition " + i + " not selected", found[i]);
}
// insert again to verify the column position shift
this.nattable.doCommand(new ShowAllColumnsCommand());
selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(6, selectedCells.size());
found = new boolean[5];
for (ILayerCell cell : selectedCells) {
if (cell.getColumnPosition() >= 5) {
fail("wrong column position selected");
} else {
found[cell.getColumnPosition()] = true;
}
}
for (int i = 0; i < found.length; i++) {
if (i == 0 || i == 2 || i == 4) {
assertTrue("columnPosition " + i + " not selected", found[i]);
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class LayerAssert method assertLayerEquals.
@SuppressWarnings("boxing")
public static void assertLayerEquals(ILayer expectedLayer, ILayer actualLayer) {
// Horizontal features
// Columns
int expectedColumnCount = expectedLayer.getColumnCount();
int actualColumnCount = actualLayer.getColumnCount();
Assert.assertEquals("Column count", expectedColumnCount, actualColumnCount);
for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
int expectedColumnIndexByPosition = expectedLayer.getColumnIndexByPosition(columnPosition);
int actualColumnIndexByPosition = actualLayer.getColumnIndexByPosition(columnPosition);
Assert.assertEquals("Column index by position (" + columnPosition + ")", expectedColumnIndexByPosition, actualColumnIndexByPosition);
}
for (int localColumnPosition = 0; localColumnPosition < expectedColumnCount; localColumnPosition++) {
int expectedLocalToUnderlyingColumnPosition = expectedLayer.localToUnderlyingColumnPosition(localColumnPosition);
int actualLocalToUnderlyingColumnPosition = actualLayer.localToUnderlyingColumnPosition(localColumnPosition);
Assert.assertEquals("Local to underlying column position (" + localColumnPosition + ")", expectedLocalToUnderlyingColumnPosition, actualLocalToUnderlyingColumnPosition);
}
// for (int underlyingColumnPosition = 0; underlyingColumnPosition <
// expectedLayer.getColumnCount(); underlyingColumnPosition++) {
// Assert.assertEquals("Underlying to local column position (" +
// underlyingColumnPosition + ")",
// expectedLayer.underlyingToLocalColumnPosition(null,
// underlyingColumnPosition),
// actualLayer.underlyingToLocalColumnPosition(null,
// underlyingColumnPosition));
// }
// Width
int expectedWidth = expectedLayer.getWidth();
int actualWidth = actualLayer.getWidth();
Assert.assertEquals("Width", expectedWidth, actualWidth);
for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
int expectedColumnWidthByPosition = expectedLayer.getColumnWidthByPosition(columnPosition);
int actualColumnWidthByPosition = actualLayer.getColumnWidthByPosition(columnPosition);
Assert.assertEquals("Column width by position (" + columnPosition + ")", expectedColumnWidthByPosition, actualColumnWidthByPosition);
}
for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
boolean expectedColumnPositionResizable = expectedLayer.isColumnPositionResizable(columnPosition);
boolean actualColumnPositionResizable = actualLayer.isColumnPositionResizable(columnPosition);
Assert.assertEquals("Column position resizable (" + columnPosition + ")", expectedColumnPositionResizable, actualColumnPositionResizable);
}
for (int x = 0; x < expectedWidth; x++) {
int expectedColumnPositionByX = expectedLayer.getColumnPositionByX(x);
int actualColumnPositionByX = actualLayer.getColumnPositionByX(x);
Assert.assertEquals("Column position by X (" + x + ")", expectedColumnPositionByX, actualColumnPositionByX);
}
for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
int expectedStartXOfColumnPosition = expectedLayer.getStartXOfColumnPosition(columnPosition);
int actualStartXOfColumnPosition = actualLayer.getStartXOfColumnPosition(columnPosition);
Assert.assertEquals("Start X of column position (" + columnPosition + ")", expectedStartXOfColumnPosition, actualStartXOfColumnPosition);
}
// Vertical features
// Rows
int expectedRowCount = expectedLayer.getRowCount();
int actualRowCount = actualLayer.getRowCount();
Assert.assertEquals("Row count", expectedRowCount, actualRowCount);
for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
int expectedRowIndexByPosition = expectedLayer.getRowIndexByPosition(rowPosition);
int actualRowIndexByPosition = actualLayer.getRowIndexByPosition(rowPosition);
Assert.assertEquals("Row index by position (" + rowPosition + ")", expectedRowIndexByPosition, actualRowIndexByPosition);
}
for (int localRowPosition = 0; localRowPosition < expectedRowCount; localRowPosition++) {
int expectedLocalToUnderlyingRowPosition = expectedLayer.localToUnderlyingRowPosition(localRowPosition);
int actualLocalToUnderlyingRowPosition = actualLayer.localToUnderlyingRowPosition(localRowPosition);
Assert.assertEquals("Local to underlying row position (" + localRowPosition + ")", expectedLocalToUnderlyingRowPosition, actualLocalToUnderlyingRowPosition);
}
// for (int underlyingRowPosition = 0; underlyingRowPosition <
// expectedLayer.getRowCount(); underlyingRowPosition++) {
// Assert.assertEquals("Underlying to local row position (" +
// underlyingRowPosition + ")",
// expectedLayer.underlyingToLocalRowPosition(null,
// underlyingRowPosition),
// actualLayer.underlyingToLocalRowPosition(null,
// underlyingRowPosition));
// }
// Height
int expectedHeight = expectedLayer.getHeight();
int actualHeight = actualLayer.getHeight();
Assert.assertEquals("Height", expectedHeight, actualHeight);
for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
int expectedRowHeightByPosition = expectedLayer.getRowHeightByPosition(rowPosition);
int actualRowHeightByPosition = actualLayer.getRowHeightByPosition(rowPosition);
Assert.assertEquals("Row height by position (" + rowPosition + ")", expectedRowHeightByPosition, actualRowHeightByPosition);
}
for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
boolean expectedRowPositionResizable = expectedLayer.isRowPositionResizable(rowPosition);
boolean actualRowPositionResizable = actualLayer.isRowPositionResizable(rowPosition);
Assert.assertEquals("Row position resizable (" + rowPosition + ")", expectedRowPositionResizable, actualRowPositionResizable);
}
for (int y = 0; y < expectedHeight; y++) {
int expectedRowPositionByY = expectedLayer.getRowPositionByY(y);
int actualRowPositionByY = actualLayer.getRowPositionByY(y);
Assert.assertEquals("Row position by Y (" + y + ")", expectedRowPositionByY, actualRowPositionByY);
}
for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
int expectedStartYOfRowPosition = expectedLayer.getStartYOfRowPosition(rowPosition);
int actualStartYOfRowPosition = actualLayer.getStartYOfRowPosition(rowPosition);
Assert.assertEquals("Start Y of row position (" + rowPosition + ")", expectedStartYOfRowPosition, actualStartYOfRowPosition);
}
for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
ILayerCell expectedCellByPosition = expectedLayer.getCellByPosition(columnPosition, rowPosition);
ILayerCell actualCellByPosition = actualLayer.getCellByPosition(columnPosition, rowPosition);
Assert.assertEquals("Cell by position (" + columnPosition + ", " + rowPosition + ")", expectedCellByPosition, actualCellByPosition);
}
}
for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
Rectangle expectedBoundsByPosition = expectedLayer.getBoundsByPosition(columnPosition, rowPosition);
Rectangle actualBoundsByPosition = actualLayer.getBoundsByPosition(columnPosition, rowPosition);
Assert.assertEquals("Bounds by position (" + columnPosition + ", " + rowPosition + ")", expectedBoundsByPosition, actualBoundsByPosition);
}
}
for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
String expectedDisplayModeByPosition = expectedLayer.getDisplayModeByPosition(columnPosition, rowPosition);
String actualDisplayModeByPosition = actualLayer.getDisplayModeByPosition(columnPosition, rowPosition);
Assert.assertEquals("Display mode by position (" + columnPosition + ", " + rowPosition + ")", expectedDisplayModeByPosition, actualDisplayModeByPosition);
}
}
for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
LabelStack expectedConfigLabelsByPosition = expectedLayer.getConfigLabelsByPosition(columnPosition, rowPosition);
LabelStack actualConfigLabelsByPosition = actualLayer.getConfigLabelsByPosition(columnPosition, rowPosition);
Assert.assertEquals("Config labels by position (" + columnPosition + ", " + rowPosition + ")", expectedConfigLabelsByPosition, actualConfigLabelsByPosition);
}
}
for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
Object expectedDataValueByPosition = expectedLayer.getDataValueByPosition(columnPosition, rowPosition);
Object actualDataValueByPosition = actualLayer.getDataValueByPosition(columnPosition, rowPosition);
Assert.assertEquals("Data value by position (" + columnPosition + ", " + rowPosition + ")", expectedDataValueByPosition, actualDataValueByPosition);
}
}
}
Aggregations