/** * 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) { ILayerCell cell = 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)) { selectionLayer.doCommand( new UpdateDataCommand( selectionLayer, selectedPosition.columnPosition, selectedPosition.rowPosition, newValue)); } else { log.warn( "Tick update failed for cell at " + selectedPosition + " and value " + newValue //$NON-NLS-1$ //$NON-NLS-2$ + ". New value is not valid!"); //$NON-NLS-1$ } } catch (Exception e) { log.warn( "Tick update failed for cell at " + selectedPosition + " and value " + newValue //$NON-NLS-1$ //$NON-NLS-2$ + ". " + e.getLocalizedMessage()); // $NON-NLS-1$ } } }
@Override public boolean doCommand(TickUpdateCommand command) { PositionCoordinate[] selectedPositions = 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(selectionLayer, configRegistry) && EditUtils.isEditorSame(selectionLayer, configRegistry) && EditUtils.isConverterSame(selectionLayer, configRegistry)) { for (PositionCoordinate position : selectedPositions) { updateSingleCell(command, position); } } } else { // Tick update for single selected cell updateSingleCell(command, selectionLayer.getLastSelectedCellPosition()); } return true; }