]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Interop common plug-in
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 26 Apr 2010 14:48:42 +0000 (14:48 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 09:22:09 +0000 (11:22 +0200)
Integration to Apros Model Browser

git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@15560 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.interop/.classpath [new file with mode: 0644]
org.simantics.interop/.project [new file with mode: 0644]
org.simantics.interop/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
org.simantics.interop/META-INF/MANIFEST.MF [new file with mode: 0644]
org.simantics.interop/build.properties [new file with mode: 0644]
org.simantics.interop/plugin.xml [new file with mode: 0644]
org.simantics.interop/src/org/simantics/interop/Activator.java [new file with mode: 0644]
org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java [new file with mode: 0644]
org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java [new file with mode: 0644]
org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java [new file with mode: 0644]
org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java [new file with mode: 0644]

diff --git a/org.simantics.interop/.classpath b/org.simantics.interop/.classpath
new file mode 100644 (file)
index 0000000..8a8f166
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
+       <classpathentry kind="src" path="src"/>\r
+       <classpathentry kind="output" path="bin"/>\r
+</classpath>\r
diff --git a/org.simantics.interop/.project b/org.simantics.interop/.project
new file mode 100644 (file)
index 0000000..4bf9b0a
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>org.simantics.interop</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>org.eclipse.jdt.core.javabuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.ManifestBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.SchemaBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>org.eclipse.pde.PluginNature</nature>\r
+               <nature>org.eclipse.jdt.core.javanature</nature>\r
+       </natures>\r
+</projectDescription>\r
diff --git a/org.simantics.interop/.settings/org.eclipse.jdt.core.prefs b/org.simantics.interop/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..c485159
--- /dev/null
@@ -0,0 +1,8 @@
+#Mon Apr 26 14:43:33 EEST 2010\r
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
+org.eclipse.jdt.core.compiler.compliance=1.6\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.6\r
diff --git a/org.simantics.interop/META-INF/MANIFEST.MF b/org.simantics.interop/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..99a5c99
--- /dev/null
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Interop
+Bundle-SymbolicName: org.simantics.interop;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.simantics.interop.Activator
+Bundle-Vendor: VTT
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.simantics.db;bundle-version="0.8.0",
+ org.simantics.db.common;bundle-version="0.8.0",
+ org.simantics.browsing.ui;bundle-version="0.9.0",
+ org.simantics.browsing.ui.common;bundle-version="0.9.0",
+ org.simantics.modeling.ui;bundle-version="1.0.0",
+ org.simantics.ui;bundle-version="1.0.0",
+ org.simantics.layer0.utils;bundle-version="0.8.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
diff --git a/org.simantics.interop/build.properties b/org.simantics.interop/build.properties
new file mode 100644 (file)
index 0000000..6f20375
--- /dev/null
@@ -0,0 +1,5 @@
+source.. = src/\r
+output.. = bin/\r
+bin.includes = META-INF/,\\r
+               .,\\r
+               plugin.xml\r
diff --git a/org.simantics.interop/plugin.xml b/org.simantics.interop/plugin.xml
new file mode 100644 (file)
index 0000000..a745faf
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<?eclipse version="3.4"?>\r
+<plugin>\r
+   <extension\r
+         point="org.simantics.browsing.ui.common.viewpointContributionBinding">\r
+      <binding\r
+            browseContext="http://www.simantics.org/Structural-1.0/ModelBrowser">\r
+         <implementation\r
+               class="org.simantics.interop.handlers.Contributor1"\r
+               preference="1.0">\r
+         </implementation>\r
+      </binding>\r
+   </extension>\r
+   <extension\r
+         point="org.simantics.browsing.ui.common.evaluatorBinding">\r
+      <binding\r
+            browseContext="http://www.simantics.org/Structural-1.0/ModelBrowser">\r
+         <implementation\r
+               class="org.simantics.interop.handlers.EvaluatorFactory1"\r
+               preference="1">\r
+         </implementation>\r
+      </binding>\r
+   </extension>\r
+\r
+</plugin>\r
diff --git a/org.simantics.interop/src/org/simantics/interop/Activator.java b/org.simantics.interop/src/org/simantics/interop/Activator.java
new file mode 100644 (file)
index 0000000..4f5160f
--- /dev/null
@@ -0,0 +1,50 @@
+package org.simantics.interop;\r
+\r
+import org.eclipse.ui.plugin.AbstractUIPlugin;\r
+import org.osgi.framework.BundleContext;\r
+\r
+/**\r
+ * The activator class controls the plug-in life cycle\r
+ */\r
+public class Activator extends AbstractUIPlugin {\r
+\r
+       // The plug-in ID\r
+       public static final String PLUGIN_ID = "org.simantics.interop";\r
+\r
+       // The shared instance\r
+       private static Activator plugin;\r
+       \r
+       /**\r
+        * The constructor\r
+        */\r
+       public Activator() {\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)\r
+        */\r
+       public void start(BundleContext context) throws Exception {\r
+               super.start(context);\r
+               plugin = this;\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)\r
+        */\r
+       public void stop(BundleContext context) throws Exception {\r
+               plugin = null;\r
+               super.stop(context);\r
+       }\r
+\r
+       /**\r
+        * Returns the shared instance\r
+        *\r
+        * @return the shared instance\r
+        */\r
+       public static Activator getDefault() {\r
+               return plugin;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java b/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java
new file mode 100644 (file)
index 0000000..a8f8338
--- /dev/null
@@ -0,0 +1,107 @@
+package org.simantics.interop.browsing;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.interop.stubs.InteropResource;\r
+import org.simantics.modeling.ui.modelBrowser.model.INode;\r
+\r
+public class ImportNode implements INode {\r
+       \r
+       private Resource project;\r
+       \r
+       public ImportNode(Resource project) {\r
+               this.project = project;\r
+       }\r
+       \r
+       @Override\r
+       public Object getAdapter(Class adapter) {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public int getCategory(ReadGraph graph) throws DatabaseException {\r
+               return 0;\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public String getLabel(ReadGraph graph) throws DatabaseException {\r
+               return "Imports";\r
+       }\r
+       \r
+       @Override\r
+       public Modifier getModifier(Session session, String columnId) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public void handleDelete(WriteGraph graph) throws DatabaseException {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void handleDrop(Session session, ISelection selection) {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public boolean hasChildren(ReadGraph graph) throws DatabaseException {\r
+               return getChildren(graph).size() > 0;\r
+       }\r
+       \r
+       @Override\r
+       public Collection<?> getChildren(ReadGraph graph) throws DatabaseException {\r
+               List<INode> nodes = new ArrayList<INode>();\r
+               Builtins b = graph.getBuiltins();\r
+               InteropResource i = InteropResource.getInstance(graph);\r
+               Collection<Resource> models = graph.getObjects(project, b.ConsistsOf);\r
+               for (Resource m : models) {\r
+                       Collection<Resource> objs = graph.getObjects(m, b.ConsistsOf);\r
+                       for (Resource o : objs) {\r
+                               if (graph.isInstanceOf(o, i.ImportLibrary)) {\r
+                                       INode node = graph.adapt(o, INode.class);\r
+                                       nodes.add(node);\r
+                               }\r
+                       }\r
+               }\r
+               return nodes;\r
+               \r
+//             ComosResource c = ComosResource.getInstance(graph);\r
+//             Collection<Resource> models = graph.getObjects(project, b.ConsistsOf);\r
+//             Collection<ComosGraphNode> comosImports = new ArrayList<ComosGraphNode>();\r
+//             for (Resource m : models) {\r
+//                     Collection<Resource> objs = graph.getObjects(m, b.ConsistsOf);\r
+//                     for (Resource o : objs) {\r
+//                             if (graph.isInstanceOf(o, c.ComosImportLibrary)) {\r
+//                                     String icon_db_path = ComosGraphTools.getIconPath(o, graph);\r
+//                                     if (icon_db_path == null)\r
+//                                             continue;\r
+//                                     ComosIconReader iconReader = new ComosIconReader(icon_db_path);\r
+//                                     comosImports.add(new ComosGraphNode(o, iconReader));\r
+//                             }\r
+//                     }\r
+//             }\r
+//             return comosImports;\r
+       }\r
+       \r
+\r
+}\r
diff --git a/org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java b/org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java
new file mode 100644 (file)
index 0000000..26d63a6
--- /dev/null
@@ -0,0 +1,36 @@
+package org.simantics.interop.handlers;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.interop.browsing.ImportNode;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ui.modelBrowser.model.INode;\r
+\r
+public class Contributor1 extends ViewpointContributor<Resource> {\r
+\r
+       \r
+       public Contributor1() {\r
+               super();\r
+       }\r
+       @Override\r
+       public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+                       throws DatabaseException {\r
+               Collection<INode> nodes = new ArrayList<INode>();\r
+               System.out.println("Contributor 1 " + input + " " + GraphUtils.getReadableName(graph, input));\r
+               nodes.add(new ImportNode(input));\r
+               return nodes;\r
+       }\r
+       \r
+       @Override\r
+       public String getViewpointId() {\r
+               return "Standard";\r
+       }\r
+       \r
+       \r
+\r
+}\r
diff --git a/org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java b/org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java
new file mode 100644 (file)
index 0000000..5178c20
--- /dev/null
@@ -0,0 +1,30 @@
+package org.simantics.interop.handlers;\r
+\r
+import java.util.Collection;\r
+\r
+import org.eclipse.jface.resource.JFaceResources;\r
+import org.eclipse.jface.resource.LocalResourceManager;\r
+import org.eclipse.swt.widgets.Display;\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.ui.SimanticsUI;\r
+\r
+public class EvaluatorFactory1 implements EvaluatorFactory {\r
+\r
+       public EvaluatorFactory1() {\r
+               // TODO Auto-generated constructor stub\r
+       }\r
+       \r
+       @Override\r
+       public Evaluator create(Collection<String> browseContexts) {\r
+               return ModelEvaluators.createNodeEvaluator(SimanticsUI.getSession(), new LocalResourceManager(JFaceResources.getResources(Display.getDefault())));\r
+       }\r
+       \r
+       @Override\r
+       public Class<?> getClazz() {\r
+               return INode.class;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java b/org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java
new file mode 100644 (file)
index 0000000..bfa3c47
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.interop.stubs;\r
+\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class InteropResource {\r
+    \r
+    public final Resource ImportLibrary;\r
+    public final Resource InteropFeature;\r
+    \r
+    public static class URIs {\r
+        public static final String ImportLibrary = "http://www.simantics.org/Interoperability-1.0/Types/ImportLibrary";\r
+        public static final String InteropFeature = "http://www.simantics.org/Interoperability-1.0/InteropFeature";\r
+    }\r
+    \r
+    public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
+        try {\r
+            return graph.getResource(uri);\r
+        } catch(DatabaseException e) {\r
+            System.err.println(e.getMessage());\r
+            return null;\r
+        }\r
+    }\r
+    \r
+    public InteropResource(ReadGraph graph) {\r
+        ImportLibrary = getResourceOrNull(graph, URIs.ImportLibrary);\r
+        InteropFeature = getResourceOrNull(graph, URIs.InteropFeature);\r
+    }\r
+    \r
+    public static InteropResource getInstance(ReadGraph graph) {\r
+        Session session = graph.getSession();\r
+        InteropResource ret = session.peekService(InteropResource.class);\r
+        if(ret == null) {\r
+            ret = new InteropResource(graph);\r
+            session.registerService(InteropResource.class, ret);\r
+        }\r
+        return ret;\r
+    }\r
+    \r
+    public static InteropResource getInstance(Session session) throws DatabaseException {\r
+        InteropResource ret = session.peekService(InteropResource.class);\r
+        if(ret == null) {\r
+            ret = session.syncRequest(new Read<InteropResource>() {\r
+                public InteropResource perform(ReadGraph graph) throws DatabaseException {\r
+                    return new InteropResource(graph);\r
+                }\r
+            });\r
+            session.registerService(InteropResource.class, ret);\r
+        }\r
+        return ret;\r
+    }\r
+    \r
+}\r
+\r