1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.scenegraph.profile.common;
16 import java.util.concurrent.ConcurrentHashMap;
18 import org.simantics.db.Resource;
19 import org.simantics.db.procedure.SetListener;
20 import org.simantics.scenegraph.profile.Group;
21 import org.simantics.scenegraph.profile.Observer;
22 import org.simantics.scenegraph.profile.Style;
24 public class ObserverGroupListener implements SetListener<Resource> {
26 final Map<Object, Object> items = new ConcurrentHashMap<Object, Object>();
27 final Map<Resource, Resource> entries = new ConcurrentHashMap<Resource, Resource>();
29 protected final Style style;
30 protected final Group group;
31 protected final Observer observer;
32 private boolean disposed = false;
34 public ObserverGroupListener(Style style, Group group, Observer observer) {
35 assert(style != null);
36 assert(group != null);
37 assert(observer != null);
40 this.observer = observer;
44 public void add(Resource item) {
45 //System.out.println("Add to group(" + this + "): " + item);
46 items.put(item, item);
51 public void remove(Resource item) {
52 // new Exception().printStackTrace();
53 //System.out.println("Remove from group(" + this + "): " + item);
59 public int hashCode() {
60 return observer.hashCode() + 31 * group.hashCode() + 41 * style.hashCode();
64 public boolean equals(Object object) {
67 else if (object == null)
69 else if (ObserverGroupListener.class != object.getClass())
71 ObserverGroupListener other = (ObserverGroupListener)object;
72 return observer.equals(other.observer) && group.equals(other.group) && style.equals(other.style);
75 public Set<Object> getItems() {
76 return items.keySet();
79 public void dispose() {
84 public boolean isDisposed() {
85 return disposed || observer.isDisposed();
89 public void exception(Throwable throwable) {
90 observer.exception(throwable);
93 public void addEntry(Resource entry) {
94 entries.put(entry, entry);
97 public void removeEntry(Resource entry) {
98 entries.remove(entry);
101 public boolean hasEntries() {
102 return !entries.isEmpty();