]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/ElementStringAdapter.java
Expose proxied subject in GroupProxySymbolItem
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / ElementStringAdapter.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.adapters;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.adaption.SimpleAdapter;
17 import org.simantics.db.exception.AdaptionException;
18 import org.simantics.db.exception.ServiceException;
19 import org.simantics.db.exception.ValidationException;
20 import org.simantics.layer0.Layer0;
21 import org.simantics.modeling.ModelingResources;
22
23 public class ElementStringAdapter extends SimpleAdapter<String> {
24
25     @Override
26     public String adapt(ReadGraph g, Resource r) throws ValidationException, ServiceException {
27
28         try {
29             ModelingResources mr = ModelingResources.getInstance(g);
30             Resource name = r;
31             Resource component = g.getPossibleObject(r, mr.ElementToComponent);
32             if (component != null)
33                 name = component;
34             StringBuilder sb = new StringBuilder();
35                 Layer0 b = Layer0.getInstance(g);
36             String nameName = g.getPossibleRelatedValue(name, b.HasName);
37             if (nameName != null)
38                 sb.append(nameName);
39             boolean first = true;
40             for (Resource rType : g.getPrincipalTypes(r)) {
41                 String s = g.adapt(rType, String.class);
42                 if (first) {
43                     sb.append(" : ");
44                     first = false;
45                 } else {
46                     sb.append(", ");
47                 }
48                 sb.append(s);
49             }
50             return sb.toString();
51         } catch (AdaptionException e) {
52             
53             throw new ValidationException(e);
54             
55         }
56         
57     }
58
59 }