Skip to content
Snippets Groups Projects
Commit 817ad778 authored by Andreas Bayha's avatar Andreas Bayha
Browse files

Kernel: Fixed dangling icons and background color in TreeTableViewers


- Icons are now removed, if a row does not contains an element anymore.

- Fixed a formating issue which prevented displaying background color on
some systems.

Issue-Ref: 4147
Issue-Url: af3#4147

Signed-off-by: default avatarAndreas Bayha <bayha@fortiss.org>
parent e0a7524c
No related branches found
No related tags found
1 merge request!148Kernel: Fixed dangling icons and background color in TreeTableViewers
Pipeline #31151 failed
......@@ -5,8 +5,8 @@ DynamicTextFieldTreeTableCell.java de24117e6f785b328f1ff62383626a0b4b54e8ff GREE
DynamicTreeContentProviderBase.java 91896b1fb5104d126544c44c1ff8c30f2a13a8d6 GREEN
DynamicTreeItem.java 7486071d20e896d6ca9a9101bf105caccf3656d0 GREEN
DynamicTreeItemBase.java d883066ecc181120302ca32f328538de7a45b093 GREEN
DynamicTreeTableUIProviderBase.java 735766bf3b046dc696eb3324378754ae6db5f4d0 GREEN
DynamicTreeTableViewer.java 9198fbd64af2c15829e63bafcab8095a173c6ff4 GREEN
DynamicTreeTableUIProviderBase.java d150a4c379cc41aab2a44a5f1643f4956332c8e3 YELLOW
DynamicTreeTableViewer.java cb289413d15159abbcccfea87d731738905b4b28 YELLOW
DynamicTreeUIProviderBase.java 82d3c051213f0147f4c67ad247a08696cee73110 GREEN
DynamicTreeViewer.java 545f1ca10b7b3cad171b294a4b447875da45c9ed GREEN
DynamicTreeViewerBase.java a2013538b62d86f6a09efdf2cd78babac2072484 GREEN
......
......@@ -77,7 +77,6 @@ public abstract class DynamicTreeTableUIProviderBase<T> {
/**
* Returns the style that shall be applied to the {@link TreeItem} of the given element. Return
*
* {@code null} for the default style.
*
* @param element
......@@ -87,6 +86,19 @@ public abstract class DynamicTreeTableUIProviderBase<T> {
* @return style of the element in the CSS format.
*/
public String getCellStyle(T element, int column) {
if(element == null) {
return null;
}
Color bgColor = getBackgroundColor(column, element);
if(bgColor != null) {
// Some transparency is necessary here, for correctly displaying the selection
// bar when selecting a row. WIth out transparency, it would not be visible on
// this cell.
double alpha = 0.5;
String colorStr = colorToRgbaString(bgColor, alpha);
return "-fx-background-color: " + colorStr + ";";
}
return null;
}
......@@ -294,25 +306,20 @@ public abstract class DynamicTreeTableUIProviderBase<T> {
T data = cell.getTreeTableRow().getItem();
if(data != null) {
Color bgColor = getBackgroundColor(columnIndex, data);
if(bgColor != null) {
// Some transparency is necessary here, for correctly displaying the selection
// bar when selecting a row. WIth out transparency, it would not be visible on
// this cell.
double alpha = 0.5;
String colorStr = colorToRgbaString(bgColor, alpha);
cell.setStyle("-fx-background-color: " + colorStr);
}
final Node icon = getIconNode(data, columnIndex);
cell.setGraphic(icon);
cell.setStyle(getCellStyle(data, columnIndex));
} else {
// reset icon for cases, in which a row was styled before, but became empty by now.
cell.setGraphic(null);
cell.setStyle(null);
}
}
}
/** Converts a {@link Color} object into a rgba format as used in css. */
private final static String colorToRgbaString(Color color, double alpha) {
return String.format("rgba(%d,%d,%d,%.1f)", (int)(color.getRed() * 255),
return String.format("rgba(%d,%d,%d,%s)", (int)(color.getRed() * 255),
(int)(color.getGreen() * 255), (int)(color.getBlue() * 255), alpha);
}
......@@ -511,11 +518,6 @@ public abstract class DynamicTreeTableUIProviderBase<T> {
// JFX-builtin handling is non-operation in Linux.
addContextMenuHandler(menu, data);
}
String style = getCellStyle(data, colIndex);
if(style != null) {
this.setStyle(style);
}
}
this.setContextMenu(menu);
......
......@@ -278,7 +278,8 @@ public final class DynamicTreeTableViewer<T> extends DynamicTreeViewerBase<T> {
/** {@inheritDoc} */
@Override
protected T getSelectedObject() {
T value = view.getSelectionModel().getSelectedItem().getValue();
final TreeItem<T> selectedItem = view.getSelectionModel().getSelectedItem();
T value = selectedItem != null ? selectedItem.getValue() : null;
return value;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment