From: Reino Ruusu Date: Mon, 9 Nov 2020 10:53:12 +0000 (+0200) Subject: Hide "enabled" column for non-component type tech type tables X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;p=simantics%2Fdistrict.git Hide "enabled" column for non-component type tech type tables gitlab #93 Change-Id: I8d9ea8008d13d6be8e2b3cff4bf56b0a6f9198b8 (cherry picked from commit c669b6c3089b28f55336f350a0178515208bbd51) --- diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/adapters/TechTypeEditorAdapter.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/adapters/TechTypeEditorAdapter.java index fcd6a7e2..fdadbda7 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/adapters/TechTypeEditorAdapter.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/adapters/TechTypeEditorAdapter.java @@ -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); }); } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTable.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTable.java index 7438269a..f15be971 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTable.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTable.java @@ -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); } }); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableDataProvider.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableDataProvider.java index af0e28d0..4d4244d7 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableDataProvider.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableDataProvider.java @@ -33,6 +33,8 @@ public class TechTypeTableDataProvider implements IDataProvider { private ListenerList enableListeners = new ListenerList(); private int[] sortedRows; + + private boolean showEnabled = true; private static final Comparator 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 ""; - } 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 comparator = columnIndex == 0 ? + int offset = columnOffset(); + Comparator 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();