From 606503c3d07783033d92fa4aaf2a5005f67d235c Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Mon, 2 Nov 2020 16:27:23 +0200 Subject: [PATCH] Handle tech type tables with no component type gitlab #93 Change-Id: I5feed458ecdebd164789666f1d2092405ccb23d6 --- .../techtype/adapters/TechTypeEditorAdapter.java | 16 ++++++++++++---- .../network/ui/techtype/table/TechTypeTable.java | 11 ++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) 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 6ab176ed..fcd6a7e2 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 @@ -64,10 +64,18 @@ public class TechTypeEditorAdapter extends AbstractResourceEditorAdapter impleme public void run(ReadGraph graph) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); Resource componentType = graph.getPossibleObject(table, DN.TechType_TechTypeTable_HasComponentType); - - TechTypeTableView.table.getDisplay().asyncExec(() -> { - TechTypeTableView.table.setComponentType(componentType); - }); + if (componentType != null) { + TechTypeTableView.table.getDisplay().asyncExec(() -> { + TechTypeTableView.table.setComponentType(componentType); + }); + } 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); + }); + } } }); } catch (DatabaseException e) { 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 a8db44c7..b18e10c8 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 @@ -325,7 +325,7 @@ public class TechTypeTable extends Composite { LOGGER.error("Failed to read possible tech type key name for {}", componentType, e); } } - return keyName.startsWith("_") ? keyName.substring(1) : keyName; + return keyName != null && keyName.startsWith("_") ? keyName.substring(1) : keyName; } @Override @@ -340,8 +340,10 @@ public class TechTypeTable extends Composite { this.componentType = componentType; this.keyName = getKeyColumnName(componentType); - - Simantics.getSession().asyncRequest(new TableDataRequest(componentType), new TableDataListener(componentType)); + + if (componentType != null) { + Simantics.getSession().asyncRequest(new TableDataRequest(componentType), new TableDataListener(componentType)); + } } private final class TableDataListener implements Listener>> { @@ -354,6 +356,9 @@ public class TechTypeTable extends Composite { @Override public void execute(Triple> result) { TechTypeTable.this.getDisplay().asyncExec(() -> { + if (isDisposed() || result == null) + return; + TechTypeTable.this.tableResource = result.first; String data = result.second; int[] enabled = result.third.stream().mapToInt(Integer::intValue).toArray(); -- 2.47.0