X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph.profile%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fprofile%2Fimpl%2FProfileActivationListener.java;fp=bundles%2Forg.simantics.scenegraph.profile%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fprofile%2Fimpl%2FProfileActivationListener.java;h=d43e8db741323f81f486eab8d83501aabf36b9bb;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/impl/ProfileActivationListener.java b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/impl/ProfileActivationListener.java new file mode 100644 index 000000000..d43e8db74 --- /dev/null +++ b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/impl/ProfileActivationListener.java @@ -0,0 +1,80 @@ +package org.simantics.scenegraph.profile.impl; + +import java.util.HashSet; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.procedure.single.SingleSetSyncListener; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.exception.DatabaseException; +import org.simantics.scenegraph.profile.ProfileEntry; +import org.simantics.scenegraph.profile.common.ProfileObserver; +import org.simantics.utils.datastructures.disposable.IDisposable; + +public class ProfileActivationListener extends SingleSetSyncListener { + + final Resource runtime; + final ProfileObserver observer; + final IDisposable disposable; + final Set active = new HashSet(); + + public ProfileActivationListener(Resource runtime, ProfileObserver observer, IDisposable disposable) { + this.runtime = runtime; + this.observer = observer; + this.disposable = disposable; + } + + @Override + public boolean start(ReadGraph graph) throws DatabaseException { + + if (observer == null || observer.isDisposed()) + return false; + if (runtime == null) + return false; + + return true; + + } + + @Override + public void add(ReadGraph graph, ProfileEntry item) throws DatabaseException { + observer.update(); + item.activate(graph, runtime, observer); + active.add(item); + if (DebugPolicy.DEBUG_PROFILE_STYLE_ACTIVATION) + System.out.println("ACTIVATED PROFILE ENTRY: " + item); + } + + @Override + public void remove(ReadGraph graph, ProfileEntry item) throws DatabaseException { + observer.update(); + active.remove(item); + if (DebugPolicy.DEBUG_PROFILE_STYLE_ACTIVATION) + System.out.println("DE-ACTIVATING PROFILE ENTRY: " + item); + item.deactivate(runtime, observer); + } + + @Override + public void finished(ReadGraph graph) throws DatabaseException { +// observer.update(); + } + + @Override + public void exception(ReadGraph graph, Throwable t) { + Logger.defaultLogError(t); + } + + @Override + public boolean isDisposed() { + return disposable.isDisposed(); + } + + public void cleanup() { + if(!active.isEmpty()) { + for(ProfileEntry entry : active) entry.deactivate(runtime, observer); + active.clear(); + } + } + +} \ No newline at end of file