]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Refactor CSV import wizard to only list each property once 10/4510/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Thu, 24 Sep 2020 11:05:47 +0000 (14:05 +0300)
committerReino Ruusu <reino.ruusu@semantum.fi>
Thu, 24 Sep 2020 11:05:47 +0000 (14:05 +0300)
gitlab #97

Change-Id: If885cde4972fefe6db9fb71b5fce0d7190d09590

org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java

index 5db4581584e6110147a87173b0fa3bb0e6aca5bf..f0961fa5804380b6b05332b01ee827c519bae180 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.district.imports.ui;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -51,61 +52,10 @@ public class CSVImportWizardPage extends WizardPage {
     private Composite tableComposite;
 //    private FileSelectionWidget wktFileSelection;
 
-    // Common for vertex and edge
-    private DynamicComboFieldEditor componentMappingSelector;
-    private DynamicComboFieldEditor idSelector;
+    List<DynamicComboFieldEditor> fieldSelectors;
     
-    // For vertex import
-    private DynamicComboFieldEditor xCoordSelector;
-    private DynamicComboFieldEditor yCoordSelector;
-    private DynamicComboFieldEditor zValueSelector;
-    private DynamicComboFieldEditor altElevationValueSelector;
-
-    private DynamicComboFieldEditor supplyTempValueSelector;
-    private DynamicComboFieldEditor returnTempValueSelector;
-    private DynamicComboFieldEditor supplyPressureValueSelector;
-    private DynamicComboFieldEditor returnPressureValueSelector;
-    private DynamicComboFieldEditor dpSelector;
-    private DynamicComboFieldEditor dtSelector;
-    private DynamicComboFieldEditor heatPowerSelector;
-    private DynamicComboFieldEditor peakPowerSelector;
-    private DynamicComboFieldEditor regionSelector;
-    private DynamicComboFieldEditor nominalHeadMSelector;
-    private DynamicComboFieldEditor nominalHeadBSelector;
-    private DynamicComboFieldEditor nominalFlowSelector;
-    private DynamicComboFieldEditor maximumHeadMSelector;
-    private DynamicComboFieldEditor heatLoadDsSelector;
-    private DynamicComboFieldEditor massFlowSelector;
-    private DynamicComboFieldEditor volFlowSelector;
-    private DynamicComboFieldEditor velocitySelector;
-    private DynamicComboFieldEditor flowAreaSelector;
-    private DynamicComboFieldEditor nominalPressureLossSelector;
-    private DynamicComboFieldEditor valvePositionSelector;
-    private DynamicComboFieldEditor addressSelector;
-    private DynamicComboFieldEditor lengthSelector;
-
-    // For edge import
-    private DynamicComboFieldEditor startXCoordSelector;
-    private DynamicComboFieldEditor startYCoordSelector;
-    private DynamicComboFieldEditor startZValueSelector;
-    private DynamicComboFieldEditor endXCoordSelector;
-    private DynamicComboFieldEditor endYCoordSelector;
-    private DynamicComboFieldEditor endZValueSelector;
-    private DynamicComboFieldEditor detailedGeometrySelector;
-    private DynamicComboFieldEditor pipeCodeSelector;
-    private DynamicComboFieldEditor installationYearSelector;
-    private DynamicComboFieldEditor wallThicknessSelector;
-    private DynamicComboFieldEditor insulationConductivitySelector;
-    private DynamicComboFieldEditor pipeSizeDNSelector;
-    private DynamicComboFieldEditor roughnessSelector;
-    private DynamicComboFieldEditor structureSelector;
-
     private Text edgeConnectionPadding;
     
-    private DynamicComboFieldEditor outerDiameterSelector;
-    private DynamicComboFieldEditor diameterSelector;
-    private DynamicComboFieldEditor nominalMassFlowSelector;
-
     private Group indexMappingGroup;
 
     private Composite composite;
@@ -114,14 +64,6 @@ public class CSVImportWizardPage extends WizardPage {
 
     private Combo sourceCRSCombo;
 
-    private DynamicComboFieldEditor edgeFlowAreaSelector;
-
-    private DynamicComboFieldEditor kReturnSelector;
-
-    private DynamicComboFieldEditor kSupplySelector;
-
-    private DynamicComboFieldEditor tGroundSelector;
-    
     protected CSVImportWizardPage(CSVImportModel model) {
         super("Import CSV Data");
         this.model = model;
@@ -292,13 +234,15 @@ public class CSVImportWizardPage extends WizardPage {
         indexMappingGroup.setText("Column index mapping");
         GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(indexMappingGroup);
         
+        fieldSelectors = new ArrayList<>();
+        
+        createCommonIndexMappingField(indexMappingGroup);
+        
         if (model.isVertexImport())
             createVertexIndexMappingField(indexMappingGroup);
         else
             createEdgeIndexMappingField(indexMappingGroup);
         
-        createCommonIndexMappingField(indexMappingGroup);
-        
         if (!model.isVertexImport()) {
             Label label = new Label(indexMappingGroup, SWT.NONE);
             label.setText("Connection point padding");
@@ -323,10 +267,10 @@ public class CSVImportWizardPage extends WizardPage {
 
     private void createCommonIndexMappingField(Group parent) {
         
-        componentMappingSelector = createComboField("componentMapping", "Apros component mapping", model::setComponentMappingIndex, parent);
+        fieldSelectors.add(createComboField("componentMapping", "Apros component mapping", model::setComponentMappingIndex, parent));
         
-        idSelector = createComboField("id", "ID", model::setIdIndex, parent);
-        regionSelector = createComboField("regionValue", "Region", model::setRegionIndex, parent);
+        fieldSelectors.add(createComboField("id", "ID", model::setIdIndex, parent));
+        fieldSelectors.add(createComboField("regionValue", "Region", model::setRegionIndex, parent));
     }
 
     private DynamicComboFieldEditor createComboField(String name, String label, Consumer<Integer> setter, Group parent) {
@@ -352,69 +296,67 @@ public class CSVImportWizardPage extends WizardPage {
     }
 
     private void createVertexIndexMappingField(Group parent) {
-        xCoordSelector = createComboField("xCoord", "X Coordinate", model::setXCoordIndex, parent);
+        fieldSelectors.add(createComboField("xCoord", "X Coordinate", model::setXCoordIndex, parent));
 
-        yCoordSelector = createComboField("yCoord", "Y Coordinate", model::setYCoordIndex, parent);
-        zValueSelector = createComboField("zValue", "Z Value", model::setZCoordIndex, parent);
+        fieldSelectors.add(createComboField("yCoord", "Y Coordinate", model::setYCoordIndex, parent));
+        fieldSelectors.add(createComboField("zValue", "Z Value", model::setZCoordIndex, parent));
 
-        altElevationValueSelector = createComboField("altElevation", "Alternative Elevation", model::setAltElevationIndex, parent);
-        
-        supplyTempValueSelector = createComboField("tempValue", "Supply Temperature value", model::setSupplyTempIndex, parent);
-        returnTempValueSelector = createComboField("returnTempValue", "Return Temperature value", model::setReturnTempIndex, parent);
-        supplyPressureValueSelector = createComboField("pressureValue", "Supply Pressure value", model::setSupplyPressureIndex, parent);
-        returnPressureValueSelector = createComboField("returnPressureValue", "Return Pressure value", model::setReturnPressureIndex, parent);
-        dpSelector = createComboField("dpValue", "Delta pressure ", model::setDeltaPressureIndex, parent);
-        dtSelector = createComboField("dtValue", "Delta temperature ", model::setDeltaTemperatureIndex, parent);
-        heatPowerSelector = createComboField("heatPowerValue", "Heat Power", model::setHeatPowerIndex, parent);
-        peakPowerSelector = createComboField("peakPowerValue", "Peak Power", model::setPeakPowerIndex, parent);
+        fieldSelectors.add(createComboField("altElevation", "Alternative Elevation", model::setAltElevationIndex, parent));
         
-        nominalHeadMSelector = createComboField("nominalHeadMValue", "nominalHeadM", model::setNominalHeadMIndex, parent);
-        nominalHeadBSelector = createComboField("nominalHeadBValue", "nominalHeadB", model::setNominalHeadBIndex, parent);
-        nominalFlowSelector = createComboField("nominalFlowValue", "nominalFlow", model::setNominalFlowIndex, parent);
-
-        maximumHeadMSelector = createComboField("maximumHeadMValue", "maximumHeadM", model::setMaximumHeadMIndex, parent);
-        heatLoadDsSelector = createComboField("heatLoadDsValue", "heatLoadDs", model::setHeatLoadDsIndex, parent);
-        massFlowSelector = createComboField("massFlowValue", "massFlow", model::setMassFlowIndex, parent);
-        volFlowSelector = createComboField("volFlowValue", "volFlow", model::setVolFlowIndex, parent);
-        velocitySelector = createComboField("velocityValue", "velocity", model::setVelocityIndex, parent);
-        flowAreaSelector = createComboField("flowAreaValue", "flowArea", model::setFlowAreaIndex, parent);
-        nominalPressureLossSelector = createComboField("nominalPressureLossValue", "nominalPressureLoss", model::setNominalPressureLossIndex, parent);
-        valvePositionSelector = createComboField("valvePositionSelectorValue", "valvePositionSelector", model::setValvePositionIndex, parent);
-        addressSelector = createComboField("addressValue", "addressSelector", model::setAddressIndex, parent);
+        fieldSelectors.add(createComboField("tempValue", "Supply Temperature value", model::setSupplyTempIndex, parent));
+        fieldSelectors.add(createComboField("returnTempValue", "Return Temperature value", model::setReturnTempIndex, parent));
+        fieldSelectors.add(createComboField("pressureValue", "Supply Pressure value", model::setSupplyPressureIndex, parent));
+        fieldSelectors.add(createComboField("returnPressureValue", "Return Pressure value", model::setReturnPressureIndex, parent));
+        fieldSelectors.add(createComboField("dpValue", "Delta pressure ", model::setDeltaPressureIndex, parent));
+        fieldSelectors.add(createComboField("dtValue", "Delta temperature ", model::setDeltaTemperatureIndex, parent));
+        fieldSelectors.add(createComboField("heatPowerValue", "Heat Power", model::setHeatPowerIndex, parent));
+        fieldSelectors.add(createComboField("peakPowerValue", "Peak Power", model::setPeakPowerIndex, parent));
         
-
+        fieldSelectors.add(createComboField("nominalHeadMValue", "nominalHeadM", model::setNominalHeadMIndex, parent));
+        fieldSelectors.add(createComboField("nominalHeadBValue", "nominalHeadB", model::setNominalHeadBIndex, parent));
+        fieldSelectors.add(createComboField("nominalFlowValue", "nominalFlow", model::setNominalFlowIndex, parent));
+
+        fieldSelectors.add(createComboField("maximumHeadMValue", "maximumHeadM", model::setMaximumHeadMIndex, parent));
+        fieldSelectors.add(createComboField("heatLoadDsValue", "heatLoadDs", model::setHeatLoadDsIndex, parent));
+        fieldSelectors.add(createComboField("massFlowValue", "massFlow", model::setMassFlowIndex, parent));
+        fieldSelectors.add(createComboField("volFlowValue", "volFlow", model::setVolFlowIndex, parent));
+        fieldSelectors.add(createComboField("velocityValue", "velocity", model::setVelocityIndex, parent));
+        fieldSelectors.add(createComboField("flowAreaValue", "flowArea", model::setFlowAreaIndex, parent));
+        fieldSelectors.add(createComboField("nominalPressureLossValue", "nominalPressureLoss", model::setNominalPressureLossIndex, parent));
+        fieldSelectors.add(createComboField("valvePositionSelectorValue", "valvePositionSelector", model::setValvePositionIndex, parent));
+        fieldSelectors.add(createComboField("addressValue", "addressSelector", model::setAddressIndex, parent));
     }
     
     private void createEdgeIndexMappingField(Group parent) {
         
 //        Composite paddingComposite = new Composite(parent, SWT.NONE);
 //        GridLayoutFactory.fillDefaults().numColumns(2).applyTo(paddingComposite);
-        startXCoordSelector = createComboField("startxCoord", "Start X Coordinate", model::setStartXCoordIndex, parent);
-        startYCoordSelector = createComboField("startyCoord", "Start Y Coordinate", model::setStartYCoordIndex, parent);
-        startZValueSelector = createComboField("startzValue", "Start Z Value", model::setStartZCoordIndex, parent);
+        fieldSelectors.add(createComboField("startxCoord", "Start X Coordinate", model::setStartXCoordIndex, parent));
+        fieldSelectors.add(createComboField("startyCoord", "Start Y Coordinate", model::setStartYCoordIndex, parent));
+        fieldSelectors.add(createComboField("startzValue", "Start Z Value", model::setStartZCoordIndex, parent));
         
-        endXCoordSelector = createComboField("endxCoord", "End X Coordinate", model::setEndXCoordIndex, parent);
-        endYCoordSelector = createComboField("endyCoord", "End Y Coordinate", model::setEndYCoordIndex, parent);
-        endZValueSelector = createComboField("endzValue", "End Z Value", model::setEndZCoordIndex, parent);
+        fieldSelectors.add(createComboField("endxCoord", "End X Coordinate", model::setEndXCoordIndex, parent));
+        fieldSelectors.add(createComboField("endyCoord", "End Y Coordinate", model::setEndYCoordIndex, parent));
+        fieldSelectors.add(createComboField("endzValue", "End Z Value", model::setEndZCoordIndex, parent));
         
-        pipeCodeSelector = createComboField("pipeCodeValue", "Pipe Code", model::setPipeCodeIndex, parent);
+        fieldSelectors.add(createComboField("pipeCodeValue", "Pipe Code", model::setPipeCodeIndex, parent));
         
-        detailedGeometrySelector = createComboField("detailedGeometryValue", "Geometry", model::detailedGeometryIndex, parent);
-        diameterSelector = createComboField("diameterValue", "Diameter value", model::setDiameterIndex, parent);
-        outerDiameterSelector = createComboField("outerDiameterValue", "Outer Diameter value", model::setOuterDiameterIndex, parent);
-        nominalMassFlowSelector = createComboField("nominalMassFlowValue", "Nominal Mass Flow", model::setNominalMassFlowIndex, parent);
-        edgeFlowAreaSelector = createComboField("edgeFlowAreaValue", "Flow Area", model::setEdgeFlowAreaIndex, parent);
-        kReturnSelector = createComboField("kReturnValue", "K Return", model::setKReturnIndex, parent);
-        kSupplySelector = createComboField("kSupplyValue", "K Supply", model::setKSupplyIndex, parent);
-        tGroundSelector = createComboField("tGroundValue", "Temperature Ground", model::setTGroundIndex, parent);
-        lengthSelector = createComboField("lengthValue", "lengthSelector", model::setLengthIndex, parent);
+        fieldSelectors.add(createComboField("detailedGeometryValue", "Geometry", model::detailedGeometryIndex, parent));
+        fieldSelectors.add(createComboField("diameterValue", "Diameter value", model::setDiameterIndex, parent));
+        fieldSelectors.add(createComboField("outerDiameterValue", "Outer Diameter value", model::setOuterDiameterIndex, parent));
+        fieldSelectors.add(createComboField("nominalMassFlowValue", "Nominal Mass Flow", model::setNominalMassFlowIndex, parent));
+        fieldSelectors.add(createComboField("edgeFlowAreaValue", "Flow Area", model::setEdgeFlowAreaIndex, parent));
+        fieldSelectors.add(createComboField("kReturnValue", "K Return", model::setKReturnIndex, parent));
+        fieldSelectors.add(createComboField("kSupplyValue", "K Supply", model::setKSupplyIndex, parent));
+        fieldSelectors.add(createComboField("tGroundValue", "Temperature Ground", model::setTGroundIndex, parent));
+        fieldSelectors.add(createComboField("lengthValue", "Length", model::setLengthIndex, parent));
         
-        pipeSizeDNSelector = createComboField("pipeSizeDNValue", "Pipe Size DN", model::setPipeSizeDNIndex, parent);
-        structureSelector = createComboField("structureValue", "Structure", model::setStructureIndex, parent);
-        installationYearSelector = createComboField("installationYearValue", "Installation Year", model::setInstallationYearIndex, parent);
-        wallThicknessSelector = createComboField("wallThicknessValue", "Wall Thickness", model::setWallThicknessIndex, parent);
-        insulationConductivitySelector = createComboField("insulationConductivityValue", "Insulation Conductivity", model::setInsulationConductivityIndex, parent);
-        roughnessSelector = createComboField("roughnessValue", "Roughness", model::setRoughnessIndex, parent);
+        fieldSelectors.add(createComboField("pipeSizeDNValue", "Pipe Size DN", model::setPipeSizeDNIndex, parent));
+        fieldSelectors.add(createComboField("structureValue", "Structure", model::setStructureIndex, parent));
+        fieldSelectors.add(createComboField("installationYearValue", "Installation Year", model::setInstallationYearIndex, parent));
+        fieldSelectors.add(createComboField("wallThicknessValue", "Wall Thickness", model::setWallThicknessIndex, parent));
+        fieldSelectors.add(createComboField("insulationConductivityValue", "Insulation Conductivity", model::setInsulationConductivityIndex, parent));
+        fieldSelectors.add(createComboField("roughnessValue", "Roughness", model::setRoughnessIndex, parent));
     }
 
     private void updateCombos() {
@@ -432,67 +374,12 @@ public class CSVImportWizardPage extends WizardPage {
             namesAndValues[i++] = nameAndValue;
         }
 
-        if (model.isVertexImport())
-            updateVertexCombos(namesAndValues);
-        else
-            updateEdgeCombos(namesAndValues);
-
-        componentMappingSelector.updateCombo(namesAndValues);
-        idSelector.updateCombo(namesAndValues);
-    }
-
-    private void updateEdgeCombos(String[][] namesAndValues) {
-        startXCoordSelector.updateCombo(namesAndValues);
-        endXCoordSelector.updateCombo(namesAndValues);
-        startYCoordSelector.updateCombo(namesAndValues);
-        endYCoordSelector.updateCombo(namesAndValues);
-        startZValueSelector.updateCombo(namesAndValues);
-        endZValueSelector.updateCombo(namesAndValues);
-        pipeCodeSelector.updateCombo(namesAndValues);
-        detailedGeometrySelector.updateCombo(namesAndValues);
-        diameterSelector.updateCombo(namesAndValues);
-        outerDiameterSelector.updateCombo(namesAndValues);
-        nominalMassFlowSelector.updateCombo(namesAndValues);
-        edgeFlowAreaSelector.updateCombo(namesAndValues);
-        kReturnSelector.updateCombo(namesAndValues);
-        kSupplySelector.updateCombo(namesAndValues);
-        tGroundSelector.updateCombo(namesAndValues);
-        lengthSelector.updateCombo(namesAndValues);
-        pipeSizeDNSelector.updateCombo(namesAndValues);
-        structureSelector.updateCombo(namesAndValues);
-        installationYearSelector.updateCombo(namesAndValues);
-        wallThicknessSelector.updateCombo(namesAndValues);
-        insulationConductivitySelector.updateCombo(namesAndValues);
-        roughnessSelector.updateCombo(namesAndValues);
+        updateCombos(namesAndValues);
     }
 
-    private void updateVertexCombos(String[][] namesAndValues) {
-        xCoordSelector.updateCombo(namesAndValues);
-        yCoordSelector.updateCombo(namesAndValues);
-        zValueSelector.updateCombo(namesAndValues);
-        altElevationValueSelector.updateCombo(namesAndValues);
-        supplyTempValueSelector.updateCombo(namesAndValues);       
-        returnTempValueSelector.updateCombo(namesAndValues);       
-        supplyPressureValueSelector.updateCombo(namesAndValues);   
-        returnPressureValueSelector.updateCombo(namesAndValues);   
-        dpSelector.updateCombo(namesAndValues);                    
-        dtSelector.updateCombo(namesAndValues);                    
-        heatPowerSelector.updateCombo(namesAndValues);             
-        valvePositionSelector.updateCombo(namesAndValues);             
-        nominalHeadMSelector.updateCombo(namesAndValues);          
-        nominalHeadBSelector.updateCombo(namesAndValues);          
-        nominalFlowSelector.updateCombo(namesAndValues);           
-        maximumHeadMSelector.updateCombo(namesAndValues);          
-        heatLoadDsSelector.updateCombo(namesAndValues);            
-        massFlowSelector.updateCombo(namesAndValues);              
-        volFlowSelector.updateCombo(namesAndValues);               
-        velocitySelector.updateCombo(namesAndValues);              
-        flowAreaSelector.updateCombo(namesAndValues);              
-        nominalPressureLossSelector.updateCombo(namesAndValues);   
-        addressSelector.updateCombo(namesAndValues);
+    private void updateCombos(String[][] namesAndValues) {
+        fieldSelectors.forEach(s -> s.updateCombo(namesAndValues));
     }
-    
-    
 
     private void updateHeaders() {
         if (headerTable != null)