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.modeling.requests;
14 import java.util.Collection;
15 import java.util.Comparator;
16 import java.util.List;
19 import java.util.Vector;
20 import java.util.concurrent.ConcurrentHashMap;
21 import java.util.concurrent.ConcurrentSkipListSet;
23 import org.eclipse.jface.viewers.IFilter;
24 import org.simantics.db.Resource;
25 import org.simantics.scl.runtime.function.Function1;
28 * @author Tuukka Lehtonen
30 public class CollectionResult {
32 public class DiagramFilter implements IFilter {
34 private final IFilter proxy;
36 public DiagramFilter(IFilter proxy) {
41 public boolean select(Object node) {
42 return diagramSet.contains(node) && (proxy == null || proxy.select(node));
47 final public Set<Node> roots = new ConcurrentSkipListSet<Node>();
48 final private Set<Node> diagramSet = new ConcurrentSkipListSet<Node>();
49 final public List<Node> diagramList = new Vector<Node>();
50 final public Map<Resource, Node> diagrams = new ConcurrentHashMap<Resource, Node>();
52 public void addDiagram(Resource r, Node n) {
58 public Collection<Node> breadthFirstFlatten() {
59 return breadthFirstFlatten(null);
62 public Collection<Node> breadthFirstFlatten(IFilter filter) {
63 return Nodes.breadthFirstFlatten(new DiagramFilter(filter), roots);
66 public Collection<Node> depthFirstFlatten() {
67 return depthFirstFlatten(null, null);
70 public Collection<Node> depthFirstFlatten(IFilter filter, Comparator<? super Node> comparator) {
71 return Nodes.depthFirstFlatten(new DiagramFilter(filter), roots, comparator);
76 * function that takes the walked Node as argument and returns a
77 * boolean to describe whether to continue the walk or cancel the
78 * walk. The returned value cannot be <code>null</code>.
79 * @return <code>true</code> if the walk was completed or <code>false</code>
80 * if the walk was cancelled
82 public boolean walkTree(Function1<Node, Boolean> f) {
83 return Nodes.walkTree(f, roots);