1 package org.simantics.district.imports.ui;
3 import java.io.IOException;
4 import java.nio.file.Path;
5 import java.util.Collections;
6 import java.util.HashMap;
10 import org.apache.commons.csv.CSVRecord;
11 import org.simantics.db.Resource;
12 import org.simantics.district.imports.DistrictImportUtils;
13 import org.simantics.district.imports.DistrictImportUtils.CSVHeader;
15 public class CSVImportModel {
17 // First page fills these
18 private Resource targetDiagram;
21 // Second page fills these
22 private char delimiter;
23 private boolean readFirstAsHeader = true;
24 private Map<String, Character> delimiters;
25 // private Path wktFile;
28 private int xCoordIndex = -1;
29 private int yCoordIndex = -1;
30 private int zCoordIndex = -1;
33 private int startXCoordIndex = -1;
34 private int startYCoordIndex = -1;
35 private int startZCoordIndex = -1;
36 private int endXCoordIndex = -1;
37 private int endYCoordIndex = -1;
38 private int endZCoordIndex = -1;
41 private int componentMappingIndex = -1;
42 private Map<String, Resource> componentMappings = new HashMap<>();
43 private boolean isVertexImport;
44 private String sourceCRS;
45 private int tempIndex;
46 private int pressureIndex;
47 private int diameterIndex;
48 private int outerDiamterIndex;
49 private int nominalMassFlowIndex;
53 public CSVImportModel() {
54 delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
57 public void setSource(Path source) {
61 public void setDelimiter(char delimiter) {
62 this.delimiter = delimiter;
65 public void setReadFirstAsHeader(boolean read) {
66 this.readFirstAsHeader = read;
69 public Path getSource() {
73 public List<CSVRecord> getRows(int amount) throws IOException {
75 return DistrictImportUtils.readRows(source, delimiter, amount);
77 return Collections.emptyList();
80 public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
82 return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount);
84 return Collections.emptyMap();
87 public Map<String, Integer> getHeader() throws IOException {
88 Map<String, Integer> header = null;
90 header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader);
92 header = Collections.emptyMap();
96 public boolean getReadFirstAsHeader() {
97 return readFirstAsHeader;
100 public String[] getDelimiterFormats() {
101 return delimiters.keySet().toArray(new String[delimiters.size()]);
104 public void setDelimiterByLabel(String item) {
105 setDelimiter(delimiters.get(item));
108 public List<Map<String, String>> readRows(int amount) throws IOException {
110 return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount);
112 return Collections.emptyList();
115 public char getDelimiter() {
119 // public Path getWKTFile() {
123 public int getXCoordIndex() {
127 public void setXCoordIndex(int xCoordIndex) {
128 this.xCoordIndex = xCoordIndex;
131 public int getYCoordIndex() {
135 public void setYCoordIndex(int yCoordIndex) {
136 this.yCoordIndex = yCoordIndex;
139 public int getZCoordIndex() {
143 public void setZCoordIndex(int zCoordIndex) {
144 this.zCoordIndex = zCoordIndex;
147 public int getComponentMappingIndex() {
148 return componentMappingIndex;
151 public void setComponentMappingIndex(int componentMappingIndex) {
152 this.componentMappingIndex = componentMappingIndex;
155 public void setParentDiagram(Resource diagram) {
156 this.targetDiagram = diagram;
159 public Resource getParentDiagram() {
160 return targetDiagram;
163 // public void setWKTFile(Path wktFile) {
164 // this.wktFile = wktFile;
167 public void setComponentMappings(String value, Resource resource) {
168 componentMappings.put(value, resource);
171 public Map<String, Resource> getComponentMappings() {
172 return componentMappings;
175 public boolean isVertexImport() {
176 return isVertexImport;
179 public void setVertexImport(boolean isVertexImport) {
180 this.isVertexImport = isVertexImport;
183 public void setStartXCoordIndex(int parseInt) {
184 this.startXCoordIndex = parseInt;
187 public int getStartXCoordIndex() {
188 return startXCoordIndex;
191 public void setStartYCoordIndex(int parseInt) {
192 this.startYCoordIndex = parseInt;
195 public int getStartYCoordIndex() {
196 return startYCoordIndex;
199 public void setStartZCoordIndex(int parseInt) {
200 this.startZCoordIndex = parseInt;
203 public int getStartZCoordIndex() {
204 return startZCoordIndex;
207 public void setEndXCoordIndex(int parseInt) {
208 this.endXCoordIndex = parseInt;
211 public int getEndXCoordIndex() {
212 return endXCoordIndex;
215 public void setEndYCoordIndex(int parseInt) {
216 this.endYCoordIndex = parseInt;
219 public int getEndYCoordIndex() {
220 return endYCoordIndex;
223 public void setEndZCoordIndex(int parseInt) {
224 this.endZCoordIndex = parseInt;
227 public int getEndZCoordIndex() {
228 return endZCoordIndex;
231 public void setSourceCRS(String crs) {
232 this.sourceCRS = crs;
235 public String getSourceCRS() {
239 public void setTempIndex(int tempIndex) {
240 this.tempIndex = tempIndex;
243 public int getTempIndex() {
247 public void setPressureIndex(int pressureIndex) {
248 this.pressureIndex = pressureIndex;
251 public int getPressureIndex() {
252 return pressureIndex;
255 public void setDiameterIndex(int parseInt) {
256 this.diameterIndex = parseInt;
259 public int getDiameterIndex() {
260 return diameterIndex;
263 public void setOuterDiameterIndex(int parseInt) {
264 this.outerDiamterIndex = parseInt;
267 public int getOuterDiamterIndex() {
268 return outerDiamterIndex;
271 public void setNominalMassFlowIndex(int parseInt) {
272 this.nominalMassFlowIndex = parseInt;
275 public int getNominalMassFlowIndex() {
276 return nominalMassFlowIndex;