use of org.eclipse.nebula.widgets.nattable.config.IConfigRegistry 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.config.IConfigRegistry in project nebula.widgets.nattable by eclipse.
the class EditTraversalStrategyUpDownTest method setUp.
@Before
public void setUp() {
// only use 10 columns to make the test cases easier
String[] propertyNames = Arrays.copyOfRange(RowDataListFixture.getPropertyNames(), 0, 10);
IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(RowDataListFixture.getList(10), new ReflectiveColumnPropertyAccessor<RowDataFixture>(propertyNames));
this.dataLayer = new DataLayer(bodyDataProvider, 20, 20);
this.selectionLayer = new SelectionLayer(this.dataLayer);
this.viewportLayer = new ViewportLayer(this.selectionLayer);
this.viewportLayer.setRegionName(GridRegion.BODY);
this.viewportLayer.addConfiguration(new DefaultEditBindings());
this.viewportLayer.addConfiguration(new DefaultEditConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor(true, true));
configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator());
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 9);
}
});
this.natTable = new NatTableFixture(this.viewportLayer);
this.natTable.enableEditingOnAllCells();
this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.EDIT, NOT_EDITABLE);
this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.OPEN_ADJACENT_EDITOR, Boolean.TRUE);
// register non editable rows
this.overrider = new RowOverrideLabelAccumulator<>(bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {
@Override
public Serializable getRowId(RowDataFixture rowObject) {
return rowObject.getSecurity_id();
}
});
this.overrider.registerRowOverrides(2, NOT_EDITABLE);
this.overrider.registerRowOverrides(5, NOT_EDITABLE);
this.overrider.registerRowOverrides(6, NOT_EDITABLE);
this.overrider.registerRowOverrides(7, NOT_EDITABLE);
this.overrider.registerRowOverrides(8, NOT_EDITABLE);
this.overrider.registerRowOverrides(9, NOT_EDITABLE);
AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
accumulator.add(this.overrider);
accumulator.add(new ColumnLabelAccumulator());
this.dataLayer.setConfigLabelAccumulator(accumulator);
}
use of org.eclipse.nebula.widgets.nattable.config.IConfigRegistry in project nebula.widgets.nattable by eclipse.
the class EditSelectionCommandHandler method doCommand.
@Override
public boolean doCommand(EditSelectionCommand command) {
Composite parent = command.getParent();
IConfigRegistry configRegistry = command.getConfigRegistry();
Character initialValue = command.getCharacter();
if (EditUtils.allCellsEditable(this.selectionLayer, configRegistry) && EditUtils.isEditorSame(this.selectionLayer, configRegistry) && EditUtils.isConverterSame(this.selectionLayer, configRegistry) && EditUtils.activateLastSelectedCellEditor(this.selectionLayer, configRegistry, command.isByTraversal())) {
// check how many cells are selected
Collection<ILayerCell> selectedCells = EditUtils.getSelectedCellsForEditing(this.selectionLayer);
if (selectedCells.size() == 1) {
// editing is triggered by key for a single cell
// we need to fire the InlineCellEditEvent here because we
// don't know the correct bounds of the cell to edit inline
// corresponding to the NatTable.
// On firing the event, a translation process is triggered,
// converting the information to the correct values
// needed for inline editing
ILayerCell cell = selectedCells.iterator().next();
this.selectionLayer.fireLayerEvent(new InlineCellEditEvent(this.selectionLayer, new PositionCoordinate(this.selectionLayer, cell.getOriginColumnPosition(), cell.getOriginRowPosition()), parent, configRegistry, (initialValue != null ? initialValue : cell.getDataValue())));
} else if (selectedCells.size() > 1) {
// determine the initial value
Object initialEditValue = initialValue;
if (initialValue == null && EditUtils.isValueSame(this.selectionLayer)) {
ILayerCell cell = selectedCells.iterator().next();
initialEditValue = this.selectionLayer.getDataValueByPosition(cell.getColumnPosition(), cell.getRowPosition());
}
EditController.editCells(selectedCells, parent, initialEditValue, configRegistry);
}
}
// successful or not
return true;
}
use of org.eclipse.nebula.widgets.nattable.config.IConfigRegistry in project nebula.widgets.nattable by eclipse.
the class ExportTableCommandHandler method doCommand.
@Override
public boolean doCommand(ExportTableCommand command) {
Shell shell = command.getShell();
IConfigRegistry configRegistry = command.getConfigRegistry();
new NatExporter(shell).exportSingleTable(this.layer, configRegistry);
return true;
}
use of org.eclipse.nebula.widgets.nattable.config.IConfigRegistry in project nebula.widgets.nattable by eclipse.
the class TickUpdateCommandHandler method doCommand.
@Override
public boolean doCommand(TickUpdateCommand command) {
PositionCoordinate[] selectedPositions = this.selectionLayer.getSelectedCellPositions();
IConfigRegistry configRegistry = command.getConfigRegistry();
// Tick update for multiple cells in selection
if (selectedPositions.length > 1) {
// Can all cells be updated ?
if (EditUtils.allCellsEditable(this.selectionLayer, configRegistry) && EditUtils.isEditorSame(this.selectionLayer, configRegistry) && EditUtils.isConverterSame(this.selectionLayer, configRegistry)) {
for (PositionCoordinate position : selectedPositions) {
updateSingleCell(command, position);
}
}
} else {
// Tick update for single selected cell
updateSingleCell(command, this.selectionLayer.getLastSelectedCellPosition());
}
return true;
}
Aggregations