@SuppressWarnings("unchecked") private <T> T readInternal(ReaderFunction<T> function) { try { T value = function.read(); if (value instanceof Data) { return (T) ((Data) value).internal().addBackReferences(); } return value; } catch (IOException e) { throw new RuntimeException(e); } }
attribute.possibleValueProvider(data -> { Set<FactoryBase<? extends L, ?, ?>> result = new HashSet<>(); for (Data factory: root.get().internal().collectChildrenDeep()){ if (factory instanceof PolymorphicFactory){ if (liveObjectClass.isAssignableFrom(((PolymorphicFactory)factory).getLiveObjectClass())){
data.internal().visitAttributesFlat((attributeVariableName, attribute) -> { if (attribute instanceof FactoryReferenceAttribute) { FactoryBase<?, ?, ?> factory = (FactoryBase<?, ?, ?>) attribute.get();
sortButton.setOnAction(event -> { referenceListAttribute.sort((d1,d2)->{ String s1 = Optional.ofNullable(d1.internal().getDisplayText()).orElse(""); String s2 = Optional.ofNullable(d2.internal().getDisplayText()).orElse(""); return s1.compareTo(s2); });
textField.setText(null); } else { textField.setText(observableAttributeValue.get().internal().getDisplayText());
result.internal().visitAttributesFlat((attributeVariableName, attribute) -> { if (attribute instanceof FactoryReferenceAttribute){ FactoryReferenceAttribute factoryReferenceAttribute = (FactoryReferenceAttribute) attribute;
private TreeItem<TreeData> constructTree(Data data){ if (data!=null){ TreeItem<TreeData> dataTreeItem = new TreeItem<>(new TreeData(data,null)); data.internal().visitAttributesFlat((attributeVariableName, attribute) -> { if (attribute instanceof ReferenceAttribute) { Data child=((ReferenceAttribute<?,?>)attribute).get();
test.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().internal().getDisplayText())); tableView.getColumns().add(test); tableView.getStyleClass().add("hidden-tableview-headers");
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); TableColumn<Data, String> test = new TableColumn<>("Data"); test.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().internal().getDisplayText())); tableView.getColumns().add(test); tableView.getStyleClass().add("hidden-tableview-headers");
stringBinding = Bindings.createStringBinding(() -> { if (observableAttributeValue.get()!=null){ return observableAttributeValue.get().internal().getDisplayText();
@SuppressWarnings("unchecked") public MergeResult<R> createMergeResult(Function<String,Boolean> permissionChecker) { MergeResult mergeResult = new MergeResult(currentData); Map<String, Data> currentMap = currentData.internal().collectChildDataMap(); Map<String, Data> originalMap = commonData.internal().collectChildDataMap(); Map<String, Data> newMap = newData.internal().collectChildDataMap(); for (Data newData : newMap.values()) {//avoid mixup with iteration countern newData.internal().resetIterationCounterFlat(); } for (Map.Entry<String, Data> entry : currentMap.entrySet()) { Data originalValue = getOriginalValue(originalMap, entry); Data newValue = getNewValue(newMap, entry); if (newValue==null && originalValue!=null){ //check for conflict for removed object entry.getValue().internal().visitAttributesDualFlat(originalValue, (name, currentAttribute, originalAttribute) -> { if (!currentAttribute.internal_ignoreForMerging()){ if (!currentAttribute.internal_mergeMatch(originalAttribute)){ mergeResult.addConflictInfo(new AttributeDiffInfo(name,entry.getValue().getId())); } } }); } if (originalValue!=null && newValue!=null){ entry.getValue().internal().merge(originalValue, newValue, mergeResult, permissionChecker); } } return mergeResult; }
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()); }
private void writeData(StringBuilder sb, Data d) { sb.append("{"); ObjectMapper mapper = new ObjectMapper(); int oldLen = sb.length(); d.internal().visitAttributesFlat((name, attribute) -> { try { Object value = attribute.get(); sb.append("\"").append(name).append("\" : "); if (value instanceof Data) { writeData(sb,(Data)value); } else { sb.append(mapper.writeValueAsString(value)); } sb.append(","); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }); if (sb.length() > oldLen) { sb.setLength(sb.length() - 1); } sb.append("}"); }
@SuppressWarnings("unchecked") public FactoryTreeBuilderBasedAttributeSetup(FactoryTreeBuilder<R> factoryTreeBuilder) { this.factoryTreeBuilder = factoryTreeBuilder; newValuesProvider = (root, attribute) -> { Class<?> referenceClazz = ((ReferenceBaseAttribute<?,?, ?>) attribute).internal_getReferenceClass(); List<?> newFactories = this.createNewFactory((Class<FactoryBase<Object, ?, R>>) referenceClazz); ArrayList result = new ArrayList(newFactories); if(result.isEmpty()){ Class referenceClazzWorkaround=referenceClazz; result.add(DataDictionary.getDataDictionary(referenceClazzWorkaround).newInstance()); } for (Object o : result) { FactoryBase<?,?,?> factory=(FactoryBase)o; for (Data child : factory.internal().collectChildrenDeepFromNode()) { if (child instanceof FactoryBase<?,?,?>) { child.internal().visitAttributesFlat((attributeVariableName, childAttribute) -> applyToAttribute(childAttribute)); } } } return result; }; }
@Override public void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (item != null) { if (dataSupplier.apply(item)!=null){ if (displayText!=null){ displayText.removeListener(changeListener); } displayText= new DataObservableDisplayText(dataSupplier.apply(item)).get(); changeListenerGarbageCollectionSave = (observable, oldValue, newValue) -> { setText(dataSupplier.apply(item).internal().getDisplayText()); }; changeListener = new WeakChangeListener<>(changeListenerGarbageCollectionSave); displayText.addListener(changeListener); changeListener.changed(displayText,null,displayText.get()); } else { setText(alternativeDisplayText.apply(item)); } } //CellUtils.updateItem(this, getConverter(), hbox, getTreeItemGraphic(), textField); }
@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); } } }
private Set<Data> getChangedFactories(R previousFactoryCopyRoot){ //one might think that the merger could do the change detection but that don't work for views and separation of concern is better anyway final HashSet<Data> result = new HashSet<>(); final HashMap<String, FactoryBase<?, ?,?>> previousFactories = previousFactoryCopyRoot.internalFactory().collectChildFactoriesDeepMapFromRoot(); for (Data data: currentFactoryRoot.collectChildFactories()){ final FactoryBase<?, ?,?> previousFactory = previousFactories.get(data.getId()); if (previousFactory!=null){ data.internal().visitAttributesDualFlat(previousFactory, (name, currentAttribute, previousAttribute) -> { if (!(currentAttribute instanceof DataViewReferenceAttribute) && !(currentAttribute instanceof DataViewListReferenceAttribute)){//Data views have no function no need to check if (!currentAttribute.internal_mergeMatch(previousAttribute)){ result.add(data); } } }); } } return result; }
@JsonIgnore public Attribute<?,?> getAttribute(Data root){ Data data = root.internal().collectChildDataMap().get(dataId); if (data!=null) { Attribute<?,?>[] result= new Attribute<?,?>[1]; data.internal().visitAttributesFlat((attributeVariableName, attribute) -> { if (attributeVariableName.equals(attributeName)){ result[0]=attribute; } }); return result[0]; } return null; }
public T getHistoryFactory(String id) { return restClient.post("historyFactory",new UserAwareRequest<>(user,passwordHash,id), factoryRootClass).internal().prepareUsableCopy(); }
/** * @see DataStorage#prepareNewFactory() * * @return new factory for editing, server assign new id for the update */ @SuppressWarnings("unchecked") public DataAndNewMetadata<R> prepareNewFactory() { DataAndNewMetadata<R> currentFactory = executeWidthServerExceptionReporting(()->microserviceResource.prepareNewFactory(new UserAwareRequest<>(user,passwordHash,null))); R root = currentFactory.root.internal().addBackReferences(); if (factoryTreeBuilderBasedAttributeSetup!=null){ factoryTreeBuilderBasedAttributeSetup.applyToRootFactoryDeep(root); } return new DataAndNewMetadata<>(root,currentFactory.metadata); }