X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Felements%2FElementPropertySetter.java;h=5e3856745dfdfda8ff72787feab1dcaa6e3f0747;hb=HEAD;hp=d2f93c428955e5113935e97b4620e2a68b3645cb;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/ElementPropertySetter.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/ElementPropertySetter.java index d2f93c428..5e3856745 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/ElementPropertySetter.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/ElementPropertySetter.java @@ -1,82 +1,82 @@ -/******************************************************************************* - * 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.elements; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.AdaptionException; -import org.simantics.db.exception.DoesNotContainValueException; -import org.simantics.db.exception.NoSingleResultException; -import org.simantics.db.exception.ServiceException; -import org.simantics.db.exception.ValidationException; -import org.simantics.diagram.G2DUtils; -import org.simantics.g2d.element.ElementHints; -import org.simantics.g2d.element.ElementHints.Properties; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.elementclass.PlainElementPropertySetter; -import org.simantics.layer0.Layer0; -import org.simantics.utils.datastructures.hints.IHintContext.Key; - -public class ElementPropertySetter extends PlainElementPropertySetter { - - private static final long serialVersionUID = 712071316674596405L; - - public static final ElementPropertySetter INSTANCE = new ElementPropertySetter(ElementHints.KEY_SG_NODE); - - public ElementPropertySetter(Key key) { - super(key); - } - - /** - * Load default properties from graph. This is called by class factory, hence not defined in the interface - * - * @param element - * @param r - * @param g - */ - public void loadProperties(IElement element, Resource r, ReadGraph g) { - Properties properties = new Properties(); - Layer0 L0 = Layer0.getInstance(g); - try { - // This way asserts do work: - for (Resource predicate : g.getPredicates(r)) { - if (g.isSubrelationOf(predicate, L0.HasProperty)) { - try { - String name = g.adapt(predicate, String.class); - Resource o = g.getPossibleObject(r, predicate); - if(o != null) { // FIXME: there should always be an object.. - Object val = G2DUtils.getObject(g, o); -// System.out.println(name+" = "+val); - properties.put(name, val); - } - } catch (AdaptionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ValidationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSingleResultException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (DoesNotContainValueException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } catch (ServiceException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - element.setHint(ElementHints.KEY_ELEMENT_PROPERTIES, properties); - } -} +/******************************************************************************* + * 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.elements; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DoesNotContainValueException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.exception.ValidationException; +import org.simantics.diagram.G2DUtils; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementHints.Properties; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.elementclass.PlainElementPropertySetter; +import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.hints.IHintContext.Key; + +public class ElementPropertySetter extends PlainElementPropertySetter { + + private static final long serialVersionUID = 712071316674596405L; + + public static final ElementPropertySetter INSTANCE = new ElementPropertySetter(ElementHints.KEY_SG_NODE); + + public ElementPropertySetter(Key key) { + super(key); + } + + /** + * Load default properties from graph. This is called by class factory, hence not defined in the interface + * + * @param element + * @param r + * @param g + */ + public void loadProperties(IElement element, Resource r, ReadGraph g) { + Properties properties = new Properties(); + Layer0 L0 = Layer0.getInstance(g); + try { + // This way asserts do work: + for (Resource predicate : g.getPredicates(r)) { + if (g.isSubrelationOf(predicate, L0.HasProperty)) { + try { + String name = g.adapt(predicate, String.class); + Resource o = g.getPossibleObject(r, predicate); + if(o != null) { // FIXME: there should always be an object.. + Object val = G2DUtils.getObject(g, o); +// System.out.println(name+" = "+val); + properties.put(name, val); + } + } catch (AdaptionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ValidationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSingleResultException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (DoesNotContainValueException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } catch (ServiceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + element.setHint(ElementHints.KEY_ELEMENT_PROPERTIES, properties); + } +}