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