Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2015-01-20 10:12:19 +0000
committerTom Schindl2015-01-20 10:12:19 +0000
commit7bc062d04313fcee502785d1d259c41a5eda1e23 (patch)
tree69b09c6d66561963671c539a78b41df85fee7af2
parent3bafb0842b8b3c8a7d4a5adbdaea705e010eab4a (diff)
downloadorg.eclipse.efxclipse-7bc062d04313fcee502785d1d259c41a5eda1e23.tar.gz
org.eclipse.efxclipse-7bc062d04313fcee502785d1d259c41a5eda1e23.tar.xz
org.eclipse.efxclipse-7bc062d04313fcee502785d1d259c41a5eda1e23.zip
Bug 457911 - SimpleListCell should accept a function to extract the
graphic to display
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/list/SimpleListCell.java35
1 files changed, 33 insertions, 2 deletions
diff --git a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/list/SimpleListCell.java b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/list/SimpleListCell.java
index 88eee879a..a4735bc31 100644
--- a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/list/SimpleListCell.java
+++ b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/list/SimpleListCell.java
@@ -13,6 +13,7 @@ package org.eclipse.fx.ui.controls.list;
import java.util.List;
import java.util.function.Function;
+import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
@@ -29,7 +30,11 @@ import org.eclipse.jdt.annotation.Nullable;
* @since 1.2
*/
public class SimpleListCell<T> extends ListCell<T> {
+ @NonNull
private final Function<@Nullable T, @Nullable CharSequence> labelExtractor;
+ @NonNull
+ private final Function<@Nullable T, @Nullable Node> graphicExtractor;
+ @NonNull
private final Function<@Nullable T, @NonNull List<@NonNull String>> cssClassProvider;
/**
@@ -41,9 +46,27 @@ public class SimpleListCell<T> extends ListCell<T> {
* get the CSS classes for the given domain object
*/
public SimpleListCell(
- Function<@Nullable T, @Nullable CharSequence> labelExtractor,
- Function<@Nullable T, @NonNull List<@NonNull String>> cssClassProvider) {
+ @NonNull Function<@Nullable T, @Nullable CharSequence> labelExtractor,
+ @NonNull Function<@Nullable T, @NonNull List<@NonNull String>> cssClassProvider) {
+ this(labelExtractor, i -> null, cssClassProvider);
+ }
+
+ /**
+ * Create a new instance
+ *
+ * @param labelExtractor
+ * extract the text from the domain object
+ * @param graphicExtractor
+ * extracts the graphic from the domain object
+ * @param cssClassProvider
+ * get the CSS classes for the given domain object
+ */
+ public SimpleListCell(
+ @NonNull Function<@Nullable T, @Nullable CharSequence> labelExtractor,
+ @NonNull Function<@Nullable T, @Nullable Node> graphicExtractor,
+ @NonNull Function<@Nullable T, @NonNull List<@NonNull String>> cssClassProvider) {
this.labelExtractor = labelExtractor;
+ this.graphicExtractor = graphicExtractor;
this.cssClassProvider = cssClassProvider;
}
@@ -57,10 +80,18 @@ public class SimpleListCell<T> extends ListCell<T> {
} else if (t instanceof StyledString) {
StyledLabel l = new StyledLabel((StyledString) t);
l.getStyleClass().addAll(this.cssClassProvider.apply(item));
+ Node g = this.graphicExtractor.apply(item);
+ if( g != null ) {
+ l.setGraphic(g);
+ }
setGraphic(l);
} else {
Label l = new Label(t.toString());
l.getStyleClass().addAll(this.cssClassProvider.apply(item));
+ Node g = this.graphicExtractor.apply(item);
+ if( g != null ) {
+ l.setGraphic(g);
+ }
setGraphic(l);
}
} else {

Back to the top