1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.chart.property;
14 import java.util.ArrayList;
15 import java.util.Collections;
17 import org.simantics.databoard.Bindings;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.RelationContext;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Statement;
22 import org.simantics.db.common.adaption.SimpleContextualAdapter;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.layer0.property.OrderedResource;
25 import org.simantics.operation.Layer0X;
28 * @author Tuukka Lehtonen
30 public class ObtainedDoubleAdapter extends SimpleContextualAdapter<Double, RelationContext> {
33 public Double adapt(ReadGraph graph, Resource source, RelationContext context) throws DatabaseException {
34 Layer0X L0X = Layer0X.getInstance(graph);
35 ArrayList<OrderedResource> order = new ArrayList<OrderedResource>();
36 for (Statement stm : graph.getStatements(context.getSubject(), L0X.ObtainsProperty)) {
37 Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation,
39 order.add(new OrderedResource(position, stm.getObject()));
42 Collections.sort(order);
43 for (OrderedResource or : order) {
44 Double result = graph.getPossibleRelatedAdapter(or.r, context.getStatement().getPredicate(), Double.class);