]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Initial implementation of ISceneGraphProvider for Sysdyn resources. Can be used to...
authorjplaine <jplaine@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 3 Mar 2010 12:51:16 +0000 (12:51 +0000)
committerjplaine <jplaine@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 3 Mar 2010 12:51:16 +0000 (12:51 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14525 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/adapters.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java [new file with mode: 0644]

index 3af512f2a48763c924795e224095aa2b920da237..21a73a133ac14a66f660b972461fd04f1578aa71 100644 (file)
@@ -6,4 +6,13 @@
                        uri="http://www.simantics.org/Sysdyn#SysdynProject"\r
                        class="org.simantics.sysdyn.ui.project.SysdynProject" />\r
        </target>\r
+       <target\r
+               interface="org.simantics.scenegraph.adapters.ISceneGraphProvider">\r
+               <type\r
+                       uri="http://www.simantics.org/Sysdyn#Configuration"\r
+                       class="org.simantics.sysdyn.ui.sg.SysdynSceneGraphProvider">\r
+                       <graph />\r
+                       <this />\r
+               </type>\r
+       </target>\r
 </adapters>
\ No newline at end of file
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java
new file mode 100644 (file)
index 0000000..98a7f24
--- /dev/null
@@ -0,0 +1,161 @@
+package org.simantics.sysdyn.ui.sg;\r
+\r
+import java.awt.AWTEvent;\r
+import java.awt.event.AWTEventListener;\r
+import java.awt.geom.Rectangle2D;\r
+\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.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.h2d.diagram.IDiagram;\r
+import org.simantics.h2d.diagram.IDiagramListener;\r
+import org.simantics.h2d.element.IElement;\r
+import org.simantics.objmap.IMapping;\r
+import org.simantics.objmap.IMappingListener;\r
+import org.simantics.objmap.MappingException;\r
+import org.simantics.objmap.Mappings;\r
+import org.simantics.scenegraph.adapters.ISceneGraphProvider;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.scenegraph.g2d.G2DSceneGraph;\r
+import org.simantics.scenegraph.g2d.nodes.NavigationNode;\r
+import org.simantics.scenegraph.g2d.nodes.PageBorderNode;\r
+import org.simantics.scenegraph.g2d.nodes.TransformNode;\r
+import org.simantics.sysdyn.ui.editor.SysdynDiagramSchema;\r
+\r
+public class SysdynSceneGraphProvider implements ISceneGraphProvider, AWTEventListener {\r
+\r
+    protected Resource resource;\r
+\r
+       IDiagram diagram;\r
+       IMapping mapping;\r
+\r
+    public SysdynSceneGraphProvider(ReadGraph g, final Resource resource) {\r
+       this.resource = resource;\r
+       \r
+               SysdynDiagramSchema schema;\r
+               try {\r
+                       schema = new SysdynDiagramSchema(g);\r
+               } catch (DatabaseException e1) {\r
+                       // TODO Auto-generated catch block\r
+                       e1.printStackTrace();\r
+                       return;\r
+               }\r
+               \r
+               mapping = Mappings.createWithListening(schema);\r
+                               \r
+               try {\r
+                       diagram = (IDiagram)mapping.map(g, resource);\r
+               } catch (MappingException e) {\r
+                       // TODO Auto-generated catch block\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+               final Session session = g.getSession();\r
+               mapping.addMappingListener(new IMappingListener() {\r
+                       \r
+                       @Override\r
+                       public void rangeModified() {                       \r
+                               session.asyncRequest(new WriteRequest() {\r
+                                       \r
+                                       @Override\r
+                                       public void perform(WriteGraph graph)\r
+                                                       throws DatabaseException {\r
+                                           try {\r
+                                               mapping.updateDomain(graph);\r
+                                           } catch(Exception e) {\r
+                                               e.printStackTrace();\r
+                                           }\r
+                                       }\r
+                                       \r
+                               });\r
+                       }\r
+                       \r
+                       @Override\r
+                       public void domainModified() {\r
+                           session.asyncRequest(new ReadRequest() {\r
+                    \r
+                    @Override\r
+                    public void run(ReadGraph graph) throws DatabaseException {\r
+                        try {\r
+                            mapping.updateRange(graph);\r
+                        } catch(Exception e) {\r
+                            e.printStackTrace();\r
+                        }\r
+                    }\r
+                });\r
+                       }\r
+               });\r
+    }\r
+\r
+       @Override\r
+       public void dispose() {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public AWTEventListener getEventListener() {\r
+               return this;\r
+       }\r
+\r
+       @Override\r
+       public G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg) {\r
+               return initializeSceneGraph(sg, null);\r
+       }\r
+\r
+    G2DSceneGraph sceneGraph;\r
+    TransformNode diagramCoordinatesNode;\r
+    G2DParentNode elementsNode;\r
+    G2DParentNode selectionNode;\r
+    G2DParentNode actionNode;\r
+\r
+       @Override\r
+       public G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg, String view) {\r
+               sceneGraph = sg;\r
+        diagramCoordinatesNode = sceneGraph.addNode(NavigationNode.class);\r
+\r
+        PageBorderNode border = diagramCoordinatesNode.addNode(PageBorderNode.class);\r
+        border.init(new Rectangle2D.Double(0.0, 0.0, 297.0, 210.0), new Rectangle2D.Double(10.0, 10.0, 277.0, 190.0), Boolean.TRUE);\r
+\r
+        elementsNode = diagramCoordinatesNode.addNode(G2DParentNode.class);\r
+        elementsNode.setZIndex(0);\r
+\r
+        selectionNode = diagramCoordinatesNode.addNode(G2DParentNode.class);\r
+        selectionNode.setZIndex(1);\r
+\r
+        actionNode = diagramCoordinatesNode.addNode(G2DParentNode.class);\r
+        actionNode.setZIndex(2);\r
+        \r
+               for(IElement element : diagram.getElements())\r
+                       element.init(elementsNode);\r
+               diagram.addDiagramListener(new IDiagramListener() {\r
+                       \r
+                       @Override\r
+                       public void elementAdded(IElement element) {\r
+                               element.init(elementsNode);\r
+                       }\r
+\r
+                       @Override\r
+                       public void elementRemoved(IElement element) {\r
+                               element.remove();\r
+                       }\r
+               });\r
+        \r
+               return sg;\r
+       }\r
+\r
+       @Override\r
+       public void setHint(Object key, Object value) {\r
+               // TODO Auto-generated method stub\r
+\r
+       }\r
+\r
+       @Override\r
+       public void eventDispatched(AWTEvent event) {\r
+               \r
+       }\r
+\r
+}\r