From: Tuukka Lehtonen Date: Mon, 27 Aug 2018 14:00:02 +0000 (+0300) Subject: Generic property map for tree node structure X-Git-Tag: v1.43.0~136^2~401^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F35%2F2035%2F1;p=simantics%2Fplatform.git 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 --- 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);