From 7ea229e50c7e5b5c8aabc7022f123e67e4ba63da Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 20 Feb 2013 10:26:03 +0000 Subject: [PATCH] ExportModule and ExportFunction used old transferable graph requests that did not work properly. Migrated them to using new ModelTransferableGraphRequest. (fixes #4081) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26813 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../exports/ExportFunctionLibrary.java | 43 +++++++------------ .../handlers/exports/ExportModuleHandler.java | 34 +++++++++------ 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java index 7aafb7cf..e583355e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Copyright (c) 2007, 2013 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -12,8 +12,6 @@ package org.simantics.sysdyn.ui.handlers.exports; import java.io.File; -import java.io.IOException; -import java.util.ArrayList; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -25,24 +23,21 @@ import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.databoard.Bindings; -import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.databoard.container.DataContainer; -import org.simantics.databoard.container.DataContainers; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.primitiverequest.PossibleRelatedValue; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.util.TransferableGraphRequest2; +import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest; +import org.simantics.db.layer0.util.TransferableGraphConfiguration2; import org.simantics.db.request.Read; -import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.graph.db.TransferableGraphSource; +import org.simantics.graph.db.TransferableGraphs; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.utils.imports.ImportUtils; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; -import org.simantics.utils.datastructures.Pair; /** * Exports a function library @@ -101,25 +96,17 @@ public class ExportFunctionLibrary extends AbstractHandler { // Asynchronously create the file using transferable graph SimanticsUI.getSession().asyncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - String name = graph.syncRequest(new PossibleRelatedValue(functionLibrary, l0.HasName, Bindings.STRING )); - ArrayList> roots = new ArrayList>(); - roots.add(Pair.make(functionLibrary, name)); - TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, functionLibrary)); - try { - DataContainers.writeFile(new File(selected), new DataContainer("sysdynFunctionLibrary", 1, new Variant(TransferableGraph1.BINDING, tg))); - } catch (RuntimeBindingConstructionException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - - } + @Override + public void run(ReadGraph graph) throws DatabaseException { + TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, functionLibrary); + TransferableGraphSource s = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf)); + try { + TransferableGraphs.writeTransferableGraph(graph, "sysdynFunctionLibrary", 1, s,new File(selected)); + } catch (Exception e) { + e.printStackTrace(); + } + } }); return null; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java index cecb5d8b..53bb5203 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Copyright (c) 2007, 2013 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -12,7 +12,6 @@ package org.simantics.sysdyn.ui.handlers.exports; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -28,9 +27,6 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.databoard.Bindings; import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.databoard.container.DataContainer; -import org.simantics.databoard.container.DataContainers; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -40,9 +36,11 @@ import org.simantics.db.common.request.ReadRequest; 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.util.TransferableGraphRequest2; +import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest; +import org.simantics.db.layer0.util.TransferableGraphConfiguration2; import org.simantics.db.request.Read; -import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.graph.db.TransferableGraphSource; +import org.simantics.graph.db.TransferableGraphs; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.structural.stubs.StructuralResource2; @@ -227,7 +225,7 @@ public class ExportModuleHandler extends AbstractHandler { * @param roots * @param component Module */ - private void export(WriteGraph graph, String path, ArrayList> roots, Resource component) { + private void export(WriteGraph graph, final String path, ArrayList> roots, final Resource component) { // FIXME: Enumeration replacement handling like this is not suitable. try { @@ -249,16 +247,28 @@ public class ExportModuleHandler extends AbstractHandler { for(Pair replacement : replacements) graph.deny(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second); - TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, component)); - DataContainers.writeFile(new File(path), new DataContainer("sysdynModule", 1, new Variant(TransferableGraph1.BINDING, tg))); + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, component); + TransferableGraphSource s = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf)); + try { + TransferableGraphs.writeTransferableGraph(graph, "sysdynModule", 1, s,new File(path)); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + for(Pair replacement : replacements) graph.claim(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second); } catch (RuntimeBindingConstructionException e) { e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); +// } catch (IOException e) { +// e.printStackTrace(); } catch (DatabaseException e) { e.printStackTrace(); } -- 2.47.1