]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java
Enhancements to district functionalities and code
[simantics/district.git] / org.simantics.district.imports.ui / src / org / simantics / district / imports / ui / CSVImportModel.java
index 50c427c4d14f66138ec17246411ecae4d617294b..53de5cfe27714ad2be556b34b065a564174a7bfe 100644 (file)
-package org.simantics.district.imports.ui;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Path;\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.simantics.district.imports.DistrictImportUtils;\r
-import org.simantics.district.imports.DistrictImportUtils.CSVHeader;\r
-\r
-public class CSVImportModel {\r
-\r
-    private Path source;\r
-    private char delimiter;\r
-    private boolean read;\r
-    private Map<String, Character> delimiters;\r
-\r
-    public CSVImportModel() {\r
-        delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();\r
-    }\r
-    \r
-    public void setSource(Path source) {\r
-        this.source = source;\r
-    }\r
-\r
-    public void setDelimiter(char delimiter) {\r
-        this.delimiter = delimiter;\r
-    }\r
-\r
-    public void setReadFirstAsHeader(boolean read) {\r
-        this.read = read;\r
-    }\r
-\r
-    public Path getSource() {\r
-        return source;\r
-    }\r
-\r
-    public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {\r
-        if (source != null)\r
-            return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, read, amount);\r
-        else\r
-            return Collections.emptyMap();\r
-    }\r
-    \r
-    public Map<String, Integer> getHeader() throws IOException {\r
-        Map<String, Integer> header = null;\r
-        if (source != null)\r
-            header = DistrictImportUtils.readCSVHeader(source, delimiter, read);\r
-        if (header == null)\r
-            header = Collections.emptyMap();\r
-        return header;\r
-    }\r
-\r
-    public boolean getReadFirstAsHeader() {\r
-        return read;\r
-    }\r
-\r
-    public String[] getDelimiterFormats() {\r
-        return delimiters.keySet().toArray(new String[delimiters.size()]);\r
-    }\r
-\r
-    public void setDelimiterByLabel(String item) {\r
-        setDelimiter(delimiters.get(item));\r
-    }\r
-\r
-    public List<Map<String, String>> readRows(int amount) throws IOException {\r
-        if (source != null)\r
-            return DistrictImportUtils.readRows(source, delimiter, read, amount);\r
-        else\r
-            return Collections.emptyList();\r
-    }\r
-}\r
+package org.simantics.district.imports.ui;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.csv.CSVRecord;
+import org.simantics.db.Resource;
+import org.simantics.district.imports.DistrictImportUtils;
+import org.simantics.district.imports.DistrictImportUtils.CSVHeader;
+
+public class CSVImportModel {
+
+    // First page fills these
+    private Resource targetDiagram;
+    private Path source;
+    
+    // Second page fills these
+    private char delimiter;
+    private boolean read;
+    private Map<String, Character> delimiters;
+    private Path wktFile;
+    
+    // Vertex import
+    private int xCoordIndex = -1;
+    private int yCoordIndex = -1;
+    private int zCoordIndex = -1;
+    
+    // Edge import
+    private int startXCoordIndex = -1;
+    private int startYCoordIndex = -1;
+    private int startZCoordIndex = -1;
+    private int endXCoordIndex = -1;
+    private int endYCoordIndex = -1;
+    private int endZCoordIndex = -1;
+    
+    // common
+    private int componentMappingIndex = -1;
+    private Map<String, Resource> componentMappings = new HashMap<>();
+    private boolean isVertexImport;
+    
+    // Third page
+
+    public CSVImportModel() {
+        delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
+    }
+    
+    public void setSource(Path source) {
+        this.source = source;
+    }
+
+    public void setDelimiter(char delimiter) {
+        this.delimiter = delimiter;
+    }
+
+    public void setReadFirstAsHeader(boolean read) {
+        this.read = read;
+    }
+
+    public Path getSource() {
+        return source;
+    }
+
+    public List<CSVRecord> getRows(int amount) throws IOException {
+        if (source != null)
+            return DistrictImportUtils.readRows(source, delimiter, amount);
+        else
+            return Collections.emptyList();
+    }
+    
+    public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
+        if (source != null)
+            return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, read, amount);
+        else
+            return Collections.emptyMap();
+    }
+    
+    public Map<String, Integer> getHeader() throws IOException {
+        Map<String, Integer> header = null;
+        if (source != null)
+            header = DistrictImportUtils.readCSVHeader(source, delimiter, read);
+        if (header == null)
+            header = Collections.emptyMap();
+        return header;
+    }
+
+    public boolean getReadFirstAsHeader() {
+        return read;
+    }
+
+    public String[] getDelimiterFormats() {
+        return delimiters.keySet().toArray(new String[delimiters.size()]);
+    }
+
+    public void setDelimiterByLabel(String item) {
+        setDelimiter(delimiters.get(item));
+    }
+
+    public List<Map<String, String>> readRows(int amount) throws IOException {
+        if (source != null)
+            return DistrictImportUtils.readRows(source, delimiter, read, amount);
+        else
+            return Collections.emptyList();
+    }
+
+    public char getDelimiter() {
+        return delimiter;
+    }
+
+    public Path getWKTFile() {
+        return wktFile;
+    }
+
+    public int getXCoordIndex() {
+        return xCoordIndex;
+    }
+
+    public void setXCoordIndex(int xCoordIndex) {
+        this.xCoordIndex = xCoordIndex;
+    }
+
+    public int getYCoordIndex() {
+        return yCoordIndex;
+    }
+
+    public void setYCoordIndex(int yCoordIndex) {
+        this.yCoordIndex = yCoordIndex;
+    }
+
+    public int getZCoordIndex() {
+        return zCoordIndex;
+    }
+
+    public void setZCoordIndex(int zCoordIndex) {
+        this.zCoordIndex = zCoordIndex;
+    }
+
+    public int getComponentMappingIndex() {
+        return componentMappingIndex;
+    }
+    
+    public void setComponentMappingIndex(int componentMappingIndex) {
+        this.componentMappingIndex = componentMappingIndex;
+    }
+
+    public void setParentDiagram(Resource diagram) {
+        this.targetDiagram = diagram;
+    }
+
+    public Resource getParentDiagram() {
+        return targetDiagram;
+    }
+
+    public void setWKTFile(Path wktFile) {
+        this.wktFile = wktFile;
+    }
+
+    public void setComponentMappings(String value, Resource resource) {
+        componentMappings.put(value, resource);
+    }
+
+    public Map<String, Resource> getComponentMappings() {
+        return componentMappings;
+    }
+
+    public boolean isVertexImport() {
+        return isVertexImport;
+    }
+    
+    public void setVertexImport(boolean isVertexImport) {
+        this.isVertexImport = isVertexImport;
+    }
+
+    public void setStartXCoordIndex(int parseInt) {
+        this.startXCoordIndex = parseInt;
+    }
+    
+    public int getStartXCoordIndex() {
+        return startXCoordIndex;
+    }
+
+    public void setStartYCoordIndex(int parseInt) {
+        this.startYCoordIndex = parseInt;
+    }
+    
+    public int getStartYCoordIndex() {
+        return startYCoordIndex;
+    }
+
+    public void setStartZCoordIndex(int parseInt) {
+        this.startZCoordIndex = parseInt;
+    }
+    
+    public int getStartZCoordIndex() {
+        return startZCoordIndex;
+    }
+
+    public void setEndXCoordIndex(int parseInt) {
+        this.endXCoordIndex = parseInt;
+    }
+    
+    public int getEndXCoordIndex() {
+        return endXCoordIndex;
+    }
+
+    public void setEndYCoordIndex(int parseInt) {
+        this.endYCoordIndex = parseInt;
+    }
+    
+    public int getEndYCoordIndex() {
+        return endYCoordIndex;
+    }
+
+    public void setEndZCoordIndex(int parseInt) {
+        this.endZCoordIndex = parseInt;
+    }
+    
+    public int getEndZCoordIndex() {
+        return endZCoordIndex;
+    }
+
+}