]> gerrit.simantics Code Review - simantics/platform.git/blob
2d136e8abfbb1d942c44f5daa14f34da6d1d3c78
[simantics/platform.git] /
1 package org.simantics.modeling.ui.diagram.monitor;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5
6 import org.simantics.databoard.Bindings;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.RelationContext;
9 import org.simantics.db.Resource;
10 import org.simantics.db.Statement;
11 import org.simantics.db.common.adaption.SimpleContextualAdapter;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.property.OrderedResource;
14 import org.simantics.operation.Layer0X;
15
16 public class ObtainedExpressionAdapter extends SimpleContextualAdapter<String, RelationContext> {
17
18         @Override
19         public String adapt(ReadGraph graph, Resource source, RelationContext context) throws DatabaseException {
20                 
21                 Layer0X L0X = Layer0X.getInstance(graph);
22                 ArrayList<OrderedResource> order = new ArrayList<OrderedResource>();
23                 for(Statement stm : graph.getStatements(context.getSubject(), L0X.ObtainsProperty)) {
24                         Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation, Bindings.INTEGER);
25                         order.add(new OrderedResource(position, stm.getObject()));
26                 }
27                 if (order.size() > 1)
28                         Collections.sort(order);
29                 for(OrderedResource or : order) {
30                         String result = graph.getPossibleRelatedAdapter(or.r, L0X.HasExpression, String.class);
31                         if(result != null) return result;
32                 }
33                 
34                 return null;
35                 
36         }
37
38 }