Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ private CellConfigAttributes() {
* @since 1.4
*/
public static final ConfigAttribute<Integer> GRID_LINE_WIDTH = new ConfigAttribute<>();

/**
* Attribute for configuring whether the selection background color should
* be blended with the normal background color. If not set or set to
* <code>false</code>, the selection background color will fully override
* the normal background color.
*
* @since 2.7
*/
public static final ConfigAttribute<Boolean> BLEND_SELECTION_BACKGROUND = new ConfigAttribute<>();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2020 Original authors and others.
* Copyright (c) 2012, 2026 Original authors and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,13 +12,18 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.painter.cell;

import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
import org.eclipse.nebula.widgets.nattable.style.CellStyleProxy;
import org.eclipse.nebula.widgets.nattable.style.CellStyleUtil;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;

/**
Expand Down Expand Up @@ -55,9 +60,64 @@ public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry
super.paintCell(cell, gc, bounds, configRegistry);
}

/**
* Get the background color for the given cell.
*
* @param cell
* The {@link ILayerCell} to get the background color for.
* @param configRegistry
* The {@link ConfigRegistry} needed to retrieve the color.
* @return The background color.
*/
protected Color getBackgroundColour(ILayerCell cell, IConfigRegistry configRegistry) {
Boolean blend = configRegistry.getConfigAttribute(
CellConfigAttributes.BLEND_SELECTION_BACKGROUND,
DisplayMode.NORMAL,
cell.getConfigLabels());
// if blending is enabled and the cell is selected, return blended color
if (blend != null && blend
&& (cell.getDisplayMode() == DisplayMode.SELECT || cell.getDisplayMode() == DisplayMode.SELECT_HOVER)) {
return getBlendedBackgroundColour(cell, configRegistry);
}

return CellStyleUtil
.getCellStyle(cell, configRegistry)
.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
}

/**
* Get the blended background color for the given cell by blending the
* normal and the select background colors.
*
* @param cell
* The {@link ILayerCell} to get the blended background color
* for.
* @param configRegistry
* The {@link ConfigRegistry} needed to retrieve the colors.
* @return The blended background color.
*
* @since 2.7
*/
protected Color getBlendedBackgroundColour(ILayerCell cell, IConfigRegistry configRegistry) {
// get background color for DisplayMode.NORMAL
Color normalBackground =
new CellStyleProxy(
configRegistry,
DisplayMode.NORMAL,
cell.getConfigLabels())
.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);

// get background color for DisplayMode.SELECT or DisplayMode.SELECT_HOVER
Color selectBackground =
new CellStyleProxy(
configRegistry,
cell.getDisplayMode(),
cell.getConfigLabels())
.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);

// blend both colors
RGB background = normalBackground.getRGB();
background = GUIHelper.blend(background, selectBackground.getRGB());
return GUIHelper.getColor(background);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2020 Dirk Fauth and others.
* Copyright (c) 2017, 2026 Dirk Fauth and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -46,6 +46,7 @@
import org.eclipse.nebula.widgets.nattable.edit.editor.DateCellEditor;
import org.eclipse.nebula.widgets.nattable.examples.AbstractNatExample;
import org.eclipse.nebula.widgets.nattable.examples.runner.StandaloneNatExampleRunner;
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
Expand Down Expand Up @@ -245,6 +246,13 @@ class EditorConfiguration extends AbstractRegistryConfiguration {

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
// configure to blend the background color on selection
configRegistry.registerConfigAttribute(
CellConfigAttributes.BLEND_SELECTION_BACKGROUND,
Boolean.TRUE,
DisplayMode.NORMAL,
GridRegion.BODY);

configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITABLE_RULE,
IEditableRule.ALWAYS_EDITABLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2020 Dirk Fauth and others.
* Copyright (c) 2017, 2026 Dirk Fauth and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -44,6 +44,7 @@
import org.eclipse.nebula.widgets.nattable.edit.editor.DateCellEditor;
import org.eclipse.nebula.widgets.nattable.examples.AbstractNatExample;
import org.eclipse.nebula.widgets.nattable.examples.runner.StandaloneNatExampleRunner;
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
Expand Down Expand Up @@ -229,6 +230,13 @@ class EditorConfiguration extends AbstractRegistryConfiguration {

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
// configure to blend the background color on selection
configRegistry.registerConfigAttribute(
CellConfigAttributes.BLEND_SELECTION_BACKGROUND,
Boolean.TRUE,
DisplayMode.NORMAL,
GridRegion.BODY);

configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITABLE_RULE,
IEditableRule.ALWAYS_EDITABLE);
Expand Down