]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java
Enable `track changes` and `split to multiple diagrams` by default
[simantics/district.git] / org.simantics.district.imports.ui / src / org / simantics / district / imports / ui / CSVImportWizard.java
1 package org.simantics.district.imports.ui;
2
3 import java.lang.reflect.InvocationTargetException;
4
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;
15
16 public class CSVImportWizard extends Wizard implements IImportWizard {
17
18     private CSVImportModel model;
19     
20     public CSVImportWizard() {
21         setWindowTitle("Import CSV data");
22         setNeedsProgressMonitor(true);
23     }
24     
25     
26     @Override
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));
32     }
33     
34     @Override
35     public boolean performFinish() {
36         try {
37             getContainer().run(true, true, new IRunnableWithProgress() {
38
39                 @Override
40                 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
41                     try {
42                         monitor.beginTask("Importing CSV", 1);
43                         
44                         if (model.isVertexImport()) {
45                             DistrictImportUtils.importVertices(model);
46                         } else {
47                             DistrictImportUtils.importEdges(model);
48                         }
49                     } catch (Exception e) {
50                         throw new InvocationTargetException(e);
51                     }
52                 }
53             });
54             return true;
55         } catch (InvocationTargetException e) {
56             Throwable t = e.getTargetException();
57             WizardPage cp = (WizardPage) getContainer().getCurrentPage();
58             cp.setErrorMessage(t.getMessage());
59             ExceptionUtils.logAndShowError(t);
60             return false;
61         } catch (InterruptedException e) {
62             ExceptionUtils.logAndShowError(e);
63             return false;
64         }
65     }
66
67
68 }