X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=inline;f=bundles%2Forg.simantics.structural.ui%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fui%2FcompositeViewer%2FCreateCompositeGraph.java;h=569426ac70db1912ae953de970915bced878571b;hb=refs%2Fchanges%2F57%2F2357%2F1;hp=2a125afe3b9a74629a405f5e2379c6f3d51f8e9f;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/compositeViewer/CreateCompositeGraph.java b/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/compositeViewer/CreateCompositeGraph.java index 2a125afe3..569426ac7 100644 --- a/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/compositeViewer/CreateCompositeGraph.java +++ b/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/compositeViewer/CreateCompositeGraph.java @@ -1,105 +1,105 @@ -/******************************************************************************* - * 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 { - - 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 connections = new HashMap(); - - 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; - } - -} +/******************************************************************************* + * 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 { + + 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 connections = new HashMap(); + + 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; + } + +}