X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FExtendedGraphChildVariable.java;h=6f1d749660e378bf53c1e5fc41ed3c3ff0cf32c7;hb=1ecae6e1ad40507badb8807fb14bb67b4adf199c;hp=d55548b41a858c3379748127773e132e0cad64a8;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ExtendedGraphChildVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ExtendedGraphChildVariable.java index d55548b41..6f1d74966 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ExtendedGraphChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ExtendedGraphChildVariable.java @@ -1,122 +1,122 @@ -package org.simantics.db.layer0.variable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.procedure.single.SingleSetSyncListener; -import org.simantics.db.common.request.ParametrizedPrimitiveRead; -import org.simantics.db.common.request.ResourceRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.VariableFactoryRequest; -import org.simantics.db.procedure.Listener; -import org.simantics.db.service.QueryControl; -import org.simantics.operation.Layer0X; - -public class ExtendedGraphChildVariable extends StandardGraphChildVariable { - - private Map extension; - private List>> listeners = new ArrayList>>(); - - public ExtendedGraphChildVariable(Variable parent, Resource resource) throws DatabaseException { - super(parent, null, resource); - } - - Map getExtension(ReadGraph graph) throws DatabaseException { - - if(extension == null) { - - extension = new HashMap(); - - QueryControl qc = graph.getService(QueryControl.class); - - qc.getIndependentGraph(graph).syncRequest(new ResourceRead>(resource) { - - @Override - public Collection perform(ReadGraph graph) throws DatabaseException { - Layer0X L0X = Layer0X.getInstance(graph); - ArrayList result = new ArrayList(); - for(Resource r : graph.getObjects(resource, L0X.HasChildVariables)) { - VariableFactory factory = graph.adapt(r, VariableFactory.class); - assert(factory != null); - result.add(factory); - } - return result; - } - - }, new SingleSetSyncListener() { - - @Override - public void add(ReadGraph graph, final VariableFactory factory) throws DatabaseException { - - graph.syncRequest(new VariableFactoryRequest(ExtendedGraphChildVariable.this, factory), new SingleSetSyncListener() { - - @Override - public void add(ReadGraph graph, final Variable child) throws DatabaseException { - String name = child.getPropertyValue(graph, Variables.NAME); - extension.put(name, child); - } - - @Override - public void remove(ReadGraph graph, Variable child) throws DatabaseException { - String name = child.getPropertyValue(graph, Variables.NAME); - Variable exist = extension.get(name); - if(exist == child) extension.remove(name); - } - - public void finished(ReadGraph graph) throws DatabaseException { - Map clone = getClone(); - for(Listener> listener : listeners) listener.execute(clone); - } - - @Override - public boolean isDisposed() { - return false; - } - - }); - - } - - @Override - public boolean isDisposed() { - return false; - } - - }); - - } - - return graph.syncRequest(new ParametrizedPrimitiveRead>(this) { - - @Override - public void register(ReadGraph graph, Listener> procedure) { - - listeners.add(procedure); - procedure.execute(getClone()); - - } - - }); - - } - - private Map getClone() { - Map clone = new HashMap(); - clone.putAll(extension); - return clone; - } - - public Variable getPossibleSpecialChild(ReadGraph graph, String name) throws DatabaseException { - return getExtension(graph).get(name); - } - - public void collectSpecialChildren(ReadGraph graph, Collection children) throws DatabaseException { - children.addAll(getExtension(graph).values()); - } - -} +package org.simantics.db.layer0.variable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.procedure.single.SingleSetSyncListener; +import org.simantics.db.common.request.ParametrizedPrimitiveRead; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.VariableFactoryRequest; +import org.simantics.db.procedure.Listener; +import org.simantics.db.service.QueryControl; +import org.simantics.operation.Layer0X; + +public class ExtendedGraphChildVariable extends StandardGraphChildVariable { + + private Map extension; + private List>> listeners = new ArrayList>>(); + + public ExtendedGraphChildVariable(Variable parent, Resource resource) throws DatabaseException { + super(parent, null, resource); + } + + Map getExtension(ReadGraph graph) throws DatabaseException { + + if(extension == null) { + + extension = new HashMap(); + + QueryControl qc = graph.getService(QueryControl.class); + + qc.getIndependentGraph(graph).syncRequest(new ResourceRead>(resource) { + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + Layer0X L0X = Layer0X.getInstance(graph); + ArrayList result = new ArrayList(); + for(Resource r : graph.getObjects(resource, L0X.HasChildVariables)) { + VariableFactory factory = graph.adapt(r, VariableFactory.class); + assert(factory != null); + result.add(factory); + } + return result; + } + + }, new SingleSetSyncListener() { + + @Override + public void add(ReadGraph graph, final VariableFactory factory) throws DatabaseException { + + graph.syncRequest(new VariableFactoryRequest(ExtendedGraphChildVariable.this, factory), new SingleSetSyncListener() { + + @Override + public void add(ReadGraph graph, final Variable child) throws DatabaseException { + String name = child.getPropertyValue(graph, Variables.NAME); + extension.put(name, child); + } + + @Override + public void remove(ReadGraph graph, Variable child) throws DatabaseException { + String name = child.getPropertyValue(graph, Variables.NAME); + Variable exist = extension.get(name); + if(exist == child) extension.remove(name); + } + + public void finished(ReadGraph graph) throws DatabaseException { + Map clone = getClone(); + for(Listener> listener : listeners) listener.execute(clone); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + } + + return graph.syncRequest(new ParametrizedPrimitiveRead>(this) { + + @Override + public void register(ReadGraph graph, Listener> procedure) { + + listeners.add(procedure); + procedure.execute(getClone()); + + } + + }); + + } + + private Map getClone() { + Map clone = new HashMap(); + clone.putAll(extension); + return clone; + } + + public Variable getPossibleSpecialChild(ReadGraph graph, String name) throws DatabaseException { + return getExtension(graph).get(name); + } + + public void collectSpecialChildren(ReadGraph graph, Collection children) throws DatabaseException { + children.addAll(getExtension(graph).values()); + } + +}