use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class BoxingStyleTest method retrievedCellShouldBeConvertedUsingTheDisplayConverter.
@Test
public void retrievedCellShouldBeConvertedUsingTheDisplayConverter() throws Exception {
IConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DisplayConverter() {
@Override
public Object canonicalToDisplayValue(Object canonicalValue) {
if (canonicalValue == null) {
return null;
} else {
return canonicalValue.toString().equals("MN") ? "Manual" : "Automatic";
}
}
@Override
public Object displayToCanonicalValue(Object displayValue) {
return displayValue.toString().equals("Manual") ? new PricingTypeBean("MN") : new PricingTypeBean("AT");
}
});
NatTableFixture natTableFixture = new NatTableFixture(new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap()), false);
natTableFixture.setConfigRegistry(configRegistry);
natTableFixture.configure();
int columnIndex = RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PRICING_TYPE_PROP_NAME);
Object dataValue = natTableFixture.getDataValueByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
// Verify displayed value
ILayerCell cell = natTableFixture.getCellByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
TextPainter cellPainter = new TextPainter();
Assert.assertEquals("Automatic", cellPainter.convertDataType(cell, configRegistry));
// Assert that the display value is converted to an Object
Assert.assertTrue(dataValue instanceof PricingTypeBean);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemovePartialCellSelectionOnRowDelete.
@Test
public void shouldRemovePartialCellSelectionOnRowDelete() {
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));
this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 2, true, false));
this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 2, true, false));
assertEquals(4, 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(2, selectedCells.size());
// moved up
for (ILayerCell cell : selectedCells) {
assertEquals(0, cell.getRowPosition());
}
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldUpdateSelectionOnShiftSelect.
@Test
public void shouldUpdateSelectionOnShiftSelect() {
// integration test case for drag/shift selection
// not really a test case for structural changes but important for
// selection interactions
assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 3, 3, false, false));
assertEquals(1, this.selectionLayer.getSelectedCells().size());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 5, 5, true, false));
Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(9, selectedCells.size());
boolean[] found = new boolean[3];
for (ILayerCell cell : selectedCells) {
if (cell.getColumnPosition() >= 5 || cell.getColumnPosition() < 2) {
fail("wrong column position selected: " + cell.getColumnPosition());
} else {
found[cell.getColumnPosition() - 2] = true;
}
}
for (int i = 0; i < found.length; i++) {
assertTrue("columnPosition " + (i + 3) + " not selected", found[i]);
}
this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, true, false));
selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(9, selectedCells.size());
found = new boolean[3];
for (ILayerCell cell : selectedCells) {
if (cell.getColumnPosition() >= 3) {
fail("wrong column position selected: " + cell.getColumnPosition());
} else {
found[cell.getColumnPosition()] = true;
}
}
for (int i = 0; i < found.length; i++) {
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 PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveCellSelectionOnColumnDelete.
@Test
public void shouldRemoveCellSelectionOnColumnDelete() {
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, 1, 2, false, true));
assertEquals(2, this.selectionLayer.getSelectedCells().size());
this.nattable.doCommand(new ColumnHideCommand(this.nattable, 1));
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 shouldRemovePartialCellSelectionOnColumnDelete.
@Test
public void shouldRemovePartialCellSelectionOnColumnDelete() {
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, 1, 2, false, true));
this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 1, false, true));
this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 2, false, true));
assertEquals(4, this.selectionLayer.getSelectedCells().size());
this.nattable.doCommand(new ColumnHideCommand(this.nattable, 1));
Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(2, selectedCells.size());
// moved to the left
for (ILayerCell cell : selectedCells) {
assertEquals(0, cell.getColumnPosition());
}
// insert again to verify the column position shift
this.nattable.doCommand(new ShowAllColumnsCommand());
// the deselected cells shouldn't get automatically selected again
selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(2, selectedCells.size());
// moved to the right
for (ILayerCell cell : selectedCells) {
assertEquals(1, cell.getColumnPosition());
}
}
Aggregations