From 205112cdaf94fe5fea8c4ba026a1addf77c1b74f Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Mon, 27 Aug 2018 17:00:02 +0300 Subject: [PATCH] Generic property map for tree node structure Allows requests generating these nodes to mark them with any data to be used later in UI or elsewhere. gitlab #87 Change-Id: Ifa0e0d6cd9be342057ff150e721cebe50105197f (cherry picked from commit 6de980c76c96ea34c5824aca8916ddb61f64f2ff) --- .../org/simantics/modeling/requests/Node.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java index 4a43e0840..721c08e54 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java @@ -15,7 +15,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.simantics.db.Resource; import org.simantics.db.common.ResourceArray; @@ -44,6 +46,8 @@ public class Node implements Comparable { private PageDesc pageDesc; private String rvi; + private Map properties; + /** * @param parent * @param name @@ -121,6 +125,25 @@ public class Node implements Comparable { return pageDesc; } + /** + * @param key + * @param value + * @return this node for chained initialization + */ + public Node setProperty(String key, Object value) { + if (properties == null) + properties = new HashMap<>(); + properties.put(key, value); + return this; + } + + @SuppressWarnings("unchecked") + public T getProperty(String key) { + if (properties == null) + return null; + return (T) properties.get(key); + } + @Override public int compareTo(Node o) { int ret = name.compareTo(o.name); -- 2.47.1