From: Reino Ruusu Date: Mon, 2 Nov 2020 14:27:23 +0000 (+0200) Subject: Handle tech type tables with no component type X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F4563%2F1;p=simantics%2Fdistrict.git Handle tech type tables with no component type gitlab #93 Change-Id: I5feed458ecdebd164789666f1d2092405ccb23d6 --- 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();