]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/ContributedActionBrowseContexts.java
Accept multiple types in browse context contributions
[simantics/platform.git] / bundles / org.simantics.browsing.ui.model / src / org / simantics / browsing / ui / model / browsecontexts / ContributedActionBrowseContexts.java
index dd3fba2c750f068b7835445429452d1905fdc356..ce70a477a6d3d34490f9afe52ae982108f068902 100644 (file)
@@ -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<Resource,Resour
 
     @Override
     public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
-        
         ViewpointResource VP = ViewpointResource.getInstance(graph);
         Instances query = graph.adapt(VP.ActionBrowseContextContribution, Instances.class);
-        Collection<Resource> result = new ArrayList<Resource>();
+        Collection<Resource> 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<Resource> acceptedTypes = graph.getObjects(contribution, VP.ActionBrowseContextContribution_HasType);
+            Collection<Resource> 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;
-        
     }
 
 }