1 package org.simantics.debug.graphical.model;
3 import java.util.ArrayList;
5 import org.simantics.databoard.Bindings;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.Statement;
9 import org.simantics.db.common.utils.NameUtils;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.debug.graphical.LabelingPreferences;
12 import org.simantics.layer0.Layer0;
14 public class NodeData {
17 ArrayList<Statement> statements = new ArrayList<Statement>();
19 public NodeData(Resource resource) {
20 this.resource = resource;
23 public String[] getLabels() {
27 public void updateData(ReadGraph g, LabelingPreferences pref) throws DatabaseException {
28 Layer0 L0 = Layer0.getInstance(g);
31 Resource label = null;
32 ArrayList<Resource> types = new ArrayList<Resource>();
33 ArrayList<Resource> tags = new ArrayList<Resource>();
36 for(Statement stat : g.getStatements(resource, L0.IsWeaklyRelatedTo)) {
37 if(stat.getSubject().equals(resource)) {
38 Resource predicate = stat.getPredicate();
39 if(predicate.equals(L0.InstanceOf))
40 types.add(stat.getObject());
41 else if(predicate.equals(L0.HasName))
42 name = stat.getObject();
43 else if(predicate.equals(L0.HasLabel))
44 label = stat.getObject();
45 else if(resource.equals(stat.getObject()))
47 else if(g.isSubrelationOf(predicate, L0.HasNext) ||
48 g.isSubrelationOf(predicate, L0.HasPrevious))
56 ArrayList<String> labels = new ArrayList<String>(4);
57 labels.add("$" + resource.getResourceId());
59 labels.add((String)g.getValue(name, Bindings.STRING));
61 labels.add((String)g.getValue(label, Bindings.STRING));
62 for(Resource type : types)
63 labels.add(": " + NameUtils.getSafeName(g, type));
64 for(Resource tag : tags)
65 labels.add("TAG " + NameUtils.getSafeName(g, tag));
66 this.labels = labels.toArray(new String[labels.size()]);
70 public Resource getResource() {
74 public ArrayList<Statement> getStatements() {
78 public void setStatements(ArrayList<Statement> statements) {
79 this.statements = statements;