]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java
Support for new edge properties in district import wizard
[simantics/district.git] / org.simantics.district.imports.ui / src / org / simantics / district / imports / ui / CSVImportWizard.java
index 7a29e7505788c6b603a34f9dbf0c7cc76f30b896..6162314e21a91b3be6d4ba0e355482099f1d9085 100644 (file)
@@ -1,18 +1,17 @@
 package org.simantics.district.imports.ui;
 
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.List;
+import java.lang.reflect.InvocationTargetException;
 
-import org.apache.commons.csv.CSVRecord;
+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.geotools.referencing.CRS;
-import org.opengis.referencing.FactoryException;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
+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 {
 
@@ -20,42 +19,51 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
     
     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 {
-            
-            
-            Path csvFile = model.getSource();
-            char delim = model.getDelimiter();
-            
-            List<CSVRecord> rows = DistrictImportUtils.readRows(csvFile, delim, -1);
-            
-            Path wktFile = model.getWKTFile();
-            
-            try {
-                
-                
-                CoordinateReferenceSystem crs = CRS.decode(null);
-            } catch (FactoryException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
-            
-            
-            DistrictImportUtils.importCSVAsLayer(csvFile);
-        } catch (IOException e) {
-            e.printStackTrace();
+            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;
         }
-        return false;
     }
 
+
 }