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.issues.common;
14 import gnu.trove.map.hash.TObjectByteHashMap;
15 import gnu.trove.set.hash.THashSet;
17 import java.util.Collection;
18 import java.util.Collections;
21 import org.simantics.Simantics;
22 import org.simantics.db.ReadGraph;
23 import org.simantics.db.Resource;
24 import org.simantics.db.common.request.BinaryRead;
25 import org.simantics.db.common.request.ObjectsWithType;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.layer0.adapter.Instances;
28 import org.simantics.db.layer0.variable.Variable;
29 import org.simantics.db.layer0.variable.Variables;
30 import org.simantics.issues.common.preferences.IssuePrefs;
31 import org.simantics.issues.ontology.IssueResource;
32 import org.simantics.layer0.Layer0;
33 import org.simantics.operation.Layer0X;
34 import org.simantics.simulation.ontology.SimulationResource;
37 * @author Tuukka Lehtonen
39 public class AllVisibleIssues extends BinaryRead<Resource, Boolean, Set<Variable>> {
41 public AllVisibleIssues(Resource project) {
42 super(project, Boolean.FALSE);
45 public AllVisibleIssues(Resource project, boolean onlyUnresolved) {
46 super(project, onlyUnresolved);
50 public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
51 Layer0 L0 = Layer0.getInstance(graph);
52 Layer0X L0X = Layer0X.getInstance(graph);
53 IssueResource ISSUE = IssueResource.getInstance(graph);
54 SimulationResource SIMU = SimulationResource.getInstance(graph);
56 Resource project = Simantics.getProjectResource();
57 boolean showHidden = false;
58 boolean showNormal = true;
59 boolean showUser = true;
60 if (project != null) {
61 showHidden = IssuePrefs.showHiddenIssues(graph, project);
62 showNormal = IssuePrefs.showNormalIssues(graph, project);
63 showUser = IssuePrefs.showUserIssues(graph, project);
66 Instances issueIndex = graph.getPossibleAdapter(ISSUE.Issue, Instances.class);
68 // Cache for source activeness.
69 // 0 == not in cache, 1 == false, 2 == true
70 TObjectByteHashMap<Resource> sourceActivenessCache = new TObjectByteHashMap<Resource>();
72 Set<Variable> result = new THashSet<Variable>(1013);
74 for (Resource model : graph.syncRequest(new ObjectsWithType(parameter, L0X.Activates, SIMU.Model))) {
75 Collection<Resource> modelIssues = graph.syncRequest(new ObjectsWithType(model, L0.ConsistsOf, ISSUE.Issue));
76 Collection<Resource> indexedIssues = issueIndex != null ? issueIndex.find(graph, model) : Collections.<Resource>emptyList();
77 Collection<Resource> issues = !indexedIssues.isEmpty() ? new THashSet<Resource>(modelIssues.size() + indexedIssues.size()) : modelIssues;
78 if (!indexedIssues.isEmpty()) {
79 issues.addAll(modelIssues);
80 issues.addAll(indexedIssues);
83 for (Resource issue : issues) {
84 // Filter out unwanted material
85 boolean resolved = graph.hasStatement(issue, ISSUE.Resolved);
86 if (parameter2 && resolved)
88 boolean hidden = graph.hasStatement(issue, ISSUE.Hidden);
89 boolean user = graph.hasStatement(issue, ISSUE.UserIssue);
90 boolean normal = !hidden && !user;
91 if (!showHidden && hidden)
93 if (!showUser && user)
95 if (!showNormal && normal)
98 Resource source = graph.getPossibleObject(issue, ISSUE.IssueSource_Manages_Inverse);
100 byte cache = sourceActivenessCache.get(source);
101 boolean active = cache == 2 ? true : false;
103 active = Boolean.TRUE.equals(graph.getPossibleRelatedValue(source, ISSUE.IssueSource_active));
104 sourceActivenessCache.put(source, active ? (byte) 2 : (byte) 1);
110 Variable var = Variables.getPossibleVariable(graph, issue);
116 // System.out.println("AllActiveIssues returned " + result.size());