X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FExpressionStyle.java;h=aa116fb881521e25d36079b54aea6fadef99fda8;hp=d58fe424553a0b3d31d0b75fdf8b04718c42a370;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ExpressionStyle.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ExpressionStyle.java index d58fe4245..aa116fb88 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ExpressionStyle.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ExpressionStyle.java @@ -1,131 +1,131 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.diagram.adapter; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.utils.OrderedSetUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.diagram.profile.StyleBase; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.ModelingResources; -import org.simantics.operation.Layer0X; -import org.simantics.scenegraph.INode; -import org.simantics.scenegraph.profile.EvaluationContext; -import org.simantics.scenegraph.profile.common.ProfileVariables; -import org.simantics.structural.stubs.StructuralResource2; - -/** - * @author Antti Villberg - */ -public class ExpressionStyle extends StyleBase> { - - final Resource style; - - public ExpressionStyle(Resource style) { - this.style = style; - } - - @Override - public Map calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable activeVariable) throws DatabaseException { - - //System.err.println("calculateExpressionStyle " + activeVariable.getURI(graph)); - - Layer0 L0 = Layer0.getInstance(graph); - Layer0X L0X = Layer0X.getInstance(graph); - DiagramResource DIA = DiagramResource.getInstance(graph); - ModelingResources MOD = ModelingResources.getInstance(graph); - StructuralResource2 SR = StructuralResource2.getInstance(graph); - - String key = graph.getPossibleRelatedValue(style, DIA.HasVariableName, Bindings.STRING); - String expression = graph.getPossibleRelatedValue(style, L0X.HasExpression, Bindings.STRING); - //System.out.println(key + ": " + expression); - - Resource module = graph.getPossibleObject(element, MOD.ElementToComponent); - if (module == null) - return null; - - Resource svg = null; - Resource elementType = graph.getPossibleType(element, L0.Entity); - if(elementType == null) return null; - Resource definition = graph.getPossibleObject(elementType, SR.IsDefinedBy); - if(definition == null) return null; - List items = OrderedSetUtils.toList(graph, definition); - if(items == null) return null; - for(Resource item : items) { - if(graph.isInstanceOf(item, DIA.AnimatedSVGElement)) { - svg = item; - break; - } - } - if(svg == null) return null; - - String moduleName = graph.getPossibleRelatedValue(module, L0.HasName, Bindings.STRING); - if (moduleName == null) - return null; - - Variable moduleVariable = activeVariable.getChild(graph, moduleName); - - //System.err.println("mv " + moduleVariable.getURI(graph)); - - Object value = moduleVariable.getPossiblePropertyValue(graph, expression); - Map values = Collections.singletonMap(key, value); - -// for(Resource desc : graph.getObjects(svg, DIA.HasConfigurationVariable)) { -// String name = graph.getRelatedValue(desc, L0.HasName); -// System.err.println("name=" + name); -// String formula = graph.getRelatedValue(desc, L0X.HasExpression); -// Object value = moduleVariable.getPossiblePropertyValue(graph, formula); -// System.err.println(name + " => " + formula + " => " + value); -// values.put(name, value); -// } - - return values; - - } - - @Override - public void applyStyleForNode(EvaluationContext evaluationContext, INode node, Map values) { - //System.out.println(this + ": apply values " + values); - if (values == null) - return; - - ProfileVariables.claimNodeProperty(node, "valuezz", values, evaluationContext); - -// Variables.set(element, "valuezz", values, observer); -//// for(Map.Entry entry : values.entrySet()) { -//// Variables.set(element, entry.getKey(), entry.getValue(), observer); -//// } -// -// PropertySetter setter = element.getElementClass().getAtMostOneItemOfClass(PropertySetter.class); -// if (setter != null) -// setter.syncPropertiesToNode(element); - } - - @Override - protected void cleanupStyleForNode(EvaluationContext observer, INode node) { - ProfileVariables.init(node, observer); - } - - @Override - public String toString() { - return "Expression"; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 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.diagram.adapter; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.diagram.profile.StyleBase; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.operation.Layer0X; +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.common.ProfileVariables; +import org.simantics.structural.stubs.StructuralResource2; + +/** + * @author Antti Villberg + */ +public class ExpressionStyle extends StyleBase> { + + final Resource style; + + public ExpressionStyle(Resource style) { + this.style = style; + } + + @Override + public Map calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable activeVariable) throws DatabaseException { + + //System.err.println("calculateExpressionStyle " + activeVariable.getURI(graph)); + + Layer0 L0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + DiagramResource DIA = DiagramResource.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + StructuralResource2 SR = StructuralResource2.getInstance(graph); + + String key = graph.getPossibleRelatedValue(style, DIA.HasVariableName, Bindings.STRING); + String expression = graph.getPossibleRelatedValue(style, L0X.HasExpression, Bindings.STRING); + //System.out.println(key + ": " + expression); + + Resource module = graph.getPossibleObject(element, MOD.ElementToComponent); + if (module == null) + return null; + + Resource svg = null; + Resource elementType = graph.getPossibleType(element, L0.Entity); + if(elementType == null) return null; + Resource definition = graph.getPossibleObject(elementType, SR.IsDefinedBy); + if(definition == null) return null; + List items = OrderedSetUtils.toList(graph, definition); + if(items == null) return null; + for(Resource item : items) { + if(graph.isInstanceOf(item, DIA.AnimatedSVGElement)) { + svg = item; + break; + } + } + if(svg == null) return null; + + String moduleName = graph.getPossibleRelatedValue(module, L0.HasName, Bindings.STRING); + if (moduleName == null) + return null; + + Variable moduleVariable = activeVariable.getChild(graph, moduleName); + + //System.err.println("mv " + moduleVariable.getURI(graph)); + + Object value = moduleVariable.getPossiblePropertyValue(graph, expression); + Map values = Collections.singletonMap(key, value); + +// for(Resource desc : graph.getObjects(svg, DIA.HasConfigurationVariable)) { +// String name = graph.getRelatedValue(desc, L0.HasName); +// System.err.println("name=" + name); +// String formula = graph.getRelatedValue(desc, L0X.HasExpression); +// Object value = moduleVariable.getPossiblePropertyValue(graph, formula); +// System.err.println(name + " => " + formula + " => " + value); +// values.put(name, value); +// } + + return values; + + } + + @Override + public void applyStyleForNode(EvaluationContext evaluationContext, INode node, Map values) { + //System.out.println(this + ": apply values " + values); + if (values == null) + return; + + ProfileVariables.claimNodeProperty(node, "valuezz", values, evaluationContext); + +// Variables.set(element, "valuezz", values, observer); +//// for(Map.Entry entry : values.entrySet()) { +//// Variables.set(element, entry.getKey(), entry.getValue(), observer); +//// } +// +// PropertySetter setter = element.getElementClass().getAtMostOneItemOfClass(PropertySetter.class); +// if (setter != null) +// setter.syncPropertiesToNode(element); + } + + @Override + protected void cleanupStyleForNode(EvaluationContext observer, INode node) { + ProfileVariables.init(node, observer); + } + + @Override + public String toString() { + return "Expression"; + } + +}