From c7ae7ac47f6b51f429a0a08bb6011d26f2653e8f Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 31 Aug 2010 10:07:43 +0000 Subject: [PATCH] Removed duplicate handler for new model, context menu uses the generic new model handler from modeling.ui git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17714 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/plugin.xml | 7 +- .../sysdyn/ui/handlers/NewModelHandler.java | 77 ------------------- .../sysdyn/ui/project/SysdynProject.java | 24 +++--- 3 files changed, 14 insertions(+), 94 deletions(-) delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 33fdf8cb..e9a7ecb7 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -197,7 +197,7 @@ @@ -345,11 +345,6 @@ id="org.simantics.sysdyn.ui.newModuleNode" name="New Module"> - - diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java deleted file mode 100644 index ed549eea..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.simantics.sysdyn.ui.handlers; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.simantics.databoard.binding.java.StringBindingDefault; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.OrderedSetUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.DiagramConstants; -import org.simantics.diagram.synchronization.graph.layer.GraphLayer; -import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.modeling.ModelingResources; -import org.simantics.modeling.ModelingUtils; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.ui.SimanticsUI; - -public class NewModelHandler extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph g) throws DatabaseException { - // Same as in SysdynProject.java. Should use the same code, not copy. - Layer0 l0 = Layer0.getInstance(g); - SysdynResource sr = SysdynResource.getInstance(g); - ModelingResources mr = ModelingResources.getInstance(g); - ModelingUtils mu = new ModelingUtils(g); - - String modelName = GraphUtils.findFreshName(g, "Model", SimanticsUI.getProject().get(), l0.ConsistsOf, "%s%d"); - - Resource model = g.newResource(); - g.claimLiteral(model, l0.HasName, modelName); - g.claimLiteral(model, l0.HasLabel, modelName); - g.claim(model, l0.InstanceOf, sr.SysdynModel); - g.claim(model, l0.PartOf, SimanticsUI.getProject().get()); - - - Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram); - GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true); - g.claim(diagram, mu.dr.HasLayer, l.getLayer()); - g.claimLiteral(diagram, l0.HasName, "Diagrammi", StringBindingDefault.INSTANCE); - - Resource conf = GraphUtils.create2(g, - sr.Configuration, - l0.PartOf, model, - l0.HasName, modelName - ); - - g.claim(conf, mr.CompositeToDiagram, diagram); - g.claim(model, mu.SIMU.HasConfiguration, conf); - - Resource mapping = g.newResource(); - g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); - g.claim(diagram, l0.HasTrigger, mapping); - - Resource report = GraphUtils.create2(g, l0.Report, l0.HasDocumentation, "===Report==="); - - GraphUtils.create2(g, mu.SIMU.Experiment, - l0.HasName, "Experiment", - l0.HasLabel, "Experiment", - l0.HasReportFactory, report, - l0.PartOf, model); - } - }); - return null; - } - - - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index b9ce5bd2..2617a0d9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -41,6 +41,7 @@ import org.simantics.project.features.UIModelManager; import org.simantics.project.features.UIModelManagerBase; import org.simantics.project.features.UIModelManagerBase.WriteRunnable; import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; import org.simantics.ui.workbench.IEditorNamingService; import org.simantics.ui.workbench.action.ChooseActionRequest; import org.simantics.utils.datastructures.Callback; @@ -83,35 +84,36 @@ public class SysdynProject extends AbstractProjectFeature { @Override public void run(WriteGraph g, Resource library, Callback callback, Callback errorCallback) { try { - SysdynResource sr = SysdynResource.getInstance(g); + Layer0 l0 = Layer0.getInstance(g); + SysdynResource sr = SysdynResource.getInstance(g); ModelingResources mr = ModelingResources.getInstance(g); ModelingUtils mu = new ModelingUtils(g); - Layer0 l0 = Layer0.getInstance(g); - Resource model = g.newResource(); - - String modelName = GraphUtils.findFreshName(g, "Model", library, l0.ConsistsOf, "%s%d"); + String modelName = GraphUtils.findFreshName(g, "Model", SimanticsUI.getProject().get(), l0.ConsistsOf, "%s%d"); + Resource model = g.newResource(); g.claimLiteral(model, l0.HasName, modelName); g.claimLiteral(model, l0.HasLabel, modelName); g.claim(model, l0.InstanceOf, sr.SysdynModel); - g.claim(model, l0.PartOf, library); + g.claim(model, l0.PartOf, SimanticsUI.getProject().get()); + Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram); GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true); g.claim(diagram, mu.dr.HasLayer, l.getLayer()); g.claimLiteral(diagram, l0.HasName, "Diagrammi", StringBindingDefault.INSTANCE); - - Resource conf = g.newResource(); - g.claimLiteral(conf, l0.HasName, modelName+"Configuration"); - g.claim(conf, l0.InstanceOf, sr.Configuration); + Resource conf = GraphUtils.create2(g, + sr.Configuration, + l0.PartOf, model, + l0.HasName, modelName + ); g.claim(conf, mr.CompositeToDiagram, diagram); g.claim(model, mu.SIMU.HasConfiguration, conf); Resource mapping = g.newResource(); - g.claim(mapping, l0.InstanceOf, null, mr.DiagramToCompositeMapping); + g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); g.claim(diagram, l0.HasTrigger, mapping); Resource report = GraphUtils.create2(g, l0.Report, l0.HasDocumentation, "===Report==="); -- 2.47.1