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