use of org.eclipse.nebula.widgets.nattable.config.IEditableRule in project nebula.widgets.nattable by eclipse.
the class EditCellCommandHandler method doCommand.
@Override
public boolean doCommand(EditCellCommand command) {
ILayerCell cell = command.getCell();
Composite parent = command.getParent();
IConfigRegistry configRegistry = command.getConfigRegistry();
if (cell != null && configRegistry != null) {
// check if the cell is editable
IEditableRule rule = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, cell.getConfigLabels().getLabels());
if (rule.isEditable(cell, configRegistry)) {
EditController.editCell(cell, parent, cell.getDataValue(), configRegistry);
}
}
// successful or not
return true;
}
use of org.eclipse.nebula.widgets.nattable.config.IEditableRule in project nebula.widgets.nattable by eclipse.
the class EditUtils method isCellEditable.
/**
* Checks if the cell at the specified coordinates is editable or not.
* <p>
* Note: The coordinates need to be related to the given layer, otherwise
* the wrong cell will be used for the check.
* </p>
*
* @param layer
* The {@link ILayer} to check the cell coordinates against.
* @param configRegistry
* The {@link IConfigRegistry} needed to access the configured
* {@link IEditableRule}s.
* @param cellCoords
* The coordinates of the cell to check the editable state,
* related to the given {@link ILayer}
* @return <code>true</code> if the cell is editable, <code>false</code> if
* not
*/
public static boolean isCellEditable(ILayer layer, IConfigRegistry configRegistry, PositionCoordinate cellCoords) {
ILayerCell layerCell = layer.getCellByPosition(cellCoords.columnPosition, cellCoords.rowPosition);
if (layerCell != null) {
LabelStack labelStack = layerCell.getConfigLabels();
IEditableRule editableRule = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, labelStack.getLabels());
if (editableRule != null) {
return editableRule.isEditable(layerCell, configRegistry);
}
}
return false;
}
use of org.eclipse.nebula.widgets.nattable.config.IEditableRule in project nebula.widgets.nattable by eclipse.
the class EditUtils method allCellsEditable.
/**
* For every selected cell it is checked whether the cell is editable or
* not. If the collection of selected cells is <code>null</code> or empty,
* this method will also return <code>true</code>.
*
* @param selectedCells
* The collection of selected cells that should be checked.
* @param configRegistry
* The {@link IConfigRegistry} needed to access the configured
* {@link IEditableRule}s.
* @return <code>true</code> if all selected cells are editable,
* <code>false</code> if at least one cell is not editable.
*/
public static boolean allCellsEditable(Collection<ILayerCell> selectedCells, IConfigRegistry configRegistry) {
if (selectedCells != null) {
for (ILayerCell layerCell : selectedCells) {
LabelStack labelStack = layerCell.getConfigLabels();
IEditableRule editableRule = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, labelStack.getLabels());
if (editableRule == null || !editableRule.isEditable(layerCell, configRegistry)) {
return false;
}
}
}
return true;
}
use of org.eclipse.nebula.widgets.nattable.config.IEditableRule 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