From ea292295267c5b1092adcf671ce62d86e0aa01b1 Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 23 Mar 2011 17:42:29 +0000 Subject: [PATCH] Hackfix to ImportModelHandler. Manually check that IsLinkedTo -relation exist git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20201 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ui/handlers/ImportModelHandler.java | 30 +++++++++++++++++-- .../sysdyn/ui/properties/FunctionTab.java | 4 +-- .../sysdyn/manager/FunctionUtils.java | 3 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java index 12aff672..566f520b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java @@ -25,11 +25,14 @@ import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.databoard.Bindings; import org.simantics.databoard.Files; import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; -import org.simantics.databoard.serialization.SerializationException; import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; import org.simantics.ui.SimanticsUI; public class ImportModelHandler extends AbstractHandler { @@ -59,9 +62,30 @@ public class ImportModelHandler extends AbstractHandler { } if(tg == null) return null; - org.simantics.graph.db.IImportAdvisor ia = new DefaultPasteImportAdvisor(project); + DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project); DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia); - + + + // FIXME: the links should be exported and imported automatically + final Resource root = ia.getRoot(); + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.0"); + Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0"); + if(!graph.hasStatement(root, l0.IsLinkedTo, sysdyn)) + graph.claim(root, l0.IsLinkedTo, sysdyn); + if(!graph.hasStatement(root, l0.IsLinkedTo, layer0)) + graph.claim(root, l0.IsLinkedTo, layer0); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return null; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java index c0b315bc..c4463d04 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java @@ -66,7 +66,7 @@ public class FunctionTab extends PropertyTabContributorImpl { Label startLabel = new Label(modelicaGroup, support, SWT.NONE); startLabel.setTextFactory(new FunctionLabelFactory(Builtins.URIs.HasName, false)); - TrackedText modelicaCode = new TrackedText(modelicaGroup, support, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); + TrackedText modelicaCode = new TrackedText(modelicaGroup, support, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.WRAP); modelicaCode.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.HasModelicaFunctionCode)); modelicaCode.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.HasModelicaFunctionCode)); modelicaCode.addModifyListener(new TextModifyListenerImpl() { @@ -88,7 +88,7 @@ public class FunctionTab extends PropertyTabContributorImpl { GridDataFactory.fillDefaults().grab(true, true).applyTo(documentationGroup); GridLayoutFactory.fillDefaults().spacing(0, 0).margins(3, 3).applyTo(documentationGroup); - TrackedText information = new TrackedText(documentationGroup, support, SWT.MULTI | SWT.BORDER); + TrackedText information = new TrackedText(documentationGroup, support, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP); information.setTextFactory(new StringPropertyFactory(Builtins.URIs.HasDescription)); information.addModifyListener(new StringPropertyModifier(context, Builtins.URIs.HasDescription)); GridDataFactory.fillDefaults().grab(true, true).applyTo(information.getWidget()); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java index b85894af..aa06e2c7 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java @@ -42,7 +42,8 @@ public class FunctionUtils { if(graph.isInstanceOf(parent, sr.SysdynModel)) { Resource configuration = graph.getPossibleObject(parent, simu.HasConfiguration); if(configuration.equals(model.configurationResource)) { - paths.add(model.getConfiguration().getName().replace(" ", "") + "_functions.mo"); + String parentName = NameUtils.getSafeName(graph, parent); + paths.add(parentName + "_functions.mo"); } } else if (graph.isInstanceOf(partof, sr.SysdynModel)) { // TODO -- 2.47.1