]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Option for exporting tg and pgraph with sharedlibrary 05/1105/2
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 13 Oct 2017 13:03:41 +0000 (16:03 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Fri, 13 Oct 2017 13:03:54 +0000 (16:03 +0300)
refs #7547

Change-Id: I3cf58e84c05d2ea220bc41a47956c7c56142dca0

bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ExportPlan.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExportPage.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java

index 1c567b1e21d39294f00652a0e8467e33cf803044..91d85ecf9732f9c5395b1094c2731a0d468e7d4c 100644 (file)
@@ -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: <input .sharedLibrary file> [<output .tg file>]");
                } 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]));
                }
index 793eb112e11d1455320bd0ac77930faa62da0164..f8cd67a8a415b3bbc4bec8bb68b50204109aefbf 100644 (file)
@@ -39,6 +39,7 @@ public class ExportPlan {
      * <code>true</code> if the model should be overwritten without a warning.
      */
     boolean         overwrite;
+    boolean         tgAndPgraph;
 
     ExportPlan(ISessionContext sessionContext, Deque<String> recentLocations) {
         this.sessionContext = sessionContext;
index f8c53be9301df964f6bf97bde4d19532a9f53789..26675fb33cd370eea845f3348b4da0b5c88865ad 100644 (file)
@@ -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) {
index 651f55f4ebe4e79f194946fa46b756435bf295ba..226aa840f88af9cf6c91da5f6b5350cafdea64ed 100644 (file)
@@ -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);
+            }
+       }
     }
        
 }