X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.debug.graphical%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fgraphical%2Fmodel%2FNodeData.java;fp=bundles%2Forg.simantics.debug.graphical%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fgraphical%2Fmodel%2FNodeData.java;h=17e6f12ca50ed2857d22d082358b0d8cc4217b76;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/model/NodeData.java b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/model/NodeData.java new file mode 100644 index 000000000..17e6f12ca --- /dev/null +++ b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/model/NodeData.java @@ -0,0 +1,81 @@ +package org.simantics.debug.graphical.model; + +import java.util.ArrayList; + +import org.simantics.databoard.Bindings; +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.debug.graphical.LabelingPreferences; +import org.simantics.layer0.Layer0; + +public class NodeData { + Resource resource; + String[] labels; + ArrayList statements = new ArrayList(); + + public NodeData(Resource resource) { + this.resource = resource; + } + + public String[] getLabels() { + return labels; + } + + public void updateData(ReadGraph g, LabelingPreferences pref) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(g); + + Resource name = null; + Resource label = null; + ArrayList types = new ArrayList(); + ArrayList tags = new ArrayList(); + + statements.clear(); + for(Statement stat : g.getStatements(resource, L0.IsWeaklyRelatedTo)) { + if(stat.getSubject().equals(resource)) { + Resource predicate = stat.getPredicate(); + if(predicate.equals(L0.InstanceOf)) + types.add(stat.getObject()); + else if(predicate.equals(L0.HasName)) + name = stat.getObject(); + else if(predicate.equals(L0.HasLabel)) + label = stat.getObject(); + else if(resource.equals(stat.getObject())) + tags.add(predicate); + else if(g.isSubrelationOf(predicate, L0.HasNext) || + g.isSubrelationOf(predicate, L0.HasPrevious)) + ; + else + statements.add(stat); + } + } + + { // Compute labels + ArrayList labels = new ArrayList(4); + labels.add("$" + resource.getResourceId()); + if(name != null) + labels.add((String)g.getValue(name, Bindings.STRING)); + if(label != null) + labels.add((String)g.getValue(label, Bindings.STRING)); + for(Resource type : types) + labels.add(": " + NameUtils.getSafeName(g, type)); + for(Resource tag : tags) + labels.add("TAG " + NameUtils.getSafeName(g, tag)); + this.labels = labels.toArray(new String[labels.size()]); + } + } + + public Resource getResource() { + return resource; + } + + public ArrayList getStatements() { + return statements; + } + + public void setStatements(ArrayList statements) { + this.statements = statements; + } +}