1 package org.simantics.district.network.ui.techtype.table;
3 import java.io.IOException;
4 import java.nio.file.Path;
5 import java.nio.file.Paths;
6 import java.util.ArrayList;
8 import java.util.stream.Collectors;
10 import org.apache.commons.csv.CSVRecord;
11 import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
12 import org.simantics.district.imports.DistrictImportUtils;
14 public class TechTypeTableDataProvider implements IDataProvider {
16 private List<CSVRecord> records = new ArrayList<>();
17 private List<CSVRecord> filteredRecords = new ArrayList<>();
18 private String filter = "";
20 public TechTypeTableDataProvider() {
23 setPath("C:\\projektit\\apros\\Semantum_VTT_Fortum portaali 2018-17-12\\järvenpää\\qgis\\TechTypeData.csv");
26 public Object getHeaderValue(int columnIndex) {
27 if (records.isEmpty()) {
30 return records.get(0).get(columnIndex);
34 public Object getDataValue(int columnIndex, int rowIndex) {
35 return filteredRecords.get(rowIndex + 1).get(columnIndex);
39 public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
44 public int getColumnCount() {
45 if (records.isEmpty()) {
48 return records.get(0).size();
52 public int getRowCount() {
53 return filteredRecords.size() - 1;
56 public boolean isEditable(int columnIndex, int rowIndex) {
60 public void setFilter(String text) {
61 this.filter = text.toLowerCase();
63 filteredRecords = records.stream().filter(record -> {
64 for (int i = 0; i < record.size(); i++) {
65 String columnContent = record.get(i);
66 if (columnContent.toLowerCase().contains(filter)) {
71 }).collect(Collectors.toList());
74 public void setPath(String path) {
76 filteredRecords.clear();
77 Path techTypeCsv = Paths.get(path);
79 DistrictImportUtils.consumeCSV(techTypeCsv, ';', false, record -> {
83 } catch (IOException e) {