This is an automated email from the git hooks/post-receive script. New commit to branch feature/7591_Correction_migration_entites_d_un_parent_a_un_autre in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit 76f8903122416bf3f8a03d6952a737c8e4784aa8 Author: Samuel Maisonneuve <maisonneuve@codelutin.com> Date: Thu Jul 28 15:23:25 2016 +0200 Fix activities move (from one road to another) action refs #7591 --- .../fr/ird/observe/ObserveOpenDataManager.java | 18 ++++++++++ .../actions/shared/MoveActivitySeinesUIAction.java | 40 ++++++++++++++++------ .../ui/content/list/ContentListUIHandler.java | 15 ++++++++ .../fr/ird/observe/ui/tree/ObserveTreeHelper.java | 15 +++++++- 4 files changed, 76 insertions(+), 12 deletions(-) diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ObserveOpenDataManager.java b/observe-application-swing/src/main/java/fr/ird/observe/ObserveOpenDataManager.java index 242fe5c..e4492b6 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ObserveOpenDataManager.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ObserveOpenDataManager.java @@ -85,6 +85,12 @@ public class ObserveOpenDataManager implements Closeable { public void closeTripSeine(String tripSeineId) { Preconditions.checkNotNull(tripSeineId, "id cant be null"); Preconditions.checkState(isOpenTripSeine(tripSeineId), "this trip is not opened"); + + if (dataContext.isOpenRoute()) { + String openRouteId = dataContext.getOpenRouteId(); + closeRoute(openRouteId); + } + dataContext.setOpenTripSeineId(null); dataContext.setOpenProgramId(null); } @@ -110,6 +116,12 @@ public class ObserveOpenDataManager implements Closeable { public void closeRoute(String routeId) { Preconditions.checkNotNull(routeId, "id cant be null"); Preconditions.checkState(isOpenRoute(routeId), "this route is not opened"); + + if (dataContext.isOpenActivitySeine()) { + String openActivitySeineId = dataContext.getOpenActivitySeineId(); + closeActivitySeine(openActivitySeineId); + } + dataContext.setOpenRouteId(null); } @@ -157,6 +169,12 @@ public class ObserveOpenDataManager implements Closeable { public void closeTripLongline(String tripLongLineId) { Preconditions.checkNotNull(tripLongLineId, "id cant be null"); Preconditions.checkState(isOpenTripLongline(tripLongLineId), "this trip is not opened"); + + if (dataContext.isOpenActivityLongline()) { + String openActivityLonglineId = dataContext.getOpenActivityLonglineId(); + closeActivitySeine(openActivityLonglineId); + } + dataContext.setOpenTripLonglineId(null); dataContext.setOpenProgramId(null); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveActivitySeinesUIAction.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveActivitySeinesUIAction.java index 4d9f92e..260038f 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveActivitySeinesUIAction.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveActivitySeinesUIAction.java @@ -44,6 +44,7 @@ import org.apache.commons.logging.LogFactory; import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; +import javax.swing.tree.TreePath; import java.awt.event.ActionEvent; import java.util.List; @@ -173,8 +174,6 @@ public class MoveActivitySeinesUIAction extends AbstractUIAction { RouteDto.PROPERTY_ACTIVITY_SEINE); ObserveNode newActivitiesNode = treeHelper.getChild(newRouteNode, activitiesNodeId); - treeHelper.selectNode(newActivitiesNode); - for (int i = 0, s = positions.size(); i < s; i++) { String actvityId = activitiyIds.get(i); @@ -186,20 +185,39 @@ public class MoveActivitySeinesUIAction extends AbstractUIAction { openDataManager.closeRoute(oldRouteId); String tripSeineId = tripNode.getId(); openDataManager.openRoute(tripSeineId, routeId); + + // Closing the road also close the activity + // As the activity was previsously opened, we need to re-opened it. + openDataManager.openActivitySeine(routeId, actvityId); } + } - ObserveNode newActivityNode = treeHelper.getChild(newActivitiesNode, actvityId); + // We need to fully reload the newActivitiesNode, + // triggering the child loadors to recreate the node's children from the database + // (since the change in the database has already been care of) + + // 1. Select the newActivitiesNode : + // only a selected node can be reloaded (@see fr.ird.observe.ui.tree.ObserveTreeBridge.canLoadChild). + // (And also it's better for user experience because it puts the focus on the activities node which receive the activities) + // + // However, the node selection has to be done after that the route has been opened : + // selecting the newAtivitiesNode opens a list layout which compute a rendering mode associated to the route state. + // After the mode has been computed, it is injected in the list component which triggers listeners on associated components, such as buttons. + // + // That's why, if we do this before the route is opened, + // we will end up with an incoherent list view (some buttons will be deactivated while they should be activated for instance) + treeHelper.selectNode(newActivitiesNode); - if (newActivityNode == null) { + // 2. Let's fully reload newActivitiesNode + treeHelper.cleanAndPopulateNode(newActivitiesNode); - // create it - if (log.isInfoEnabled()) { - log.info("Insert activity node: "); - } - treeHelper.insertNode(newActivitiesNode, activityNode, positions.get(i)); - } - } + // 3. We ensure the path until the newActivitiesNode is expanded + // so that the user can see the activities he moved + TreePath path = new TreePath(newActivitiesNode.getPath()); + treeHelper.getUI().collapsePath(path); // FIXME : sometimes the path don't expand because its state seems to indicate that it's already expanded.. + treeHelper.expandPath(path); + // Finally, let's refresh the nodes' label of the whole trip treeHelper.reloadNode(tripNode, true); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java index 6581a0e..3524e2a 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java @@ -127,6 +127,21 @@ public abstract class ContentListUIHandler<E extends IdDto, C extends DataDto> e if (log.isInfoEnabled()) { log.info(prefix + "content mode = " + mode); } + + // We want to force the bindings on "mode" to be triggered each time we open a list ui. + // + // The ui mode can already be set to the mode we're currently applying now. + // As the state of the buttons is bound to that mode, + // we need to force a mode change to ensure the buttons state will be refreshed. + // + // For example : + // The button of the activities list of a route "Go to the open activity of another road" may need to disapear + // because that road has just been deleted.. + // + // As the ui state of the buttons is usually only bound to the mode of the model + // and as the state of those buttons usually not only depends on that mode (but also on attributes of the data context for instance, such as a route/activity/trip is open or not), + // we need to force the buttons to recompute their state by forcing the mode's listeners to be triggered. + model.setMode(null); model.setMode(mode); boolean canReopen = mode == ContentMode.CREATE; diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java index ef3a305..503d7d2 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java @@ -541,7 +541,7 @@ public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { } refreshNode(node, refreshChilds); } - + public void reloadNode(ObserveNode node, boolean refreshChilds) { ((AbstrctReferenceNodeSupport) node).setReloadEntity(true); refreshNode(node, refreshChilds); @@ -577,4 +577,17 @@ public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { setDataProvider(provider); } + public void populateNode(ObserveNode node) { + node.populateNode(getBridge(), getDataProvider(), true); + } + + public void cleanAndPopulateNode(ObserveNode node) { + // 1. We delete all children of the node because populating only *add* child, it never refreshes totally + for (int i=0, l = node.getChildCount(); i < l; i++) { + removeNode(node.getChildAt(i)); + } + + // 2. We re-generate newActivitiesNode's children + populateNode(node); + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.