1 package org.simantics.modeling.ui.diagram.monitor;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Collections;
\r
6 import org.simantics.databoard.Bindings;
\r
7 import org.simantics.db.ReadGraph;
\r
8 import org.simantics.db.RelationContext;
\r
9 import org.simantics.db.Resource;
\r
10 import org.simantics.db.Statement;
\r
11 import org.simantics.db.common.adaption.SimpleContextualAdapter;
\r
12 import org.simantics.db.exception.DatabaseException;
\r
13 import org.simantics.db.layer0.property.OrderedResource;
\r
14 import org.simantics.operation.Layer0X;
\r
16 public class ObtainedExpressionAdapter extends SimpleContextualAdapter<String, RelationContext> {
\r
19 public String adapt(ReadGraph graph, Resource source, RelationContext context) throws DatabaseException {
\r
21 Layer0X L0X = Layer0X.getInstance(graph);
\r
22 ArrayList<OrderedResource> order = new ArrayList<OrderedResource>();
\r
23 for(Statement stm : graph.getStatements(context.getSubject(), L0X.ObtainsProperty)) {
\r
24 Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation, Bindings.INTEGER);
\r
25 order.add(new OrderedResource(position, stm.getObject()));
\r
27 if (order.size() > 1)
\r
28 Collections.sort(order);
\r
29 for(OrderedResource or : order) {
\r
30 String result = graph.getPossibleRelatedAdapter(or.r, L0X.HasExpression, String.class);
\r
31 if(result != null) return result;
\r