use of org.eclipse.nebula.widgets.nattable.data.validate.IDataValidator 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();
}
use of org.eclipse.nebula.widgets.nattable.data.validate.IDataValidator in project nebula.widgets.nattable by eclipse.
the class TickUpdateCommandHandler method updateSingleCell.
/**
* Will calculate the new value after tick update processing for the cell at
* the given coordinates, trying to update the value represented by that
* cell. The update will only be processed if the new value is valid.
*
* @param command
* The command to process
* @param selectedPosition
* The coordinates of the cell on which the tick update should be
* executed
*/
private void updateSingleCell(TickUpdateCommand command, PositionCoordinate selectedPosition) {
if (selectedPosition != null) {
ILayerCell cell = this.selectionLayer.getCellByPosition(selectedPosition.columnPosition, selectedPosition.rowPosition);
IConfigRegistry configRegistry = command.getConfigRegistry();
IEditableRule editableRule = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, cell.getConfigLabels().getLabels());
IDataValidator validator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, cell.getConfigLabels().getLabels());
if (editableRule.isEditable(cell, configRegistry)) {
// process the tick update
Object newValue = getNewCellValue(command, cell);
// validate the value
try {
if (validator == null || validator.validate(cell, configRegistry, newValue)) {
this.selectionLayer.doCommand(new UpdateDataCommand(this.selectionLayer, selectedPosition.columnPosition, selectedPosition.rowPosition, newValue));
} else {
LOG.warn(// $NON-NLS-1$ //$NON-NLS-2$
"Tick update failed for cell at " + selectedPosition + " and value " + newValue + // $NON-NLS-1$
". New value is not valid!");
}
} catch (Exception e) {
LOG.warn(// $NON-NLS-1$ //$NON-NLS-2$
"Tick update failed for cell at " + selectedPosition + " and value " + newValue + ". " + // $NON-NLS-1$
e.getLocalizedMessage());
}
}
}
}
Aggregations