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 {
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;
}
+
}