]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Generic <String, Object> property map for tree node structure 35/2035/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 27 Aug 2018 14:00:02 +0000 (17:00 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 27 Aug 2018 14:00:02 +0000 (17:00 +0300)
Allows requests generating these nodes to mark them with any data to be
used later in UI or elsewhere.

gitlab #87

Change-Id: Ifa0e0d6cd9be342057ff150e721cebe50105197f

bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java

index 4a43e0840a907cecc3bfd0bfbc847113775e8161..721c08e549e9fd5bd22137e961c56ad8b94c954a 100644 (file)
@@ -15,7 +15,9 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 import org.simantics.db.Resource;
 import org.simantics.db.common.ResourceArray;
 
 import org.simantics.db.Resource;
 import org.simantics.db.common.ResourceArray;
@@ -44,6 +46,8 @@ public class Node implements Comparable<Node> {
     private PageDesc         pageDesc;
     private String           rvi;
 
     private PageDesc         pageDesc;
     private String           rvi;
 
+    private Map<String, Object> properties;
+
     /**
      * @param parent
      * @param name
     /**
      * @param parent
      * @param name
@@ -121,6 +125,25 @@ public class Node implements Comparable<Node> {
         return pageDesc;
     }
 
         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> 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);
     @Override
     public int compareTo(Node o) {
         int ret = name.compareTo(o.name);