]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/wizard/SchemaConversionWizard.java
XML data based schema and ontology generation
[simantics/interop.git] / org.simantics.xml.sax.ui / src / org / simantics / xml / sax / ui / wizard / SchemaConversionWizard.java
index fae0a576deffcbae1383198979e1612a30e36433..3c27632b6bcccbbe012de1b105568ca6a6cc24e0 100644 (file)
@@ -1,20 +1,23 @@
 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
 \r
-//     FileSelectionPage fileselectionPage;\r
-//     FileSelectionPage configurationSelectionPage;\r
-//     DirectorySelectionPage pluginSelectionPage;\r
-       InputSelectionPage inputSelectionPage ;\r
+       InputSelectionPage inputSelectionPage;\r
        ImportProcessPage importProcessPage;\r
+       SchemaCombinationPage schemaCombinationPage;\r
        \r
        public SchemaConversionWizard() {\r
                setWindowTitle("XML Schema conversion");\r
@@ -22,7 +25,6 @@ public class SchemaConversionWizard extends Wizard implements IImportWizard {
 \r
        @Override\r
        public void init(IWorkbench workbench, IStructuredSelection selection) {\r
-               // TODO Auto-generated method stub\r
 \r
        }\r
 \r
@@ -36,28 +38,54 @@ public class SchemaConversionWizard extends Wizard implements IImportWizard {
        \r
        @Override\r
        public void addPages() {\r
-//             fileselectionPage = new FileSelectionPage();\r
-//             fileselectionPage.setFilterExtensions(new String[]{"*.xsd"});\r
-//             fileselectionPage.setFilterNames(new String[]{"XML schema files"});\r
-//             pluginSelectionPage = new DirectorySelectionPage();\r
-//             addPage(fileselectionPage);\r
-//             addPage(pluginSelectionPage);\r
                addPage(inputSelectionPage = new InputSelectionPage());\r
                addPage(importProcessPage = new ImportProcessPage());\r
+               addPage(schemaCombinationPage = new SchemaCombinationPage());\r
        }\r
        \r
        public void doConversion() throws Exception {\r
-               SchemaConverter converter = new SchemaConverter();\r
-//             File inputFile = new File(fileselectionPage.getFilename());\r
-//             File outputPlugin = new File(pluginSelectionPage.getFilename());\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.convert();\r
                \r
-               converter.convertSchema(inputFile,configurationFile,outputPlugin);\r
+               schemaCombinationPage.setOutputPlugin(outputPlugin);\r
        }\r
 \r
 }\r