]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ExpressionStyle.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / ExpressionStyle.java
index d58fe424553a0b3d31d0b75fdf8b04718c42a370..aa116fb881521e25d36079b54aea6fadef99fda8 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.diagram.adapter;\r
-\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.diagram.profile.StyleBase;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.operation.Layer0X;\r
-import org.simantics.scenegraph.INode;\r
-import org.simantics.scenegraph.profile.EvaluationContext;\r
-import org.simantics.scenegraph.profile.common.ProfileVariables;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-\r
-/**\r
- * @author Antti Villberg\r
- */\r
-public class ExpressionStyle extends StyleBase<Map<String, Object>> {\r
-\r
-       final Resource style;\r
-\r
-       public ExpressionStyle(Resource style) {\r
-               this.style = style;\r
-       }\r
-\r
-       @Override\r
-       public Map<String, Object> calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable activeVariable) throws DatabaseException {\r
-\r
-               //System.err.println("calculateExpressionStyle " + activeVariable.getURI(graph));\r
-\r
-               Layer0 L0 = Layer0.getInstance(graph);\r
-               Layer0X L0X = Layer0X.getInstance(graph);\r
-               DiagramResource DIA = DiagramResource.getInstance(graph);\r
-               ModelingResources MOD = ModelingResources.getInstance(graph);\r
-               StructuralResource2 SR = StructuralResource2.getInstance(graph);\r
-               \r
-               String key = graph.getPossibleRelatedValue(style, DIA.HasVariableName, Bindings.STRING);\r
-               String expression = graph.getPossibleRelatedValue(style, L0X.HasExpression, Bindings.STRING);\r
-               //System.out.println(key + ": " + expression);\r
-\r
-               Resource module = graph.getPossibleObject(element, MOD.ElementToComponent);\r
-               if (module == null)\r
-                       return null;\r
-\r
-               Resource svg = null;\r
-               Resource elementType = graph.getPossibleType(element, L0.Entity);\r
-               if(elementType == null) return null;\r
-               Resource definition = graph.getPossibleObject(elementType, SR.IsDefinedBy);\r
-               if(definition == null) return null;\r
-               List<Resource> items = OrderedSetUtils.toList(graph, definition);\r
-               if(items == null) return null;\r
-               for(Resource item : items) {\r
-                       if(graph.isInstanceOf(item, DIA.AnimatedSVGElement)) {\r
-                               svg = item;\r
-                               break;\r
-                       }\r
-               }\r
-               if(svg == null) return null;\r
-\r
-               String moduleName = graph.getPossibleRelatedValue(module, L0.HasName, Bindings.STRING);\r
-               if (moduleName == null)\r
-                       return null;\r
-\r
-               Variable moduleVariable = activeVariable.getChild(graph, moduleName);\r
-\r
-               //System.err.println("mv " + moduleVariable.getURI(graph));\r
-\r
-               Object value = moduleVariable.getPossiblePropertyValue(graph, expression);\r
-               Map<String, Object> values = Collections.singletonMap(key, value);\r
-               \r
-//             for(Resource desc : graph.getObjects(svg, DIA.HasConfigurationVariable)) {\r
-//                     String name = graph.getRelatedValue(desc, L0.HasName);\r
-//                     System.err.println("name=" + name);\r
-//                     String formula = graph.getRelatedValue(desc, L0X.HasExpression);\r
-//                     Object value = moduleVariable.getPossiblePropertyValue(graph, formula);\r
-//                     System.err.println(name + " => " + formula + " => " + value);\r
-//                     values.put(name, value);\r
-//             }\r
-\r
-               return values;\r
-\r
-       }\r
-\r
-       @Override\r
-       public void applyStyleForNode(EvaluationContext evaluationContext, INode node, Map<String, Object> values) {\r
-           //System.out.println(this + ": apply values " + values);\r
-           if (values == null)\r
-               return;\r
-\r
-           ProfileVariables.claimNodeProperty(node, "valuezz", values, evaluationContext);\r
-           \r
-//         Variables.set(element, "valuezz", values, observer);\r
-////       for(Map.Entry<String, Object> entry : values.entrySet()) {\r
-////           Variables.set(element, entry.getKey(), entry.getValue(), observer);\r
-////       }\r
-//\r
-//         PropertySetter setter = element.getElementClass().getAtMostOneItemOfClass(PropertySetter.class);\r
-//         if (setter != null)\r
-//             setter.syncPropertiesToNode(element);\r
-       }\r
-\r
-       @Override\r
-       protected void cleanupStyleForNode(EvaluationContext observer, INode node) {\r
-           ProfileVariables.init(node, observer);\r
-       }\r
-\r
-       @Override\r
-       public String toString() {\r
-               return "Expression";\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * 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<Map<String, Object>> {
+
+       final Resource style;
+
+       public ExpressionStyle(Resource style) {
+               this.style = style;
+       }
+
+       @Override
+       public Map<String, Object> 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<Resource> 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<String, Object> 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<String, Object> 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<String, Object> 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";
+       }
+
+}