]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Enhancements to TabContributions 07/307/1
authorjsimomaa <jani.simomaa@gmail.com>
Thu, 12 Jan 2017 13:59:41 +0000 (15:59 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 1 Feb 2017 10:03:07 +0000 (12:03 +0200)
Change-Id: I4df883661c0836a2b19288e7c9fd9456f16988fa

17 files changed:
bundles/org.simantics.annotation.ontology/graph/AnnotationView.pgraph
bundles/org.simantics.document.ui.ontology/graph/DocumentProperty.pgraph
bundles/org.simantics.document.ui.ontology/graph/DocumentUI.pgraph
bundles/org.simantics.modeling.template2d.ontology/graph/DrawingTemplateVP.pgraph
bundles/org.simantics.platform.ui.ontology/graph.tg
bundles/org.simantics.platform.ui.ontology/graph/PlatformUI.pgraph
bundles/org.simantics.platform.ui.ontology/graph/PlatformUIViews.pgraph
bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph
bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractResourceTabContribution.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractTabContribution.java [new file with mode: 0644]
bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractTypedResourceTabContribution.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractTypedTabContribution.java [new file with mode: 0644]
bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractTypedVariableTabContribution.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractVariableTabContribution.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/MultiTypedTabContribution.java [new file with mode: 0644]
bundles/org.simantics.selectionview/src/org/simantics/selectionview/TypedVariableTabContribution.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariableTabContribution.java

index 8b6a15520296c2beb974d2994b180153c7a1d9aa..39740b52cd0ac3c070aa0f4948c14831852a39d9 100644 (file)
@@ -40,15 +40,15 @@ ANNO.Functions.descriptionText : L0.Function
     L0.HasValueType "String"
 
 ANNO.SelectionTabContribution : SEL.TypedVariableTabContribution
-    SEL.TypedVariableTabContribution.HasType L0.Entity
+    SEL.TypedTabContribution.HasType L0.Entity
     SEL.VariableTabContribution.HasView ANNO.SelectionTab
-    SEL.VariableTabContribution.HasPriority -10
+    SEL.TabContribution.HasPriority -10
     L0.HasLabel "Annotations"
 
 ANNO.SelectionTabContribution2 : SEL.TypedVariableTabContribution
-    SEL.TypedVariableTabContribution.HasType ANNO.Annotation
+    SEL.TypedTabContribution.HasType ANNO.Annotation
     SEL.VariableTabContribution.HasView ANNO.SelectionTab2
-    SEL.VariableTabContribution.HasPriority -9
+    SEL.TabContribution.HasPriority -9
     L0.HasLabel "Annotation Properties"
 
 ANNO.SelectionTab.BC : SEL_UI.StandardProperties.BrowseContextStandardChildren
index c6263c034b628d454c462bd0ff9f20eb37b5710f..8b9b8fbda878fdc1c4536cccc2f5aab4aa9f6194 100644 (file)
@@ -12,7 +12,7 @@ UI = <http://www.simantics.org/DocumentUI-1.1>
 
 UI.DocumentTabContributionType <T SEL.AbstractResourceTabContribution
 UI.DocumentTabContribution : UI.DocumentTabContributionType
-     SEL.AbstractResourceTabContribution.HasPriority 1
+     SEL.TabContribution.HasPriority 1
      
 UI.SearchFunction : L0.Function
    L0.HasLabel "Document Search" : L0.String
index 3ac065d5e5ef78299553b91710f9538720db247c..c0a784e9f21dbc58654ab12494fc22bc821c428a 100644 (file)
@@ -25,9 +25,9 @@ UI.CSSEditorContribution
         "\r -> isInstanceOf r L0.IndexRoot"
 
 UI.WikitextContribution : SEL.VariableTabContribution
-    SEL.VariableTabContribution.HasTest UI.Functions.isWikitext : L0.Function
+    SEL.TabContribution.HasTest UI.Functions.isWikitext : L0.Function
     SEL.VariableTabContribution.HasView UI.WikitextContribution.View
-    SEL.VariableTabContribution.HasPriority 1
+    SEL.TabContribution.HasPriority 1
     L0.HasLabel "Wiki"
 
 UI.WikitextContribution.View : VIEWS.Composite
index 66d2b336c4250982310bb31c5ff2ae3005f69cf0..d01861d591542f430831f4f1220b27207134ea74 100644 (file)
@@ -33,9 +33,9 @@ TEMPLATE2D.FlagTableUI.ColumnUI.HeaderUI <T TEMPLATE2D.BrowseNode
 TEMPLATE2D.CompositeUI <T TEMPLATE2D.BrowseNode
 
 TEMPLATE2D.TemplateTabContribution : SEL.TypedVariableTabContribution
-    SEL.TypedVariableTabContribution.HasType SG.Node
+    SEL.TypedTabContribution.HasType SG.Node
     SEL.VariableTabContribution.HasView SEL_UI.StandardProperties
-    SEL.VariableTabContribution.HasPriority 1
+    SEL.TabContribution.HasPriority 1
     L0.HasLabel "Parameters"
 
 TEMPLATE2D.DiagramTemplateBC.ScenegraphChildren : VP.ChildRule
index eafb6ec76ba847404f9b0cc19d1c6a9714fa9d4e..ea0cc187dd5d549a0e2ddcf89980aca5d4031edc 100644 (file)
Binary files a/bundles/org.simantics.platform.ui.ontology/graph.tg and b/bundles/org.simantics.platform.ui.ontology/graph.tg differ
index 3d3dc3c8aea221cc4c60d1343619207ca35c5743..a6b6a064573e8c435524b810803cc2e88276fba7 100644 (file)
@@ -38,7 +38,7 @@ PlatformUI.SharedOntology <T MOD.SharedOntology
     @L0.assert L0.IsLinkedTo PlatformUI
 
 PlatformUI.StandardPropertiesTabContribution : SEL.TypedVariableTabContribution
-    SEL.TypedVariableTabContribution.HasType L0.Entity
+    SEL.TypedTabContribution.HasType L0.Entity
     SEL.VariableTabContribution.HasView SEL_UI.StandardProperties
-    SEL.VariableTabContribution.HasPriority -1
+    SEL.TabContribution.HasPriority -1
     L0.HasLabel "Properties" 
\ No newline at end of file
index a265df8b136b86e9711d84843e5b8417d3e9cba3..f14f769020d7c39a13a9af13bad54158e758b1b6 100644 (file)
@@ -94,8 +94,8 @@ SharedLibraries.UnlinkEvent
   @DOC.singleData SharedLibraries.DefVar2 SharedLibraries.Explorer1 SharedLibraries.UnlinkButton DOC.Relations.click "selection" "selection" _ _ _
 
 VIEWS.SharedLibraryContribution : SWT.TypedVariableTabContribution
-    SEL.AbstractVariableTabContribution.HasPriority 1
-    SEL.AbstractTypedVariableTabContribution.HasType L0.IndexRoot
+    SEL.TabContribution.HasPriority 1
+    SEL.TypedTabContribution.HasType L0.IndexRoot
     SWT.TypedVariableTabContribution.HasView SharedLibraries
     L0.HasLabel "Shared Libraries"
 
@@ -144,8 +144,8 @@ VIEWS.sclEvent : L0.Template
               L0.HasValueType "EventHandler"
 
 VIEWS.RangeSelectionTabContribution : SWT.TypedVariableTabContribution
-    SEL.AbstractVariableTabContribution.HasPriority 1
-    SEL.AbstractTypedVariableTabContribution.HasType SHEET.Spreadsheet
+    SEL.TabContribution.HasPriority 1
+    SEL.TypedTabContribution.HasType SHEET.Spreadsheet
     SWT.TypedVariableTabContribution.HasView RangeSelectionTab
     L0.HasLabel "Ranges"
 
index 58eba84710132a5ab488f22f38be866ada848eef..f4770b7efd6278e571bf9a3d046f87c608bc58ed 100644 (file)
@@ -7,7 +7,17 @@ SEL = <http://www.simantics.org/SelectionView-1.2> : L0.Ontology
 
 SEL.Functions : L0.Library
 
+SEL.TabContribution.Multi <R L0.HasProperty : L0.FunctionalRelation
+  L0.RequiresValueType "Boolean"
+
 SEL.TabContribution <T L0.Entity
+  @L0.assert SEL.TabContribution.Multi false
+  >-- SEL.TabContribution.HasTest --> L0.Value <R L0.DependsOn
+  >-- SEL.TabContribution.HasPriority ==> "Integer" <R L0.DependsOn
+
+SEL.TypedTabContribution <T SEL.TabContribution
+  >-- SEL.TypedTabContribution.HasType --> L0.Type <R L0.DependsOn
+
 SEL.SelectionTransformation <T L0.Function
 
 SEL.Functions.getEnumerationValues : L0.Function
@@ -18,31 +28,24 @@ SEL.Functions.standardSelectionInputTransformation : SEL.SelectionTransformation
 
 SEL.AbstractVariableTabContribution <T SEL.TabContribution
   >-- SEL.AbstractVariableTabContribution.testFunction ==> "Variable -> <ReadGraph> Boolean" <R L0.HasProperty
-  >-- SEL.AbstractVariableTabContribution.HasPriority ==> "Integer" <R L0.HasProperty : SEL.GenericParameterType
-  // This is deprecated
-  >-- SEL.AbstractVariableTabContribution.HasTest --> L0.Value <R L0.DependsOn
 
 SEL.AbstractResourceTabContribution <T SEL.TabContribution
-  >-- SEL.AbstractResourceTabContribution.HasTest --> L0.Value <R L0.DependsOn
-  >-- SEL.AbstractResourceTabContribution.HasPriority ==> "Integer" <R L0.DependsOn
 
 SEL.AbstractTypedVariableTabContribution <T SEL.AbstractVariableTabContribution
-  >-- SEL.AbstractTypedVariableTabContribution.HasType --> L0.Type <R L0.DependsOn
 
 SEL.AbstractTypedResourceTabContribution <T SEL.AbstractResourceTabContribution
-  >-- SEL.AbstractTypedResourceTabContribution.HasType --> L0.Type <R L0.DependsOn
 
 SEL.SCLTabContribution <T SEL.TabContribution
   >-- SEL.SCLTabContribution.instantiate ==> "() -> <Proc> TabContribution" <R L0.HasProperty
 
 SEL.VariableTabContribution <T SEL.TabContribution
-  >-- SEL.VariableTabContribution.HasTest <R L0.DependsOn
   >-- SEL.VariableTabContribution.transformation ==> "Variable -> <ReadGraph> Variable" <R L0.HasProperty
   >-- SEL.VariableTabContribution.HasView <R L0.DependsOn
-  >-- SEL.VariableTabContribution.HasPriority <R L0.DependsOn
+
+SEL.MultiTypedVariableTabContribution <T SEL.TypedVariableTabContribution
+  @L0.assert SEL.TabContribution.Multi true
 
 SEL.TypedVariableTabContribution <T SEL.VariableTabContribution
-  >-- SEL.TypedVariableTabContribution.HasType <R L0.DependsOn
 
 SEL.HasDisplayColumn <R L0.HasProperty : L0.FunctionalRelation
 
index 8f0a9fdd4eb263cc1e4430edfb4cffdffd2e8618..b293f3aee6dd4da2a7f2ec74db1fde71eac00b82 100644 (file)
@@ -1,52 +1,19 @@
 package org.simantics.selectionview;
 
-import java.util.Collection;
-
-import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
-import org.simantics.db.common.utils.Functions;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.layer0.Layer0;
-
-abstract public class AbstractResourceTabContribution implements TabContribution<Resource> {
 
-       final protected Resource configuration;
+abstract public class AbstractResourceTabContribution extends AbstractTabContribution<Resource> {
 
        public AbstractResourceTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
-               this.configuration = configuration;
-       }
-
-       public abstract void getContributors(ReadGraph graph, Resource resource, Integer priority, String label, Collection<ComparableTabContributor> result) throws DatabaseException;
-       
-       @Override
-       public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
-
-               if (!(input instanceof Resource))
-                       return false;
-               Resource resource = (Resource) input;
-
-               SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
-               for(Resource r : graph.getObjects(configuration, SEL.AbstractResourceTabContribution_HasTest)) {
-                       Boolean pass = Functions.exec(graph, r, graph, resource);
-                       if(!pass) return false;
-               }
-               
-               return true;
-               
+           super(graph, configuration);
        }
        
-       @Override
-       final public void contribute(ReadGraph graph, final Resource resource, Collection<ComparableTabContributor> result) throws DatabaseException {
-
-               Layer0 L0 = Layer0.getInstance(graph);
-               SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
-
-               Integer priority = graph.getPossibleRelatedValue(configuration, SEL.AbstractResourceTabContribution_HasPriority, Bindings.INTEGER);
-               String label = graph.getPossibleRelatedValue(configuration, L0.HasLabel);
-
-               getContributors(graph, resource, priority, label, result);
-
-       }
-
+    @Override
+    public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
+        if (!(input instanceof Resource))
+            return false;
+        return super.accept(graph, input);
+    }
 }
diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractTabContribution.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractTabContribution.java
new file mode 100644 (file)
index 0000000..7356698
--- /dev/null
@@ -0,0 +1,68 @@
+package org.simantics.selectionview;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Objects;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.Functions;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+
+public abstract class AbstractTabContribution<T> implements TabContribution<T> {
+
+    protected final Resource configuration;
+    protected final String uri;
+
+    public AbstractTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
+        this.configuration = Objects.requireNonNull(configuration);
+        this.uri = graph.getURI(configuration);
+    }
+
+    @Override
+    public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
+        SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
+        // Lets see if multi or single support
+        Boolean multi = graph.getRelatedValue2(configuration, SEL.TabContribution_Multi, Bindings.BOOLEAN);
+        if (input instanceof Collection<?>) {
+            Collection<?> inputs = (Collection<?>) input;
+            if (inputs.isEmpty())
+                return false;
+            if (inputs.size() > 1 && !multi)
+                return false;
+        } else if (input.getClass().isArray()) {
+            int arrayLength = Array.getLength(input);
+            if (arrayLength == 0)
+                return false;
+            if (arrayLength > 1 && !multi)
+                return false;
+        }
+        // HasTest seems to be deprecated but lets support it just for fun
+        for(Resource r : graph.getObjects(configuration, SEL.TabContribution_HasTest)) {
+            Boolean pass = Functions.exec(graph, r, graph, input);
+            if(!pass)
+                return false;
+        }
+        return true;
+    }
+    
+    public abstract void getContributors(ReadGraph graph, T input, Integer priority, String label, Collection<ComparableTabContributor> result) throws DatabaseException;
+
+    @Override
+    public final void contribute(ReadGraph graph, T input, Collection<ComparableTabContributor> result) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
+
+        Integer priority = graph.getPossibleRelatedValue(configuration, SEL.TabContribution_HasPriority, Bindings.INTEGER);
+        String label = graph.getPossibleRelatedValue(configuration, L0.HasLabel);
+        
+        getContributors(graph, input, priority, label, result);
+    }
+    
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + "[" + uri + "]";
+    }
+}
index 06c0e1e3737ced5cc350a5e9275f7366414c0164..f1148084e2c8f34f0fd0c3e2c1e08d938813bf1e 100644 (file)
@@ -1,32 +1,24 @@
 package org.simantics.selectionview;
 
+import java.util.Collection;
+import java.util.Collections;
+
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 
-abstract public class AbstractTypedResourceTabContribution extends AbstractResourceTabContribution {
+abstract public class AbstractTypedResourceTabContribution extends AbstractTypedTabContribution<Resource> {
 
        public AbstractTypedResourceTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
                super(graph, configuration);
        }
 
-       
-       @Override
-       public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
-
-               if (!(input instanceof Resource))
-                       return false;
-               Resource resource = (Resource) input;
-
-               SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
-
-               Resource type = graph.getPossibleObject(configuration, SEL.AbstractTypedResourceTabContribution_HasType);
-               if(type == null) throw new DatabaseException("No type for " + graph.getPossibleURI(configuration));
-
-               if(!graph.isInstanceOf(resource, type)) return false;
-               
-               return super.accept(graph, resource);
-               
-       }
-       
+    @Override
+    public boolean accept(ReadGraph graph, Object input, Collection<Resource> types) throws DatabaseException {
+        if (!(input instanceof Resource))
+            return false;
+        Resource resource = (Resource) input;
+        Collection<Resource> ts = graph.getTypes(resource);
+        return !Collections.disjoint(types, ts);
+    }
 }
diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractTypedTabContribution.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractTypedTabContribution.java
new file mode 100644 (file)
index 0000000..1c8a86e
--- /dev/null
@@ -0,0 +1,34 @@
+package org.simantics.selectionview;
+
+import java.util.Collection;
+import java.util.Objects;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+
+public abstract class AbstractTypedTabContribution<T> extends AbstractTabContribution<T> {
+
+    protected final Collection<Resource> types;
+    
+    public AbstractTypedTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
+        super(graph, configuration);
+        this.types = Objects.requireNonNull(graph.getObjects(configuration, SelectionViewResources.getInstance(graph).TypedTabContribution_HasType));
+        if(types.isEmpty())
+            throw new DatabaseException("No type for " + graph.getPossibleURI(configuration));
+    }
+    
+    @Override
+    public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
+        if (!super.accept(graph, input))
+            return false;
+        return accept(graph, input, types);
+    }
+    
+    public abstract boolean accept(ReadGraph graph, Object input, Collection<Resource> type) throws DatabaseException;
+
+    @Override
+    public String toString() {
+        return super.toString() + " type=" + types;
+    }
+}
index 741cbd39674c5eb64d34c78e546d7fd94a8ea5af..13f88b9fb896c35ee6260fe24621405d791715d7 100644 (file)
@@ -1,31 +1,31 @@
 package org.simantics.selectionview;
 
+import java.util.Collection;
+import java.util.Collections;
+
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 
-abstract public class AbstractTypedVariableTabContribution extends AbstractVariableTabContribution {
+abstract public class AbstractTypedVariableTabContribution extends AbstractTypedTabContribution<Variable> {
 
        public AbstractTypedVariableTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
                super(graph, configuration);
        }
 
-       @Override
-       public boolean accept(ReadGraph graph, Variable variable, Object selection) throws DatabaseException {
-
-               SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
+    @Override
+    public boolean accept(ReadGraph graph, Object input, Collection<Resource> types) throws DatabaseException {
+        
+        if (!(input instanceof Variable))
+            return false;
+        Variable variable = (Variable) input;
 
-               Resource type = graph.getPossibleObject(configuration, SEL.AbstractTypedVariableTabContribution_HasType);
-               if(type == null) throw new DatabaseException("No type for " + graph.getPossibleURI(configuration));
+        Resource resource = variable.getPossibleRepresents(graph);
+        if (resource == null)
+            return false;
 
-               Resource resource = variable.getPossibleRepresents(graph);
-               if(resource == null) return false;
-               
-               if(!graph.isInstanceOf(resource, type)) return false;
-               
-               return super.accept(graph, variable, selection);
-               
-       }
-       
+        Collection<Resource> ts = graph.getTypes(resource);
+        return !Collections.disjoint(types, ts);
+    }
 }
index 8063eb3c1489d206d3f21650ba3a2e10ec95fc31..2d4fcf2238bea6156e018be8e4923bcc3eb5ad6a 100644 (file)
@@ -1,45 +1,31 @@
 package org.simantics.selectionview;
 
-import java.util.Collection;
-
 import org.simantics.Simantics;
-import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
-import org.simantics.db.common.utils.Functions;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
-import org.simantics.layer0.Layer0;
 import org.simantics.scl.runtime.function.Function;
 import org.simantics.ui.selection.WorkbenchSelectionUtils;
 
-abstract public class AbstractVariableTabContribution implements TabContribution<Object> {
-
-       final private String uri;
-       final protected Resource configuration;
+abstract public class AbstractVariableTabContribution extends AbstractTabContribution<SelectionInput> {
 
        public AbstractVariableTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
-               this.configuration = configuration;
-               this.uri = graph.getURI(configuration);
-       }
-
-       public abstract void getContributors(ReadGraph graph, Variable variable, Integer priority, String label, Collection<ComparableTabContributor> result) throws DatabaseException;
-
-       @Override
-       public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
-               return true;
+           super(graph, configuration);
        }
 
-       public boolean accept(ReadGraph graph, Variable variable, Object selection) throws DatabaseException {
+    @Override
+    public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
+        if (!super.accept(graph, input))
+            return false;
+        Variable variable = getPossibleVariable(graph, input);
+        if (variable == null)
+            return false;
 
-               if(selection instanceof SelectionInput) {
+               if(input instanceof SelectionInput) {
                
                        SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
-                       for(Resource r : graph.getObjects(configuration, SEL.AbstractVariableTabContribution_HasTest)) {
-                               Boolean pass = Functions.exec(graph, r, graph, (SelectionInput)selection);
-                               if(!pass) return false;
-                       }
                
                        Variable configurationVariable = Variables.getVariable(graph, configuration);
                        Function f = configurationVariable.getPossiblePropertyValue(graph, SEL.AbstractVariableTabContribution_testFunction);
@@ -49,13 +35,9 @@ abstract public class AbstractVariableTabContribution implements TabContribution
                        }
                        
                } else {
-                       
                        return false;
-                       
                }
-               
                return true;
-               
        }
        
        final private Variable getPossibleVariable(ReadGraph graph, Object selection) throws DatabaseException {
@@ -67,28 +49,4 @@ abstract public class AbstractVariableTabContribution implements TabContribution
                }
                return null;
        } 
-       
-       @Override
-       final public void contribute(ReadGraph graph, final Object selection, Collection<ComparableTabContributor> result) throws DatabaseException {
-               
-               Variable variable = getPossibleVariable(graph, selection);
-               if(variable == null) return;
-
-               Layer0 L0 = Layer0.getInstance(graph);
-               SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
-
-               Integer priority = graph.getPossibleRelatedValue(configuration, SEL.AbstractVariableTabContribution_HasPriority, Bindings.INTEGER);
-               String label = graph.getPossibleRelatedValue(configuration, L0.HasLabel);
-               
-               if(!accept(graph, variable, selection)) return;
-
-               getContributors(graph, variable, priority, label, result);              
-
-       }
-       
-       @Override
-       public String toString() {
-               return "AbstractVariableTabContribution[" + uri + "]";
-       }
-
 }
diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/MultiTypedTabContribution.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/MultiTypedTabContribution.java
new file mode 100644 (file)
index 0000000..9ffd74a
--- /dev/null
@@ -0,0 +1,135 @@
+package org.simantics.selectionview;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.IWorkbenchSite;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.ui.selection.AnyResource;
+import org.simantics.ui.selection.WorkbenchSelectionElement;
+import org.simantics.views.swt.SWTViewLoaderProcess;
+import org.simantics.views.swt.client.base.SWTRoot;
+
+public class MultiTypedTabContribution extends AbstractTypedTabContribution<Object> {
+
+       public MultiTypedTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
+           super(graph, configuration);
+       }
+       
+       static class Contribution extends ModelledTabContributor {
+
+               private String viewURI;
+               
+               public Contribution(String viewURI) {
+                       this.viewURI = viewURI;
+               }
+               
+               @Override
+               public void createControls(Composite body, IWorkbenchSite site) {
+
+                       try {
+
+                               final SWTViewLoaderProcess loader = new SWTViewLoaderProcess(null, site);
+                               final SWTRoot root = loader.load(viewURI, runtime);
+                               root.createControls(body);
+                               body.addListener(SWT.Dispose, new Listener() {
+                                       
+                                       @Override
+                                       public void handleEvent(Event event) {
+                                               if(!loader.isDisposed())
+                                                       loader.dispose();
+                                       }
+                                       
+                               });
+                               
+                       } catch (DatabaseException e) {
+
+                               e.printStackTrace();
+                               Logger.defaultLogError(e);
+
+                       }
+
+               }
+               
+           @Override
+           public boolean equals(Object obj) {
+               if (this == obj)
+                   return true;
+               else if (obj == null)
+                   return false;
+               else if (!(obj instanceof Contribution))
+                   return false;
+               Contribution c = (Contribution)obj;
+               return viewURI.equals(c.viewURI);
+           }
+           
+           @Override
+           public int hashCode() {
+               return viewURI.hashCode();
+           }
+               
+       }
+       
+       @Override
+       public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
+           return true;
+       }
+       
+       @Override
+       public boolean accept(ReadGraph graph, Object input, Collection<Resource> type) throws DatabaseException {
+           return true;
+       }
+       
+       @Override
+       public void getContributors(ReadGraph graph, Object input, Integer priority, String label, Collection<ComparableTabContributor> result) throws DatabaseException {
+        Collection<?> objects;
+        if (input instanceof Collection<?>) {
+            objects = (Collection<?>) input;
+        } else {
+            objects = Collections.singletonList(input);
+        }
+        
+        SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
+        Resource view = graph.getPossibleObject(configuration, SEL.VariableTabContribution_HasView);
+        if(view == null) {
+            throw new DatabaseException("No view for " + graph.getPossibleURI(configuration));
+        }
+
+        Set<Variable> actualResult = new HashSet<>(objects.size());
+        for (Object obj : objects) {
+            Resource resource = getPossibleResource(graph, obj);
+            if (resource == null)
+                continue;
+            
+            Collection<Resource> ts = graph.getTypes(resource);
+            
+            if (!Collections.disjoint(types, ts)) {
+                Variable variable = Variables.getVariable(graph, resource);
+                actualResult.add(variable);
+            }
+        }
+        if (!actualResult.isEmpty()) {
+            final String viewURI = graph.getPossibleURI(view);
+            result.add(new ComparableTabContributor(new Contribution(viewURI), priority, actualResult, label));
+        }
+       }
+
+    private Resource getPossibleResource(ReadGraph graph, Object obj) {
+        if (obj instanceof Resource)
+            return (Resource) obj;
+        if (obj instanceof WorkbenchSelectionElement)
+            return ((WorkbenchSelectionElement) obj).getContent(new AnyResource(graph));
+        return null;
+    }
+}
index 68d6cdae48e66f1b0657ee605a022014cc573e89..10d4b465d44a487e364855eda0cce7f6e4c61fb5 100644 (file)
@@ -108,13 +108,13 @@ public class TypedVariableTabContribution implements TabContribution<Object> {
                
                Layer0 L0 = Layer0.getInstance(graph);
                SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
-               Collection<Resource> types = graph.getObjects(configuration, SEL.TypedVariableTabContribution_HasType);
+               Collection<Resource> types = graph.getObjects(configuration, SEL.TypedTabContribution_HasType);
                if(types.isEmpty()) throw new DatabaseException("No type for " + graph.getPossibleURI(configuration));
                Resource view = graph.getPossibleObject(configuration, SEL.VariableTabContribution_HasView);
                if(view == null) {
                        throw new DatabaseException("No view for " + graph.getPossibleURI(configuration));
                }
-               Integer priority = graph.getPossibleRelatedValue(configuration, SEL.VariableTabContribution_HasPriority, Bindings.INTEGER);
+               Integer priority = graph.getPossibleRelatedValue(configuration, SEL.TabContribution_HasPriority, Bindings.INTEGER);
                String label = graph.getPossibleRelatedValue(configuration, L0.HasLabel);
                final String viewURI = graph.getPossibleURI(view);
 
@@ -126,7 +126,7 @@ public class TypedVariableTabContribution implements TabContribution<Object> {
         
         if (!Collections.disjoint(types, ts)) {
 
-               for(Resource r : graph.getObjects(configuration, SEL.VariableTabContribution_HasTest)) {
+               for(Resource r : graph.getObjects(configuration, SEL.TabContribution_HasTest)) {
                        Boolean pass = Functions.exec(graph, r, graph, variable);
                        if(!pass) return;
                }
index a3e59985c075e1ff4db98ac9a66b4b3c67e70aed..2287aab00d017b6605f2cf475188388bd150c62f 100644 (file)
@@ -43,10 +43,10 @@ public class VariableTabContribution implements TabContribution<Variable> {
                Resource view = graph.getPossibleObject(configuration, SEL.VariableTabContribution_HasView);
                if(view == null) throw new DatabaseException("No view for " + graph.getPossibleURI(configuration));
 
-               Integer priority = graph.getPossibleRelatedValue(configuration, SEL.VariableTabContribution_HasPriority, Bindings.INTEGER);
+               Integer priority = graph.getPossibleRelatedValue(configuration, SEL.TabContribution_HasPriority, Bindings.INTEGER);
                String label = graph.getPossibleRelatedValue(configuration, L0.HasLabel);
                
-               for(Resource r : graph.getObjects(configuration, SEL.VariableTabContribution_HasTest)) {
+               for(Resource r : graph.getObjects(configuration, SEL.TabContribution_HasTest)) {
                        Boolean pass = Functions.exec(graph, r, graph, variable);
                        if(!pass) return;
                }