Search in sources :

Example 21 with ILayerCell

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());
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Example 22 with ILayerCell

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;
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 23 with ILayerCell

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IEditableRule(org.eclipse.nebula.widgets.nattable.config.IEditableRule) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 24 with ILayerCell

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;
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) IEditableRule(org.eclipse.nebula.widgets.nattable.config.IEditableRule) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 25 with ILayerCell

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;
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) IEditableRule(org.eclipse.nebula.widgets.nattable.config.IEditableRule) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Aggregations

ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)118 Test (org.junit.Test)45 Rectangle (org.eclipse.swt.graphics.Rectangle)23 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)14 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)14 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)11 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)10 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)10 Color (org.eclipse.swt.graphics.Color)10 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)9 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)9 DataProviderFixture (org.eclipse.nebula.widgets.nattable.test.fixture.data.DataProviderFixture)9 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)8 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)5 Point (org.eclipse.swt.graphics.Point)5 HashSet (java.util.HashSet)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)4 IEditableRule (org.eclipse.nebula.widgets.nattable.config.IEditableRule)4 ICellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)4