This is an automated email from the git hooks/post-receive script. New commit to branch feature/7623 in repository observe. See http://git.codelutin.com/observe.git commit 9b987b193e4b3b7a6287fd8037bf0d251500eaca Author: Kevin Morin <morin@codelutin.com> Date: Wed Nov 18 12:46:43 2015 +0100 correction dans le déplacement des routes (récupération des marées via les noeuds de l'arbre, fix npe quand on clique sur annuler pendant le choix de la marée, mise à jour du model inutile vu qu'on a déjà changer de noeud) (refs #7622) --- .../ui/actions/shared/MoveRoutesUIAction.java | 78 +++++++++++----------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveRoutesUIAction.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveRoutesUIAction.java index 1077cec..4a87d2a 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveRoutesUIAction.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveRoutesUIAction.java @@ -28,12 +28,12 @@ import fr.ird.observe.services.dto.ReferenceDto; import fr.ird.observe.services.dto.ReferenceDtos; import fr.ird.observe.services.dto.seine.TripSeineDto; import fr.ird.observe.services.service.seine.RouteService; -import fr.ird.observe.services.service.seine.TripSeineService; import fr.ird.observe.ui.DecoratorService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.content.ContentUI; import fr.ird.observe.ui.content.list.ContentListUIModel; import fr.ird.observe.ui.content.list.impl.seine.RoutesUI; +import fr.ird.observe.ui.tree.DtoNodeSupport; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; import org.apache.commons.logging.Log; @@ -44,8 +44,6 @@ import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.LinkedHashSet; import java.util.List; import static org.nuiton.i18n.I18n.n; @@ -100,59 +98,64 @@ public class MoveRoutesUIAction extends AbstractUIAction { // get current tripseine id ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); ObserveNode oldRoutesNode = treeHelper.getSelectedNode(); - String oldTripSeineId = oldRoutesNode.getParent().getId(); + ObserveNode oldTripSeineNode = oldRoutesNode.getParent(); + String oldTripSeineId = oldTripSeineNode.getId(); // choose the new tripseine - String tripSeineId = chooseNewTripSeine(ui, oldTripSeineId); + String tripSeineId = chooseNewTripSeine(ui, oldTripSeineNode); - // change the tripseine of the selected routes - List<ReferenceDto> selectedDatas = ((ContentListUIModel) ui.getModel()).getSelectedDatas(); - List<String> routeIds = Lists.transform(selectedDatas, ReferenceDtos.getIdFunction()); - RouteService service = ObserveSwingApplicationContext.get().newService(RouteService.class); - List<Integer> positions = service.moveRoutesToTripSeine(routeIds, tripSeineId); + if (tripSeineId != null) { + // change the tripseine of the selected routes + List<ReferenceDto> selectedDatas = ((ContentListUIModel) ui.getModel()).getSelectedDatas(); + List<String> routeIds = Lists.transform(selectedDatas, ReferenceDtos.getIdFunction()); + RouteService service = ObserveSwingApplicationContext.get().newService(RouteService.class); + List<Integer> positions = service.moveRoutesToTripSeine(routeIds, tripSeineId); - // update the tree - updateTree(ui, oldRoutesNode, oldTripSeineId, tripSeineId, routeIds, positions); + // update the tree + updateTree(oldRoutesNode, oldTripSeineId, tripSeineId, routeIds, positions); + } } }); } - protected String chooseNewTripSeine(ContentUI<?> ui, String oldProgramId) { - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - - LinkedHashSet<ReferenceDto> allTripSeines = applicationContext.newService(TripSeineService.class) - .getAllTripSeine() - .getReference(); - - List<ReferenceDto<TripSeineDto>> tripSeines = new ArrayList<>(ReferenceDtos.castToCollectionOfReferenceDto(allTripSeines)); + protected String chooseNewTripSeine(ContentUI<?> ui, ObserveNode oldTripSeineNode) { + ObserveNode programNode = oldTripSeineNode.getParent(); + String oldTripSeineId = oldTripSeineNode.getId(); + int tripSeineNb = programNode.getChildCount(); + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); Decorator<ReferenceDto> decorator = applicationContext.getDecorator(ReferenceDto.class, TripSeineDto.class.getSimpleName()); - //on crée un tableau avec un tripseine en moins car on ne propose pas le tripseine actuel - DecoratedTripSeine[] decoratedTripSeines = new DecoratedTripSeine[tripSeines.size() - 1]; + //on crée un tableau avec une route en moins car on ne propose pas la route actuel + DecoratedTripSeine[] decoratedTripSeines = new DecoratedTripSeine[tripSeineNb - 1]; int j = 0; - for (ReferenceDto tripSeine : tripSeines) { - if (!oldProgramId.equals(tripSeine.getId())) { - decoratedTripSeines[j++] = new DecoratedTripSeine(tripSeine.getId(), decorator.toString(tripSeine)); + for (int i = 0 ; i < tripSeineNb ; i++) { + + ObserveNode tripSeineNode = programNode.getChildAt(i); + + String tripSeineId = tripSeineNode.getId(); + + if (!oldTripSeineId.equals(tripSeineId)) { + decoratedTripSeines[j++] = new DecoratedTripSeine(tripSeineId, + decorator.toString(((DtoNodeSupport) tripSeineNode).getEntity())); } } - Object decoratedProgram = JOptionPane.showInputDialog(ui, - t("observe.action.choose.program.message"), - t("observe.action.choose.program.title"), - JOptionPane.QUESTION_MESSAGE, - null, - decoratedTripSeines, - null); - return ((DecoratedTripSeine) decoratedProgram).getId(); + Object decoratedTripSeine = JOptionPane.showInputDialog(ui, + t("observe.action.choose.tripSeine.message"), + t("observe.action.choose.tripSeine.title"), + JOptionPane.QUESTION_MESSAGE, + null, + decoratedTripSeines, + null); + return decoratedTripSeine != null ? ((DecoratedTripSeine) decoratedTripSeine).getId() : null; } - protected void updateTree(ContentUI<?> ui, - ObserveNode oldRoutesNode, + protected void updateTree(ObserveNode oldRoutesNode, String oldTripSeineId, String tripSeineId, List<String> routeIds, @@ -197,11 +200,6 @@ public class MoveRoutesUIAction extends AbstractUIAction { treeHelper.reloadNode(programNode, true); - ContentListUIModel model = (ContentListUIModel) ui.getModel(); - List<ReferenceDto> data = new ArrayList<>(model.getData()); - data.removeAll(model.getSelectedDatas()); - model.setData(data); - } public static class DecoratedTripSeine { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.