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.diagram.profile;
14 import java.util.Collection;
15 import java.util.HashSet;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.RequestProcessor;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.primitiverequest.OrderedSet;
22 import org.simantics.db.common.procedure.wrapper.SetListenerToSingleSetListener;
23 import org.simantics.db.common.request.BinaryRead;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.procedure.SetListener;
26 import org.simantics.diagram.stubs.DiagramResource;
27 import org.simantics.scenegraph.profile.Group;
30 * @author Tuukka Lehtonen
32 public abstract class DiagramElementGroup implements Group {
34 protected DiagramResource DIA;
36 public DiagramElementGroup(ReadGraph graph) {
37 this.DIA = DiagramResource.getInstance(graph);
41 public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) throws DatabaseException {
42 processor.syncRequest(new BinaryRead<Class<?>, Resource, Collection<Resource>>(getClass(), runtimeDiagram) {
45 public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
46 HashSet<Resource> result = new HashSet<Resource>();
48 Resource realDiagram = graph.getPossibleObject(parameter2, DIA.RuntimeDiagram_HasConfiguration);
49 if (realDiagram == null)
52 Collection<Resource> elements = graph.syncRequest(new OrderedSet(realDiagram));
53 for (Resource element : elements) {
54 if (test(graph, element)) {
62 }, new SetListenerToSingleSetListener<Resource>(listener));
65 protected abstract boolean test(ReadGraph graph, Resource element) throws DatabaseException;
68 public int hashCode() {
69 return this.getClass().hashCode();
73 public boolean equals(Object obj) {
74 return obj.getClass().equals(this.getClass());