From: Tuukka Lehtonen Date: Fri, 9 Feb 2018 09:27:08 +0000 (+0200) Subject: Fixed code breakage caused by platform issue #7728 changes X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=817f779927962991646b6ce9c9e4ee8b5f25571f;p=simantics%2Fsysdyn.git Fixed code breakage caused by platform issue #7728 changes refs #7759 Change-Id: I2a0be56450ac278e2102dc9880e71acba762f34a --- diff --git a/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsExportPage.java b/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsExportPage.java index 785df451..372fe621 100644 --- a/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsExportPage.java +++ b/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsExportPage.java @@ -1,10 +1,10 @@ package org.simantics.sysdyn.ui.wizards.functions; import java.io.File; -import java.io.IOException; -import java.util.ArrayList; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.PixelConverter; import org.eclipse.jface.viewers.ISelection; @@ -29,22 +29,23 @@ import org.eclipse.swt.widgets.Tree; import org.simantics.browsing.ui.swt.AdaptableHintContext; import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; import org.simantics.databoard.Bindings; -import org.simantics.databoard.Files; -import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; 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.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.TGStatusMonitor; +import org.simantics.graph.db.TransferableGraphSource; +import org.simantics.graph.db.TransferableGraphs; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.ArrayMap; -import org.simantics.utils.datastructures.Pair; public class WizardFunctionsExportPage extends WizardPage { @@ -171,52 +172,36 @@ public class WizardFunctionsExportPage extends WizardPage { Label title = new Label(workArea, SWT.NONE); title.setText("Select Function Library to export:"); - try { - Resource input = SimanticsUI.getSession().syncRequest(new Read() { + Resource input = SimanticsUI.getProject().get(); - @Override - public Resource perform(ReadGraph graph) - throws DatabaseException { - Resource model = SimanticsUI.getProject().get(); - return model; - } + functionLibraryExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); - }); + functionLibraryExplorer + .setBrowseContexts(SysdynResource.URIs.FunctionTree); - functionLibraryExplorer = new GraphExplorerComposite(ArrayMap.keys( - "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); + functionLibraryExplorer.finish(); - functionLibraryExplorer - .setBrowseContexts(SysdynResource.URIs.FunctionTree); + functionLibraryExplorer.setInput(null, input); - functionLibraryExplorer.finish(); - - functionLibraryExplorer.setInput(null, input); - - GridDataFactory.fillDefaults().grab(true, true).applyTo( - functionLibraryExplorer); - - ((Tree)functionLibraryExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent e) { - setMessage(null); - selectionMade = true; - validatePage(); - } - @Override - public void widgetDefaultSelected(SelectionEvent e) { - setMessage(null); - selectionMade = true; - validatePage(); - } - }); - - } catch (DatabaseException e) { - e.printStackTrace(); - } + GridDataFactory.fillDefaults().grab(true, true).applyTo( + functionLibraryExplorer); + ((Tree)functionLibraryExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + setMessage(null); + selectionMade = true; + validatePage(); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + setMessage(null); + selectionMade = true; + validatePage(); + } + }); } //Set filePathField active @@ -295,30 +280,22 @@ public class WizardFunctionsExportPage extends WizardPage { } }); - } catch (DatabaseException e1) { - e1.printStackTrace(); + } catch (DatabaseException ex) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Failed to read name of function library " + functionLibrary + ", see exception for details.", ex)); } if(name == null) return false; - + 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 { - Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); - } catch (RuntimeBindingConstructionException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); + TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, functionLibrary); + try (TransferableGraphSource tgs = graph.syncRequest( new ModelTransferableGraphSourceRequest(conf) )) { + TransferableGraphs.writeTransferableGraph(graph, tgs, new File(selected), TGStatusMonitor.NULL_MONITOR); + } catch (Exception e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Failed to export function library, see exception for details.", e)); } - - } }); @@ -355,7 +332,8 @@ public class WizardFunctionsExportPage extends WizardPage { return; } } catch (DatabaseException e) { - e.printStackTrace(); + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Failed to validate wizard page contents, see exception for details.", e)); } } diff --git a/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsExportPage.java b/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsExportPage.java index ae1f0e8e..f53eb7ec 100644 --- a/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsExportPage.java +++ b/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsExportPage.java @@ -1,10 +1,10 @@ package org.simantics.sysdyn.ui.wizards.models; import java.io.File; -import java.io.IOException; -import java.util.ArrayList; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.PixelConverter; import org.eclipse.jface.viewers.ISelection; @@ -28,22 +28,19 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.simantics.browsing.ui.swt.AdaptableHintContext; import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; -import org.simantics.databoard.Bindings; -import org.simantics.databoard.Files; -import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; 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.request.Read; -import org.simantics.graph.representation.TransferableGraph1; -import org.simantics.layer0.Layer0; +import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest; +import org.simantics.db.layer0.util.TransferableGraphConfiguration2; +import org.simantics.graph.db.TGStatusMonitor; +import org.simantics.graph.db.TransferableGraphSource; +import org.simantics.graph.db.TransferableGraphs; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.ArrayMap; -import org.simantics.utils.datastructures.Pair; public class WizardModelsExportPage extends WizardPage { @@ -167,59 +164,43 @@ public class WizardModelsExportPage extends WizardPage { }); } - + private void createTree(Composite workArea){ - + //set label for tree Label title = new Label(workArea, SWT.NONE); title.setText("Select Model to export:"); - try { - Resource input = SimanticsUI.getSession().syncRequest(new Read() { + Resource input = SimanticsUI.getProject().get(); - @Override - public Resource perform(ReadGraph graph) - throws DatabaseException { - Resource model = SimanticsUI.getProject().get(); - return model; - } + modelExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); - }); + modelExplorer + .setBrowseContexts(SysdynResource.URIs.ImportModuleTree); - modelExplorer = new GraphExplorerComposite(ArrayMap.keys( - "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); + modelExplorer.finish(); - modelExplorer - .setBrowseContexts(SysdynResource.URIs.ImportModuleTree); + modelExplorer.setInput(null, input); - modelExplorer.finish(); + GridDataFactory.fillDefaults().grab(true, true).applyTo( + modelExplorer); - modelExplorer.setInput(null, input); - - GridDataFactory.fillDefaults().grab(true, true).applyTo( - modelExplorer); - - ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent e) { - selectionMade = true; - validatePage(); - } - @Override - public void widgetDefaultSelected(SelectionEvent e) { - selectionMade = true; - validatePage(); - } - }); - - - } catch (DatabaseException e) { - e.printStackTrace(); - } + ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + selectionMade = true; + validatePage(); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + selectionMade = true; + validatePage(); + } + }); } - + //Set filePathField active public void setVisible(boolean visible) { super.setVisible(visible); @@ -241,7 +222,7 @@ public class WizardModelsExportPage extends WizardPage { File path = new File(dirName); if (path.exists()) { - dialog.setFilterPath(new Path(dirName).toOSString()); + dialog.setFilterPath(new Path(dirName).toOSString()); } String selectedFile = dialog.open(); @@ -276,7 +257,7 @@ public class WizardModelsExportPage extends WizardPage { final String selected = previouslyBrowsedFile; if(selected == null) return false; - selectedModel= getExplorerResource(modelExplorer, Resource.class); + selectedModel = getExplorerResource(modelExplorer, Resource.class); if(selectedModel == null) return false; @@ -287,20 +268,13 @@ public class WizardModelsExportPage extends WizardPage { @Override public void run(ReadGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - String name = graph.syncRequest(new PossibleRelatedValue(selectedModel, l0.HasName, Bindings.STRING )); - ArrayList> roots = new ArrayList>(); - roots.add(Pair.make(selectedModel, name)); - TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, selectedModel)); - - try { - Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); - } catch (RuntimeBindingConstructionException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); + TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, selectedModel); + try (TransferableGraphSource tgs = graph.syncRequest( new ModelTransferableGraphSourceRequest(conf) )) { + TransferableGraphs.writeTransferableGraph(graph, tgs, new File(selected), TGStatusMonitor.NULL_MONITOR); + } catch (Exception e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Failed to export model, see exception for details.", e)); } - } }); diff --git a/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesExportPage.java b/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesExportPage.java index 3625dd9d..e57a8210 100644 --- a/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesExportPage.java +++ b/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesExportPage.java @@ -1,11 +1,12 @@ package org.simantics.sysdyn.ui.wizards.modules; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.PixelConverter; import org.eclipse.jface.viewers.ISelection; @@ -30,24 +31,25 @@ import org.eclipse.swt.widgets.Tree; import org.simantics.browsing.ui.swt.AdaptableHintContext; import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; import org.simantics.databoard.Bindings; -import org.simantics.databoard.Files; -import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; -import org.simantics.db.common.primitiverequest.PossibleRelatedValue; import org.simantics.db.common.request.ObjectsWithType; 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.TGStatusMonitor; +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; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.ArrayMap; import org.simantics.utils.datastructures.Pair; @@ -176,53 +178,38 @@ public class WizardModulesExportPage extends WizardPage { Label title = new Label(workArea, SWT.NONE); title.setText("Select Module to export:"); - try { - Resource input = SimanticsUI.getSession().syncRequest(new Read() { + Resource input = SimanticsUI.getProject().get(); - @Override - public Resource perform(ReadGraph graph) - throws DatabaseException { - Resource model = SimanticsUI.getProject().get(); - return model; - } + modelExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); - }); + modelExplorer + .setBrowseContexts(SysdynResource.URIs.ExportModuleTree); - modelExplorer = new GraphExplorerComposite(ArrayMap.keys( - "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); + modelExplorer.finish(); - modelExplorer - .setBrowseContexts(SysdynResource.URIs.ExportModuleTree); + modelExplorer.setInput(null, input); - modelExplorer.finish(); - - modelExplorer.setInput(null, input); + GridDataFactory.fillDefaults().grab(true, true).applyTo( + modelExplorer); - GridDataFactory.fillDefaults().grab(true, true).applyTo( - modelExplorer); - - ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent e) { - setMessage(null); - selectionMade = true; - validatePage(); - } - @Override - public void widgetDefaultSelected(SelectionEvent e) { - setMessage(null); - selectionMade = true; - validatePage(); - } - }); - - } catch (DatabaseException e) { - e.printStackTrace(); - } + ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + setMessage(null); + selectionMade = true; + validatePage(); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + setMessage(null); + selectionMade = true; + validatePage(); + } + }); } - + //Set filePathField active public void setVisible(boolean visible) { super.setVisible(visible); @@ -307,7 +294,7 @@ public class WizardModulesExportPage extends WizardPage { ArrayList dependencies = null; for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) { if(dependencies == null) - dependencies = new ArrayList(); + dependencies = new ArrayList<>(); String name = NameUtils.getSafeName(graph, r); String instanceOf = NameUtils.getSafeName(graph, graph.getSingleObject(r, l0.InstanceOf)); dependencies.add(name + " : " + instanceOf); @@ -331,15 +318,10 @@ public class WizardModulesExportPage extends WizardPage { @Override public void run(ReadGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - final Resource component = selectedModule; //final Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType); if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf)) return; - String name = graph.syncRequest(new PossibleRelatedValue(component, l0.HasName, Bindings.STRING )); - final ArrayList> roots = new ArrayList>(); - roots.add(Pair.make(component, name)); graph.asyncRequest(new WriteRequest() { @@ -361,7 +343,7 @@ public class WizardModulesExportPage extends WizardPage { graph.claim(configuration, l0.PartOf, l0.ConsistsOf, component); graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, component); - export(graph, selected, roots, component); + export(graph, selected, component); graph.deny(configuration, l0.PartOf); graph.deny(modulesymbol, l0.PartOf); @@ -369,9 +351,11 @@ public class WizardModulesExportPage extends WizardPage { graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, previousPartof); } else { // Normal export - export(graph, selected, roots, component); + export(graph, selected, component); } } + }, e -> { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to export module, see exception for details.", e)); }); } @@ -380,43 +364,45 @@ public class WizardModulesExportPage extends WizardPage { return true; } - private void export(WriteGraph graph, String path, ArrayList> roots, Resource component) { - + private void export(WriteGraph graph, String path, Resource component) throws DatabaseException { // FIXME: Enumeration replacement handling like this is not suitable. - try { - Layer0 l0 = Layer0.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - StructuralResource2 sr2 = StructuralResource2.getInstance(graph); - Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy); - ArrayList> replacements = new ArrayList>(); + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); - for(Resource enumeration : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) { - if(graph.hasStatement(enumeration, sr.Redeclaration_replacedEnumeration_Inverse)) { - for(Resource replacement : graph.getObjects(enumeration, sr.Redeclaration_replacedEnumeration_Inverse)) { - replacements.add(new Pair(enumeration, replacement)); - } + Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy); + ArrayList> replacements = new ArrayList<>(); + + for(Resource enumeration : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) { + if(graph.hasStatement(enumeration, sr.Redeclaration_replacedEnumeration_Inverse)) { + for(Resource replacement : graph.getObjects(enumeration, sr.Redeclaration_replacedEnumeration_Inverse)) { + replacements.add(Pair.make(enumeration, replacement)); } } - - for(Pair replacement : replacements) - graph.deny(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second); - - TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, component)); - Files.createFile(new File(path), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); - - for(Pair replacement : replacements) - graph.claim(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second); + } - } catch (RuntimeBindingConstructionException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); + for(Pair replacement : replacements) + graph.deny(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second); + + try { + TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, component); + try (TransferableGraphSource tgs = graph.syncRequest( new ModelTransferableGraphSourceRequest(conf) )) { + TransferableGraphs.writeTransferableGraph(graph, tgs, new File(path), TGStatusMonitor.NULL_MONITOR); + } catch (Exception e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Failed to export module, see exception for details.", e)); + } } catch (DatabaseException e) { - e.printStackTrace(); + throw e; + } catch (Exception e) { + throw new DatabaseException(e); + } finally { + for(Pair replacement : replacements) + graph.claim(replacement.first, sr.Redeclaration_replacedEnumeration_Inverse, replacement.second); } } - + class ContainsDependenciesException extends DatabaseException { private static final long serialVersionUID = -1533706136673146020L; @@ -462,7 +448,8 @@ public class WizardModulesExportPage extends WizardPage { return; } } catch (DatabaseException e) { - e.printStackTrace(); + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Failed to validate wizard page contents, see exception for details.", e)); } }