From eef3c57d3796d53644204baccfce0fee7bd88507 Mon Sep 17 00:00:00 2001
From: Alexander Diewald <diewald@fortiss.org>
Date: Thu, 10 Sep 2020 18:25:44 +0200
Subject: [PATCH] JFX UI Providers: Enable per Item Styles.

Issue-Ref: 3541
Issue-Url: https://af3-developer.fortiss.org/issues/3541
Signed-off-by: Alexander Diewald <diewald@fortiss.org>
---
 .../ui/javafx/control/treetableview/.ratings  |  2 +-
 .../treetableview/ModelElementTreeViewer.java |  5 +++++
 .../ui/javafx/control/treetableview/.ratings  |  6 +++---
 .../DynamicTreeTableUIProviderBase.java       | 19 +++++++++++++++++++
 .../DynamicTreeUIProviderBase.java            | 13 +++++++++++++
 .../treetableview/DynamicTreeViewer.java      |  2 ++
 6 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/javafx/control/treetableview/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/javafx/control/treetableview/.ratings
index 14fc759a5..3a83dfaa4 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/javafx/control/treetableview/.ratings
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/javafx/control/treetableview/.ratings
@@ -1,2 +1,2 @@
 DynamicTreeTableNameProvider.java 3ca45f24b94e97b02313e80b16ba8b370f541541 GREEN
-ModelElementTreeViewer.java 52cc8d0da50af8211de741eddc4d345b76e316fa GREEN
+ModelElementTreeViewer.java b541376d1b21d38dec80ae6dd5357fe289dcb643 YELLOW
diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/javafx/control/treetableview/ModelElementTreeViewer.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/javafx/control/treetableview/ModelElementTreeViewer.java
index 52cc8d0da..b541376d1 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/javafx/control/treetableview/ModelElementTreeViewer.java
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/javafx/control/treetableview/ModelElementTreeViewer.java
@@ -134,4 +134,9 @@ public class ModelElementTreeViewer<T extends INamedElement> {
 		DynamicTreeItemBase<T> item = dynTreeViewer.findItem(value);
 		dynTreeViewer.expandItem(item);
 	}
+
+	/** Returns the {@link DynamicTreeItemBase} of the given {@code value} if it exists. */
+	public DynamicTreeItemBase<T> findItem(T value) {
+		return dynTreeViewer.findItem(value);
+	}
 }
diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings
index e09955e05..0354ee32e 100644
--- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings
+++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings
@@ -4,10 +4,10 @@ DynamicStreamContentProvider.java f46e91400609cba54793dd240be0fe2aa0d5cced GREEN
 DynamicTreeContentProviderBase.java 0f6e0a6894752d135847608bc45efa504972bb28 GREEN
 DynamicTreeItem.java 7486071d20e896d6ca9a9101bf105caccf3656d0 GREEN
 DynamicTreeItemBase.java d883066ecc181120302ca32f328538de7a45b093 GREEN
-DynamicTreeTableUIProviderBase.java 94d94d2e6ca1944a0fa166bb49e040b278979686 GREEN
+DynamicTreeTableUIProviderBase.java 1078bd28a6bce5a5a2c60500f2aa1d8b1fdd341b YELLOW
 DynamicTreeTableViewer.java ea4ac3530edfa179cfce53bdd7e3a7ae80c435e4 GREEN
-DynamicTreeUIProviderBase.java e9b68607683de279d0cb8712a28dc131c5c33ece GREEN
-DynamicTreeViewer.java 8c20c0941bd299afce1cf237c8e29e21821c2631 GREEN
+DynamicTreeUIProviderBase.java 82d3c051213f0147f4c67ad247a08696cee73110 YELLOW
+DynamicTreeViewer.java e58d2cf7239e45f1b790ce9770a8a8649b1b5fb9 YELLOW
 DynamicTreeViewerBase.java a2013538b62d86f6a09efdf2cd78babac2072484 GREEN
 EmptyChildrenContentProvider.java 51b4468f9df8423abeea5ac6aa2f6cf99c2eb512 GREEN
 IDoubleClickHandler.java 447f7769dead9a106b3ea3139ef0da51eb0b9a89 GREEN
diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java
index 94d94d2e6..1078bd28a 100644
--- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java
+++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java
@@ -61,6 +61,20 @@ public abstract class DynamicTreeTableUIProviderBase<T> {
 		return null;
 	}
 
+	/**
+	 * Returns the style that shall be applied to the {@link TreeItem} of the given element. Return
+	 * {@code null} for the default style.
+	 * 
+	 * @param element
+	 *            to apply a style to.
+	 * @param column
+	 *            column of to apply the style (the element is a row in the table).
+	 * @return style of the element in the CSS format.
+	 */
+	public String getCellStyle(T element, int column) {
+		return null;
+	}
+
 	/**
 	 * @param element
 	 *            the element to be displayed in the current row
@@ -319,6 +333,11 @@ 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.setGraphic(icon);
 					this.setContextMenu(menu);
diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeUIProviderBase.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeUIProviderBase.java
index e9b686076..82d3c0512 100644
--- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeUIProviderBase.java
+++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeUIProviderBase.java
@@ -15,6 +15,7 @@ package org.fortiss.tooling.common.ui.javafx.control.treetableview;
 
 import javafx.scene.Node;
 import javafx.scene.control.ContextMenu;
+import javafx.scene.control.TreeItem;
 import javafx.scene.input.ClipboardContent;
 import javafx.scene.input.Dragboard;
 
@@ -41,6 +42,18 @@ public abstract class DynamicTreeUIProviderBase<T> {
 		return null;
 	}
 
+	/**
+	 * Returns the style that shall be applied to the {@link TreeItem} of the given element. Return
+	 * {@code null} for the default style.
+	 * 
+	 * @param element
+	 *            to apply a style to.
+	 * @return style of the element in the CSS format.
+	 */
+	public String getCellStyle(T element) {
+		return null;
+	}
+
 	/**
 	 * @param element
 	 *            the displayed element
diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeViewer.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeViewer.java
index 8c20c0941..e58d2cf72 100644
--- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeViewer.java
+++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeViewer.java
@@ -159,6 +159,8 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> {
 
 						this.setText(uiProvider.getLabel(item));
 						this.setGraphic(uiProvider.getIconNode(item));
+						this.setStyle(uiProvider.getCellStyle(item));
+
 						this.setOnDragDetected(evt -> {
 							dragDetected(evt, this, item);
 						});
-- 
GitLab