1 package org.simantics.diagram.profile;
3 import java.util.ArrayList;
4 import java.util.HashMap;
7 import java.util.concurrent.ConcurrentHashMap;
9 import org.simantics.db.Resource;
10 import org.simantics.scenegraph.profile.DataNodeMap;
11 import org.simantics.scenegraph.profile.EvaluationContext;
12 import org.simantics.scenegraph.profile.Style;
13 import org.simantics.scenegraph.profile.common.ObserverGroupListener;
14 import org.simantics.scl.runtime.tuple.Tuple;
15 import org.simantics.scl.runtime.tuple.Tuple3;
18 * @author Antti Villberg
21 public class StyleBaseData {
23 private static StyleBaseData INSTANCE;
25 protected final Map<Tuple, Object> values = new ConcurrentHashMap<>();
27 private Map<Tuple3, ObserverGroupListener> listeners = new HashMap<>();
29 private final Map<Style, List<Resource>> removals = new HashMap<>();
31 private StyleBaseData() {
34 public static StyleBaseData getInstance() {
35 if (INSTANCE == null) {
36 synchronized (StyleBaseData.class) {
37 if (INSTANCE == null) {
38 INSTANCE = new StyleBaseData();
45 public void removeValue(Tuple t) {
49 public void putValue(Tuple t, Object o) {
53 @SuppressWarnings("unchecked")
54 public <T> T getValue(Tuple t) {
55 return (T) values.get(t);
58 public synchronized void removeItem(Style s, Resource r) {
59 List<Resource> l = removals.get(s);
61 l = new ArrayList<>();
67 public void putListener(Tuple3 key, ObserverGroupListener listener) {
68 listeners.put(key, listener);
71 public void removeListener(Tuple3 key) {
72 listeners.remove(key);
75 public ObserverGroupListener getListener(Tuple3 key) {
76 return listeners.get(key);
79 public synchronized void applyRemovals(EvaluationContext evaluationContext, StyleBase<?> s) {
80 List<Resource> rs = removals.remove(s);
84 DataNodeMap map = evaluationContext.getConstant(ProfileKeys.NODE_MAP);
86 for (Resource item : rs) {
87 s.cleanupStyleForItem(evaluationContext, map, item);