-package org.simantics.xml.sax.ui.wizard;\r
-\r
-import java.io.File;\r
-import java.io.FilenameFilter;\r
-import java.io.IOException;\r
-import java.util.Arrays;\r
-\r
-import org.eclipse.jface.layout.GridDataFactory;\r
-import org.eclipse.jface.viewers.CheckboxTableViewer;\r
-import org.eclipse.jface.viewers.IStructuredContentProvider;\r
-import org.eclipse.jface.viewers.ITableLabelProvider;\r
-import org.eclipse.jface.viewers.LabelProvider;\r
-import org.eclipse.jface.viewers.Viewer;\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.simantics.xml.sax.OntologyCombinator;\r
-\r
-public class SchemaCombinationPage extends WizardPage {\r
- private Composite composite;\r
- \r
- File outputPlugin;\r
- File srcDir;\r
- \r
- CheckboxTableViewer fileSelector;\r
- Text outputText;\r
- \r
- public SchemaCombinationPage() {\r
- super("XML Schema conversion","Combining schema versions", null);\r
- setPageComplete(false);\r
- }\r
- \r
- @Override\r
- public void setVisible(boolean visible) {\r
- super.setVisible(visible);\r
- if (visible) {\r
- if (outputPlugin == null) {\r
- Label label = new Label(composite, SWT.NONE);\r
- label.setText("Output plug-in has not been set, cannot create combination resources");\r
- return;\r
- }\r
- String name = outputPlugin.getName();\r
- name = name.replaceAll("\\.", "/");\r
- srcDir = new File(outputPlugin.getAbsolutePath() +"/src/" + name);\r
- fileSelector.setInput(srcDir);\r
- }\r
- }\r
- \r
- \r
- @Override\r
- public void createControl(Composite parent) {\r
- composite = new Composite(parent, SWT.NONE);\r
- composite.setLayout(new GridLayout(1,true));\r
- setControl(composite); \r
-\r
- Label label = new Label(composite, SWT.NONE);\r
- label.setText("Ontology resource files");\r
- fileSelector = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);\r
- fileSelector.setContentProvider(new FileContentProvider());\r
- fileSelector.setLabelProvider(new FileLabelProvider());\r
-\r
- label = new Label(composite, SWT.NONE);\r
- label.setText("Output file");\r
- outputText = new Text(composite, SWT.BORDER|SWT.SINGLE);\r
- Button button = new Button(composite, SWT.PUSH);\r
- button.setText("Combine");\r
- button.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- doCombination();\r
- }\r
- });\r
- \r
- GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(fileSelector.getControl());\r
- GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(outputText);\r
- GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(button);\r
- }\r
- \r
- public void setOutputPlugin(File outputPlugin) {\r
- this.outputPlugin = outputPlugin;\r
- }\r
- \r
- private void doCombination() {\r
- String outputName = outputText.getText();\r
- if (outputName == null || outputName.length() < 2)\r
- return;\r
- if (!outputName.endsWith(".java"))\r
- outputName+=".java";\r
- \r
- File outputFile = new File(srcDir.getAbsolutePath()+"/"+outputName);\r
- \r
- Object sel[] = fileSelector.getCheckedElements();\r
- File inputFiles[] = new File[sel.length];\r
- for (int i = 0; i < sel.length; i++) {\r
- inputFiles[i] = (File)sel[i];\r
- }\r
- \r
- try {\r
- OntologyCombinator.combine(inputFiles, outputFile);\r
- setPageComplete(true);\r
- } catch (IOException e) {\r
- setErrorMessage(e.getMessage());\r
- e.printStackTrace();\r
- }\r
- \r
- }\r
- \r
- private static class FileContentProvider implements IStructuredContentProvider {\r
- @Override\r
- public Object[] getElements(Object inputElement) {\r
- File directory = (File)inputElement;\r
- if (!directory.isDirectory())\r
- return new Object[0];\r
- File[] files = directory.listFiles(new FilenameFilter() {\r
- \r
- @Override\r
- public boolean accept(File dir, String name) {\r
- return name.endsWith("java");\r
- }\r
- });\r
- return files;\r
- }\r
- \r
- @Override\r
- public void dispose() {\r
- \r
- }\r
- \r
- @Override\r
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r
- \r
- }\r
- }\r
- \r
- private static class FileLabelProvider extends LabelProvider implements ITableLabelProvider {\r
- @Override\r
- public Image getColumnImage(Object element, int columnIndex) {\r
- return null;\r
- }\r
- \r
- @Override\r
- public String getColumnText(Object element, int columnIndex) {\r
- File file = (File)element;\r
- if (columnIndex == 0)\r
- return file.getName();\r
- else\r
- return null;\r
- }\r
- }\r
-\r
-}\r
+package org.simantics.xml.sax.ui.wizard;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.simantics.xml.sax.OntologyCombinator;
+import org.simantics.xml.sax.SCLCombinator;
+
+public class SchemaCombinationPage extends WizardPage {
+ private Composite composite;
+
+ File outputPlugin;
+ File srcDir;
+
+ CheckboxTableViewer fileSelector;
+ Text javaOutputText;
+ Text sclOutputText;
+
+ public SchemaCombinationPage() {
+ super("XML Schema conversion","Combining schema versions", null);
+ setPageComplete(false);
+ }
+
+ @Override
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible) {
+ if (outputPlugin == null) {
+ Label label = new Label(composite, SWT.NONE);
+ label.setText("Output plug-in has not been set, cannot create combination resources");
+ return;
+ }
+ String name = outputPlugin.getName();
+ name = name.replaceAll("\\.", "/");
+ srcDir = new File(outputPlugin.getAbsolutePath() +"/src/" + name);
+ fileSelector.setInput(srcDir);
+ }
+ }
+
+
+ @Override
+ public void createControl(Composite parent) {
+ composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(1,true));
+ setControl(composite);
+
+ Label label = new Label(composite, SWT.NONE);
+ label.setText("Ontology resource files");
+ fileSelector = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
+ fileSelector.setContentProvider(new FileContentProvider());
+ fileSelector.setLabelProvider(new FileLabelProvider());
+
+ label = new Label(composite, SWT.NONE);
+ label.setText("Java Output file");
+ javaOutputText = new Text(composite, SWT.BORDER|SWT.SINGLE);
+
+ label = new Label(composite, SWT.NONE);
+ label.setText("SCL Output file");
+ sclOutputText = new Text(composite, SWT.BORDER|SWT.SINGLE);
+
+ Button button = new Button(composite, SWT.PUSH);
+ button.setText("Combine");
+ button.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ doCombination();
+ }
+ });
+
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(fileSelector.getControl());
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(javaOutputText);
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(sclOutputText);
+ GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(button);
+ }
+
+ public void setOutputPlugin(File outputPlugin) {
+ this.outputPlugin = outputPlugin;
+ }
+
+ private void doCombination() {
+ Object sel[] = fileSelector.getCheckedElements();
+ File inputFiles[] = new File[sel.length];
+ for (int i = 0; i < sel.length; i++) {
+ inputFiles[i] = (File)sel[i];
+ }
+
+ try {
+ String javaOutputName = javaOutputText.getText();
+ if (javaOutputName != null && javaOutputName.length() > 2) {
+ if (!javaOutputName.endsWith(".java"))
+ javaOutputName+=".java";
+
+ File outputFile = new File(srcDir.getAbsolutePath()+"/"+javaOutputName);
+ OntologyCombinator combinator = new OntologyCombinator();
+ combinator.combine(inputFiles, outputFile);
+
+ }
+ // TODO: SCL code depends on Java, allowing generating just SCL makes sense only for testing purposes.
+ String sclOutputName = sclOutputText.getText();
+ if (sclOutputName != null && sclOutputName.length() > 2) {
+ if (!sclOutputName.endsWith(".scl"))
+ sclOutputName+=".scl";
+
+ File outputFile = new File(srcDir.getAbsolutePath()+"/"+sclOutputName);
+ OntologyCombinator combinator = new SCLCombinator();
+ combinator.combine(inputFiles, outputFile);
+ }
+
+ setPageComplete(true);
+ } catch (IOException e) {
+ setErrorMessage(e.getMessage());
+ e.printStackTrace();
+ }
+
+ }
+
+ private static class FileContentProvider implements IStructuredContentProvider {
+ @Override
+ public Object[] getElements(Object inputElement) {
+ File directory = (File)inputElement;
+ if (!directory.isDirectory())
+ return new Object[0];
+ File[] files = directory.listFiles(new FilenameFilter() {
+
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith("java");
+ }
+ });
+ return files;
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+ }
+
+ private static class FileLabelProvider extends LabelProvider implements ITableLabelProvider {
+ @Override
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ @Override
+ public String getColumnText(Object element, int columnIndex) {
+ File file = (File)element;
+ if (columnIndex == 0)
+ return file.getName();
+ else
+ return null;
+ }
+ }
+
+}