]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/model/NodeData.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.debug.graphical / src / org / simantics / debug / graphical / model / NodeData.java
1 package org.simantics.debug.graphical.model;
2
3 import java.util.ArrayList;
4
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;
13
14 public class NodeData {
15     Resource resource;    
16     String[] labels;
17     ArrayList<Statement> statements = new ArrayList<Statement>();
18     
19     public NodeData(Resource resource) {
20         this.resource = resource;
21     }
22
23     public String[] getLabels() {
24         return labels;
25     }
26     
27     public void updateData(ReadGraph g, LabelingPreferences pref) throws DatabaseException {
28         Layer0 L0 = Layer0.getInstance(g);
29         
30         Resource name = null;
31         Resource label = null;
32         ArrayList<Resource> types = new ArrayList<Resource>(); 
33         ArrayList<Resource> tags = new ArrayList<Resource>();
34         
35         statements.clear();
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()))
46                     tags.add(predicate);
47                 else if(g.isSubrelationOf(predicate, L0.HasNext) ||
48                                 g.isSubrelationOf(predicate, L0.HasPrevious))
49                         ;
50                 else
51                     statements.add(stat);
52             }
53         }
54
55         { // Compute labels
56             ArrayList<String> labels = new ArrayList<String>(4);
57             labels.add("$" + resource.getResourceId());
58             if(name != null)
59                 labels.add((String)g.getValue(name, Bindings.STRING));
60             if(label != null)
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()]);
67         }
68     }
69     
70     public Resource getResource() {
71         return resource;
72     }
73     
74     public ArrayList<Statement> getStatements() {
75         return statements;
76     }
77     
78     public void setStatements(ArrayList<Statement> statements) {
79         this.statements = statements;
80     }
81 }