--- /dev/null
+package org.simantics.scenegraph.profile.impl;\r
+\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.procedure.single.SingleSetSyncListener;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.scenegraph.profile.ProfileEntry;\r
+import org.simantics.scenegraph.profile.common.ProfileObserver;\r
+import org.simantics.utils.datastructures.disposable.IDisposable;\r
+\r
+public class ProfileActivationListener extends SingleSetSyncListener<ProfileEntry> {\r
+\r
+ final Resource runtime;\r
+ final ProfileObserver observer;\r
+ final IDisposable disposable;\r
+ final Set<ProfileEntry> active = new HashSet<ProfileEntry>();\r
+ \r
+ public ProfileActivationListener(Resource runtime, ProfileObserver observer, IDisposable disposable) {\r
+ this.runtime = runtime;\r
+ this.observer = observer;\r
+ this.disposable = disposable;\r
+ }\r
+ \r
+ @Override\r
+ public boolean start(ReadGraph graph) throws DatabaseException {\r
+ \r
+ if (observer == null || observer.isDisposed())\r
+ return false;\r
+ if (runtime == null)\r
+ return false;\r
+\r
+ return true;\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void add(ReadGraph graph, ProfileEntry item) throws DatabaseException {\r
+ observer.update();\r
+ item.activate(graph, runtime, observer);\r
+ active.add(item);\r
+ if (DebugPolicy.DEBUG_PROFILE_STYLE_ACTIVATION)\r
+ System.out.println("ACTIVATED PROFILE ENTRY: " + item);\r
+ }\r
+\r
+ @Override\r
+ public void remove(ReadGraph graph, ProfileEntry item) throws DatabaseException {\r
+ observer.update();\r
+ active.remove(item);\r
+ if (DebugPolicy.DEBUG_PROFILE_STYLE_ACTIVATION)\r
+ System.out.println("DE-ACTIVATING PROFILE ENTRY: " + item);\r
+ item.deactivate(runtime, observer);\r
+ }\r
+\r
+ @Override\r
+ public void finished(ReadGraph graph) throws DatabaseException {\r
+// observer.update();\r
+ }\r
+\r
+ @Override\r
+ public void exception(ReadGraph graph, Throwable t) {\r
+ Logger.defaultLogError(t);\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return disposable.isDisposed();\r
+ }\r
+ \r
+ public void cleanup() {\r
+ if(!active.isEmpty()) {\r
+ for(ProfileEntry entry : active) entry.deactivate(runtime, observer);\r
+ active.clear();\r
+ }\r
+ }\r
+\r
+}
\ No newline at end of file