X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.diagram.profile%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fprofile%2Fview%2FCreateEntryAction.java;fp=bundles%2Forg.simantics.diagram.profile%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fprofile%2Fview%2FCreateEntryAction.java;h=acdb9b26f53b1478a460baf2234c6a46047e1a58;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/CreateEntryAction.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/CreateEntryAction.java new file mode 100644 index 000000000..acdb9b26f --- /dev/null +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/CreateEntryAction.java @@ -0,0 +1,66 @@ +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 { + + 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(); + } + + } + +}