]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/SelectedProfile.java
Better support for ontological profiles
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / view / SelectedProfile.java
1 package org.simantics.diagram.profile.view;
2
3 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;
4 import org.simantics.databoard.Bindings;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.Resource;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.diagram.stubs.DiagramResource;
9 import org.simantics.layer0.Layer0;
10 import org.simantics.utils.strings.StringUtils;
11
12 public class SelectedProfile extends ReadFactoryImpl<Resource, String> {
13
14         @Override
15         public String perform(ReadGraph graph, Resource runtimeDiagram) throws DatabaseException {
16                 Layer0 L0 = Layer0.getInstance(graph);
17                 DiagramResource DIA = DiagramResource.getInstance(graph);
18                 Resource profile = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile);
19                 if(profile == null) return null;
20                 String name = graph.getPossibleRelatedValue(profile, L0.HasName, Bindings.STRING);
21                 return StringUtils.safeString(name);
22         }
23
24 }