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