X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax.ui%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2Fui%2Fdatawizard%2FImportProcessPage.java;fp=org.simantics.xml.sax.ui%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2Fui%2Fdatawizard%2FImportProcessPage.java;h=c42f682bf8f825126bba4b2da51e6504337b5686;hb=fc60d91049c46ee5b6107da4d4c54eada4a9f21c;hp=0000000000000000000000000000000000000000;hpb=ab4fc05981803ce2c430f93f34b8b6a8f85a53ce;p=simantics%2Finterop.git diff --git a/org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/datawizard/ImportProcessPage.java b/org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/datawizard/ImportProcessPage.java new file mode 100644 index 0000000..c42f682 --- /dev/null +++ b/org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/datawizard/ImportProcessPage.java @@ -0,0 +1,111 @@ +package org.simantics.xml.sax.ui.datawizard; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.operation.IRunnableWithProgress; +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.eclipse.swt.widgets.Label; +import org.simantics.utils.ui.ErrorLogger; + + +public class ImportProcessPage extends WizardPage { + private Composite composite; + + private Button button; + private Label label; + + private boolean doneImport = false; + private boolean importing = false; + + public ImportProcessPage() { + super("XML Data conversion","Conversion Summary", null); + setPageComplete(false); + + } + + public boolean isDoneImport() { + return doneImport; + } + + @Override + public void createControl(Composite parent) { + composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(1,true)); + + Label fileLabel = new Label(composite, SWT.NONE); + fileLabel.setText("File: "); + + label = new Label(composite, SWT.NONE); + label.setText("Import has not been started."); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BOTTOM).grab(true, false).applyTo(label); + button = new Button(composite, SWT.PUSH); + button.setText("Import"); + GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(button); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + doImport(); + + } + }); + setControl(composite); + } + + private Exception exception; + + private void doImport() { + button.setEnabled(false); + label.setText("Import started."); + importing = true; + try { + getWizard().getContainer().run(true, true, new IRunnableWithProgress() { + + @Override + public void run(final IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + try { + + monitor.beginTask("XML Data conversion", IProgressMonitor.UNKNOWN); + final DataConversionWizard wizard = (DataConversionWizard)getWizard(); + wizard.doConversion(); + + + } catch (final Exception err) { + exception = err; + } + monitor.done(); + } + }); + } catch (InvocationTargetException err) { + exception = err; + } catch (InterruptedException err) { + exception = err; + } + if (exception != null) { + setErrorMessage("Conversion failed: " + exception.getMessage()); + ErrorLogger.defaultLogError("XML data conversion failed.",exception); + label.setText("Schema conversion failed."); + } else { + label.setText("Schema conversion done."); + } + doneImport = true; + importing = false; + setPreviousPage(null); + setPageComplete(true); + getContainer().updateButtons(); + + } + + public boolean isImporting() { + return importing; + } + +}