--- /dev/null
+/*******************************************************************************\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.modeling.adapters;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.adaption.SimpleAdapter;\r
+import org.simantics.db.exception.AdaptionException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.exception.ValidationException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
+\r
+public class ElementStringAdapter extends SimpleAdapter<String> {\r
+\r
+ @Override\r
+ public String adapt(ReadGraph g, Resource r) throws ValidationException, ServiceException {\r
+\r
+ try {\r
+ ModelingResources mr = ModelingResources.getInstance(g);\r
+ Resource name = r;\r
+ Resource component = g.getPossibleObject(r, mr.ElementToComponent);\r
+ if (component != null)\r
+ name = component;\r
+ StringBuilder sb = new StringBuilder();\r
+ Layer0 b = Layer0.getInstance(g);\r
+ String nameName = g.getPossibleRelatedValue(name, b.HasName);\r
+ if (nameName != null)\r
+ sb.append(nameName);\r
+ boolean first = true;\r
+ for (Resource rType : g.getPrincipalTypes(r)) {\r
+ String s = g.adapt(rType, String.class);\r
+ if (first) {\r
+ sb.append(" : ");\r
+ first = false;\r
+ } else {\r
+ sb.append(", ");\r
+ }\r
+ sb.append(s);\r
+ }\r
+ return sb.toString();\r
+ } catch (AdaptionException e) {\r
+ \r
+ throw new ValidationException(e);\r
+ \r
+ }\r
+ \r
+ }\r
+\r
+}\r