]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/wizard/SchemaConversionWizard.java
Refactoring and preparing the conversion code to handle references between XML schemas.
[simantics/interop.git] / org.simantics.xml.sax.ui / src / org / simantics / xml / sax / ui / wizard / SchemaConversionWizard.java
index 627381bfd84277adc17ad27210106d4c464431fb..3c27632b6bcccbbe012de1b105568ca6a6cc24e0 100644 (file)
@@ -1,11 +1,16 @@
 package org.simantics.xml.sax.ui.wizard;\r
 \r
 import java.io.File;\r
+import java.io.IOException;\r
 \r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.wizard.Wizard;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.FileDialog;\r
 import org.eclipse.ui.IImportWizard;\r
 import org.eclipse.ui.IWorkbench;\r
+import org.simantics.xml.sax.ManualSchemaFileImport;\r
 import org.simantics.xml.sax.SchemaConverter;\r
 \r
 public class SchemaConversionWizard extends Wizard implements IImportWizard {\r
@@ -39,18 +44,46 @@ public class SchemaConversionWizard extends Wizard implements IImportWizard {
        }\r
        \r
        public void doConversion() throws Exception {\r
-               SchemaConverter converter = new SchemaConverter();\r
-               converter.setCreateExporter(inputSelectionPage.createExporter);\r
-               converter.setCreateImporter(inputSelectionPage.createImporter);\r
-               converter.setCreatePGraph(inputSelectionPage.createPGraph);\r
-\r
+               \r
+               \r
                File inputFile = new File(inputSelectionPage.getSchemaFilename());\r
                File configurationFile = null;\r
                if (inputSelectionPage.getConfigurationFilename() != null)\r
                        configurationFile = new File(inputSelectionPage.getConfigurationFilename());\r
                File outputPlugin = new File(inputSelectionPage.getPluginFilename());\r
+\r
+               SchemaConverter converter = new SchemaConverter(inputFile,configurationFile,outputPlugin);\r
+               converter.setCreateExporter(inputSelectionPage.createExporter);\r
+               converter.setCreateImporter(inputSelectionPage.createImporter);\r
+               converter.setCreatePGraph(inputSelectionPage.createPGraph);\r
+               converter.setFileImport(new ManualSchemaFileImport() {\r
+                       \r
+                       String filename;\r
+                       @Override\r
+                       public File getFileForLocation(final String location) throws IOException {\r
+                               if (Display.getCurrent() == null)\r
+                                       Display.getDefault().syncExec(new Runnable() {\r
+                                               @Override\r
+                                               public void run() {\r
+                                                       showDialog(location);\r
+                                               }\r
+                                       });\r
+                               else {\r
+                                       showDialog(location);\r
+                               }\r
+                               if (filename == null)\r
+                                       return null;\r
+                               return new File(filename);\r
+                       }\r
+                       \r
+                       protected void showDialog(String location) {\r
+                               FileDialog dialog = new FileDialog(SchemaConversionWizard.this.getShell(), SWT.OPEN);\r
+                               dialog.setText("Open schema file for " + location);\r
+                               filename = dialog.open();\r
+                       }\r
+               });\r
                \r
-               converter.convertSchema(inputFile,configurationFile,outputPlugin);\r
+               converter.convert();\r
                \r
                schemaCombinationPage.setOutputPlugin(outputPlugin);\r
        }\r