]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Handle tech type tables with no component type 99/4599/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Mon, 2 Nov 2020 14:27:23 +0000 (16:27 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Mon, 2 Nov 2020 14:27:23 +0000 (16:27 +0200)
gitlab #93

Change-Id: I5feed458ecdebd164789666f1d2092405ccb23d6

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

index 6ab176ede84979537a7b1dc303cbcfcf8984afd7..fcd6a7e259075f81894f1613ee4d9699071e97b5 100644 (file)
@@ -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) {
index a8db44c789200fb8015596916ade28ed8283e9fa..b18e10c8d63f50c8971ef2fd90150ae783b37e69 100644 (file)
@@ -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<Triple<Resource, String, List<Integer>>> {
@@ -354,6 +356,9 @@ public class TechTypeTable extends Composite {
                @Override
                public void execute(Triple<Resource, String, List<Integer>> 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();