diff --git a/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java b/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java index 46f94148521ec36a8c58137af23bd5756a37f7c7..174c9c6076c7ef64e335a2d3ac9aab695ee5f729 100644 --- a/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java +++ b/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java @@ -45,6 +45,7 @@ import org.apache.commons.io.FileUtils; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.controlsfx.control.CheckTreeView; import org.json.JSONArray; import org.json.JSONObject; @@ -155,31 +156,47 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { GeneralFile current = itineraryFile.getProcessFile(); Dialog<ButtonType> addStep = new Dialog<>(); - addStep.getDialogPane().setPrefSize(500, 200); + addStep.getDialogPane().setPrefSize(300, 500); addStep.initModality(Modality.WINDOW_MODAL); addStep.initOwner(MainApp.primaryStage); ObservableList<String> listStep = FXCollections.observableArrayList(current.getListStep().stream().filter(s -> !itineraryFile.getListStep().contains(s)).map(s -> s.getOntoType() + " (" + s.getId()+")").collect(Collectors.toList())); FXCollections.sort(listStep, Comparator.comparing(String::toLowerCase)); - GridPane pane = new GridPane(); - pane.add(new Label("Step to add :"), 0, 0); - ComboBox<String> comboStep = new ComboBox<>(); - comboStep.setEditable(false); - comboStep.setItems(listStep); + AnchorPane pane = new AnchorPane(); + VBox vb = new VBox(1.0); + vb.getChildren().add(new Label("Select steps to add")); + CheckBoxTreeItem<StepFile> fakeRoot = new CheckBoxTreeItem<>(null); + CheckTreeView<StepFile> treeStep = new CheckTreeView<>(fakeRoot); + treeStep.setShowRoot(false); + itineraryFile.getProcessFile().getItinerary().stream().filter(iti -> iti != itineraryFile).forEach(itiFile -> { + CheckBoxTreeItem<StepFile> ckIti = new CheckBoxTreeItem<>(null, new Label(itiFile.getItineraryNumber() + " - " + itiFile.getItineraryName())); + fakeRoot.getChildren().add(ckIti); + itiFile.getListStep().filtered(step -> step.isLeaf() && !itineraryFile.getListStep().contains(step)).forEach(step -> { + CheckBoxTreeItem<StepFile> ckStep = new CheckBoxTreeItem<>(step); + ckIti.getChildren().add(ckStep); + }); + }); + + vb.getChildren().add(treeStep); + pane.getChildren().add(vb); + + AnchorPane.setTopAnchor(vb, 2.0); + AnchorPane.setLeftAnchor(vb, 2.0); + AnchorPane.setRightAnchor(vb, 2.0); + AnchorPane.setBottomAnchor(vb, 2.0); - pane.add(comboStep, 0, 1); addStep.getDialogPane().setContent(pane); addStep.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); - addStep.getDialogPane().lookupButton(ButtonType.OK).disableProperty().bind(comboStep.getSelectionModel().selectedItemProperty().isNotNull().not()); Optional<ButtonType> result = addStep.showAndWait(); if (result.isPresent()) { if (result.get().equals(ButtonType.OK)) { - String fat = comboStep.getSelectionModel().getSelectedItem(); - StepFile sFat = current.getListStep().stream().filter(s -> s.getNameProperty().getValue().equalsIgnoreCase(fat)).findFirst().get(); - - itineraryFile.addLinkItinerary(sFat, null); - + treeStep.getCheckModel().getCheckedItems().forEach(ti -> { + StepFile step = ti.getValue(); + if(step != null && !itineraryFile.getListStep().contains(step)) { + itineraryFile.addLinkItinerary(step, null); + } + }); MainApp.getDataControler().buildItineraryTree(itineraryFile); MainApp.getDataControler().selectNode(itineraryFile); }