package org.simantics.district.imports.ui; import java.lang.reflect.InvocationTargetException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; import org.simantics.district.imports.CSVImportModel; import org.simantics.district.imports.DistrictImportUtils; import org.simantics.utils.ui.ExceptionUtils; public class CSVImportWizard extends Wizard implements IImportWizard { private CSVImportModel model; public CSVImportWizard() { setWindowTitle("Import CSV data"); setNeedsProgressMonitor(true); } @Override public void init(IWorkbench workbench, IStructuredSelection selection) { model = new CSVImportModel(); addPage(new CSVImportWizardFirstPage(model)); addPage(new CSVImportWizardPage(model)); addPage(new ComponentMappingPage(model)); } @Override public boolean performFinish() { try { getContainer().run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask("Importing CSV", 1); if (model.isVertexImport()) { DistrictImportUtils.importVertices(model); } else { DistrictImportUtils.importEdges(model); } } catch (Exception e) { throw new InvocationTargetException(e); } } }); return true; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); WizardPage cp = (WizardPage) getContainer().getCurrentPage(); cp.setErrorMessage(t.getMessage()); ExceptionUtils.logAndShowError(t); return false; } catch (InterruptedException e) { ExceptionUtils.logAndShowError(e); return false; } } }