]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.common/src/org/simantics/issues/common/IssuesWithContext.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.issues.common / src / org / simantics / issues / common / IssuesWithContext.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.issues.common;
13
14 import gnu.trove.set.hash.THashSet;
15
16 import java.util.Set;
17
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.request.ResourceRead2;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.layer0.request.Model;
23 import org.simantics.db.layer0.variable.Variable;
24
25 /**
26  * @author Antti Villberg
27  */
28 public class IssuesWithContext extends ResourceRead2<Set<Variable>> {
29
30     public IssuesWithContext(ReadGraph graph, Resource context) throws DatabaseException {
31         super(graph.sync(new Model(context)), context);
32     }
33
34     public IssuesWithContext(Resource model, Resource context) {
35         super(model, context);
36     }
37
38     @Override
39     public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
40         
41         Set<Variable> result = new THashSet<Variable>();
42         for(Resource issue : graph.sync(new AllModelIssues(resource))) {
43             Set<Resource> contexts = graph.sync(new IssueResourceContexts(issue));
44             if(contexts.contains(resource2)) result.add(graph.adapt(issue, Variable.class)); 
45         }
46         return result;
47         
48     }
49
50 }