From 9bf20adbd213c9dff8aee036f5c2e5cff9e37baa Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Wed, 16 Oct 2019 11:26:21 +0300 Subject: [PATCH] Accept multiple types in browse context contributions gitlab #397 Change-Id: Ie653266a7a54cdf78cad923dcb2e62e46e31423d --- .../ContributedActionBrowseContexts.java | 36 +++++++++---------- .../ContributedBrowseContexts.java | 30 ++++++++-------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/ContributedActionBrowseContexts.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/ContributedActionBrowseContexts.java index dd3fba2c7..ce70a477a 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/ContributedActionBrowseContexts.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/ContributedActionBrowseContexts.java @@ -2,6 +2,7 @@ package org.simantics.browsing.ui.model.browsecontexts; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import org.simantics.browsing.ui.model.tests.Test; import org.simantics.databoard.Bindings; @@ -21,34 +22,33 @@ public class ContributedActionBrowseContexts extends TernaryRead perform(ReadGraph graph) throws DatabaseException { - ViewpointResource VP = ViewpointResource.getInstance(graph); Instances query = graph.adapt(VP.ActionBrowseContextContribution, Instances.class); - Collection result = new ArrayList(); + Collection result = new ArrayList<>(); for(Resource contribution : query.find(graph, parameter)) { - Resource type = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasType); - if(type != null) { - if(!graph.isInstanceOf(parameter2, type)) continue; - } + Collection acceptedTypes = graph.getObjects(contribution, VP.ActionBrowseContextContribution_HasType); + Collection allTypes = graph.getTypes(parameter2); + if(Collections.disjoint(acceptedTypes, allTypes)) + continue; + + Resource context = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasActionBrowseContext); + if(context == null) + continue; + Resource testResource = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasTest); if(testResource != null) { - Test test = graph.getPossibleAdapter(testResource, Test.class); - if(test != null) { - if(!test.test(graph, parameter2)) continue; - } + Test test = graph.getPossibleAdapter(testResource, Test.class); + if(test != null && !test.test(graph, parameter2)) + continue; } - - Resource context = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasActionBrowseContext); - if(context == null) continue; + String[] allowedContexts = graph.getPossibleRelatedValue(contribution, VP.ActionBrowseContextContribution_allowedUIContexts, Bindings.STRING_ARRAY); - if(allowedContexts != null) - if(!Arrays.contains(allowedContexts, parameter3)) - continue; + if(allowedContexts != null && !Arrays.contains(allowedContexts, parameter3)) + continue; + result.add(context); - } return result; - } } diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/ContributedBrowseContexts.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/ContributedBrowseContexts.java index f2015257f..3fb20eeb9 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/ContributedBrowseContexts.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/ContributedBrowseContexts.java @@ -2,6 +2,7 @@ package org.simantics.browsing.ui.model.browsecontexts; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; @@ -20,25 +21,26 @@ public class ContributedBrowseContexts extends TernaryRead perform(ReadGraph graph) throws DatabaseException { - ViewpointResource VP = ViewpointResource.getInstance(graph); Instances query = graph.adapt(VP.BrowseContextContribution, Instances.class); - Collection result = new ArrayList(); + Collection result = new ArrayList<>(); for(Resource contribution : query.find(graph, parameter)) { - Resource type = graph.getPossibleObject(contribution, VP.BrowseContextContribution_HasType); - if(type == null) continue; - if(graph.isInstanceOf(parameter2, type)) { - Resource context = graph.getPossibleObject(contribution, VP.BrowseContextContribution_HasBrowseContext); - if(context == null) continue; - String[] allowedContexts = graph.getPossibleRelatedValue(contribution, VP.BrowseContextContribution_allowedUIContexts, Bindings.STRING_ARRAY); - if(allowedContexts != null) - if(!Arrays.contains(allowedContexts, parameter3)) - continue; - result.add(context); - } + Collection acceptedTypes = graph.getObjects(contribution, VP.BrowseContextContribution_HasType); + Collection allTypes = graph.getTypes(parameter2); + if(Collections.disjoint(acceptedTypes, allTypes)) + continue; + + Resource context = graph.getPossibleObject(contribution, VP.BrowseContextContribution_HasBrowseContext); + if(context == null) + continue; + + String[] allowedContexts = graph.getPossibleRelatedValue(contribution, VP.BrowseContextContribution_allowedUIContexts, Bindings.STRING_ARRAY); + if(allowedContexts != null && !Arrays.contains(allowedContexts, parameter3)) + continue; + + result.add(context); } return result; - } } -- 2.43.2