+
+ public void setComponentType(Resource componentType) {
+ if (Objects.equals(this.componentType, componentType))
+ return;
+
+ this.componentType = componentType;
+ this.keyName = getKeyColumnName(componentType);
+
+ Simantics.getSession().asyncRequest(new TableDataRequest(componentType), new TableDataListener(componentType));
+ }
+
+ private final class TableDataListener implements Listener<Triple<Resource, String, List<Integer>>> {
+ private final Resource componentType;
+
+ private TableDataListener(Resource componentType) {
+ this.componentType = componentType;
+ }
+
+ @Override
+ public void execute(Triple<Resource, String, List<Integer>> result) {
+ TechTypeTable.this.getDisplay().asyncExec(() -> {
+ TechTypeTable.this.tableResource = result.first;
+ String data = result.second;
+ int[] enabled = result.third.stream().mapToInt(Integer::intValue).toArray();
+
+ setTechTypeData(data, enabled);
+ setValidationResult(null);
+ });
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ LOGGER.error("Error updating tech type table data for {}", componentType, t);
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return TechTypeTable.this.table != null && TechTypeTable.this.table.isDisposed() ||
+ !Objects.equals(TechTypeTable.this.componentType, componentType);
+ }
+ }
+
+ private final class TableDataRequest extends ResourceRead<Triple<Resource, String, List<Integer>>> {
+ private TableDataRequest(Resource componentType) {
+ super(componentType);
+ }
+
+ @Override
+ public Triple<Resource, String, List<Integer>> perform(ReadGraph graph) throws DatabaseException {
+ Resource model = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
+ if (model == null)
+ return null;
+ Resource tableResource = graph.syncRequest(new PossibleTechTypeTable(model, this.resource));
+ if (tableResource == null)
+ return null;
+
+ String data = graph.getRelatedValue2(tableResource, DistrictNetworkResource.getInstance(graph).TechType_TechTypeTable_HasData);
+ int[] enabled = graph.getRelatedValue2(tableResource, DistrictNetworkResource.getInstance(graph).TechType_TechTypeTable_HasEnabledItems);
+ List<Integer> list = Arrays.stream(enabled).mapToObj(Integer::valueOf).collect(Collectors.toList());
+ return Triple.make(tableResource, data, list);
+ }
+ }