X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph.profile%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fprofile%2Fcommon%2FObserverGroupListener.java;h=10e2abe67fb1f347ce8cc91dcf9553d9abc7c529;hp=d9151fb4f56a5a3b5ae209fe1d023afc96d7c0e0;hb=883a1447e1da4fb8365b85817e4d04588a0eb11d;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/common/ObserverGroupListener.java b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/common/ObserverGroupListener.java index d9151fb4f..10e2abe67 100644 --- a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/common/ObserverGroupListener.java +++ b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/common/ObserverGroupListener.java @@ -1,105 +1,105 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.scenegraph.profile.common; - -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import org.simantics.db.Resource; -import org.simantics.db.procedure.SetListener; -import org.simantics.scenegraph.profile.Group; -import org.simantics.scenegraph.profile.Observer; -import org.simantics.scenegraph.profile.Style; - -public class ObserverGroupListener implements SetListener { - - final Map items = new ConcurrentHashMap(); - final Map entries = new ConcurrentHashMap(); - - protected final Style style; - protected final Group group; - protected final Observer observer; - private boolean disposed = false; - - public ObserverGroupListener(Style style, Group group, Observer observer) { - assert(style != null); - assert(group != null); - assert(observer != null); - this.style = style; - this.group = group; - this.observer = observer; - } - - @Override - public void add(Resource item) { - //System.out.println("Add to group(" + this + "): " + item); - items.put(item, item); - observer.update(); - } - - @Override - public void remove(Resource item) { -// new Exception().printStackTrace(); - //System.out.println("Remove from group(" + this + "): " + item); - items.remove(item); - observer.update(); - } - - @Override - public int hashCode() { - return observer.hashCode() + 31 * group.hashCode() + 41 * style.hashCode(); - } - - @Override - public boolean equals(Object object) { - if (this == object) - return true; - else if (object == null) - return false; - else if (ObserverGroupListener.class != object.getClass()) - return false; - ObserverGroupListener other = (ObserverGroupListener)object; - return observer.equals(other.observer) && group.equals(other.group) && style.equals(other.style); - } - - public Set getItems() { - return items.keySet(); - } - - public void dispose() { - this.disposed = true; - } - - @Override - public boolean isDisposed() { - return disposed || observer.isDisposed(); - } - - @Override - public void exception(Throwable throwable) { - observer.exception(throwable); - } - - public void addEntry(Resource entry) { - entries.put(entry, entry); - } - - public void removeEntry(Resource entry) { - entries.remove(entry); - } - - public boolean hasEntries() { - return !entries.isEmpty(); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.scenegraph.profile.common; + +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import org.simantics.db.Resource; +import org.simantics.db.procedure.SetListener; +import org.simantics.scenegraph.profile.Group; +import org.simantics.scenegraph.profile.Observer; +import org.simantics.scenegraph.profile.Style; + +public class ObserverGroupListener implements SetListener { + + final Map items = new ConcurrentHashMap(); + final Map entries = new ConcurrentHashMap(); + + protected final Style style; + protected final Group group; + protected final Observer observer; + private boolean disposed = false; + + public ObserverGroupListener(Style style, Group group, Observer observer) { + assert(style != null); + assert(group != null); + assert(observer != null); + this.style = style; + this.group = group; + this.observer = observer; + } + + @Override + public void add(Resource item) { + //System.out.println("Add to group(" + this + "): " + item); + items.put(item, item); + observer.update(style, item); + } + + @Override + public void remove(Resource item) { +// new Exception().printStackTrace(); + //System.out.println("Remove from group(" + this + "): " + item); + items.remove(item); + observer.update(style, item); + } + + @Override + public int hashCode() { + return observer.hashCode() + 31 * group.hashCode() + 41 * style.hashCode(); + } + + @Override + public boolean equals(Object object) { + if (this == object) + return true; + else if (object == null) + return false; + else if (getClass() != object.getClass()) + return false; + ObserverGroupListener other = (ObserverGroupListener)object; + return observer.equals(other.observer) && group.equals(other.group) && style.equals(other.style); + } + + public Set getItems() { + return items.keySet(); + } + + public void dispose() { + this.disposed = true; + } + + @Override + public boolean isDisposed() { + return disposed || observer.isDisposed(); + } + + @Override + public void exception(Throwable throwable) { + observer.exception(throwable); + } + + public void addEntry(Resource entry) { + entries.put(entry, entry); + } + + public void removeEntry(Resource entry) { + entries.remove(entry); + } + + public boolean hasEntries() { + return !entries.isEmpty(); + } + +}