+ 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));
+ Resource model = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
+ if (model != null) {
+ tableResource = graph.syncRequest(new PossibleTechTypeTable(model, componentType));
+ }
+ }
+ });
+ } catch (DatabaseException e) {
+ LOGGER.error("Failed to write tech type table data to model", e);
+ }
+
+ setTechTypeData(data);
+ setValidationResult(null);
+ }
+
+ public void setTechTypeData(String data) {
+ bodyDataProvider.setData(data);
+ table.refresh(true);
+ }
+
+ public void setComponentType(Resource componentType) {
+ this.componentType = componentType;
+ }
+
+ /**
+ * 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) {
+ String keyName = getKeyColumnName(componentType);
+
+ bodyDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
+ @Override
+ public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
+ if (keyName != null) {
+ int keyColumn = bodyDataProvider.getVariableIndex(keyName);
+ if (keyColumn >= 0) {
+ String key = (String) bodyDataProvider.getDataValue(keyColumn, rowPosition);
+ String columnName = bodyDataProvider.getVariableName(columnPosition);
+
+ if (validationResult.contains(key + "/" + columnName)) {
+ configLabels.addLabel(INVALID_LABEL);
+ }
+ }
+ }
+ }
+ });
+ } else {
+ bodyDataLayer.setConfigLabelAccumulator(null);
+ }
+
+ table.refresh();
+ }