提交 02e70614 编写于 作者: S serge-rider

#5951 Spreadsheet columns coloring

上级 7a88b8b1
......@@ -313,8 +313,6 @@ class ColorSettingsDialog extends BaseDialog {
}
bgColorSelector2.setEnabled(isRange);
fgColorSelector2.setEnabled(isRange);
singleColumnCheck.setEnabled(false);
}
private IValueEditor createValueEditor(Composite panel, int index) {
......
......@@ -618,14 +618,14 @@ public class ResultSetModel {
private void updateRowColors(boolean reset, List<ResultSetRow> rows) {
if (colorMapping.isEmpty() || reset) {
for (ResultSetRow row : rows) {
row.foreground = null;
row.background = null;
row.colorInfo = null;
}
}
if (!colorMapping.isEmpty()) {
for (Map.Entry<DBDAttributeBinding, List<AttributeColorSettings>> entry : colorMapping.entrySet()) {
for (ResultSetRow row : rows) {
for (AttributeColorSettings acs : entry.getValue()) {
Color background = null, foreground = null;
if (acs.rangeCheck) {
if (acs.attributeValues != null && acs.attributeValues.length > 1) {
double minValue = ResultSetUtils.makeNumericValue(acs.attributeValues[0]);
......@@ -635,18 +635,47 @@ public class ResultSetModel {
final Object cellValue = getCellValue(binding, row);
double value = ResultSetUtils.makeNumericValue(cellValue);
if (value >= minValue && value <= maxValue) {
foreground = acs.colorForeground;
RGB rowRGB = ResultSetUtils.makeGradientValue(acs.colorBackground.getRGB(), acs.colorBackground2.getRGB(), minValue, maxValue, value);
row.background = UIUtils.getSharedColor(rowRGB);
background = UIUtils.getSharedColor(rowRGB);
}
}
}
} else {
final DBDAttributeBinding binding = entry.getKey();
final Object cellValue = getCellValue(binding, row);
if (acs.evaluate(cellValue)) {
row.foreground = acs.colorForeground;
row.background = acs.colorBackground;
foreground = acs.colorForeground;
background = acs.colorBackground;
}
}
if (foreground != null || background != null) {
ResultSetRow.ColorInfo colorInfo = row.colorInfo;
if (colorInfo == null) {
colorInfo = new ResultSetRow.ColorInfo();
row.colorInfo = colorInfo;
}
if (!acs.singleColumn) {
colorInfo.rowForeground = acs.colorForeground;
colorInfo.rowBackground = acs.colorBackground;
} else {
// Single column color
if (foreground != null) {
Color[] cellFgColors = colorInfo.cellFgColors;
if (cellFgColors == null) {
cellFgColors = new Color[attributes.length];
colorInfo.cellFgColors = cellFgColors;
}
cellFgColors[entry.getKey().getOrdinalPosition()] = foreground;
}
if (background != null) {
Color[] cellBgColors = colorInfo.cellBgColors;
if (cellBgColors == null) {
cellBgColors = new Color[attributes.length];
colorInfo.cellBgColors = cellBgColors;
}
cellBgColors[entry.getKey().getOrdinalPosition()] = background;
}
}
}
}
......
......@@ -37,6 +37,17 @@ public class ResultSetRow {
public static final byte STATE_ADDED = 2;
public static final byte STATE_REMOVED = 3;
public static class ColorInfo {
@Nullable
public Color rowForeground;
@Nullable
public Color rowBackground;
@Nullable
public Color[] cellFgColors;
@Nullable
public Color[] cellBgColors;
}
// Physical row number
private int rowNumber;
// Row number in grid
......@@ -50,7 +61,8 @@ public class ResultSetRow {
private byte state;
@Nullable
public Map<DBDValue, CollectionElementData> collections;
public Color foreground, background;
@Nullable
public ColorInfo colorInfo;
ResultSetRow(int rowNumber, @NotNull Object[] values) {
this.rowNumber = rowNumber;
......
......@@ -2226,6 +2226,7 @@ public class ResultSetViewer extends Viewer
viewMenu.add(customizeAction);
}
viewMenu.add(new TransformComplexTypesToggleAction());
viewMenu.add(new Separator());
viewMenu.add(new ColorizeDataTypesToggleAction());
{
if (valueController != null) {
......@@ -2238,8 +2239,8 @@ public class ResultSetViewer extends Viewer
if (getModel().getSingleSource() != null && getModel().hasColorMapping(getModel().getSingleSource())) {
viewMenu.add(new ResetAllColorAction());
}
viewMenu.add(new Separator());
}
viewMenu.add(new Separator());
viewMenu.add(new VirtualEntityEditAction());
viewMenu.add(new Action(ResultSetMessages.controls_resultset_viewer_action_data_formats) {
@Override
......
......@@ -1625,8 +1625,16 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
return foregroundSelected;
}
ResultSetRow row = (ResultSetRow) (!controller.isRecordMode() ? rowElement : colElement);
if (row.foreground != null) {
return row.foreground;
if (row.colorInfo != null) {
if (row.colorInfo.cellFgColors != null) {
Color cellFG = row.colorInfo.cellFgColors[((DBDAttributeBinding) (rowElement instanceof DBDAttributeBinding ? rowElement : colElement)).getOrdinalPosition()];
if (cellFG != null) {
return cellFG;
}
}
if (row.colorInfo.rowForeground != null) {
return row.colorInfo.rowForeground;
}
}
Object value = getCellValue(colElement, rowElement, false);
......@@ -1687,8 +1695,16 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
return backgroundModified;
}
if (row.background != null) {
return row.background;
if (row.colorInfo != null) {
if (row.colorInfo.cellBgColors != null) {
Color cellBG = row.colorInfo.cellBgColors[((DBDAttributeBinding) (rowElement instanceof DBDAttributeBinding ? rowElement : colElement)).getOrdinalPosition()];
if (cellBG != null) {
return cellBG;
}
}
if (row.colorInfo.rowBackground != null) {
return row.colorInfo.rowBackground;
}
}
Object value = controller.getModel().getCellValue(attribute, row);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册