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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations