From: Jussi Koskela Date: Tue, 20 Dec 2016 12:13:57 +0000 (+0200) Subject: Show modelled STS tests in model browser in execution order X-Git-Tag: v1.26.0~17^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=5e702879e0ee3f352b5c88625fe05e1bf50f8889;p=simantics%2Fplatform.git Show modelled STS tests in model browser in execution order refs #6890 Change-Id: Ib86a41bb738cf9fab476ce062811deeeccc3f317 --- diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg b/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg index 862131139..7935f8a67 100644 Binary files a/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg and b/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg differ diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph b/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph index b51213dc8..ecebcf8fa 100644 --- a/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph +++ b/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph @@ -33,6 +33,13 @@ MBC @VP.namedRelationChildRule TestsUI.Contributions.STSTests L0.Entity L0.ConsistsOf TESTS.STSTest @VP.namedConstantImageRule TestsUI.Contributions.TestImage TESTS.STSTest TestsUI.testImage +MBC + VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType TESTS.STSSuite + VP.VisualsContribution.HasRule MBC.STSSuiteSorterRule + +MBC.STSSuiteSorterRule : VP.SorterRule + MAC = TestsUI.ModelingActionContext : VP.BrowseContext VP.BrowseContext.IsIncludedIn PROJECT.ProjectActionContext diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java b/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java index 897d42c9d..752d44620 100644 --- a/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java +++ b/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java @@ -11,6 +11,7 @@ import org.simantics.db.service.QueryControl; public class TestsUIResource { public final Resource BrowseContext; + public final Resource BrowseContext_STSSuiteSorterRule; public final Resource Contributions; public final Resource Contributions_NewSTSSuite; public final Resource Contributions_NewSTSTest; @@ -29,6 +30,7 @@ public class TestsUIResource { public static class URIs { public static final String BrowseContext = "http://www.simantics.org/TestsUI-1.0/BrowseContext"; + public static final String BrowseContext_STSSuiteSorterRule = "http://www.simantics.org/TestsUI-1.0/BrowseContext/STSSuiteSorterRule"; public static final String Contributions = "http://www.simantics.org/TestsUI-1.0/Contributions"; public static final String Contributions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSSuite"; public static final String Contributions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSTest"; @@ -57,6 +59,7 @@ public class TestsUIResource { public TestsUIResource(ReadGraph graph) { BrowseContext = getResourceOrNull(graph, URIs.BrowseContext); + BrowseContext_STSSuiteSorterRule = getResourceOrNull(graph, URIs.BrowseContext_STSSuiteSorterRule); Contributions = getResourceOrNull(graph, URIs.Contributions); Contributions_NewSTSSuite = getResourceOrNull(graph, URIs.Contributions_NewSTSSuite); Contributions_NewSTSTest = getResourceOrNull(graph, URIs.Contributions_NewSTSTest); diff --git a/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF index 0e787d233..776eea39e 100644 --- a/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF @@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.ui, org.simantics.tests.modelled.ui.ontology;bundle-version="1.0.0", org.simantics.tests.modelled;bundle-version="1.0.0", org.eclipse.e4.ui.model.workbench, - org.simantics.scl.osgi + org.simantics.scl.osgi, + org.simantics.browsing.ui.model Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Bundle-Vendor: Semantum Oy diff --git a/bundles/org.simantics.tests.modelled.ui/adapters.xml b/bundles/org.simantics.tests.modelled.ui/adapters.xml new file mode 100644 index 000000000..d68f46686 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/adapters.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSSuiteSorterRule.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSSuiteSorterRule.java new file mode 100644 index 000000000..bdb55b6a2 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSSuiteSorterRule.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * 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.tests.modelled.ui; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.model.browsecontexts.BrowseContext; +import org.simantics.browsing.ui.model.sorters.Sorter; +import org.simantics.browsing.ui.model.sorters.SorterRule; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.RuntimeDatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.tests.modelled.ontology.TestsResource; +import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.strings.AlphanumComparator; + +public class STSSuiteSorterRule implements SorterRule, Sorter { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Sorter getSorter(ReadGraph graph, Object content) throws DatabaseException { + return this; + } + + @Override + public void sort(ReadGraph graph, BrowseContext context, List nodes) throws DatabaseException + { + try { + STSTestComparator stc = new STSTestComparator(); + stc.graph = graph; + Collections.sort(nodes, stc); + } catch (RuntimeDatabaseException e) { + if (e.getCause()!=null && e.getCause() instanceof DatabaseException) throw (DatabaseException) e.getCause(); + throw e; + } + } + + static class STSTestQuery extends ResourceRead> { + + public STSTestQuery(Resource resource) { + super(resource); + } + + @Override + public Pair perform(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + TestsResource TESTS = TestsResource.getInstance(graph); + + String name = graph.getRelatedValue2(resource, L0.HasName, Bindings.STRING); + Integer priority = graph.getRelatedValue2(resource, TESTS.STSTest_executionPriority, Bindings.INTEGER); + + return new Pair(priority, name); + } + + } + + static class STSTestComparator implements Comparator { + ReadGraph graph; + + @Override + public int compare(NodeContext nc1, NodeContext nc2) { + Resource r1 = (Resource) nc1.getConstant(BuiltinKeys.INPUT); + Resource r2 = (Resource) nc2.getConstant(BuiltinKeys.INPUT); + + try { + Pair test1 = graph.sync(new STSTestQuery(r1)); + Pair test2 = graph.sync(new STSTestQuery(r2)); + + if (test1.first < test2.first) + return -1; + else if (test1.first > test2.first) + return 1; + else return AlphanumComparator.COMPARATOR.compare(test1.second, test2.second); + + } catch (DatabaseException e) { + throw new RuntimeDatabaseException(e); + } + } + } +}