]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Removed os.modelling.ui.modelBrowser.model.INode dependency.
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 1 Sep 2011 12:13:04 +0000 (12:13 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 09:22:15 +0000 (11:22 +0200)
git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@22024 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.interop/META-INF/MANIFEST.MF
org.simantics.interop/src/org/simantics/interop/browsing/INode.java [new file with mode: 0644]
org.simantics.interop/src/org/simantics/interop/browsing/INodeEvaluators.java [new file with mode: 0644]
org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java
org.simantics.interop/src/org/simantics/interop/browsing/ImportNode2.java
org.simantics.interop/src/org/simantics/interop/browsing/InteropChildRule.java
org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java
org.simantics.interop/src/org/simantics/interop/handlers/Contributor2.java
org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java

index 4b19fd47f821f786c96f38c02c588ded14a6afb6..168f429ac136d754359913ac20204885de8b1392 100644 (file)
@@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.ui,
  org.simantics.browsing.ui.model;bundle-version="1.0.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
-Export-Package: org.simantics.interop.issues,
+Export-Package: org.simantics.interop.browsing,
+ org.simantics.interop.issues,
  org.simantics.interop.stubs,
  org.simantics.interop.test,
  org.simantics.interop.utils
diff --git a/org.simantics.interop/src/org/simantics/interop/browsing/INode.java b/org.simantics.interop/src/org/simantics/interop/browsing/INode.java
new file mode 100644 (file)
index 0000000..b849a02
--- /dev/null
@@ -0,0 +1,29 @@
+package org.simantics.interop.browsing;\r
+\r
+import java.util.Collection;\r
+\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.simantics.browsing.ui.common.node.IDeletable;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public interface INode extends IAdaptable {\r
+    String getLabel(ReadGraph graph) throws DatabaseException;\r
+    int getCategory(ReadGraph graph) throws DatabaseException;\r
+    Collection<?> getChildren(ReadGraph graph) throws DatabaseException;\r
+    boolean hasChildren(ReadGraph graph) throws DatabaseException;\r
+    ImageDescriptor getImage(ReadGraph graph) throws DatabaseException;\r
+    void handleDrop(Session session, ISelection selection);\r
+    Modifier getModifier(Session session, String columnId);\r
+\r
+    /**\r
+     * Delete node in the background system. The node is considered deletable\r
+     * only if it implements {@link IDeletable}.\r
+     */\r
+    void handleDelete(WriteGraph graph) throws DatabaseException;\r
+}\r
diff --git a/org.simantics.interop/src/org/simantics/interop/browsing/INodeEvaluators.java b/org.simantics.interop/src/org/simantics/interop/browsing/INodeEvaluators.java
new file mode 100644 (file)
index 0000000..e6216ed
--- /dev/null
@@ -0,0 +1,181 @@
+package org.simantics.interop.browsing;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.Map;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.simantics.browsing.ui.BuiltinKeys;\r
+import org.simantics.browsing.ui.DataSource;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
+import org.simantics.browsing.ui.BuiltinKeys.ImagerKey;\r
+import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;\r
+import org.simantics.browsing.ui.BuiltinKeys.ViewpointKey;\r
+import org.simantics.browsing.ui.GraphExplorer.ModificationContext;\r
+import org.simantics.browsing.ui.common.ColumnKeys;\r
+import org.simantics.browsing.ui.common.EvaluatorImpl;\r
+import org.simantics.browsing.ui.common.EvaluatorData.Evaluator;\r
+import org.simantics.browsing.ui.common.comparators.AlphanumericComparatorFactory;\r
+import org.simantics.browsing.ui.common.imagers.ContainerImager;\r
+import org.simantics.browsing.ui.content.Imager;\r
+import org.simantics.browsing.ui.content.ImagerFactory;\r
+import org.simantics.browsing.ui.content.Labeler;\r
+import org.simantics.browsing.ui.content.LabelerFactory;\r
+import org.simantics.browsing.ui.content.Viewpoint;\r
+import org.simantics.browsing.ui.content.ViewpointFactory;\r
+import org.simantics.browsing.ui.graph.impl.LazyGraphLabeler;\r
+import org.simantics.browsing.ui.graph.impl.LazyViewpoint;\r
+import org.simantics.browsing.ui.graph.impl.MissingImageDescriptor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.modeling.ui.modelBrowser.model.IChildrenCallback;\r
+import org.simantics.modeling.ui.modelBrowser.model.IDisposable;\r
+import org.simantics.modeling.ui.modelBrowser.model.IUpdateable;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Callable;\r
+import org.simantics.utils.datastructures.Callback;\r
+\r
+\r
+public class INodeEvaluators {\r
+       public static Evaluator createEvaluator() {\r
+               Evaluator nodeEvaluator = new EvaluatorImpl();\r
+\r
+        nodeEvaluator.addViewpoint(new NodeViewpointFactory(), 1.0);\r
+        nodeEvaluator.addComparator(new AlphanumericComparatorFactory(ColumnKeys.SINGLE), 2.0);\r
+        nodeEvaluator.addLabeler(new NodeLabelerFactory(), 1.0);\r
+        nodeEvaluator.addImager(new NodeImagerFactory(), 1.0);\r
+        \r
+        return nodeEvaluator;\r
+       }\r
+}\r
+\r
+abstract class BaseViewpointFactory implements ViewpointFactory {\r
+    protected abstract class VPB extends LazyViewpoint implements Callable<Boolean>, IChildrenCallback {\r
+        public VPB(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) {\r
+            super(updater, context, key);\r
+        }\r
+\r
+        @Override\r
+        public String toString() {\r
+            return BaseViewpointFactory.this.toString();\r
+        }\r
+\r
+        @Override\r
+        public Object getIdentity() {\r
+            // This is necessary to give graph requests related to this\r
+            // LazyViewpoint a unique-enough identity so that they don't collide\r
+            // unexpectedly with other users of ModelEvaluators.\r
+            // This makes requests created with different concrete classes of\r
+            // BaseViewpointFactory unique.\r
+            return BaseViewpointFactory.this.getClass();\r
+        }\r
+\r
+        @Override\r
+        public Boolean call() {\r
+            return Boolean.valueOf(updater.isDisposed());\r
+        }\r
+\r
+        @Override\r
+        public void refreshChildren(Collection<?> newChildren) {\r
+            NodeContext[] ncs = toContextsWithInput(newChildren);\r
+            setHasChildren(ncs.length > 0);\r
+            setChildren(ncs);\r
+            updater.scheduleReplace(context, key, this);\r
+        }\r
+\r
+        @Override\r
+        public Boolean hasChildren(ReadGraph graph) throws DatabaseException {\r
+            // hasChildren must do the same graph operations as children\r
+            // since they both share the same PrimitiveQueryUpdater.\r
+            return children(graph).length > 0;\r
+        }\r
+    };\r
+}\r
+\r
+class NodeViewpointFactory extends BaseViewpointFactory {\r
+    @Override\r
+    public String toString() {\r
+        return "Standard";\r
+    }\r
+\r
+    class VP extends VPB {\r
+        public VP(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) {\r
+            super(updater, context, key);\r
+        }\r
+\r
+        @Override\r
+        public NodeContext[] children(ReadGraph graph) throws DatabaseException {\r
+            INode node = (INode) context.getConstant(BuiltinKeys.INPUT);\r
+            if (node instanceof IUpdateable)\r
+                ((IUpdateable) node).setChildrenCallback(this);\r
+\r
+            Collection<?> children = node.getChildren(graph);\r
+            for (Object child : children) {\r
+                if (child instanceof IDisposable)\r
+                    ((IDisposable) child).setDisposedCallable(this);\r
+            }\r
+            return toContextsWithInput(children);\r
+        }\r
+    };\r
+\r
+    @Override\r
+    public Viewpoint create(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) {\r
+        return new VP(updater, context, key);\r
+    }\r
+}\r
+\r
+class NodeLabelerFactory implements LabelerFactory {\r
+    @Override\r
+    public Labeler create(PrimitiveQueryUpdater updater, final NodeContext context, LabelerKey key) {\r
+        return new LazyGraphLabeler(updater, context, key) {\r
+            @Override\r
+            public Object getIdentity(LabelerKey key) {\r
+                return NodeLabelerFactory.this.getClass();\r
+            }\r
+\r
+            @Override\r
+            public Map<String, String> labels(ReadGraph graph) throws DatabaseException {\r
+                return Collections.singletonMap(ColumnKeys.SINGLE,\r
+                        ((INode) context.getConstant(BuiltinKeys.INPUT)).getLabel(graph));\r
+            }\r
+\r
+            @Override\r
+            public Modifier getModifier(ModificationContext sourcePart, String key) {\r
+                return ((INode) context.getConstant(BuiltinKeys.INPUT)).getModifier(SimanticsUI.getSession(), key);\r
+            }\r
+\r
+            @Override\r
+            public int category(ReadGraph graph) throws DatabaseException {\r
+                return ((INode) context.getConstant(BuiltinKeys.INPUT)).getCategory(graph);\r
+            }\r
+        };\r
+    }\r
+}\r
+\r
+class NodeImagerFactory implements ImagerFactory {\r
+\r
+    @Override\r
+    public Imager create(final PrimitiveQueryUpdater updater, final NodeContext context, final ImagerKey key) {\r
+        final ContainerImager<ImageDescriptor> result = new ContainerImager<ImageDescriptor>();\r
+        result.setImage(MissingImageDescriptor.getInstance());\r
+\r
+        DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);\r
+\r
+        source.schedule(new Callback<ReadGraph>() {\r
+            @Override\r
+            public void run(ReadGraph g) {\r
+                try {\r
+                    ImageDescriptor descriptor = ((INode)context.getConstant(BuiltinKeys.INPUT)).getImage(g);\r
+                    result.setImage(descriptor);\r
+                    updater.scheduleReplace(context, key, result);\r
+                } catch (DatabaseException e) {\r
+                    e.printStackTrace();\r
+                }\r
+            }\r
+        });\r
+\r
+        return result;\r
+    }\r
+\r
+}
\ No newline at end of file
index 496eb9b12c7c00d29033346dba4f4e8cafb17c88..af39f8936e228778d3b5f31e7f5da7d8418e9f0b 100644 (file)
@@ -14,9 +14,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.interop.Activator;\r
 import org.simantics.interop.stubs.InteropResource;\r
-import org.simantics.modeling.ui.modelBrowser.model.INode;\r
 \r
-@SuppressWarnings("deprecation")\r
 public class ImportNode implements INode {\r
        \r
        //private Resource project;\r
index 54a8adaef71298bef19509f12e241ad7570b87c6..f746a9fe5052efff5b4447e6de096f13c46ed053 100644 (file)
@@ -14,9 +14,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.interop.Activator;\r
 import org.simantics.interop.stubs.InteropResource;\r
-import org.simantics.modeling.ui.modelBrowser.model.INode;\r
 \r
-@SuppressWarnings("deprecation")\r
 public class ImportNode2 implements INode {\r
        \r
        private Resource project;\r
index cf889aabcd3724ca0ed42f1e899d209168592f18..dacd74d72aadf3ab3eac01de33a4e03ad6d62efa 100644 (file)
@@ -9,9 +9,7 @@ import org.simantics.browsing.ui.model.children.ChildRule;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.modeling.ui.modelBrowser.model.INode;\r
 \r
-@SuppressWarnings("deprecation")\r
 public class InteropChildRule implements ChildRule{\r
        @Override\r
     public boolean isCompatible(Class<?> contentType) {\r
index 7e0344b97265a92c621dbb6bb7d3ec454a343e2d..1f90997131c09623411e03be4b873a8a9964c914 100644 (file)
@@ -6,12 +6,11 @@ import java.util.Collection;
 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.interop.browsing.INode;\r
 import org.simantics.interop.browsing.ImportNode;\r
-import org.simantics.modeling.ui.modelBrowser.model.INode;\r
 import org.simantics.structural.ui.modelBrowser.nodes.ModelNode;\r
 \r
 \r
-@SuppressWarnings("deprecation")\r
 public class Contributor1 extends ViewpointContributor<ModelNode> {\r
 \r
        \r
index 89315547536da95406ef99e2b78c7ea9f74e4e9b..62dd734177f2811abde837cd8f202a0ce6d6257a 100644 (file)
@@ -7,11 +7,11 @@ import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributo
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.interop.browsing.INode;\r
 import org.simantics.interop.browsing.ImportNode2;\r
-import org.simantics.modeling.ui.modelBrowser.model.INode;\r
 \r
 \r
-@SuppressWarnings("deprecation")\r
+\r
 public class Contributor2 extends ViewpointContributor<Resource> {\r
 \r
        \r
index aa9b72ef8b0e392cb630323d26b8302729ab660c..1028e36badfa7b2156d9a4835c12631ff6ce2b59 100644 (file)
@@ -4,10 +4,9 @@ import java.util.Collection;
 \r
 import org.simantics.browsing.ui.common.EvaluatorData.Evaluator;\r
 import org.simantics.browsing.ui.common.extension.EvaluatorFactory;\r
-import org.simantics.modeling.ui.modelBrowser.ModelEvaluators;\r
-import org.simantics.modeling.ui.modelBrowser.model.INode;\r
+import org.simantics.interop.browsing.INode;\r
+import org.simantics.interop.browsing.INodeEvaluators;\r
 \r
-@SuppressWarnings("deprecation")\r
 public class EvaluatorFactory1 implements EvaluatorFactory {\r
 \r
        public EvaluatorFactory1() {\r
@@ -15,12 +14,19 @@ public class EvaluatorFactory1 implements EvaluatorFactory {
        \r
        @Override\r
        public Evaluator create(Collection<String> browseContexts) {\r
-               return ModelEvaluators.createNodeEvaluator();\r
+               \r
+\r
+        return INodeEvaluators.createEvaluator();\r
        }\r
        \r
        @Override\r
        public Class<?> getClazz() {\r
                return INode.class;\r
        }\r
-\r
+       \r
+       \r
 }\r
+       \r
+       \r
+\r
+\r