1 package org.simantics.district.network.ui.table;
3 import java.nio.file.Files;
4 import java.nio.file.Path;
5 import java.nio.file.Paths;
8 import javax.inject.Inject;
9 import javax.inject.Named;
11 import org.eclipse.e4.core.di.annotations.Execute;
12 import org.eclipse.e4.ui.services.IServiceConstants;
13 import org.eclipse.e4.ui.workbench.modeling.EPartService;
14 import org.eclipse.swt.widgets.FileDialog;
15 import org.eclipse.swt.widgets.Shell;
16 import org.simantics.district.imports.DistrictImportUtils;
17 import org.simantics.district.network.ui.techtype.table.TechTypeTableView;
18 import org.simantics.utils.ui.ExceptionUtils;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class ImportTechTypeCSVHandler {
24 private static final Logger LOGGER = LoggerFactory.getLogger(ImportTechTypeCSVHandler.class);
27 EPartService partService;
30 public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell s) {
31 // here we can import based on the current CSV table data
33 FileDialog dialog = new FileDialog(s);
34 String path = dialog.open();
38 Path p = Paths.get(path);
39 if (Files.exists(p)) {
40 Map<String, Integer> readCSVHeader = DistrictImportUtils.readCSVHeader(p, ';', true);
41 TechTypeTableView.table.setTechTypePath(path);
43 LOGGER.warn("Path does not exist even though path != null: {}", p);
46 LOGGER.error("Invalid file path given {}", path);
48 } catch (Exception e) {
49 LOGGER.error("Could not read file {}", path, e);
50 ExceptionUtils.logAndShowError("Could not read file " + path + " : " + e.getMessage(), e);