0
我想用TreeItems從HashMap填充我的TreeView。一些數據攜帶屬性「isProject」,這意味着它是某個客戶端的項目。我正在嘗試將這些Project節點添加到更高級的客戶端節點中......但是建立一個可怕的反饋循環。有沒有更好的方法來獲取特定節點(TreeItem)並添加另一個節點?或者讓代碼有效的方法?謝謝!查找並添加TreeItem到JavaFX中的現有節點
@SuppressWarnings({ "rawtypes", "unchecked" })
private void showTimeRecords() {
ArrayList<TimeRecord> timeRecords = new ArrayList<>();
ObservableList<PerformanceLogTableData> pflData = FXCollections.observableArrayList();
TimeDataRecords rootValue = new TimeDataRecords("Client/Project", "", "", false, timeRecords, pflData);
YearMonth setYM = YearMonth.of(2016, currMonth);
root = new TreeItem<TimeDataRecords>();
HashMap<String,TimeDataRecords> timeDataRecsMap = timeDataRecsBigMap.get(setYM);
for (HashMap.Entry<String, TimeDataRecords> entry : timeDataRecsMap.entrySet()) {
TreeItem<TimeDataRecords> node = new TreeItem<TimeDataRecords>(entry.getValue());
if (entry.getValue().isProject()) {
for (int i = 0; i < root.getChildren().size(); i++) {
if(root.getChildren().get(i).getValue().getName().equals(entry.getValue().getName())){
TreeItem<TimeDataRecords> tempNode = new TreeItem<TimeDataRecords>(root.getChildren().get(i).getValue());
tempNode.getChildren().add(node);
root.getChildren().add(tempNode);
}
}
}else{
root.getChildren().add(node);
System.out.println(entry.getValue().getId() + " --- " + entry.getValue().getProject() + " --- " + entry.getValue().isProject());
}
}
root.setValue(rootValue);
root.setExpanded(true);
treeView.setRoot(root);
treeView.setEditable(false);
}