X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram.profile%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fprofile%2Fview%2FCreateEntryAction.java;h=10af5d011b4a98133df879d7bdeb973edb1af19c;hb=HEAD;hp=acdb9b26f53b1478a460baf2234c6a46047e1a58;hpb=969bd23cab98a79ca9101af33334000879fb60c5;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 index acdb9b26f..10af5d011 100644 --- 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 @@ -1,66 +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(); - } - - } - -} +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(); + } + + } + +}