1 package org.simantics.modeling.ui.view;
3 import java.util.Collection;
6 import org.simantics.charts.ontology.ChartResource;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.databoard.util.URIStringUtils;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.common.utils.NameUtils;
12 import org.simantics.db.common.utils.Versions;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.layer0.Layer0;
15 import org.simantics.modeling.All;
16 import org.simantics.modeling.ModelingResources;
17 import org.simantics.modeling.adapters.ChangeInformation;
18 import org.simantics.modeling.subscription.SubscriptionItemLabel;
19 import org.simantics.utils.format.ValueFormat;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
25 private static final Logger LOGGER = LoggerFactory.getLogger(Bean.class);
27 public String createdBy = "";
28 public String modifiedBy = "";
29 public long modifiedAt = 0;
30 public long createdAt = 0;
31 public String name = "";
32 public String path = "";
33 public String types = "";
39 public Bean(ReadGraph graph, Resource r, ChangeInformation i, String baseURI) throws DatabaseException {
41 Layer0 L0 = Layer0.getInstance(graph);
42 ModelingResources MOD = ModelingResources.getInstance(graph);
43 ChartResource CHART = ChartResource.getInstance(graph);
45 Collection<Resource> principalTypes = graph.getPrincipalTypes(r);
47 if (principalTypes.contains(MOD.Subscription)) {
48 String label = graph.getPossibleRelatedValue2(r, L0.HasLabel, Bindings.STRING);
49 setName((label != null && !label.isEmpty()) ? label : "<unnamed subscription>");
50 } else if (principalTypes.contains(MOD.Subscription_Item)) {
51 String label = SubscriptionItemLabel.resolveLabel(graph, r, ValueFormat.Default, true, true, false);
53 } else if (principalTypes.contains(CHART.Chart_Item)) {
54 String label = graph.getPossibleRelatedValue2(r, L0.HasLabel, Bindings.STRING);
55 setName((label != null && !label.isEmpty()) ? label : "<unlabeled chart item>");
58 Resource possibleComponent = graph.getPossibleObject(r, MOD.ElementToComponent);
59 Resource possibleComposite = graph.getPossibleObject(r, MOD.DiagramToComposite);
61 Resource nameResource = r;
62 if(possibleComponent != null) nameResource = possibleComponent;
63 if(possibleComposite != null) nameResource = possibleComposite;
65 String name = Versions.getStandardNameString(graph, nameResource);
67 if(possibleComponent != null) name += " Element";
68 if(possibleComposite != null) name += " Diagram";
74 StringBuilder types = new StringBuilder();
75 for(Resource t : principalTypes) {
76 if(types.length() > 0) types.append(" ");
77 types.append(NameUtils.getSafeName(graph, t));
80 setTypes(types.toString());
82 Resource parent = graph.getPossibleObject(r, L0.PartOf);
84 String uri = graph.getPossibleURI(parent);
86 if(uri.endsWith("/__CONTAINER__/__DIAGRAM__")) uri = uri.substring(0, uri.length()-"/__CONTAINER__/__DIAGRAM__".length());
87 if(uri.endsWith("/__CONTAINER__")) uri = uri.substring(0, uri.length()-"/__CONTAINER__".length());
88 if(uri.equals(baseURI)) uri = "<selected resource>";
89 if(uri.startsWith(baseURI)) uri = uri.substring(baseURI.length());
90 if(uri.startsWith("/Configuration/")) uri = uri.substring("/Configuration/".length());
92 uri = uri.replace("http://Projects/Development%20Project/", "");
93 uri = URIStringUtils.unescape(uri);
95 if(graph.isInstanceOf(parent, MOD.Subscription)) {
97 String name = graph.getPossibleRelatedValue(parent, L0.HasName, Bindings.STRING);
98 String label = graph.getPossibleRelatedValue(parent, L0.HasLabel, Bindings.STRING);
99 uri = uri.replace(name, label);
105 LOGGER.warn("Could not resolve path (URI) for parent resource {} of child {}", parent, r);
112 setCreatedBy(i.createdBy);
113 setModifiedBy(i.modifiedBy);
114 setModifiedAt(i.modifiedAt);
115 setCreatedAt(i.createdAt);
119 public String getCreatedBy() {
123 public void setCreatedBy(String createdBy) {
124 this.createdBy = createdBy;
127 public String getModifiedBy() {
131 public void setModifiedBy(String modifiedBy) {
132 this.modifiedBy = modifiedBy;
135 public String getModifiedAt() {
136 return All.sdfLong.format(new Date(modifiedAt));
139 public void setModifiedAt(long modifiedAt) {
140 this.modifiedAt = modifiedAt;
143 public String getCreatedAt() {
144 return All.sdfLong.format(new Date(createdAt));
147 public void setCreatedAt(long createdAt) {
148 this.createdAt = createdAt;
151 public String getName() {
155 public void setName(String name) {
159 public String getPath() {
163 public void setPath(String path) {
167 public String getTypes() {
171 public void setTypes(String types) {