1 package org.simantics.district.imports.ui;
3 import java.lang.reflect.InvocationTargetException;
5 import org.eclipse.core.runtime.IProgressMonitor;
6 import org.eclipse.jface.operation.IRunnableWithProgress;
7 import org.eclipse.jface.viewers.IStructuredSelection;
8 import org.eclipse.jface.wizard.Wizard;
9 import org.eclipse.jface.wizard.WizardPage;
10 import org.eclipse.ui.IImportWizard;
11 import org.eclipse.ui.IWorkbench;
12 import org.simantics.district.imports.CSVImportModel;
13 import org.simantics.district.imports.DistrictImportUtils;
14 import org.simantics.utils.ui.ExceptionUtils;
16 public class CSVImportWizard extends Wizard implements IImportWizard {
18 private CSVImportModel model;
20 public CSVImportWizard() {
21 setWindowTitle("Import CSV data");
22 setNeedsProgressMonitor(true);
27 public void init(IWorkbench workbench, IStructuredSelection selection) {
28 model = new CSVImportModel();
29 addPage(new CSVImportWizardFirstPage(model));
30 addPage(new CSVImportWizardPage(model));
31 addPage(new ComponentMappingPage(model));
35 public boolean performFinish() {
37 getContainer().run(true, true, new IRunnableWithProgress() {
40 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
42 monitor.beginTask("Importing CSV", 1);
44 if (model.isVertexImport()) {
45 DistrictImportUtils.importVertices(model);
47 DistrictImportUtils.importEdges(model);
49 } catch (Exception e) {
50 throw new InvocationTargetException(e);
55 } catch (InvocationTargetException e) {
56 Throwable t = e.getTargetException();
57 WizardPage cp = (WizardPage) getContainer().getCurrentPage();
58 cp.setErrorMessage(t.getMessage());
59 ExceptionUtils.logAndShowError(t);
61 } catch (InterruptedException e) {
62 ExceptionUtils.logAndShowError(e);