use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class EditIntegrationTest method testEditorRegisteredInActiveCellEditorRegistry.
/**
* Test case that ensures that the active editor is also available via the
* {@linkplain ActiveCellEditorRegistry}.
* <p>
* Ensures that the backward compatibility is not broken.
* </p>
*/
@Test
public void testEditorRegisteredInActiveCellEditorRegistry() {
this.natTable.enableEditingOnAllCells();
ILayerCell cell = this.natTable.getCellByPosition(4, 4);
this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
assertNotNull(this.natTable.getActiveCellEditor());
assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor());
assertEquals(this.natTable.getActiveCellEditor(), ActiveCellEditorRegistry.getActiveCellEditor());
// Close the editor again
this.natTable.getActiveCellEditor().getEditorControl().notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.CR));
assertNull(this.natTable.getActiveCellEditor());
assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.
the class BlinkLayer method getConfigLabelsByPosition.
@Override
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) {
if (!this.blinkingEnabled) {
return getUnderlyingLayer().getConfigLabelsByPosition(columnPosition, rowPosition);
}
ILayerCell cell = this.underlyingLayer.getCellByPosition(columnPosition, rowPosition);
int columnIndex = getUnderlyingLayer().getColumnIndexByPosition(columnPosition);
String columnProperty = this.columnPropertyResolver.getColumnProperty(columnIndex);
int rowIndex = getUnderlyingLayer().getRowIndexByPosition(rowPosition);
String rowId = this.rowIdAccessor.getRowId(this.rowDataProvider.getRowObject(rowIndex)).toString();
String key = this.updateEventsCache.getKey(columnProperty, rowId);
LabelStack underlyingLabelStack = getUnderlyingLayer().getConfigLabelsByPosition(columnPosition, rowPosition);
// Cell has been updated
if (this.updateEventsCache.isUpdated(key)) {
PropertyUpdateEvent<T> event = this.updateEventsCache.getEvent(key);
// Old update in middle of a blink - cancel it
ScheduledFuture<?> scheduledFuture = this.blinkingTasks.remove(key);
this.blinkingUpdates.remove(key);
if (scheduledFuture != null) {
scheduledFuture.cancel(true);
}
LabelStack blinkingConfigTypes = resolveConfigTypes(cell, event.getOldValue(), event.getNewValue());
// start blinking cell
if (blinkingConfigTypes != null) {
Runnable stopBlinkTask = getStopBlinkTask(key, this);
this.blinkingUpdates.put(key, event);
this.updateEventsCache.remove(key);
this.blinkingTasks.put(key, this.scheduler.schedule(stopBlinkTask, this.blinkDurationInMilis, TimeUnit.MILLISECONDS));
return blinkingConfigTypes;
} else {
return underlyingLabelStack;
}
}
// Previous blink timer is still running
if (this.blinkingUpdates.containsKey(key)) {
PropertyUpdateEvent<T> event = this.blinkingUpdates.get(key);
return resolveConfigTypes(cell, event.getOldValue(), event.getNewValue());
}
return underlyingLabelStack;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell 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.layer.cell.ILayerCell 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.layer.cell.ILayerCell 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;
}
Aggregations