]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java
Add support for importing regions to district models
[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
50                     } catch (Exception e) {
51                         throw new InvocationTargetException(e);
52                     }
53                 }
54             });
55             return true;
56         } catch (InvocationTargetException e) {
57             Throwable t = e.getTargetException();
58             WizardPage cp = (WizardPage) getContainer().getCurrentPage();
59             cp.setErrorMessage(t.getMessage());
60             ExceptionUtils.logAndShowError(t);
61             return false;
62         } catch (InterruptedException e) {
63             ExceptionUtils.logAndShowError(e);
64             return false;
65         }
66     }
67
68
69 }