X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax.ui%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2Fui%2Fwizard%2FSchemaCombinationPage.java;fp=org.simantics.xml.sax.ui%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2Fui%2Fwizard%2FSchemaCombinationPage.java;h=dd5d97f5d64fafeafa59adbf1904430f36d383fc;hb=8c7637425667bd9710be0fe6afe437050fea59b7;hp=1539f508c3fb1d808d3a601d45658d32f3d5bd8f;hpb=3474f080188aca472256339b9c3458bac3dd6b82;p=simantics%2Finterop.git diff --git a/org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/wizard/SchemaCombinationPage.java b/org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/wizard/SchemaCombinationPage.java index 1539f50..dd5d97f 100644 --- a/org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/wizard/SchemaCombinationPage.java +++ b/org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/wizard/SchemaCombinationPage.java @@ -1,158 +1,178 @@ -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; - -public class SchemaCombinationPage extends WizardPage { - private Composite composite; - - File outputPlugin; - File srcDir; - - CheckboxTableViewer fileSelector; - Text outputText; - - 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("Output file"); - outputText = 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(outputText); - GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(button); - } - - public void setOutputPlugin(File outputPlugin) { - this.outputPlugin = outputPlugin; - } - - private void doCombination() { - String outputName = outputText.getText(); - if (outputName == null || outputName.length() < 2) - return; - if (!outputName.endsWith(".java")) - outputName+=".java"; - - File outputFile = new File(srcDir.getAbsolutePath()+"/"+outputName); - - Object sel[] = fileSelector.getCheckedElements(); - File inputFiles[] = new File[sel.length]; - for (int i = 0; i < sel.length; i++) { - inputFiles[i] = (File)sel[i]; - } - - try { - OntologyCombinator.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; - } - } - -} +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; + } + } + +}