-package org.simantics.diagram.profile.view;\r
-\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.simantics.Simantics;\r
-import org.simantics.browsing.ui.swt.ModelledActionImpl;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.SelectionHints;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
-\r
-public class CreateEntryAction extends ModelledActionImpl<Resource> {\r
-\r
- public CreateEntryAction(Resource configuration) {\r
- super(configuration);\r
- }\r
- \r
- public void run(final Resource runtimeDiagram) {\r
-\r
- ISelection groupSelection = getParameter(DiagramResource.URIs.ProfilesView_NewEntryGroup);\r
- final Resource selectedGroup = ISelectionUtils.getSinglePossibleKey(groupSelection, SelectionHints.KEY_MAIN, Resource.class);\r
- if(selectedGroup == null) return;\r
-\r
- ISelection styleSelection = getParameter(DiagramResource.URIs.ProfilesView_NewEntryStyle);\r
- final Resource selectedStyle = ISelectionUtils.getSinglePossibleKey(styleSelection, SelectionHints.KEY_MAIN, Resource.class);\r
- if(selectedStyle == null) return;\r
-\r
- try {\r
- \r
- Simantics.getSession().syncRequest(new WriteRequest() {\r
- \r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- \r
- Layer0 L0 = Layer0.getInstance(graph);\r
- DiagramResource DIA = DiagramResource.getInstance(graph);\r
- String modelURI = graph.getPossibleRelatedValue((Resource)runtimeDiagram, DIA.RuntimeDiagram_HasModelURI);\r
- if (modelURI == null) return;\r
- \r
- Resource model = graph.getPossibleResource(modelURI);\r
- if(model == null) return;\r
- \r
- String name = NameUtils.findFreshEscapedName(graph, "Entry", model, L0.ConsistsOf);\r
- \r
- Resource newGroup = graph.newResource();\r
- graph.claim(newGroup, L0.InstanceOf, DIA.GroupStyleProfileEntry);\r
- graph.claimLiteral(newGroup, L0.HasName, name);\r
- graph.claim(newGroup, DIA.ProfileEntry_HasGroup, selectedGroup);\r
- graph.claim(newGroup, DIA.ProfileEntry_HasStyle, selectedStyle);\r
- graph.claim(model, L0.ConsistsOf, newGroup);\r
- \r
- }\r
- \r
- });\r
- \r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
-\r
- }\r
-\r
-}\r
+package org.simantics.diagram.profile.view;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.swt.ModelledActionImpl;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.SelectionHints;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.layer0.Layer0;
+import org.simantics.utils.ui.ISelectionUtils;
+
+public class CreateEntryAction extends ModelledActionImpl<Resource> {
+
+ public CreateEntryAction(Resource configuration) {
+ super(configuration);
+ }
+
+ public void run(final Resource runtimeDiagram) {
+
+ ISelection groupSelection = getParameter(DiagramResource.URIs.ProfilesView_NewEntryGroup);
+ final Resource selectedGroup = ISelectionUtils.getSinglePossibleKey(groupSelection, SelectionHints.KEY_MAIN, Resource.class);
+ if(selectedGroup == null) return;
+
+ ISelection styleSelection = getParameter(DiagramResource.URIs.ProfilesView_NewEntryStyle);
+ final Resource selectedStyle = ISelectionUtils.getSinglePossibleKey(styleSelection, SelectionHints.KEY_MAIN, Resource.class);
+ if(selectedStyle == null) return;
+
+ try {
+
+ Simantics.getSession().syncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+
+ Layer0 L0 = Layer0.getInstance(graph);
+ DiagramResource DIA = DiagramResource.getInstance(graph);
+ String modelURI = graph.getPossibleRelatedValue((Resource)runtimeDiagram, DIA.RuntimeDiagram_HasModelURI);
+ if (modelURI == null) return;
+
+ Resource model = graph.getPossibleResource(modelURI);
+ if(model == null) return;
+
+ String name = NameUtils.findFreshEscapedName(graph, "Entry", model, L0.ConsistsOf);
+
+ Resource newGroup = graph.newResource();
+ graph.claim(newGroup, L0.InstanceOf, DIA.GroupStyleProfileEntry);
+ graph.claimLiteral(newGroup, L0.HasName, name);
+ graph.claim(newGroup, DIA.ProfileEntry_HasGroup, selectedGroup);
+ graph.claim(newGroup, DIA.ProfileEntry_HasStyle, selectedStyle);
+ graph.claim(model, L0.ConsistsOf, newGroup);
+
+ }
+
+ });
+
+ } catch (DatabaseException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}