X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fprofile%2FStyleBaseData.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fprofile%2FStyleBaseData.java;h=5bd51b20bc476a5974e66cad1b092fc9cd0886aa;hb=6cc84e9fd4fb1bf95a20538aeca2cae9b8325968;hp=0000000000000000000000000000000000000000;hpb=6c70e409e03187c96b057aa5705d49800c6b8b07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBaseData.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBaseData.java new file mode 100644 index 000000000..5bd51b20b --- /dev/null +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBaseData.java @@ -0,0 +1,84 @@ +package org.simantics.diagram.profile; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.simantics.db.Resource; +import org.simantics.scenegraph.profile.DataNodeMap; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.Style; +import org.simantics.scenegraph.profile.common.ObserverGroupListener; +import org.simantics.scl.runtime.tuple.Tuple; +import org.simantics.scl.runtime.tuple.Tuple3; + +public class StyleBaseData { + + protected final Map values = new ConcurrentHashMap<>(); + + private Map listeners = new HashMap<>(); + + private final Map> removals = new HashMap<>(); + + private StyleBaseData() { + + } + + private static StyleBaseData INSTANCE; + + public static StyleBaseData getInstance() { + if(INSTANCE == null) { + INSTANCE = new StyleBaseData(); + } + return INSTANCE; + } + + public void removeValue(Tuple t) { + values.remove(t); + } + + public void putValue(Tuple t, Object o) { + values.put(t, o); + } + + public T getValue(Tuple t) { + return (T)values.get(t); + } + + public synchronized void removeItem(Style s, Resource r) { + List l = removals.get(s); + if(l == null) { + l = new ArrayList<>(); + removals.put(s, l); + } + l.add(r); + } + + public void putListener(Tuple3 key, ObserverGroupListener listener) { + listeners.put(key, listener); + } + + public void removeListener(Tuple3 key) { + listeners.remove(key); + } + + public ObserverGroupListener getListener(Tuple3 key) { + return listeners.get(key); + } + + public synchronized void applyRemovals(EvaluationContext evaluationContext, StyleBase s) { + + List rs = removals.remove(s); + if(rs == null) return; + + DataNodeMap map = evaluationContext.getConstant(ProfileKeys.NODE_MAP); + + for (Resource item : rs) { + s.cleanupStyleForItem(evaluationContext, map, item); + } + + } + +}