diff --git a/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java b/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java index 5ee9a57bb682cd2e278cabef6d952cbdc5c3a8c6..f363952677127a4132f304900ce794142540b283 100644 --- a/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java +++ b/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java @@ -55,6 +55,7 @@ import org.json.JSONObject; import java.io.*; import java.util.*; +import java.util.stream.Collectors; public class DataTreeCell extends TextFieldTreeCell<DataNode> { @@ -162,19 +163,23 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { 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); + CheckBoxTreeItem<Object> fakeRoot = new CheckBoxTreeItem<>(null); + CheckTreeView<Object> 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())); + CheckBoxTreeItem<Object> ckIti = new CheckBoxTreeItem<>(itiFile, 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); + CheckBoxTreeItem<Object> ckStep = new CheckBoxTreeItem<>(step); ckIti.getChildren().add(ckStep); }); }); vb.getChildren().add(treeStep); + + CheckBox addLink = new CheckBox("include links between steps"); + vb.getChildren().add(addLink); + pane.getChildren().add(vb); AnchorPane.setTopAnchor(vb, 2.0); @@ -189,11 +194,26 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { if (result.isPresent()) { if (result.get().equals(ButtonType.OK)) { treeStep.getCheckModel().getCheckedItems().forEach(ti -> { - StepFile step = ti.getValue(); - if(step != null && !itineraryFile.getListStep().contains(step)) { - itineraryFile.addLinkItinerary(step, null); + if(ti.getValue() instanceof StepFile) { + StepFile step = (StepFile) ti.getValue(); + if(step != null && !itineraryFile.getListStep().contains(step)) { + itineraryFile.addLinkItinerary(step, null); + } } }); + if(addLink.isSelected()) { // we need to copy link also + treeStep.getCheckModel().getCheckedItems().forEach(ti -> { + if(ti.getValue() instanceof StepFile) { + StepFile step = (StepFile) ti.getValue(); + ItineraryFile iti = (ItineraryFile) ti.getParent().getValue(); + List<StepFile> listChild = iti.getItinerary().stream().filter(link -> link.getKey().getValue().get() != null && link.getKey().getValue().get().equals(step)).map(link -> link.getValue().getValue().get()).collect(Collectors.toList()); + List<StepFile> listParent = iti.getItinerary().stream().filter(link -> link.getValue().getValue().get() != null && link.getValue().getValue().get().equals(step)).map(link -> link.getKey().getValue().get()).collect(Collectors.toList()); + + listChild.stream().filter(s -> itineraryFile.contains(s)).forEach(s -> itineraryFile.addLinkItinerary(step, s)); + listParent.stream().filter(p -> itineraryFile.contains(p)).forEach(p -> itineraryFile.addLinkItinerary(p, step)); + } + }); + } MainApp.getDataControler().buildItineraryTree(itineraryFile); MainApp.getDataControler().selectNode(itineraryFile); } diff --git a/src/main/resources/resources/changelog.txt b/src/main/resources/resources/changelog.txt index 2fb41b10c245b2dee043104781e3059664ac481d..7cc6df107775df88d9040ae87c69aa60ed25571a 100644 --- a/src/main/resources/resources/changelog.txt +++ b/src/main/resources/resources/changelog.txt @@ -1,4 +1,5 @@ ------------------ NEXT ------------------ + * Enhancement (PO2-Tools/po2manager#107) : Ajout d'une option lors de l'ajout d'étape existante à l'itinéraire pour y inclure les liens entre étapes * Enhancement (PO2-Tools/po2manager#95) : uniformiser les fonctionnalités de copies (step / itinerary / ....) ------------------ V1.8.3.4 ------------------