/******************************************************************************* * 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.awt.AlphaComposite; import java.awt.Color; import java.util.HashMap; import java.util.Map; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.profile.ProfileKeys; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.layer0.Layer0; import org.simantics.scenegraph.INode; import org.simantics.scenegraph.profile.DataNodeMap; import org.simantics.scenegraph.profile.EvaluationContext; import org.simantics.scenegraph.profile.Group; import org.simantics.scenegraph.profile.Style; import org.simantics.scenegraph.profile.common.ObserverGroupListener; import org.simantics.scenegraph.profile.common.ProfileVariables; public class ConstantStyle implements Style { final String name; final Map values = new HashMap(); ObserverGroupListener listener = null; double priority; public ConstantStyle(ReadGraph graph, Resource style) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); DiagramResource DIA = DiagramResource.getInstance(graph); this.name = graph.getPossibleRelatedValue(style, L0.HasName, Bindings.STRING); String[] values = graph.getPossibleRelatedValue(style, DIA.HasValues, Bindings.getBindingUnchecked(String[].class)); for(int i=0;i value : values.entrySet()) { for(Object item : listener.getItems()) { final INode node = map.getNode(item); // final IElement element = map.getElement(diagram, item); if(node == null) { //observer.exception(new NullPointerException("ConstantStyle.apply: no element for " + item)); evaluationContext.update(); return; } ProfileVariables.claimNodeProperty(node, value.getKey(), value.getValue(), evaluationContext); //// System.out.println("apply[" + element + "]: " + value.getKey() + " => " + value.getValue()); // Variables.set(node, value.getKey(), value.getValue(), evaluationContext); // // PropertySetter setter = element.getElementClass().getAtMostOneItemOfClass(PropertySetter.class); // if(setter != null) // setter.syncPropertiesToNode(element); } } } @Override public final void apply2(Object item, final EvaluationContext evaluationContext) { final DataNodeMap map = evaluationContext.getConstant(ProfileKeys.NODE_MAP); final INode node = map.getNode(item); for(Map.Entry value : values.entrySet()) { ProfileVariables.claimNodeProperty(node, value.getKey(), value.getValue(), evaluationContext); } } @Override public String toString() { return name; } }