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;
17 public class StyleBaseData {
19 private static StyleBaseData INSTANCE;
21 protected final Map<Tuple, Object> values = new ConcurrentHashMap<>();
23 private Map<Tuple3, ObserverGroupListener> listeners = new HashMap<>();
25 private final Map<Style, List<Resource>> removals = new HashMap<>();
27 private StyleBaseData() {
30 public static StyleBaseData getInstance() {
31 if (INSTANCE == null) {
32 synchronized (StyleBaseData.class) {
33 if (INSTANCE == null) {
34 INSTANCE = new StyleBaseData();
41 public void removeValue(Tuple t) {
45 public void putValue(Tuple t, Object o) {
49 public <T> T getValue(Tuple t) {
50 return (T) values.get(t);
53 public synchronized void removeItem(Style s, Resource r) {
54 List<Resource> l = removals.get(s);
56 l = new ArrayList<>();
62 public void putListener(Tuple3 key, ObserverGroupListener listener) {
63 listeners.put(key, listener);
66 public void removeListener(Tuple3 key) {
67 listeners.remove(key);
70 public ObserverGroupListener getListener(Tuple3 key) {
71 return listeners.get(key);
74 public synchronized void applyRemovals(EvaluationContext evaluationContext, StyleBase s) {
75 List<Resource> rs = removals.remove(s);
79 DataNodeMap map = evaluationContext.getConstant(ProfileKeys.NODE_MAP);
81 for (Resource item : rs) {
82 s.cleanupStyleForItem(evaluationContext, map, item);