X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fchart%2Fproperty%2FObtainedDoubleAdapter.java;h=ff257169ca01e1272b57e62ff1dd259d82aa6601;hp=7ae1cd835f2058cd0bf1f5ca74d04e985145dc9e;hb=4e8f62e4f5a8da113ee576a856b18274ca2a472f;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/ObtainedDoubleAdapter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/ObtainedDoubleAdapter.java index 7ae1cd835..ff257169c 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/ObtainedDoubleAdapter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/ObtainedDoubleAdapter.java @@ -1,52 +1,53 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.ui.chart.property; - -import java.util.ArrayList; -import java.util.Collections; - -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.RelationContext; -import org.simantics.db.Resource; -import org.simantics.db.Statement; -import org.simantics.db.common.adaption.SimpleContextualAdapter; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.property.OrderedResource; -import org.simantics.operation.Layer0X; - -/** - * @author Tuukka Lehtonen - */ -public class ObtainedDoubleAdapter extends SimpleContextualAdapter { - - @Override - public Double adapt(ReadGraph graph, Resource source, RelationContext context) throws DatabaseException { - Layer0X L0X = Layer0X.getInstance(graph); - ArrayList order = new ArrayList(); - for (Statement stm : graph.getStatements(context.getSubject(), L0X.ObtainsProperty)) { - Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation, - Bindings.INTEGER); - order.add(new OrderedResource(position, stm.getObject())); - } - if (order.size() > 1) - Collections.sort(order); - for (OrderedResource or : order) { - Double result = graph.getPossibleRelatedAdapter(or.r, context.getStatement().getPredicate(), Double.class); - if (result != null) - return result; - } - - return null; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.chart.property; + +import java.util.ArrayList; +import java.util.Collections; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.RelationContext; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.common.adaption.SimpleContextualAdapter; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.property.OrderedResource; +import org.simantics.operation.Layer0X; + +/** + * @author Tuukka Lehtonen + */ +public class ObtainedDoubleAdapter extends SimpleContextualAdapter { + + @Override + public Double adapt(ReadGraph graph, Resource source, RelationContext context) throws DatabaseException { + Layer0X L0X = Layer0X.getInstance(graph); + ArrayList order = new ArrayList(); + for (Statement stm : graph.getStatements(context.getSubject(), L0X.ObtainsProperty)) { + Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation, + Bindings.INTEGER); + order.add(new OrderedResource(position, stm.getObject())); + } + if (order.size() > 1) + Collections.sort(order); + for (OrderedResource or : order) { + Double result = graph.getPossibleRelatedAdapter(or.r, context.getStatement().getPredicate(), Double.class); + if (result != null) + return result; + } + + throw new AdaptionException("No obtained double available"); + } + +}