package org.simantics.xml.sax.ui.wizard; import org.eclipse.jface.layout.GridDataFactory; 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.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.simantics.utils.ui.widgets.DirectorySelectionWidget; import org.simantics.utils.ui.widgets.FileOrDirectorySelectionWidget; import org.simantics.utils.ui.widgets.FileSelectionListener; import org.simantics.utils.ui.widgets.FileSelectionWidget; public class InputSelectionPage extends WizardPage implements FileSelectionListener{ public InputSelectionPage() { super("InputPage","Select input files and output plug-in",null); } private FileSelectionWidget schemaSelection; private FileSelectionWidget configurationSelection; private DirectorySelectionWidget pluginSelection; boolean createPGraph = true; boolean createImporter = true; boolean createExporter = true; @Override public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1,false)); GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(composite); schemaSelection = new FileSelectionWidget(composite, "Schema file", SWT.OPEN); configurationSelection = new FileSelectionWidget(composite, "Configuration file (Optional)", SWT.OPEN); pluginSelection = new DirectorySelectionWidget(composite, "Output plug-in", SWT.SAVE); schemaSelection.setFilterExtensions(new String[]{"*.xsd"}); schemaSelection.setFilterNames(new String[]{"XML schema files"}); configurationSelection.setFilterExtensions(new String[]{"*.xml"}); configurationSelection.setFilterNames(new String[]{"XML files"}); schemaSelection.addListener(this); pluginSelection.addListener(this); final Button pGraphButton = new Button(composite, SWT.CHECK); final Button importButton = new Button(composite, SWT.CHECK); final Button exportButton = new Button(composite, SWT.CHECK); pGraphButton.setText("Create Ontology / .pgraph file"); importButton.setText("Create Importer"); exportButton.setText("Create Exporter"); pGraphButton.setSelection(createPGraph); importButton.setSelection(createImporter); exportButton.setSelection(createExporter); pGraphButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { createPGraph = pGraphButton.getSelection(); } }); importButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { createImporter = importButton.getSelection(); } }); exportButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { createExporter = exportButton.getSelection(); } }); setControl(composite); setPageComplete(false); } @Override public void fileSelected(FileOrDirectorySelectionWidget source, String[] filename) { setPageComplete(schemaSelection.getFilename() != null && pluginSelection.getFilename() != null); } public boolean isCreateExporter() { return createExporter; } public boolean isCreateImporter() { return createImporter; } public boolean isCreatePGraph() { return createPGraph; } public String getSchemaFilename() { if (schemaSelection.getFilename() == null ||schemaSelection.getFilename().length == 0) return null; return schemaSelection.getFilename()[0]; } public String getConfigurationFilename() { if (configurationSelection.getFilename() == null || configurationSelection.getFilename().length == 0) return null; return configurationSelection.getFilename()[0]; } public String getPluginFilename() { if (pluginSelection.getFilename() == null ||pluginSelection.getFilename().length == 0) return null; return pluginSelection.getFilename()[0]; } }