use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture in project nebula.widgets.nattable by eclipse.
the class MaxCellBoundsHelperTest method getPreferedRowHeights.
@Test
public void getPreferedRowHeights() throws Exception {
DataLayerFixture dataLayer = new DataLayerFixture(3, 2, 10, 10);
IDataProvider dataProvider = dataLayer.getDataProvider();
// Row 0
dataProvider.setDataValue(0, 0, "..");
dataProvider.setDataValue(1, 0, "...");
dataProvider.setDataValue(2, 0, "...");
// Row 1
dataProvider.setDataValue(0, 1, "Elephant");
dataProvider.setDataValue(1, 1, "Cat");
dataProvider.setDataValue(2, 1, "Rat");
AutoResizeRowCommandFixture command = new AutoResizeRowCommandFixture();
GCFactory gcFactory = command.getGCFactory();
IConfigRegistry registry = command.getConfigRegistry();
GC gc = gcFactory.createGC();
int row0MaxTextHeight = new TextPainter().getPreferredHeight(new CellFixture(".."), gc, registry);
int row1MaxTextHeight = new TextPainter().getPreferredHeight(new CellFixture("Elephant"), gc, registry);
gc.dispose();
int[] maxRowHeights = MaxCellBoundsHelper.getPreferredRowHeights(registry, gcFactory, dataLayer, new int[] { 0, 1 });
// Adjust heights
int row0AdjustedMaxHeight = dataLayer.getLayerPainter().adjustCellBounds(0, 0, new Rectangle(0, 0, 10, maxRowHeights[0])).height;
int row1AdjustedMaxHeight = dataLayer.getLayerPainter().adjustCellBounds(0, 1, new Rectangle(0, 0, 10, maxRowHeights[1])).height;
Assert.assertEquals(row0MaxTextHeight, row0AdjustedMaxHeight);
Assert.assertEquals(row1MaxTextHeight, row1AdjustedMaxHeight);
}
use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture in project nebula.widgets.nattable by eclipse.
the class MaxCellBoundsHelperTest method getPreferedColumnWidths.
@Test
public void getPreferedColumnWidths() throws Exception {
DataLayerFixture dataLayer = new DataLayerFixture(2, 3, 10, 10);
IDataProvider dataProvider = dataLayer.getDataProvider();
// Col 0
dataProvider.setDataValue(0, 0, "Long");
dataProvider.setDataValue(0, 1, "Longer");
dataProvider.setDataValue(0, 2, "Longest Text");
// Col 1
dataProvider.setDataValue(1, 0, "Elephant");
dataProvider.setDataValue(1, 1, "Cat");
dataProvider.setDataValue(1, 2, "Rat");
AutoResizeColumnCommandFixture command = new AutoResizeColumnCommandFixture();
GCFactory gcFactory = command.getGCFactory();
IConfigRegistry registry = command.getConfigRegistry();
GC gc = gcFactory.createGC();
int col0MaxTextWidth = new TextPainter().getPreferredWidth(new CellFixture("Longest Text"), gc, registry);
int col1MaxTextWidth = new TextPainter().getPreferredWidth(new CellFixture("Elephant"), gc, registry);
gc.dispose();
int[] maxColumnWidths = MaxCellBoundsHelper.getPreferredColumnWidths(registry, gcFactory, dataLayer, new int[] { 0, 1 });
// Adjust widths
int col0AdjustedMaxWidth = dataLayer.getLayerPainter().adjustCellBounds(0, 0, new Rectangle(0, 0, maxColumnWidths[0], 10)).width;
int col1AdjustedMaxWidth = dataLayer.getLayerPainter().adjustCellBounds(1, 0, new Rectangle(0, 0, maxColumnWidths[1], 10)).width;
Assert.assertEquals(col0MaxTextWidth, col0AdjustedMaxWidth);
Assert.assertEquals(col1MaxTextWidth, col1AdjustedMaxWidth);
}
use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture in project nebula.widgets.nattable by eclipse.
the class MultiCellEditDialogRunner method shouldOpenDefaultDialogWithoutIncrementDecrementBox.
public void shouldOpenDefaultDialogWithoutIncrementDecrementBox() {
CellFixture cell = new CellFixture();
cell.setBounds(new Rectangle(100, 100, 100, 20));
cell.setConfigLabels(new LabelStack("Cell_Edit"));
cell.setDataValue("123");
cell.setDisplayMode(DisplayMode.NORMAL);
TextCellEditor cellEditor = new TextCellEditor();
IDisplayConverter dataTypeConverter = new DisplayConverter() {
@Override
public Object canonicalToDisplayValue(Object canonicalValue) {
return canonicalValue;
}
@Override
public Object displayToCanonicalValue(Object displayValue) {
return displayValue;
}
};
final Character newValue = Character.valueOf('4');
IDataValidator dataValidator = new DataValidator() {
@Override
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
Assert.assertEquals(newValue, newValue);
return false;
}
};
Shell shell = new Shell(Display.getDefault(), SWT.H_SCROLL | SWT.V_SCROLL | SWT.RESIZE);
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, dataTypeConverter);
configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, dataValidator);
final CellEditDialog dialog = new CellEditDialog(shell, newValue, cell, cellEditor, configRegistry);
if (!this.interactive) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
dialog.close();
}
}
});
}
dialog.open();
}
Aggregations