Search in sources :

Example 16 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class CellLabelMouseEventMatcherTest method shouldMatchCellsWithCustomLabels.

@Test
public void shouldMatchCellsWithCustomLabels() throws Exception {
    CellLabelMouseEventMatcher matcher = new CellLabelMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON, TEST_LABEL);
    boolean match = matcher.matches(this.natTableFixture, new MouseEvent(SWTUtils.getLeftClickEvent(100, 100, 0, this.natTableFixture)), new LabelStack(GridRegion.BODY));
    Assert.assertTrue(match);
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) CellLabelMouseEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.CellLabelMouseEventMatcher) Test(org.junit.Test)

Example 17 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack 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 18 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class BlinkLayer method resolveConfigTypes.

/**
 * Checks if there is a {@link IBlinkingCellResolver} registered in the
 * {@link ConfigRegistry} and use it to add config type labels associated
 * with a blinking cell to the label stack.
 *
 * @param cell
 *            the cell
 * @param oldValue
 *            the old value
 * @param newValue
 *            the new value
 * @return a LabelStack containing resolved config types associated with the
 *         cell
 */
public LabelStack resolveConfigTypes(ILayerCell cell, Object oldValue, Object newValue) {
    // Acquire default config types for the coordinate. Use these to search
    // for the associated resolver.
    LabelStack underlyingLabelStack = this.underlyingLayer.getConfigLabelsByPosition(cell.getColumnIndex(), cell.getRowIndex());
    IBlinkingCellResolver resolver = this.configRegistry.getConfigAttribute(BlinkConfigAttributes.BLINK_RESOLVER, DisplayMode.NORMAL, underlyingLabelStack.getLabels());
    String[] blinkConfigTypes = null;
    if (resolver != null) {
        blinkConfigTypes = resolver.resolve(cell, this.configRegistry, oldValue, newValue);
    }
    if (blinkConfigTypes != null && blinkConfigTypes.length > 0) {
        for (String configType : blinkConfigTypes) {
            underlyingLabelStack.addLabelOnTop(configType);
        }
    }
    return underlyingLabelStack;
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack)

Example 19 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack 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 20 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack 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

LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)80 Test (org.junit.Test)30 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)14 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)13 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)11 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)10 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)10 HashMap (java.util.HashMap)9 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)9 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)9 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 Composite (org.eclipse.swt.widgets.Composite)9 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)8 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)8 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)8 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)8 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)8