]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/compositeViewer/CreateCompositeGraph.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / compositeViewer / CreateCompositeGraph.java
index 2a125afe3b9a74629a405f5e2379c6f3d51f8e9f..569426ac70db1912ae953de970915bced878571b 100644 (file)
-/*******************************************************************************\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.structural.ui.compositeViewer;\r
-\r
-import java.util.HashMap;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Statement;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.graphviz.Edge;\r
-import org.simantics.graphviz.Graph;\r
-import org.simantics.graphviz.Node;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-\r
-public class CreateCompositeGraph implements Read<Graph> {\r
-\r
-       Resource composite;\r
-       \r
-       public CreateCompositeGraph(Resource composite) {\r
-               this.composite = composite;\r
-       }\r
-       \r
-       static class Connection {\r
-               Node parent;\r
-               String label;\r
-               public Connection(Node parent, String label) {\r
-                       this.parent = parent;\r
-                       this.label = label;\r
-               }       \r
-       }\r
-\r
-       private static String getName(ReadGraph g, Resource r) throws DatabaseException {\r
-               String s = g.getPossibleRelatedValue(r, Layer0.getInstance(g).HasName);\r
-               if (s == null)\r
-                       s = NameUtils.getSafeName(g, r);\r
-               return s;\r
-       }\r
-       \r
-       Graph graph;\r
-       HashMap<Resource, Node> connections = new HashMap<Resource, Node>();\r
-       \r
-       private void connect(Node parent, String label, Resource connection) {\r
-               Node cn = connections.get(connection);\r
-               if(cn == null) {\r
-                       cn = new Node(graph);\r
-                       cn.setShape("diamond");\r
-                       cn.setFixedSize(true);\r
-                       cn.setWidth(0.2);\r
-                       cn.setHeight(0.2);\r
-                       connections.put(connection, cn);\r
-               }\r
-               Edge edge = new Edge(parent, cn);\r
-               edge.setArrowhead("none");\r
-               if(label.contains("Self"))\r
-                       edge.setColor("red");\r
-               else\r
-                       edge.setTailLabel(label);\r
-               edge.set("fontsize", "8");\r
-       }\r
-       \r
-       @Override\r
-       public Graph perform(ReadGraph g) throws DatabaseException {\r
-               Layer0 L0 = Layer0.getInstance(g);\r
-               StructuralResource2 STR = StructuralResource2.getInstance(g);\r
-               \r
-               graph = new Graph();\r
-               graph.set("overlap", "false");\r
-               graph.set("splines", "true");\r
-               \r
-               for(Resource child : g.getObjects(composite, L0.ConsistsOf)) {\r
-                       Node node = new Node(graph, getName(g, child));\r
-                       node.setShape("rect");\r
-                       if(g.isInstanceOf(child, STR.Composite)) {\r
-                               for(Resource c : g.getObjects(child, STR.HasConnectionJoin))\r
-                                       connect(node, "", c);\r
-                       }\r
-                       else {\r
-                               for(Statement stat : g.getStatements(child, STR.IsConnectedTo)) {\r
-                                       String label = getName(g, stat.getPredicate());                                 \r
-                                       connect(node, label, stat.getObject());\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               Graph rgraph = graph;\r
-               graph = null;\r
-               connections.clear();\r
-               \r
-               return rgraph;\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.structural.ui.compositeViewer;
+
+import java.util.HashMap;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.graphviz.Edge;
+import org.simantics.graphviz.Graph;
+import org.simantics.graphviz.Node;
+import org.simantics.layer0.Layer0;
+import org.simantics.structural.stubs.StructuralResource2;
+
+public class CreateCompositeGraph implements Read<Graph> {
+
+       Resource composite;
+       
+       public CreateCompositeGraph(Resource composite) {
+               this.composite = composite;
+       }
+       
+       static class Connection {
+               Node parent;
+               String label;
+               public Connection(Node parent, String label) {
+                       this.parent = parent;
+                       this.label = label;
+               }       
+       }
+
+       private static String getName(ReadGraph g, Resource r) throws DatabaseException {
+               String s = g.getPossibleRelatedValue(r, Layer0.getInstance(g).HasName);
+               if (s == null)
+                       s = NameUtils.getSafeName(g, r);
+               return s;
+       }
+       
+       Graph graph;
+       HashMap<Resource, Node> connections = new HashMap<Resource, Node>();
+       
+       private void connect(Node parent, String label, Resource connection) {
+               Node cn = connections.get(connection);
+               if(cn == null) {
+                       cn = new Node(graph);
+                       cn.setShape("diamond");
+                       cn.setFixedSize(true);
+                       cn.setWidth(0.2);
+                       cn.setHeight(0.2);
+                       connections.put(connection, cn);
+               }
+               Edge edge = new Edge(parent, cn);
+               edge.setArrowhead("none");
+               if(label.contains("Self"))
+                       edge.setColor("red");
+               else
+                       edge.setTailLabel(label);
+               edge.set("fontsize", "8");
+       }
+       
+       @Override
+       public Graph perform(ReadGraph g) throws DatabaseException {
+               Layer0 L0 = Layer0.getInstance(g);
+               StructuralResource2 STR = StructuralResource2.getInstance(g);
+               
+               graph = new Graph();
+               graph.set("overlap", "false");
+               graph.set("splines", "true");
+               
+               for(Resource child : g.getObjects(composite, L0.ConsistsOf)) {
+                       Node node = new Node(graph, getName(g, child));
+                       node.setShape("rect");
+                       if(g.isInstanceOf(child, STR.Composite)) {
+                               for(Resource c : g.getObjects(child, STR.HasConnectionJoin))
+                                       connect(node, "", c);
+                       }
+                       else {
+                               for(Statement stat : g.getStatements(child, STR.IsConnectedTo)) {
+                                       String label = getName(g, stat.getPredicate());                                 
+                                       connect(node, label, stat.getObject());
+                               }
+                       }
+               }
+               
+               Graph rgraph = graph;
+               graph = null;
+               connections.clear();
+               
+               return rgraph;
+       }
+
+}