+ 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);
+ }
+ }
+
+ public void setTechTypePath(String path) {
+ String data;
+ try {
+ data = Files.lines(Paths.get(path), Charset.defaultCharset()).collect(Collectors.joining("\n"));
+ } catch (IOException e) {
+ LOGGER.error("Failed to read contents of file '{}' as {}", path, Charset.defaultCharset(), e);
+ return;
+ }
+
+ try {
+ Simantics.getSession().syncRequest(new WriteRequest() {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ graph.syncRequest(new WriteTechTypeTable(componentType, data));
+ }
+ });
+ } catch (DatabaseException e) {
+ LOGGER.error("Failed to write tech type table data to model", e);
+ }
+
+ setComponentType(componentType);
+ }
+
+ public void setTechTypeData(String data, int[] enabled) {
+ bodyDataProvider.setData(data);
+ bodyDataProvider.setEnabledFlags(enabled);
+ table.refresh(true);
+ }
+
+ /**
+ * Set results of a validation operation
+ *
+ * Invalid entries are designated by a string of the form "<type_code>/<property_name>".
+ *
+ * This method must be called in the SWT thread.
+ *
+ * @param result A set of strings representing invalid entries
+ */
+ public void setValidationResult(Set<String> result) {
+ if (result != null && result.isEmpty())
+ result = null;
+
+ this.validationResult = result;
+ if (result != null) {
+ keyName = getKeyColumnName(componentType);
+ }
+
+ table.refresh();
+ }
+
+ /**
+ * Get a resource representation of the currently open table, or null if
+ * table is not stored in the model.
+ */
+ public Resource getCurrentTable() {
+ return tableResource;
+ }