private void validate(R root) { List<ValidationError> validationErrors=new ArrayList<>(); for (Data data : root.internal().collectChildrenDeep()) { validationErrors.addAll(data.internal().validateFlat()); } if (!validationErrors.isEmpty()){ throw new IllegalStateException("\n Factory tree contains validation errors:\n --------------------------------\n"+ validationErrors.stream().map(ValidationError::getSimpleErrorDescription).collect(Collectors.joining( "\n --------------------------------\n"))+ "\n --------------------------------" ); } }
private void validate(TreeTableView<ValidationAndData> tableView){ final TreeItem<ValidationAndData> root = new TreeItem<>(); tableView.setRoot(root); tableView.setShowRoot(false); HashMap<Data,Data> child2parent = this.root.internal().getChildToParentMap(); List<ValidationError> validationErrors= new ArrayList<>(); for (Data data: this.root.internal().collectChildrenDeep()){ TreeItem<ValidationAndData> dataItem = new TreeItem<>(); dataItem.setExpanded(true); data.internal().validateFlat().forEach(validationError->{ validationErrors.add(validationError); TreeItem<ValidationAndData> error =new TreeItem<>(new ValidationAndData(validationError,data,data.internal().getDisplayText())); dataItem.getChildren().add(error); }); if (!dataItem.getChildren().isEmpty()){ dataItem.setValue(new ValidationAndData(null,data,data.internal().getPathFromRoot(child2parent).stream().map(d->d.internal().getDisplayText()).collect(Collectors.joining("/")))); root.getChildren().add(dataItem); } } tableView.getStyleClass().remove("error"); if (!validationErrors.isEmpty()){ tableView.getStyleClass().add("error"); } tableView.getSelectionModel().clearSelection(); dataEditor.reset(); isValid.set(validationErrors.isEmpty()); }
@SuppressWarnings("unchecked") private Node createEditor(Data newValue, Data previousValue){ if (newValue==null) { return new Label("empty"); } else { if (newValue.internal().attributeListGrouped().size()==1){ final Node attributeGroupVisual = createAttributeGroupVisual(newValue.internal().attributeListGrouped().get(0).group,previousValue, () -> newValue.internal().validateFlat()); return customizeVis(attributeGroupVisual,newValue); } else { TabPane tabPane = new TabPane(); for (AttributeGroup attributeGroup: newValue.internal().attributeListGrouped()) { Tab tab=new Tab(uniformDesign.getText(attributeGroup.title)); tab.setClosable(false); tab.setContent(createAttributeGroupVisual(attributeGroup.group,previousValue, () -> newValue.internal().validateFlat())); tabPane.getTabs().add(tab); } return customizeVis(tabPane,newValue); } } }