]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeverityRecursive.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.issues.common / src / org / simantics / issues / common / MaxIssueSeverityRecursive.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * 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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.issues.common;\r
13 \r
14 import java.util.Set;\r
15 \r
16 import org.simantics.db.AsyncReadGraph;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.db.common.request.TernaryAsyncRead;\r
19 import org.simantics.db.procedure.AsyncMultiProcedure;\r
20 import org.simantics.db.procedure.AsyncProcedure;\r
21 import org.simantics.issues.Severity;\r
22 import org.simantics.issues.ontology.IssueResource;\r
23 \r
24 /**\r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public class MaxIssueSeverityRecursive extends TernaryAsyncRead<Resource, Resource, Set<Resource>, Severity> {\r
28 \r
29     public MaxIssueSeverityRecursive(Resource resource, Resource childRelation, Set<Resource> typesToRecurse) {\r
30         super(resource, childRelation, typesToRecurse);\r
31     }\r
32 \r
33 //    @Override\r
34 //    public Severity perform(ReadGraph graph) throws DatabaseException {\r
35 //        Layer0 L0 = Layer0.getInstance(graph);\r
36 //        IssueResource ISSUE = IssueResource.getInstance(graph);\r
37 //        //System.out.println("severity: " + NameUtils.getSafeName(graph, resource));\r
38 //        Collection<Resource> issues = graph.getObjects(resource, ISSUE.IsIssueContextOf);\r
39 //        if (issues.isEmpty()) {\r
40 //            // This content does not have directly attached issues, try to look\r
41 //            // for some in the child components.\r
42 //            return graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf));\r
43 //        }\r
44 //\r
45 //        Severity maxSeverity = graph.syncRequest(new MaxIssueSeveritySingle(resource));\r
46 //        if (maxSeverity == null)\r
47 //            maxSeverity = graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf));\r
48 //\r
49 //        return maxSeverity;\r
50 //    }\r
51 \r
52     @Override\r
53     public void perform(AsyncReadGraph graph, final AsyncProcedure<Severity> procedure) {\r
54         IssueResource ISSUE = graph.getService(IssueResource.class);\r
55         //System.out.println(getClass().getSimpleName() + ": " + parameter);\r
56 \r
57         graph.forEachObject(parameter, ISSUE.Issue_HasContext_Inverse, new AsyncMultiProcedure<Resource>() {\r
58             volatile int issues = 0;\r
59             @Override\r
60             public void execute(AsyncReadGraph graph, Resource result) {\r
61                 ++issues;\r
62             }\r
63             @Override\r
64             public void finished(AsyncReadGraph graph) {\r
65                 if (issues == 0) {\r
66                     // This content does not have directly attached issues, try to look\r
67                     // for some in the child components.\r
68                     graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);\r
69                 } else {\r
70                     // Try local issues first\r
71                     graph.asyncRequest(new MaxIssueSeveritySingle(parameter), new AsyncProcedure<Severity>() {\r
72                         @Override\r
73                         public void execute(AsyncReadGraph graph, Severity maxSeverity) {\r
74                             if (maxSeverity == null)\r
75                                 // No severity for local issues, try children next.\r
76                                 graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);\r
77                             else\r
78                                 procedure.execute(graph, maxSeverity);\r
79                         }\r
80                         @Override\r
81                         public void exception(AsyncReadGraph graph, Throwable throwable) {\r
82                             procedure.exception(graph, throwable);\r
83                         }\r
84                     });\r
85                 }\r
86             }\r
87             @Override\r
88             public void exception(AsyncReadGraph graph, Throwable throwable) {\r
89                 procedure.exception(graph, throwable);\r
90             }\r
91         });\r
92     }\r
93 \r
94 }\r