]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Hide "enabled" column for non-component type tech type tables 08/4608/1 release/1.35.3
authorReino Ruusu <reino.ruusu@semantum.fi>
Mon, 9 Nov 2020 10:53:12 +0000 (12:53 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Mon, 9 Nov 2020 10:53:12 +0000 (12:53 +0200)
gitlab #93

Change-Id: I8d9ea8008d13d6be8e2b3cff4bf56b0a6f9198b8

org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/adapters/TechTypeEditorAdapter.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTable.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableDataProvider.java

index fcd6a7e259075f81894f1613ee4d9699071e97b5..fdadbda7858fc736903198d2c31f2941b2ec23fc 100644 (file)
@@ -70,10 +70,9 @@ public class TechTypeEditorAdapter extends AbstractResourceEditorAdapter impleme
                                                });
                                        } else {
                                                String data = graph.getRelatedValue2(table, DN.TechType_TechTypeTable_HasData);
-                                               int[] enabled = graph.getPossibleRelatedValue2(table, DN.TechType_TechTypeTable_HasEnabledItems);
                                                TechTypeTableView.table.getDisplay().asyncExec(() -> {
                                                        TechTypeTableView.table.setComponentType(null);
-                                                       TechTypeTableView.table.setTechTypeData(data, enabled);
+                                                       TechTypeTableView.table.setTechTypeData(data, null);
                                                });
                                        }
                                }
index 7438269aba7071990b2b052cc21c539725d48d3d..f15be971df842fab31d5527669dc79e1fe0e29df 100644 (file)
@@ -181,7 +181,7 @@ public class TechTypeTable extends Composite {
                bodyDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
                        @Override
                        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
-                               if (columnPosition == 0) {
+                               if (bodyDataProvider.isCheckBoxColumn(columnPosition)) {
                                        configLabels.addLabel(CHECK_BOX_LABEL);
                                } else if (validationResult != null && keyName != null) {
                                        int keyColumn = bodyDataProvider.getVariableIndex(keyName);
@@ -270,7 +270,7 @@ public class TechTypeTable extends Composite {
                                                new EditableRule() {
                                                        @Override
                                                        public boolean isEditable(int columnIndex, int rowIndex) {
-                                                               return columnIndex == 0;
+                                                               return bodyDataProvider.isEditable(columnIndex, rowIndex);
                                                        }
                                                });
                                
index af0e28d07bc84be4b9b01ab221105b2f3c5269a9..4d4244d7caf43d677f7132ba77617be34917a9e5 100644 (file)
@@ -33,6 +33,8 @@ public class TechTypeTableDataProvider implements IDataProvider {
     private ListenerList<EnableListener> enableListeners = new ListenerList<EnableListener>();
 
     private int[] sortedRows;
+    
+       private boolean showEnabled = true;
 
        private static final Comparator<? super String> VALUE_COMPARATOR = (a, b) -> {
                try {
@@ -47,11 +49,12 @@ public class TechTypeTableDataProvider implements IDataProvider {
     public TechTypeTableDataProvider(String data, int[] enabledList) {
         setData(data);
         setEnabledFlags(enabledList);
+        showEnabled = enabledList != null;
     }
     
     public TechTypeTableDataProvider(String data) {
-        // load csv
         setData(data);
+        showEnabled = false;
     }
     
     public void setEnabledFlags(int[] enabledList) {
@@ -62,14 +65,26 @@ public class TechTypeTableDataProvider implements IDataProvider {
                     enabled[i] = true;
             }
         }
+        
+        showEnabled = enabledList != null;
+    }
+    
+    public boolean isCheckBoxColumn(int columnIndex) {
+       return isEnabledColumn(columnIndex);
     }
 
     public String getVariableName(int columnIndex) {
-        return variables != null && columnIndex > 0 && columnIndex <= variables.size() ? variables.get(columnIndex - 1) : null;
+        return variables != null && columnIndex > 0 && columnIndex <= variables.size()
+                       ? variables.get(columnIndex - columnOffset())
+                               : null;
     }
 
+       private int columnOffset() {
+               return showEnabled ? 1 : 0;
+       }
+
     public int getVariableIndex(String variableName) {
-        return variables != null ? variables.indexOf(variableName) + 1 : -1;
+        return variables != null ? variables.indexOf(variableName) + columnOffset() : -1;
     }
     
     public CSVRecord getRecord(int rowIndex) {
@@ -87,24 +102,24 @@ public class TechTypeTableDataProvider implements IDataProvider {
     public String getHeaderValue(int columnIndex) {
         if (headers == null) {
             return "<empty>";
-        } else if (columnIndex == 0) {
+        } else if (isEnabledColumn(columnIndex)) {
             return "Enabled";
         } else {
-            return headers.get(columnIndex - 1);
+            return headers.get(columnIndex - columnOffset());
         }
     }
 
     @Override
     public Object getDataValue(int columnIndex, int rowIndex) {
-        if (columnIndex == 0) {
+        if (isEnabledColumn(columnIndex)) {
             return isEnabled(rowIndex);
         }
-        return getRecord(rowIndex).get(columnIndex - 1);
+        return getRecord(rowIndex).get(columnIndex - columnOffset());
     }
 
     @Override
     public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
-        if (columnIndex == 0) {
+        if (isEnabledColumn(columnIndex)) {
             boolean value = Boolean.parseBoolean((String) newValue);
             enabled[recordIndex(rowIndex)] = value;
             fireEnableEvent(rowIndex, value);
@@ -124,7 +139,7 @@ public class TechTypeTableDataProvider implements IDataProvider {
         if (records.isEmpty()) {
             return 0;
         }
-        return records.get(0).size() + 1;
+        return records.get(0).size() + columnOffset();
     }
 
     @Override
@@ -133,9 +148,13 @@ public class TechTypeTableDataProvider implements IDataProvider {
     }
 
     public boolean isEditable(int columnIndex, int rowIndex) {
-        return columnIndex == 0;
+        return isEnabledColumn(columnIndex);
     }
 
+       private boolean isEnabledColumn(int columnIndex) {
+               return showEnabled && columnIndex == 0;
+       }
+
     public void setFilter(String text) {
         this.filter = text != null ? text.toLowerCase() : null;
 
@@ -238,9 +257,10 @@ public class TechTypeTableDataProvider implements IDataProvider {
     public void sortBy(int columnIndex, SortDirectionEnum sortDirection) {
         
         if (columnIndex >= 0 && !sortDirection.equals(SortDirectionEnum.NONE)) {
-            Comparator<Integer> comparator = columnIndex == 0 ?
+               int offset = columnOffset();
+            Comparator<Integer> comparator = isEnabledColumn(columnIndex) ?
                     Comparator.comparing(k -> enabled[sortedRows[(int) k]]) :
-                    Comparator.comparing(k -> records.get(sortedRows[(int) k]).get(columnIndex-1), VALUE_COMPARATOR);
+                    Comparator.comparing(k -> records.get(sortedRows[(int) k]).get(columnIndex-offset), VALUE_COMPARATOR);
             
             if (sortDirection.equals(SortDirectionEnum.DESC))
                 comparator = comparator.reversed();