From: jsimomaa Date: Fri, 13 Oct 2017 13:03:41 +0000 (+0300) Subject: Option for exporting tg and pgraph with sharedlibrary X-Git-Tag: v1.31.0~121 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=fa806341cc06b72051d5e8d709674eb9d5c2bf00;hp=3b4bf8acfe0a6126ce44c5452ffee4dd9af119e3 Option for exporting tg and pgraph with sharedlibrary refs #7547 Change-Id: I3cf58e84c05d2ea220bc41a47956c7c56142dca0 --- diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java index 1c567b1e2..91d85ecf9 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java @@ -40,17 +40,33 @@ public class FixExportedOntology { } } + + public static void createTg(Path input) throws Exception { + Path output = input.getParent().resolve("graph.tg"); + createTg(input, output); + } + + private static void createTg(Path input, Path output) throws Exception { + convertExportedSharedOntologyIntoBundleOntology(input, output); + } + + public static void createPGraph(Path input) throws Exception { + Path output1 = input.getParent().resolve("graph.tg"); + TransferableGraph1 tg = convertExportedSharedOntologyIntoBundleOntology(input, output1); + String listing = PrettyPrintTG.print(tg, false); + String newName = input.getFileName().toString(); + if (newName.contains("\\.")) + newName = newName.split("\\.")[0]; + Path output2 = input.getParent().resolve(newName + ".pgraph"); + Files.write(output2, listing.getBytes(),StandardOpenOption.CREATE); + } public static void main(String[] args) throws Exception { if (args.length == 0) { System.out.println("Required arguments: []"); } else if (args.length == 1) { Path input = Paths.get(args[0]); - Path output1 = input.getParent().resolve("graph.tg"); - TransferableGraph1 tg = convertExportedSharedOntologyIntoBundleOntology(input, output1); - String listing = PrettyPrintTG.print(tg, false); - Path output2 = Paths.get(args[0].substring(0, args[0].length() - ".sharedLibrary".length()) + ".pgraph"); - Files.write(output2, listing.getBytes(),StandardOpenOption.CREATE); + createPGraph(input); } else { convertExportedSharedOntologyIntoBundleOntology(Paths.get(args[0]), Paths.get(args[1])); } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ExportPlan.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ExportPlan.java index 793eb112e..f8cd67a8a 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ExportPlan.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ExportPlan.java @@ -39,6 +39,7 @@ public class ExportPlan { * true if the model should be overwritten without a warning. */ boolean overwrite; + boolean tgAndPgraph; ExportPlan(ISessionContext sessionContext, Deque recentLocations) { this.sessionContext = sessionContext; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExportPage.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExportPage.java index f8c53be93..26675fb33 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExportPage.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExportPage.java @@ -15,6 +15,7 @@ import java.io.File; import java.util.Collections; import java.util.List; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.wizard.WizardPage; @@ -145,7 +146,21 @@ public class SharedOntologyExportPage extends WizardPage { validatePage(); } }); + String prop = System.getProperty("org.simantics.modeling.exportTgAndPgraph"); + if (prop != null || Platform.inDevelopmentMode()) { + Button tgAndPgraph = new Button(container, SWT.CHECK); + tgAndPgraph.setText("&Generate TG and Pgraph with export"); + tgAndPgraph.setSelection(exportModel.tgAndPgraph); + GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(tgAndPgraph); + tgAndPgraph.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + exportModel.tgAndPgraph = tgAndPgraph.getSelection(); + } + }); + } + try { initializeData(); } catch (DatabaseException e) { diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java index 651f55f4e..226aa840f 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java @@ -14,6 +14,8 @@ package org.simantics.modeling.ui.sharedontology.wizard; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.nio.file.Path; +import java.nio.file.Paths; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubMonitor; @@ -23,15 +25,18 @@ import org.simantics.databoard.binding.error.BindingException; import org.simantics.databoard.serialization.SerializationException; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; +import org.simantics.graph.refactoring.FixExportedOntology; import org.simantics.modeling.ModelingUtils; import org.simantics.modeling.ModelingUtils.LibraryInfo; import org.simantics.utils.ui.dialogs.ShowMessage; +import org.slf4j.LoggerFactory; /** * @author Antti Villberg */ public class SharedOntologyExporter implements IRunnableWithProgress { + private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(SharedOntologyExporter.class); ExportPlan exportModel; public SharedOntologyExporter(ExportPlan exportModel) { @@ -56,7 +61,7 @@ public class SharedOntologyExporter implements IRunnableWithProgress { void exportModel(SubMonitor mon) throws IOException, DatabaseException, SerializationException, BindingException{ try { - doExport(mon, exportModel.exportLocation, exportModel.model); + doExport(mon, exportModel.exportLocation, exportModel.model, exportModel.tgAndPgraph); } catch (DatabaseException e) { e.printStackTrace(); @@ -69,7 +74,20 @@ public class SharedOntologyExporter implements IRunnableWithProgress { } public static void doExport(IProgressMonitor monitor, File location, final LibraryInfo info) throws DatabaseException, IOException { + doExport(monitor, location, info, false); + } + + public static void doExport(IProgressMonitor monitor, File location, final LibraryInfo info, boolean pgraphAndTg) throws DatabaseException, IOException { ModelingUtils.exportSharedOntology(monitor, Simantics.getSession(), location,Constants.SHARED_LIBRARY_FORMAT, Constants.SHARED_LIBRARY_CURRENT_VERSION, info); + if (pgraphAndTg) { + try { + Path input = Paths.get(location.toURI()); + FixExportedOntology.createTg(input); + FixExportedOntology.createPGraph(input); + } catch (Exception e) { + LOGGER.error("Could not generate TG and Pgraph", e); + } + } } }