This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 95043cf68e2a0144754fe868f488c70679b099ab Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Apr 24 22:17:09 2016 +0200 A la sauvegarde d'une opération, on doit rafraîchir le contexte de données --- .../actions/SaveFishingOperationAction.java | 102 ++++++++++++--------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/actions/SaveFishingOperationAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/actions/SaveFishingOperationAction.java index e5c4d87..9e9d421 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/actions/SaveFishingOperationAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/fishing/actions/SaveFishingOperationAction.java @@ -29,7 +29,6 @@ import fr.ifremer.tutti.persistence.entities.data.CatchBatchs; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.ValidationService; -import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport; import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUI; import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUIModel; @@ -37,6 +36,7 @@ import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUIModel; import fr.ifremer.tutti.ui.swing.content.operation.fishing.AbstractCaracteristicTabUIModel; import fr.ifremer.tutti.ui.swing.content.operation.fishing.GearUseFeatureTabUIModel; import fr.ifremer.tutti.ui.swing.content.operation.fishing.VesselUseFeatureTabUIModel; +import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -49,9 +49,7 @@ import org.apache.commons.logging.LogFactory; public class SaveFishingOperationAction extends LongActionSupport<EditFishingOperationUIModel, EditFishingOperationUI, EditFishingOperationUIHandler> { /** Logger. */ - private static final Log log = - LogFactory.getLog(SaveFishingOperationAction.class); - + private static final Log log = LogFactory.getLog(SaveFishingOperationAction.class); /** * A flag to update ui after create or save the edit fishing operation. @@ -80,15 +78,13 @@ public class SaveFishingOperationAction extends LongActionSupport<EditFishingOpe public void doAction() throws Exception { // previous fishingOperation was modified, let's save it - EditFishingOperationUIModel beanToSave = - handler.getFishingOperationMonitor().getBean(); + EditFishingOperationUIModel beanToSave = handler.getFishingOperationMonitor().getBean(); - // must save when bean is new or was modifiy and is valid - boolean mustSave = beanToSave.getFishingOperation() != null - && beanToSave.isValid(); + moveTab = true; + // must save when bean is new or was modifiy and is valid + boolean mustSave = beanToSave.getFishingOperation() != null && beanToSave.isValid(); - moveTab = true; if (mustSave) { // prepare model @@ -113,19 +109,14 @@ public class SaveFishingOperationAction extends LongActionSupport<EditFishingOpe subModel.setModify(false); } - sendMessage( - "[ Trait - Caractéristiques générales ] " + - "Sauvegarde des modifications de " + decorate(toSave) + - "." - ); + sendMessage("[ Trait - Caractéristiques générales ] Sauvegarde des modifications de " + decorate(toSave) + "."); if (log.isInfoEnabled()) { - log.info("FishingOperation " + toSave.getId() + - " was modified, will save it."); + log.info("FishingOperation " + toSave.getId() + " was modified, will save it."); } - saveFishingOperation(toSave); + } } @@ -143,48 +134,71 @@ public class SaveFishingOperationAction extends LongActionSupport<EditFishingOpe protected void saveFishingOperation(FishingOperation toSave) { - PersistenceService service = getContext().getPersistenceService(); - boolean create = TuttiEntities.isNew(toSave); - FishingOperationsUIModel model = - getHandler().getParentUi().getModel(); - FishingOperation savedFishingOperation; - if (create) { - // create fishing operation - savedFishingOperation = service.createFishingOperation(toSave); - - // create then the CatchBatch - CatchBatch catchBatch = CatchBatchs.newCatchBatch(); - catchBatch.setFishingOperation(savedFishingOperation); - service.createCatchBatch(catchBatch); - - // add new created fishing operation to list - model.addFishingOperation(savedFishingOperation); - - // select it (will reload editing fishing operation) - model.setSelectedFishingOperation(savedFishingOperation); + createFishingOperation(toSave); } else { + FishingOperationsUIModel model = getHandler().getParentUi().getModel(); model.setEditionAdjusting(true); try { - // save fishing operation - savedFishingOperation = service.saveFishingOperation(toSave); - - model.setSelectedFishingOperation(null); - // reinject it in model - model.updateFishingOperation(savedFishingOperation); + persistFishingOperation(toSave); - model.setSelectedFishingOperation(savedFishingOperation); } finally { + model.setEditionAdjusting(false); + } + } + + } + + private void createFishingOperation(FishingOperation toSave) { + + FishingOperationsUIModel model = getHandler().getParentUi().getModel(); + PersistenceService service = getContext().getPersistenceService(); + + // create fishing operation + FishingOperation savedFishingOperation = service.createFishingOperation(toSave); + + // create then the CatchBatch + CatchBatch catchBatch = CatchBatchs.newCatchBatch(); + catchBatch.setFishingOperation(savedFishingOperation); + service.createCatchBatch(catchBatch); + + // add new created fishing operation to list + model.addFishingOperation(savedFishingOperation); + + // select it (will reload editing fishing operation) + model.setSelectedFishingOperation(savedFishingOperation); + + } + + private void persistFishingOperation(FishingOperation toSave) { + + + PersistenceService service = getContext().getPersistenceService(); + + FishingOperationsUIModel model = getHandler().getParentUi().getModel(); + + // save fishing operation + FishingOperation savedFishingOperation = service.saveFishingOperation(toSave); + + model.setSelectedFishingOperation(null); + + // reinject it in model + model.updateFishingOperation(savedFishingOperation); + + model.setSelectedFishingOperation(savedFishingOperation); + + getDataContext().reloadFishingOperation(); + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.