1 package org.simantics.scenegraph.profile.impl;
3 import java.util.HashSet;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.procedure.single.SingleSetSyncListener;
9 import org.simantics.db.common.utils.Logger;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.scenegraph.profile.ProfileEntry;
12 import org.simantics.scenegraph.profile.common.ProfileObserver;
13 import org.simantics.utils.datastructures.disposable.IDisposable;
15 public class ProfileActivationListener extends SingleSetSyncListener<ProfileEntry> {
17 final Resource runtime;
18 final ProfileObserver observer;
19 final IDisposable disposable;
20 final Set<ProfileEntry> active = new HashSet<ProfileEntry>();
22 public ProfileActivationListener(Resource runtime, ProfileObserver observer, IDisposable disposable) {
23 this.runtime = runtime;
24 this.observer = observer;
25 this.disposable = disposable;
29 public boolean start(ReadGraph graph) throws DatabaseException {
31 if (observer == null || observer.isDisposed())
41 public void add(ReadGraph graph, ProfileEntry item) throws DatabaseException {
43 item.activate(graph, runtime, observer);
45 if (DebugPolicy.DEBUG_PROFILE_STYLE_ACTIVATION)
46 System.out.println("ACTIVATED PROFILE ENTRY: " + item);
50 public void remove(ReadGraph graph, ProfileEntry item) throws DatabaseException {
53 if (DebugPolicy.DEBUG_PROFILE_STYLE_ACTIVATION)
54 System.out.println("DE-ACTIVATING PROFILE ENTRY: " + item);
55 item.deactivate(runtime, observer);
59 public void finished(ReadGraph graph) throws DatabaseException {
64 public void exception(ReadGraph graph, Throwable t) {
65 Logger.defaultLogError(t);
69 public boolean isDisposed() {
70 return disposable.isDisposed();
73 public void cleanup() {
74 if(!active.isEmpty()) {
75 for(ProfileEntry entry : active) entry.deactivate(runtime, observer);