X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.issues.common%2Fsrc%2Forg%2Fsimantics%2Fissues%2Fcommon%2FChildMaxIssueSeverity.java;h=1103b5f262af788774072ef3d400ada1800fea51;hb=0d9b90834ce56b292c00b1a39850ed842c3e4d42;hp=760f75dbb06325be388ebec372bbe3e58cabddd3;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/ChildMaxIssueSeverity.java b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/ChildMaxIssueSeverity.java index 760f75dbb..1103b5f26 100644 --- a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/ChildMaxIssueSeverity.java +++ b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/ChildMaxIssueSeverity.java @@ -1,97 +1,97 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.issues.common; - -import java.util.Collections; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; - -import org.simantics.db.AsyncReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.TernaryAsyncRead; -import org.simantics.db.procedure.AsyncMultiProcedure; -import org.simantics.db.procedure.AsyncProcedure; -import org.simantics.issues.Severity; - -/** - * @author Tuukka Lehtonen - */ -public class ChildMaxIssueSeverity extends TernaryAsyncRead, Severity>{ - - public ChildMaxIssueSeverity(Resource resource, Resource childRelation, Set typesToRecurse) { - super(resource, childRelation, typesToRecurse); - } - -// @Override -// public Severity perform(ReadGraph graph) throws DatabaseException { -// Severity maxSeverity = null; -// //System.out.println("severityForChildren: " + NameUtils.getSafeName(graph, resource)); -// for (Resource child : graph.getObjects(resource, resource2)) { -// Severity s = graph.syncRequest(new MaxIssueSeverityRecursive(child)); -// maxSeverity = Severity.moreSevere(maxSeverity, s); -// } -// //System.out.println("severityForChildren: " + NameUtils.getSafeName(graph, resource) + " : " + maxSeverity); -// return maxSeverity; -// } - - @Override - public void perform(AsyncReadGraph graph, final AsyncProcedure procedure) { - //System.out.println(getClass().getSimpleName() + ": " + parameter); - - graph.forTypes(parameter, new AsyncProcedure>() { - @Override - public void execute(AsyncReadGraph graph, Set result) { - if (!Collections.disjoint(parameter3, result)) { - checkChildren(graph, procedure); - } else { - procedure.execute(graph, null); - } - } - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - procedure.exception(graph, throwable); - } - }); - } - - protected void checkChildren(AsyncReadGraph graph, final AsyncProcedure procedure) { - graph.forEachObject(parameter, parameter2, new AsyncMultiProcedure() { - AtomicReference maxSeverity = new AtomicReference(); - @Override - public void execute(AsyncReadGraph graph, Resource child) { - graph.asyncRequest(new MaxIssueSeverityRecursive(child, parameter2, parameter3), new AsyncProcedure() { - @Override - public void execute(AsyncReadGraph graph, Severity severity) { - if (severity != null) { - synchronized (maxSeverity) { - maxSeverity.set(Severity.moreSevere(maxSeverity.get(), severity)); - } - } - } - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - procedure.exception(graph, throwable); - } - }); - } - @Override - public void finished(AsyncReadGraph graph) { - procedure.execute(graph, maxSeverity.get()); - } - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - procedure.exception(graph, throwable); - } - }); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.issues.common; + +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.TernaryAsyncRead; +import org.simantics.db.procedure.AsyncMultiProcedure; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.issues.Severity; + +/** + * @author Tuukka Lehtonen + */ +public class ChildMaxIssueSeverity extends TernaryAsyncRead, Severity>{ + + public ChildMaxIssueSeverity(Resource resource, Resource childRelation, Set typesToRecurse) { + super(resource, childRelation, typesToRecurse); + } + +// @Override +// public Severity perform(ReadGraph graph) throws DatabaseException { +// Severity maxSeverity = null; +// //System.out.println("severityForChildren: " + NameUtils.getSafeName(graph, resource)); +// for (Resource child : graph.getObjects(resource, resource2)) { +// Severity s = graph.syncRequest(new MaxIssueSeverityRecursive(child)); +// maxSeverity = Severity.moreSevere(maxSeverity, s); +// } +// //System.out.println("severityForChildren: " + NameUtils.getSafeName(graph, resource) + " : " + maxSeverity); +// return maxSeverity; +// } + + @Override + public void perform(AsyncReadGraph graph, final AsyncProcedure procedure) { + //System.out.println(getClass().getSimpleName() + ": " + parameter); + + graph.forTypes(parameter, new AsyncProcedure>() { + @Override + public void execute(AsyncReadGraph graph, Set result) { + if (!Collections.disjoint(parameter3, result)) { + checkChildren(graph, procedure); + } else { + procedure.execute(graph, null); + } + } + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); + } + }); + } + + protected void checkChildren(AsyncReadGraph graph, final AsyncProcedure procedure) { + graph.forEachObject(parameter, parameter2, new AsyncMultiProcedure() { + AtomicReference maxSeverity = new AtomicReference(); + @Override + public void execute(AsyncReadGraph graph, Resource child) { + graph.asyncRequest(new MaxIssueSeverityRecursive(child, parameter2, parameter3), new AsyncProcedure() { + @Override + public void execute(AsyncReadGraph graph, Severity severity) { + if (severity != null) { + synchronized (maxSeverity) { + maxSeverity.set(Severity.moreSevere(maxSeverity.get(), severity)); + } + } + } + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); + } + }); + } + @Override + public void finished(AsyncReadGraph graph) { + procedure.execute(graph, maxSeverity.get()); + } + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); + } + }); + } + +}