-/*******************************************************************************\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.elements;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.AdaptionException;\r
-import org.simantics.db.exception.DoesNotContainValueException;\r
-import org.simantics.db.exception.NoSingleResultException;\r
-import org.simantics.db.exception.ServiceException;\r
-import org.simantics.db.exception.ValidationException;\r
-import org.simantics.diagram.G2DUtils;\r
-import org.simantics.g2d.element.ElementHints;\r
-import org.simantics.g2d.element.ElementHints.Properties;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.elementclass.PlainElementPropertySetter;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-\r
-public class ElementPropertySetter extends PlainElementPropertySetter {\r
-\r
- private static final long serialVersionUID = 712071316674596405L;\r
-\r
- public static final ElementPropertySetter INSTANCE = new ElementPropertySetter(ElementHints.KEY_SG_NODE);\r
-\r
- public ElementPropertySetter(Key key) {\r
- super(key);\r
- }\r
-\r
- /**\r
- * Load default properties from graph. This is called by class factory, hence not defined in the interface\r
- * \r
- * @param element\r
- * @param r\r
- * @param g\r
- */\r
- public void loadProperties(IElement element, Resource r, ReadGraph g) {\r
- Properties properties = new Properties();\r
- Layer0 L0 = Layer0.getInstance(g);\r
- try {\r
- // This way asserts do work:\r
- for (Resource predicate : g.getPredicates(r)) {\r
- if (g.isSubrelationOf(predicate, L0.HasProperty)) {\r
- try {\r
- String name = g.adapt(predicate, String.class);\r
- Resource o = g.getPossibleObject(r, predicate);\r
- if(o != null) { // FIXME: there should always be an object..\r
- Object val = G2DUtils.getObject(g, o);\r
-// System.out.println(name+" = "+val);\r
- properties.put(name, val);\r
- }\r
- } catch (AdaptionException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (ValidationException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (NoSingleResultException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (DoesNotContainValueException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
- } catch (ServiceException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- }\r
- element.setHint(ElementHints.KEY_ELEMENT_PROPERTIES, properties);\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.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);
+ }
+}