Author: tchemit Date: 2013-02-10 16:04:13 +0100 (Sun, 10 Feb 2013) New Revision: 388 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/388 Log: begin of save operation cinematic Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SaveCatchBatchAction.java Removed: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SelectFishingOperationAction.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/CancelEditFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/NewFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SaveFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/CancelEditFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/CancelEditFishingOperationAction.java 2013-02-10 15:03:24 UTC (rev 387) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/CancelEditFishingOperationAction.java 2013-02-10 15:04:13 UTC (rev 388) @@ -46,7 +46,12 @@ /** Logger. */ private static final Log log = LogFactory.getLog(SaveFishingOperationAction.class); - private final SelectFishingOperationAction delegate; + /** + * Delegate edit action. + * + * @since 1.0 + */ + protected EditFishingOperationAction editAction; public CancelEditFishingOperationAction(EditFishingOperationUIHandler handler) { super(handler, @@ -56,9 +61,15 @@ _("tutti.action.cancel.editFishingOperation.tip"), true ); - delegate = new SelectFishingOperationAction(handler.getParentUi().getHandler()); } + public EditFishingOperationAction getEditAction() { + if (editAction == null) { + editAction = new EditFishingOperationAction(getHandler().getParentUi().getHandler()); + } + return editAction; + } + /** * If the event source is an EditFishingOperationUIHandler, * then the tab panel of the parent switch to the index set @@ -69,38 +80,39 @@ */ @Override protected void doAction(ActionEvent event) throws Exception { - FishingOperationsUI parentUi = getHandler().getParentUi(); - FishingOperationsUIHandler parentHandler = parentUi.getHandler(); + + EditFishingOperationAction action = getEditAction(); + if (getModel().isCreate()) { if (log.isInfoEnabled()) { - log.info("Cancel edition for fishingOperation "); + log.info("Cancel creation for fishingOperation"); } // cancel to create a new fishingOperation - delegate.setFishingOperation(null); - delegate.doAction(event); + action.setFishingOperation(null); + action.doAction(event); -// parentUi.getFishingOperationTabContent().getHandler().selectFishingOperation(null); -// parentUi.getCatchesTabContent().getHandler().selectFishingOperation(null, ""); -// parentHandler.closeCurrentFishingOperation(); - } else { - // reload fishing operation - delegate.setFishingOperation(parentHandler.getModel().getSelectedFishingOperation()); - delegate.doAction(event); -// parentHandler.reloadFishingOperation(); + if (log.isInfoEnabled()) { + log.info("Can edition of fishingOperation"); + } + + // re-edit current fishing operation (but do not perform any check) + action.setCheckPreviousEdit(false); + action.setFishingOperation(getModel().getFishingOperation()); + action.actionPerformed(event); } - // if called directly from the EditFishingOperationUIHandler: - // the user does not want to save the modifications before - // selecting another tab, we must reload the current tab before setting - // the new index of the tab pane - if (event.getSource() != null - && event.getSource().getClass().isAssignableFrom(EditFishingOperationUIHandler.class)) { - - int newIndex = event.getID(); - parentHandler.getTabPanel().setSelectedIndex(newIndex); - } +// // if called directly from the EditFishingOperationUIHandler: +// // the user does not want to save the modifications before +// // selecting another tab, we must reload the current tab before setting +// // the new index of the tab pane +// if (event.getSource() != null +// && event.getSource().getClass().isAssignableFrom(EditFishingOperationUIHandler.class)) { +// +// int newIndex = event.getID(); +// parentHandler.getTabPanel().setSelectedIndex(newIndex); +// } } } Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-02-10 15:04:13 UTC (rev 388) @@ -0,0 +1,422 @@ +package fr.ifremer.tutti.ui.swing.content.operation; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; +import fr.ifremer.tutti.persistence.entities.referential.Person; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SaveCatchBatchAction; +import fr.ifremer.tutti.ui.swing.content.operation.fishing.environment.EnvironmentTabUI; +import fr.ifremer.tutti.ui.swing.content.operation.fishing.gearshooting.GearShootingTabUI; +import fr.ifremer.tutti.ui.swing.content.operation.fishing.hydrology.HydrologyTabUI; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JTabbedPane; +import javax.swing.SwingUtilities; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.util.List; + +import static org.nuiton.i18n.I18n._; + +/** + * To edit the given fishing operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class EditFishingOperationAction extends AbstractTuttiAction<FishingOperationsUIModel, FishingOperationsUI, FishingOperationsUIHandler> { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(EditFishingOperationAction.class); + + /** + * The incoming fishing operation to edit. + * <p/> + * Can be null (means do not edit any fishing operation), or with no id + * (means create a ne fishing operation), or with an id (means edit an + * existing fishing operation). + * + * @since 1.0 + */ + protected FishingOperation fishingOperation; + + /** + * A flag to not check if there is a previous edit. + * <p/> + * This flag is used when we launch the cancel action. + * + * @since 1.0 + */ + protected boolean checkPreviousEdit = true; + + /** + * Delegate action to save Fising Operation. + * + * @since 1.0 + */ + protected SaveFishingOperationAction saveFishingOperationAction; + + /** + * Delgate action to save catch batch. + * + * @since 1.0 + */ + protected SaveCatchBatchAction saveCatchBatchAction; + + public EditFishingOperationAction(FishingOperationsUIHandler handler) { + super(handler, + "editFishingOperation", + "edit", + null, + _("tutti.action.editFishingOperation.tip"), + true); + } + + public void setFishingOperation(FishingOperation fishingOperation) { + this.fishingOperation = fishingOperation; + } + + public void setCheckPreviousEdit(boolean checkPreviousEdit) { + this.checkPreviousEdit = checkPreviousEdit; + } + + @Override + protected void releaseAction(ActionEvent event) { + fishingOperation = null; + checkPreviousEdit = true; + super.releaseAction(event); + } + + protected SaveFishingOperationAction getSaveFishingOperationAction() { + if (saveFishingOperationAction == null) { + saveFishingOperationAction = new SaveFishingOperationAction(getUI().getFishingOperationTabContent().getHandler()); + } + return saveFishingOperationAction; + } + + protected SaveCatchBatchAction getSaveCatchBatchAction() { + if (saveCatchBatchAction == null) { + saveCatchBatchAction = new SaveCatchBatchAction(getUI().getCatchesTabContent().getHandler()); + } + return saveCatchBatchAction; + } + + @Override + protected void doAction(ActionEvent event) throws Exception { + + if (log.isInfoEnabled()) { + log.info("Try to edit fishingOperation: " + fishingOperation); + } + + FishingOperationsUI ui = getUI(); + + FishingOperationsUIModel model = ui.getModel(); + + FishingOperation editFishingOperation = model.getEditFishingOperation(); + + boolean canContinue; + + String editFishingOperationId; + + if (editFishingOperation == null) { + + // no previous fishing operation in edition, can continue + canContinue = true; + editFishingOperationId = null; + + } else { + + editFishingOperationId = editFishingOperation.getId(); + + boolean create = TuttiEntities.isNew(editFishingOperation); + + // must close current edition + String message; + + if (create) { + message = _("tutti.dialog.askSaveBeforeLeaving.createFishingOperation"); + } else { + message = _("tutti.dialog.askSaveBeforeLeaving.saveFishingOperation"); + } + + int answer = getHandler().askSaveBeforeLeaving(message); + + canContinue = false; + switch (answer) { + case JOptionPane.OK_OPTION: + + // persist previous fishing operation + getSaveFishingOperationAction().setUpdateUI(false); + getSaveFishingOperationAction().actionPerformed(event); + getSaveCatchBatchAction().setUpdateUI(false); + getSaveCatchBatchAction().actionPerformed(event); + + canContinue = true; + break; + + case JOptionPane.NO_OPTION: + + // won't save modification + // so since we will edit a new operation, nothing to do here + + canContinue = true; + break; + } + } + + if (canContinue) { + + // edit new fishing operation + if (log.isInfoEnabled()) { + log.info("Edit in ui fishingOperation: " + fishingOperation); + } + + selectNewFishingOperation(fishingOperation); + + selectNewCatchBatch(fishingOperation); + + JTabbedPane form = ui.getTabPane(); + JLabel noContentPane = ui.getNoTraitPane(); + + if (fishingOperation == null) { + + // nothing to display + + ui.remove(form); + + // just display <no trait!> + ui.add(noContentPane, BorderLayout.CENTER); + + } else { + + ui.remove(noContentPane); + + // wait last minute to display (avoid dirty display effects) + ui.add(form, BorderLayout.CENTER); + } + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + getUI().repaint(); + } + }); + } else { + + // user cancel save of previous bean + + // get previous edit fishing operation (in selection model) + FishingOperation selectFishingOperation = + model.getFishingOperation(editFishingOperationId); + + model.setEditionAdjusting(true); + + try { + model.setSelectedFishingOperation(selectFishingOperation); + } finally { + model.setEditionAdjusting(false); + } + } + } + + protected void selectNewFishingOperation(FishingOperation bean) { + + EditFishingOperationUI ui = getUI().getFishingOperationTabContent(); + + EditFishingOperationUIHandler handler = ui.getHandler(); + + EditFishingOperationUIModel editFishingOperationUIModel = ui.getModel(); + + handler.uninstallStartDateListener(); + + if (bean == null) { + + editFishingOperationUIModel.fromBean(new FishingOperation()); + + editFishingOperationUIModel.setFishingOperation(bean); + + handler.clearValidators(); + + handler.resetAllModels(); + + } else { //if (!bean.equals(editFishingOperationUIModel.getFishingOperation()) || handler.isAModelModified()) { + + FishingOperationLocation strata = bean.getStrata(); + FishingOperationLocation subStrata = bean.getSubStrata(); + FishingOperationLocation location = bean.getLocation(); + + Cruise cruise = bean.getCruise(); + if (cruise != null) { + // update gear universe + ui.getGearComboBox().setData(Lists.newArrayList(cruise.getGear())); + + // update vessel universe + ui.getVesselComboBox().setData(Lists.newArrayList(cruise.getVessel())); + } + + editFishingOperationUIModel.fromBean(bean); + + // to be sure combo list will be reloaded + editFishingOperationUIModel.setStrata(null); + editFishingOperationUIModel.setSubStrata(null); + editFishingOperationUIModel.setLocation(null); + editFishingOperationUIModel.convertGearShootingCoordinatesDDToDMS(); + + if (strata != null) { + ui.getStrataComboBox().setSelectedItem(strata); + } + + if (subStrata != null) { + ui.getSubStrataComboBox().setSelectedItem(subStrata); + } + + if (location != null) { + ui.getLocationComboBox().setSelectedItem(location); + } + + editFishingOperationUIModel.setFishingOperation(bean); + + // update saisissuer selection + List<Person> saisisseur = editFishingOperationUIModel.getSaisisseur(); + ui.getSaisisseurList().getModel().setSelected(saisisseur); + + // update model empty property + editFishingOperationUIModel.setEmpty(false); + + //reset gear shooting + GearShootingTabUI gearShootingTab = ui.getGearShootingTabContent(); + gearShootingTab.getHandler().reset(bean); + + //reset environment + EnvironmentTabUI environmentTab = ui.getEnvironmentTabContent(); + environmentTab.getHandler().reset(bean); + + //reset hydrology + HydrologyTabUI hydrologyTab = ui.getHydrologyTabContent(); + hydrologyTab.getHandler().reset(bean); + + editFishingOperationUIModel.setModify(false); + handler.getFishingOperationMonitor().clearModified(); + + handler.registerValidator(); + } + + handler.installStartDateListener(); + } + + protected void selectNewCatchBatch(FishingOperation bean) { + + boolean empty = bean == null || TuttiEntities.isNew(bean); + + EditCatchesUI ui = getUI().getCatchesTabContent(); + TuttiBeanMonitor<EditCatchesUIModel> catchBatchMonitor = + ui.getHandler().getCatchBatchMonitor(); + + EditCatchesUIModel catchesUIModel = ui.getModel(); + + CatchBatch batch; + + if (empty) { + + // create a new CatchBatch + if (log.isInfoEnabled()) { + log.info("Create a new CatchBatch (fishing operation is null)"); + } + batch = new CatchBatch(); + batch.setFishingOperation(bean); + + } else { + + String operationId = bean.getId(); + + if (log.isInfoEnabled()) { + log.info("Load existing CatchBatch from operation id: " + + operationId); + } + + PersistenceService persistenceService = + getService(PersistenceService.class); + + batch = persistenceService.getCatchBatchFromFishingOperation( + operationId); + batch.setFishingOperation(bean); + } + + catchesUIModel.setCatchBatch(batch); + catchesUIModel.setFishingOperation(bean); + + catchesUIModel.fromBean(batch); + + catchesUIModel.setModify(false); + catchBatchMonitor.clearModified(); + + Decorator<FishingOperation> decorator = + getDecorator(FishingOperation.class, null); + + String fishingOperationText; + + if (bean == null) { + fishingOperationText = null; + } else { + fishingOperationText = _("tutti.label.traitReminder", + decorator.toString(fishingOperation)); + } + + // 3) Propagate title to others tabs + ui.getCatchesCaracteristicsTabPane().setTitle(fishingOperationText); + ui.getSpeciesTabFishingOperationReminderLabel().setTitle(fishingOperationText); +// ui.getBenthosTabFishingOperationReminderLabel().setTitle(fishingOperationText); +// ui.getPlanktonTabFishingOperationReminderLabel().setTitle(fishingOperationText); +// ui.getMacroWasteTabFishingOperationReminderLabel().setTitle(fishingOperationText); +// ui.getAccidentalTabFishingOperationReminderLabel().setTitle(fishingOperationText); + + // 4) Propagate new selected fishingoperation to others tabs + + ui.getSpeciesTabContent().getHandler().selectFishingOperation(bean); +// ui.getBenthosTabContent().getHandler().selectFishingOperation(bean); +// ui.getPlanktonTabContent().getHandler().selectFishingOperation(bean); +// ui.getMacroWasteTabContent().getHandler().selectFishingOperation(bean); +// ui.getAccidentalTabContent().getHandler().selectFishingOperation(bean); + + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2013-02-10 15:03:24 UTC (rev 387) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2013-02-10 15:04:13 UTC (rev 388) @@ -30,11 +30,9 @@ import com.javadocmd.simplelatlng.LatLngTool; import com.javadocmd.simplelatlng.util.LengthUnit; import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; import fr.ifremer.tutti.persistence.entities.referential.Gear; -import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.persistence.entities.referential.Zone; import fr.ifremer.tutti.service.PersistenceService; @@ -42,17 +40,13 @@ import fr.ifremer.tutti.ui.swing.TuttiScreen; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.operation.fishing.CaracteristicTabUIModel; -import fr.ifremer.tutti.ui.swing.content.operation.fishing.environment.EnvironmentTabUI; import fr.ifremer.tutti.ui.swing.content.operation.fishing.environment.EnvironmentTabUIModel; -import fr.ifremer.tutti.ui.swing.content.operation.fishing.gearshooting.GearShootingTabUI; import fr.ifremer.tutti.ui.swing.content.operation.fishing.gearshooting.GearShootingTabUIModel; -import fr.ifremer.tutti.ui.swing.content.operation.fishing.hydrology.HydrologyTabUI; import fr.ifremer.tutti.ui.swing.content.operation.fishing.hydrology.HydrologyTabUIModel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiTabContainerUIHandler; import fr.ifremer.tutti.ui.swing.util.TabHandler; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import fr.ifremer.tutti.ui.swing.util.editor.CoordinateEditorType; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.time.DateUtils; @@ -61,8 +55,6 @@ import javax.swing.JOptionPane; import javax.swing.JTabbedPane; -import java.awt.Color; -import java.awt.Component; import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -101,43 +93,8 @@ getModel().setGearShootingEndDate(newDate); } } - }; - - private final PropertyChangeListener coordinatePropertiesListener = new PropertyChangeListener() { - private List<String> properties = Lists.newArrayList( - EditFishingOperationUIModel.PROPERTY_FISHING_OPERATION_RECTILIGNE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LATITUDE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LATITUDE_DECIMAL_MINUTE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LATITUDE_DEGREE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LATITUDE_MINUTE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LATITUDE_SECOND, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LONGITUDE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LONGITUDE_DECIMAL_MINUTE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LONGITUDE_DEGREE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LONGITUDE_MINUTE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_END_LONGITUDE_SECOND, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LATITUDE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LATITUDE_DECIMAL_MINUTE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LATITUDE_DEGREE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LATITUDE_MINUTE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LATITUDE_SECOND, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LONGITUDE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LONGITUDE_DECIMAL_MINUTE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LONGITUDE_DEGREE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LONGITUDE_MINUTE, - EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_LONGITUDE_SECOND - ); - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (properties.contains(evt.getPropertyName())) { - EditFishingOperationUIModel source = (EditFishingOperationUIModel) evt.getSource(); - if (source.isFishingOperationRectiligne()) { - source.computeDictance(); - } - } - } }; /** @@ -180,24 +137,6 @@ EditFishingOperationUIModel model = new EditFishingOperationUIModel(); model.setCoordinateEditorType(getConfig().getCoordinateEditorType()); model.setValidationContext(getContext().getValidationContext()); - -// model.addPropertyChangeListener(EditFishingOperationUIModel.PROPERTY_EMPTY, new PropertyChangeListener() { -// @Override -// public void propertyChange(PropertyChangeEvent evt) { -// JPanel form = ui.getFishingOperationPane(); -// JLabel noContentPane = ui.getNoTraitPane(); -// -// Boolean empty = (Boolean) evt.getNewValue(); -// ui.remove(form); -// ui.remove(noContentPane); -// if (empty) { -// ui.add(noContentPane, BorderLayout.CENTER); -// } else { -// ui.add(form, BorderLayout.CENTER); -// } -// ui.repaint(); -// } -// }); model.addPropertyChangeListener(EditFishingOperationUIModel.PROPERTY_STRATA, new PropertyChangeListener() { @Override @@ -217,23 +156,26 @@ } }); - model.addPropertyChangeListener(EditFishingOperationUIModel.PROPERTY_FISHING_OPERATION_VALID, new PropertyChangeListener() { + model.addPropertyChangeListener(EditFishingOperationUIModel.PROPERTY_FISHING_OPERATION_RECTILIGNE, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - Boolean valid = (Boolean) evt.getNewValue(); - Color color = null; - Color fontColor = Color.BLACK; - if (valid == Boolean.TRUE) { - color = Color.GREEN; + Boolean rectiligne = (Boolean) evt.getNewValue(); + if (rectiligne) { + EditFishingOperationUIModel source = (EditFishingOperationUIModel) evt.getSource(); + Float latS = source.getGearShootingStartLatitude(); + Float longS = source.getGearShootingStartLongitude(); + Float latE = source.getGearShootingEndLatitude(); + Float longE = source.getGearShootingEndLongitude(); - } else if (valid == Boolean.FALSE) { - color = Color.RED; - fontColor = Color.WHITE; + if (latS != null && longS != null + && latE != null && longE != null) { + LatLng start = new LatLng(latS, longS); + LatLng end = new LatLng(latE, longE); + Double distance = LatLngTool.distance(start, end, LengthUnit.METER); + source.setTrawlDistance(distance.floatValue()); + } } - Component tab = getTabPanel().getTabComponentAt(0); - tab.setForeground(fontColor); - tab.setBackground(color); } }); @@ -412,6 +354,10 @@ @Override public void onShowTab(int currentIndex, int newIndex) { +// registerValidators(ui.getValidator()); + } + + public void registerValidator() { registerValidators(ui.getValidator()); } @@ -437,94 +383,96 @@ }; } - public void clearFishingOperation() { - EditFishingOperationUIModel model = getModel(); - model.fromBean(new FishingOperation()); +// public void clearFishingOperation() { +// EditFishingOperationUIModel model = getModel(); +// model.fromBean(new FishingOperation()); +// +// model.setModify(false); +// fishingOperationMonitor.clearModified(); +// +// model.setEmpty(true); +// +// } - model.setModify(false); - fishingOperationMonitor.clearModified(); +// public void selectFishingOperation(FishingOperation bean) { +// boolean empty = bean == null; +// +// EditFishingOperationUIModel editFishingOperationUIModel = getModel(); +// +// uninstallStartDateListener(); +// +// if (empty || !bean.equals(editFishingOperationUIModel.getFishingOperation()) || isAModelModified()) { +// if (empty) { +// bean = new FishingOperation(); +// } +// +// FishingOperationLocation strata = bean.getStrata(); +// FishingOperationLocation subStrata = bean.getSubStrata(); +// FishingOperationLocation location = bean.getLocation(); +// +// Cruise cruise = bean.getCruise(); +// if (cruise != null) { +// // update gear universe +// ui.getGearComboBox().setData(Lists.newArrayList(cruise.getGear())); +// +// // update vessel universe +// ui.getVesselComboBox().setData(Lists.newArrayList(cruise.getVessel())); +// } +// +// editFishingOperationUIModel.fromBean(bean); +// +// // to be sure combo list will be reloaded +// editFishingOperationUIModel.setStrata(null); +// editFishingOperationUIModel.setSubStrata(null); +// editFishingOperationUIModel.setLocation(null); +// editFishingOperationUIModel.convertGearShootingCoordinatesDDToDMS(); +// +// if (strata != null) { +// ui.getStrataComboBox().setSelectedItem(strata); +// } +// +// if (subStrata != null) { +// ui.getSubStrataComboBox().setSelectedItem(subStrata); +// } +// +// if (location != null) { +// ui.getLocationComboBox().setSelectedItem(location); +// } +// +// editFishingOperationUIModel.setFishingOperation(bean); +// +// // update saisissuer selection +// List<Person> saisisseur = editFishingOperationUIModel.getSaisisseur(); +// ui.getSaisisseurList().getModel().setSelected(saisisseur); +// +// // update model empty property +// editFishingOperationUIModel.setEmpty(empty); +// +// //reset gear shooting +// GearShootingTabUI gearShootingTab = ui.getGearShootingTabContent(); +// gearShootingTab.getHandler().reset(bean); +// +// //reset environment +// EnvironmentTabUI environmentTab = ui.getEnvironmentTabContent(); +// environmentTab.getHandler().reset(bean); +// +// //reset hydrology +// HydrologyTabUI hydrologyTab = ui.getHydrologyTabContent(); +// hydrologyTab.getHandler().reset(bean); +// +// editFishingOperationUIModel.setModify(false); +// fishingOperationMonitor.clearModified(); +// +// editFishingOperationUIModel.addPropertyChangeListener(EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_DATE, startDateListener); +// } +// } - model.setEmpty(true); - + public void uninstallStartDateListener() { + getModel().removePropertyChangeListener(EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_DATE, startDateListener); } - public void selectFishingOperation(FishingOperation bean) { - boolean empty = bean == null; - - EditFishingOperationUIModel model = getModel(); - - model.removePropertyChangeListener(EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_DATE, startDateListener); - model.removePropertyChangeListener(coordinatePropertiesListener); - - if (empty || !bean.equals(model.getFishingOperation()) || isAModelModified()) { - if (empty) { - bean = new FishingOperation(); - } - - List<FishingOperation> operations = parentUi.getModel().getFishingOperation(); - operations.remove(bean); - model.setExistingOperations(operations); - - FishingOperationLocation strata = bean.getStrata(); - FishingOperationLocation subStrata = bean.getSubStrata(); - FishingOperationLocation location = bean.getLocation(); - - Cruise cruise = bean.getCruise(); - if (cruise != null) { - // update gear universe - ui.getGearComboBox().setData(Lists.newArrayList(cruise.getGear())); - - // update vessel universe - ui.getVesselComboBox().setData(Lists.newArrayList(cruise.getVessel())); - } - - model.fromBean(bean); - - // to be sure combo list will be reloaded - model.setStrata(null); - model.setSubStrata(null); - model.setLocation(null); - model.convertGearShootingCoordinatesDDToDMS(); - - if (strata != null) { - ui.getStrataComboBox().setSelectedItem(strata); - } - - if (subStrata != null) { - ui.getSubStrataComboBox().setSelectedItem(subStrata); - } - - if (location != null) { - ui.getLocationComboBox().setSelectedItem(location); - } - - model.setFishingOperation(bean); - - // update saisissuer selection - List<Person> saisisseur = model.getSaisisseur(); - ui.getSaisisseurList().getModel().setSelected(saisisseur); - - // update model empty property - model.setEmpty(empty); - - //reset gear shooting - GearShootingTabUI gearShootingTab = ui.getGearShootingTabContent(); - gearShootingTab.getHandler().reset(bean); - - //reset environment - EnvironmentTabUI environmentTab = ui.getEnvironmentTabContent(); - environmentTab.getHandler().reset(bean); - - //reset hydrology - HydrologyTabUI hydrologyTab = ui.getHydrologyTabContent(); - hydrologyTab.getHandler().reset(bean); - - model.setModify(false); - fishingOperationMonitor.clearModified(); - - model.addPropertyChangeListener(EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_DATE, startDateListener); - model.addPropertyChangeListener(coordinatePropertiesListener); - } + public void installStartDateListener() { + getModel().addPropertyChangeListener(EditFishingOperationUIModel.PROPERTY_GEAR_SHOOTING_START_DATE, startDateListener); } public FishingOperationsUI getParentUi() { @@ -576,8 +524,6 @@ if (CollectionUtils.isEmpty(subStrata)) { // try to load localite - - ui.getLocationComboBox().grabFocus(); } } @@ -629,4 +575,12 @@ return result; } + protected void resetAllModels() { + + for (CaracteristicTabUIModel subModel : getSubModels()) { + subModel.setModify(false); + } + getModel().setModify(false); + } + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx 2013-02-10 15:03:24 UTC (rev 387) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.jaxx 2013-02-10 15:04:13 UTC (rev 388) @@ -58,7 +58,7 @@ <Table fill='both' id='topPanel' constraints='BorderLayout.NORTH'> - <!-- FishingOperations fishingOperation --> + <!-- Cruise fishingOperations --> <row> <cell anchor='west' weightx='1.0'> <BeanComboBox id='fishingOperationComboBox' constructorParams='this' @@ -70,8 +70,7 @@ </row> </Table> - <JLabel id='noTraitPane' constraints='BorderLayout.CENTER'/> - + <!-- Current selected fishingOperation --> <JTabbedPane id='tabPane'> <tab id='fishingOperationTab' title='tutti.label.tab.fishingOperation'> <EditFishingOperationUI id='fishingOperationTabContent' @@ -82,4 +81,7 @@ </tab> </JTabbedPane> + <!-- When no fishing operation selected --> + <JLabel id='noTraitPane' constraints='BorderLayout.CENTER'/> + </JPanel> \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java 2013-02-10 15:03:24 UTC (rev 387) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java 2013-02-10 15:04:13 UTC (rev 388) @@ -41,9 +41,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.List; -import java.util.Timer; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; /** * Handler of UI {@link FishingOperationsUI}. @@ -59,13 +56,8 @@ private final PersistenceService persistenceService; - private static final ExecutorService executorService = - Executors.newSingleThreadExecutor(); + protected EditFishingOperationAction editFishingOperationAction; - private static final Timer t = new Timer(); - - protected SelectFishingOperationAction selectFishingOperationAction; - public FishingOperationsUIHandler(TuttiUI parentUI, FishingOperationsUI ui) { super(parentUI.getHandler().getContext(), ui); @@ -138,10 +130,11 @@ initUI(ui); - selectFishingOperationAction = createAction(SelectFishingOperationAction.class); + editFishingOperationAction = + createAction(EditFishingOperationAction.class); + FishingOperationsUIModel model = getModel(); - List<FishingOperation> fishingOperations = model.getFishingOperation(); initBeanComboBox(ui.getFishingOperationComboBox(), @@ -155,16 +148,36 @@ log.debug("propertyChange " + FishingOperationsUIModel.PROPERTY_SELECTED_FISHING_OPERATION); } - if (!getModel().isValueIsAdjusting()) { + if (!getModel().isEditionAdjusting()) { - // only rebuild stuff if model is not adjusting - selectFishingOperationAction.setFishingOperation((FishingOperation) evt.getNewValue()); - selectFishingOperationAction.actionPerformed(null); -// selectFishingOperation((FishingOperation) evt.getNewValue()); + // selected fishing operation is now the editing one + + FishingOperation newValue = (FishingOperation) evt.getNewValue(); + + FishingOperation operation; + if (newValue == null) { + operation = null; + } else { + operation = persistenceService.getFishingOperation(newValue.getId()); + } + getModel().setEditFishingOperation(operation); } } }); + model.addPropertyChangeListener(FishingOperationsUIModel.PROPERTY_EDITED_FISHING_OPERATION, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (log.isDebugEnabled()) { + log.debug("propertyChange " + FishingOperationsUIModel.PROPERTY_EDITED_FISHING_OPERATION); + } + + // only rebuild stuff if model is not adjusting + editFishingOperationAction.setFishingOperation((FishingOperation) evt.getNewValue()); + editFishingOperationAction.actionPerformed(null); + + } + }); model.addPropertyChangeListener(FishingOperationsUIModel.PROPERTY_FISHING_OPERATION, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { @@ -212,78 +225,4 @@ return ui.getTabPane(); } -// public void selectFishingOperation(FishingOperation fishingOperation) { -// -// if (log.isInfoEnabled()) { -// log.info("New selected fishingOperation: " + fishingOperation); -// } -// -// // back to general tab of fishingOperation tabs -// ui.getFishingOperationTabContent().getFishingOperationTabPane().setSelectedIndex(0); -// -// if (fishingOperation != null) { -// Decorator<FishingOperation> decorator = -// getDecorator(FishingOperation.class, null); -// -// String fishingOperationText = -// _("tutti.label.traitReminder", -// decorator.toString(fishingOperation)); -// -// // propagate fishingOperation to his tabs -// ui.getFishingOperationTabContent().getHandler().selectFishingOperation(fishingOperation); -// if (ui.getFishingOperationTabContent().getModel().isCreate()) { -// // back to fishingOperation tab -// ui.getTabPane().setSelectedIndex(0); -// } -// -// ui.getCatchesTabContent().getHandler().selectFishingOperation(fishingOperation, -// fishingOperationText); -// -// // repaint tabs -// ui.getTabPane().repaint(); -// -// } else { -// ui.getFishingOperationTabContent().getHandler().clearFishingOperation(); -// // back to fishingOperation tab -// ui.getTabPane().setSelectedIndex(0); -// } -// } - -// public void closeCurrentFishingOperation() { -// ui.getFishingOperationTabContent().getHandler().selectFishingOperation(null); -// ui.getCatchesTabContent().getHandler().selectFishingOperation(null, ""); -// } - -// public void saveFishingOperation(FishingOperation toSave) { -// -// // persist the fishingOperation -// -// boolean create = toSave.getId() == null; -// FishingOperationsUIModel model = getModel(); -// FishingOperation savedFishingOperation; -// -// if (create) { -// -// savedFishingOperation = persistenceService.createFishingOperation(toSave); -// model.addFishingOperation(savedFishingOperation); -// model.setSelectedFishingOperation(savedFishingOperation); -// -// } else { -// savedFishingOperation = persistenceService.saveFishingOperation(toSave); -// -// // add the saved fishingOperation to fishingOperation list -// List<FishingOperation> data = model.getFishingOperation(); -// -// FishingOperation existingFishingOperation = -// TuttiEntities.findById(data, savedFishingOperation.getId()); -// model.updateFishingOperation(existingFishingOperation, savedFishingOperation); -// } -// } - -// public void reloadFishingOperation() { -// FishingOperation operation = getModel().getSelectedFishingOperation(); -// selectFishingOperation(operation); -// } - - } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java 2013-02-10 15:03:24 UTC (rev 387) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java 2013-02-10 15:04:13 UTC (rev 388) @@ -24,8 +24,12 @@ * #L% */ +import com.ezware.oxbow.swingbits.util.Preconditions; import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jdesktop.beans.AbstractSerializableBean; import java.util.List; @@ -40,16 +44,68 @@ private static final long serialVersionUID = 1L; + /** Logger. */ + private static final Log log = + LogFactory.getLog(FishingOperationsUIModel.class); + public static final String PROPERTY_FISHING_OPERATION = "fishingOperation"; public static final String PROPERTY_SELECTED_FISHING_OPERATION = "selectedFishingOperation"; + public static final String PROPERTY_EDITED_FISHING_OPERATION = "editedFishingOperation"; + + /** + * List of existing fishing operation for the selected cruise. + * <p/> + * <strong>Note:</strong> These objects are not fully loaded, they will + * never be edited. + * + * @since 0.1 + */ protected List<FishingOperation> fishingOperation; + /** + * Selected fishing operation in the combo box. + * <p/> + * For example if you create a new fishing operation then + * {@code selectedFishingOperation} will be {@code null}. + * <p/> + * <strong>Note:</strong> These object ise not fully loaded, they will + * never be edited. + * + * @since 0.1 + */ protected FishingOperation selectedFishingOperation; - private boolean valueIsAdjusting; + /** + * Current editied fishing operation. + * + * @since 1.0 + */ + protected FishingOperation editFishingOperation; + /** + * Flag to not listen the {@link #selectedFishingOperation} + * changes while adjusting the model. + * <p/> + * When flag is {@code true}, then the changes of the + * {@link #selectedFishingOperation} should not trigger any changes. + * + * @since 1.0 + */ + protected boolean selectionAdjusting; + + /** + * Flag to not listen the {@link #editFishingOperation} + * changes while adjusting the model. + * <p/> + * When flag is {@code true}, then the changes of the + * {@link #editFishingOperation} should not trigger any changes. + * + * @since 1.0 + */ + protected boolean editionAdjusting; + public List<FishingOperation> getFishingOperation() { return fishingOperation; } @@ -72,15 +128,21 @@ firePropertyChange(PROPERTY_FISHING_OPERATION, oldValue, this.fishingOperation); } - public void updateFishingOperation(FishingOperation oldFishingOperation, - FishingOperation newFishingOperation) { + public void updateFishingOperation(FishingOperation newFishingOperation) { + + Preconditions.checkNotNull(newFishingOperation); + String id = newFishingOperation.getId(); + Preconditions.checkNotNull(id); + FishingOperation oldFishingOperation = getFishingOperation(id); + Preconditions.checkNotNull(oldFishingOperation); + + if (log.isInfoEnabled()) { + log.info("Update existing fishing operation: " + id); + } + int oldFishingOperationIndex = fishingOperation.indexOf(oldFishingOperation); fishingOperation.remove(oldFishingOperation); - if (oldFishingOperationIndex >= 0) { - fishingOperation.add(oldFishingOperationIndex, newFishingOperation); - } else { - fishingOperation.add(newFishingOperation); - } + fishingOperation.add(oldFishingOperationIndex, newFishingOperation); firePropertyChange(PROPERTY_FISHING_OPERATION, null, fishingOperation); } @@ -91,14 +153,46 @@ public void setSelectedFishingOperation(FishingOperation selectedFishingOperation) { Object oldValue = getSelectedFishingOperation(); this.selectedFishingOperation = selectedFishingOperation; - firePropertyChange(PROPERTY_SELECTED_FISHING_OPERATION, oldValue, selectedFishingOperation); + if (!isSelectionAdjusting()) { + + // only fires when authorize to + firePropertyChange(PROPERTY_SELECTED_FISHING_OPERATION, oldValue, selectedFishingOperation); + } } - public void setValueIsAdjusting(boolean valueIsAdjusting) { - this.valueIsAdjusting = valueIsAdjusting; + public FishingOperation getEditFishingOperation() { + return editFishingOperation; } - public boolean isValueIsAdjusting() { - return valueIsAdjusting; + public void setEditFishingOperation(FishingOperation editFishingOperation) { + Object oldValue = getEditFishingOperation(); + this.editFishingOperation = editFishingOperation; + if (!isEditionAdjusting()) { + + // only fires when authorize to + firePropertyChange(PROPERTY_EDITED_FISHING_OPERATION, oldValue, editFishingOperation); + } } + + public boolean isSelectionAdjusting() { + return selectionAdjusting; + } + + public void setSelectionAdjusting(boolean selectionAdjusting) { + this.selectionAdjusting = selectionAdjusting; + } + + public boolean isEditionAdjusting() { + return editionAdjusting; + } + + public void setEditionAdjusting(boolean editionAdjusting) { + this.editionAdjusting = editionAdjusting; + } + + public FishingOperation getFishingOperation(String id) { + FishingOperation result = + TuttiEntities.findById(fishingOperation, id); + return result; + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/NewFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/NewFishingOperationAction.java 2013-02-10 15:03:24 UTC (rev 387) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/NewFishingOperationAction.java 2013-02-10 15:04:13 UTC (rev 388) @@ -37,7 +37,7 @@ import static org.nuiton.i18n.I18n._; /** - * TODO + * To create a new fishing operation. * * @author tchemit <chemit@codelutin.com> * @since 1.0 @@ -46,7 +46,12 @@ private static final long serialVersionUID = 1L; - private final SelectFishingOperationAction delegate; + /** + * Delegate action to edit new FishingOperation. + * + * @since 1.0 + */ + protected EditFishingOperationAction editFishingOperationAction; public NewFishingOperationAction(FishingOperationsUIHandler handler) { super(handler, @@ -55,8 +60,6 @@ null, _("tutti.action.newFishingOperation.tip"), true); - - delegate = new SelectFishingOperationAction(getHandler()); } @Override @@ -64,45 +67,50 @@ FishingOperationsUIModel model = getModel(); - model.setValueIsAdjusting(true); + // deselect selected fishingOperation + // Will remove the selection fishing operation from the comboBox + model.setEditionAdjusting(true); try { - // deselect selected fishingOperation model.setSelectedFishingOperation(null); + } finally { + model.setEditionAdjusting(false); + } - // use a new empty fishingOperation - FishingOperation newFishingOperation = new FishingOperation(); - Cruise cruise = TuttiUIUtil.getCruise(getContext()); - newFishingOperation.setCruise(cruise); + // creates a empty bean - //TODO Should select vessel from possible one ? - List<Vessel> vessels = cruise.getVessel(); - if (vessels.size() == 1) { - newFishingOperation.setVessel(vessels.get(0)); - } + FishingOperation newFishingOperation = new FishingOperation(); + Cruise cruise = TuttiUIUtil.getCruise(getContext()); + newFishingOperation.setCruise(cruise); - //TODO Should select gear from possible one ? - List<Gear> gears = cruise.getGear(); - if (gears.size() == 1) { - newFishingOperation.setGear(gears.get(0)); - } + //TODO Should select vessel from possible one ? + List<Vessel> vessels = cruise.getVessel(); + if (vessels.size() == 1) { + newFishingOperation.setVessel(vessels.get(0)); + } - if (cruise.getMultirigNumber() == 1) { - newFishingOperation.setMultirigAggregation("1"); - } + //TODO Should select gear from possible one ? + List<Gear> gears = cruise.getGear(); + if (gears.size() == 1) { + newFishingOperation.setGear(gears.get(0)); + } - // by default use the current day with no time information -// Date currentDate = DateUtils.setMinutes( -// DateUtils.setHours(new Date(), 0), 0); + if (cruise.getMultirigNumber() == 1) { + newFishingOperation.setMultirigAggregation("1"); + } - newFishingOperation.setGearShootingStartDate(null); - newFishingOperation.setGearShootingEndDate(null); + newFishingOperation.setGearShootingStartDate(null); + newFishingOperation.setGearShootingEndDate(null); - delegate.setFishingOperation(newFishingOperation); - delegate.doAction(event); + getEditFishingOperationAction().setFishingOperation(newFishingOperation); + getEditFishingOperationAction().actionPerformed(event); - } finally { - model.setValueIsAdjusting(false); + } + + public EditFishingOperationAction getEditFishingOperationAction() { + if (editFishingOperationAction == null) { + editFishingOperationAction = new EditFishingOperationAction(getHandler()); } + return editFishingOperationAction; } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SaveFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SaveFishingOperationAction.java 2013-02-10 15:03:24 UTC (rev 387) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SaveFishingOperationAction.java 2013-02-10 15:04:13 UTC (rev 388) @@ -27,10 +27,10 @@ import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; -import fr.ifremer.tutti.ui.swing.TuttiScreen; import fr.ifremer.tutti.ui.swing.content.operation.fishing.CaracteristicTabUIModel; import fr.ifremer.tutti.ui.swing.content.operation.fishing.environment.EnvironmentTabUIModel; import fr.ifremer.tutti.ui.swing.content.operation.fishing.gearshooting.GearShootingTabUIModel; @@ -41,7 +41,6 @@ import org.apache.commons.logging.LogFactory; import java.awt.event.ActionEvent; -import java.util.List; import static org.nuiton.i18n.I18n._; @@ -56,8 +55,17 @@ private static final long serialVersionUID = 1L; /** 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. + * + * @since 1.0 + */ + protected boolean updateUI; + public SaveFishingOperationAction(EditFishingOperationUIHandler handler) { super(handler, "saveFishingOperation", @@ -68,6 +76,16 @@ ); } + public void setUpdateUI(boolean updateUI) { + this.updateUI = updateUI; + } + + @Override + protected void releaseAction(ActionEvent event) { + updateUI = true; + super.releaseAction(event); + } + /** * If the event source is an EditFishingOperationUIHandler, * then the tab panel of the parent switch to the index set @@ -75,13 +93,11 @@ * If the event source is a TuttiScreen, then the screen changes to the source. * * @param event - * @throws Exception */ @Override protected void doAction(ActionEvent event) { EditFishingOperationUIHandler handler = getHandler(); - FishingOperationsUIHandler parentHandler = getHandler().getParentUi().getHandler(); TuttiBeanMonitor<EditFishingOperationUIModel> monitor = handler.getFishingOperationMonitor(); @@ -89,13 +105,14 @@ // previous fishingOperation was modified, let's save it EditFishingOperationUIModel beanToSave = monitor.getBean(); - if (beanToSave.isEmpty()) { + // must save when bean is new or was modifiy and is valid + boolean mustSave = (beanToSave.isCreate() || !beanToSave.isEmpty()) && + beanToSave.isValid(); - // user must use save button - if (log.isWarnEnabled()) { - log.warn("Won't save new fishing operation, use explicit save button instead..."); - } - } else if (beanToSave.isValid()) { + if (mustSave) { + + // prepare model + if (beanToSave.getCoordinateEditorType() != CoordinateEditorType.DD) { beanToSave.convertGearShootingCoordinatesDMSToDD(); } @@ -119,7 +136,7 @@ } } - handler.showInformationMessage( + sendMessage( "[ Trait - Caractéristiques générales ] " + "Sauvegarde des modifications de " + decorate(toSave) + "."); @@ -132,47 +149,61 @@ monitor.clearModified(); getModel().setModify(false); - // persist current fishingOperation saveFishingOperation(toSave); } - if (event.getSource() != null) { - Class<?> sourceClass = event.getSource().getClass(); - if (sourceClass.isAssignableFrom(EditFishingOperationUIHandler.class)) { - int newIndex = event.getID(); - parentHandler.getTabPanel().setSelectedIndex(newIndex); - - } else if (sourceClass.isAssignableFrom(TuttiScreen.class)) { - TuttiScreen nextScreen = (TuttiScreen) event.getSource(); - getContext().setScreen(nextScreen); - } - } +// if (event.getSource() != null) { +// Class<?> sourceClass = event.getSource().getClass(); +// if (sourceClass.isAssignableFrom(EditFishingOperationUIHandler.class)) { +// int newIndex = event.getID(); +// parentHandler.getTabPanel().setSelectedIndex(newIndex); +// +// } else if (sourceClass.isAssignableFrom(TuttiScreen.class)) { +// TuttiScreen nextScreen = (TuttiScreen) event.getSource(); +// getContext().setScreen(nextScreen); +// } +// } } protected void saveFishingOperation(FishingOperation toSave) { - PersistenceService service = - getContext().getService(PersistenceService.class); + PersistenceService service = getService(PersistenceService.class); - boolean create = toSave.getId() == null; - FishingOperationsUIModel model = getHandler().getParentUi().getModel(); + 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 = new CatchBatch(); + 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); } else { - savedFishingOperation = service.saveFishingOperation(toSave); - // add the saved fishingOperation to fishingOperation list - List<FishingOperation> data = model.getFishingOperation(); + model.setEditionAdjusting(true); - FishingOperation existingFishingOperation = - TuttiEntities.findById(data, savedFishingOperation.getId()); - model.updateFishingOperation(existingFishingOperation, savedFishingOperation); + try { + // save fishing operation + savedFishingOperation = service.saveFishingOperation(toSave); + + // reinject it in model + model.updateFishingOperation(savedFishingOperation); + } finally { + model.setEditionAdjusting(false); + } } } Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SelectFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SelectFishingOperationAction.java 2013-02-10 15:03:24 UTC (rev 387) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/SelectFishingOperationAction.java 2013-02-10 15:04:13 UTC (rev 388) @@ -1,140 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.decorator.Decorator; - -import javax.swing.JLabel; -import javax.swing.JTabbedPane; -import javax.swing.SwingUtilities; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; - -import static org.nuiton.i18n.I18n._; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0 - */ -public class SelectFishingOperationAction extends AbstractTuttiAction<FishingOperationsUIModel, FishingOperationsUI, FishingOperationsUIHandler> { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = - LogFactory.getLog(SelectFishingOperationAction.class); - - protected FishingOperation fishingOperation; - - public SelectFishingOperationAction(FishingOperationsUIHandler handler) { - super(handler, - "selectFishingOperation", - "select", - null, - _("tutti.action.selectFishingOperation.tip"), - true); - } - - public void setFishingOperation(FishingOperation fishingOperation) { - this.fishingOperation = fishingOperation; - } - - @Override - protected void releaseAction(ActionEvent event) { - fishingOperation = null; - super.releaseAction(event); - } - - @Override - protected void doAction(ActionEvent event) throws Exception { - - if (log.isInfoEnabled()) { - log.info("New selected fishingOperation: " + fishingOperation); - } - - FishingOperationsUI ui = getHandler().getUi(); - - JTabbedPane form = ui.getTabPane(); - JLabel noContentPane = ui.getNoTraitPane(); - - if (fishingOperation == null) { - - // nothing to display - - ui.remove(form); - - // just display <no trait!> - ui.add(noContentPane, BorderLayout.CENTER); - - } else { - - // select a fishing operation - - Decorator<FishingOperation> decorator = - getDecorator(FishingOperation.class, null); - - String fishingOperationText = - _("tutti.label.traitReminder", - decorator.toString(fishingOperation)); - - // propagate fishingOperation to his tabs - ui.getFishingOperationTabContent().getHandler().selectFishingOperation(fishingOperation); - if (ui.getFishingOperationTabContent().getModel().isCreate()) { - - // back to fishingOperation tab - ui.getTabPane().setSelectedIndex(0); - } - - ui.getCatchesTabContent().getHandler().selectFishingOperation(fishingOperation, - fishingOperationText); - - // back to general tab of fishingOperation tabs - ui.getFishingOperationTabContent().getFishingOperationTabPane().setSelectedIndex(0); - - ui.remove(noContentPane); - - // wait last minute to display (avoid dirty display effects) - ui.add(form, BorderLayout.CENTER); - - // repaint tabs -// ui.getTabPane().repaint(); - - } - - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - getHandler().getUi().repaint(); - } - }); - - } -} \ No newline at end of file Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java 2013-02-10 15:04:13 UTC (rev 388) @@ -0,0 +1,87 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; +import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * To cancel edit of a {@link CatchBatch}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class CancelEditCatchBatchAction extends AbstractTuttiAction<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(CancelEditCatchBatchAction.class); + + /** + * A flag to update ui after create or save the edit catch batch. + * + * @since 1.0 + */ + protected boolean updateUI; + + public CancelEditCatchBatchAction(EditCatchesUIHandler handler) { + super(handler, + "cancelEditCatchBatch", + "cancel", + _("tutti.action.cancelEditCatchBatch"), + _("tutti.action.cancelEditCatchBatch.tip"), + true + ); + } + + @Override + protected void doAction(ActionEvent event) throws Exception { + + if (getModel().isCreate()) { + if (log.isInfoEnabled()) { + log.info("Cancel creation for catchBatch"); + } + + // cancel to create a catch batch ? + + } else { + + if (log.isInfoEnabled()) { + log.info("Can edition of catchBatch"); + } + } + + } + + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-02-10 15:03:24 UTC (rev 387) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-02-10 15:04:13 UTC (rev 388) @@ -24,11 +24,6 @@ * #L% */ -import com.google.common.base.Preconditions; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; -import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.TuttiUI; import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiTabContainerUIHandler; @@ -36,7 +31,6 @@ import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import jaxx.runtime.swing.CardLayout2Ext; import jaxx.runtime.validator.swing.SwingValidator; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTitledPanel; @@ -45,6 +39,7 @@ import javax.swing.JTabbedPane; import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.n_; /** * @author tchemit <chemit@codelutin.com> @@ -65,24 +60,24 @@ private static final Log log = LogFactory.getLog(EditCatchesUIHandler.class); - /** - * Persistence service. - * - * @since 0.3 - */ - private final PersistenceService persistenceService; +// /** +// * Persistence service. +// * +// * @since 0.3 +// */ +// private final PersistenceService persistenceService; /** * To monitor changes on the incoming fishing operation. * * @since 0.3 */ - private final TuttiBeanMonitor<EditCatchesUIModel> fishingOperationMonitor; + private final TuttiBeanMonitor<EditCatchesUIModel> catchBatchMonitor; public EditCatchesUIHandler(FishingOperationsUI parentUi, EditCatchesUI ui) { super(parentUi.getHandler().getContext(), ui); - this.persistenceService = context.getService(PersistenceService.class); - this.fishingOperationMonitor = new TuttiBeanMonitor<EditCatchesUIModel>( +// this.persistenceService = context.getService(PersistenceService.class); + this.catchBatchMonitor = new TuttiBeanMonitor<EditCatchesUIModel>( EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_WEIGHT, EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT, EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, @@ -105,7 +100,7 @@ listModelIsModify(model); - fishingOperationMonitor.setBean(model); + catchBatchMonitor.setBean(model); } @Override @@ -168,108 +163,113 @@ //-- Public methods --// //------------------------------------------------------------------------// - public void selectFishingOperation(FishingOperation bean, - String fishingOperationText) { - - boolean empty = bean == null; - Preconditions.checkState(!empty, "can not edit a null fishing operation."); - boolean newOperation = TuttiEntities.isNew(bean); - boolean wasModified = fishingOperationMonitor.wasModified(); - - // 1) Save any modification of the current fishingOperation - - if (wasModified) { - save(); - } - - ui.getSpeciesTabContent().getHandler().clearTableSelection(); -// ui.getBenthosTabContent().getHandler().clearTableSelection(); -// ui.getPlanktonTabContent().getHandler().clearTableSelection(); -// ui.getMacroWasteTabContent().getHandler().clearTableSelection(); -// ui.getAccidentalTabContent().getHandler().clearTableSelection(); - - // 2) Use new selected fishingOperation - - EditCatchesUIModel model = getModel(); - - boolean otherOperation = - ObjectUtils.notEqual(bean, model.getFishingOperation()); - - if (empty || newOperation || otherOperation || wasModified) { - - CatchBatch batch; - - if (empty || newOperation) { - - // create a new CatchBatch - if (log.isInfoEnabled()) { - log.info("Create a new CatchBatch"); - } - batch = new CatchBatch(); - batch.setFishingOperation(bean); - - } else { - - String operationId = bean.getId(); - - if (log.isInfoEnabled()) { - log.info("Load existing CatchBatch from operation id: " + - operationId); - } - - batch = persistenceService.getCatchBatchFromFishingOperation( - operationId); - -// model.setCatchBatch(batch); -// model.setFishingOperation(bean); - } - - model.setCatchBatch(batch); - model.setFishingOperation(bean); - - model.fromBean(batch); - - model.setModify(false); - fishingOperationMonitor.clearModified(); - - // 3) Propagate title to others tabs - ui.getCatchesCaracteristicsTabPane().setTitle(fishingOperationText); - ui.getSpeciesTabFishingOperationReminderLabel().setTitle(fishingOperationText); -// ui.getBenthosTabFishingOperationReminderLabel().setTitle(fishingOperationText); -// ui.getPlanktonTabFishingOperationReminderLabel().setTitle(fishingOperationText); -// ui.getMacroWasteTabFishingOperationReminderLabel().setTitle(fishingOperationText); -// ui.getAccidentalTabFishingOperationReminderLabel().setTitle(fishingOperationText); - - // 4) Propagate new selected fishingoperation to others tabs - - ui.getSpeciesTabContent().getHandler().selectFishingOperation(bean); -// ui.getBenthosTabContent().getHandler().selectFishingOperation(bean); -// ui.getPlanktonTabContent().getHandler().selectFishingOperation(bean); -// ui.getMacroWasteTabContent().getHandler().selectFishingOperation(bean); -// ui.getAccidentalTabContent().getHandler().selectFishingOperation(bean); - - ui.getTabPane().repaint(); - } + public TuttiBeanMonitor<EditCatchesUIModel> getCatchBatchMonitor() { + return catchBatchMonitor; } - protected void save() { - // previous fishingOperation was modified, let's save it - EditCatchesUIModel beanToSave = fishingOperationMonitor.getBean(); +// public void selectFishingOperation(FishingOperation bean, +// String fishingOperationText) { +// +// boolean empty = bean == null; +// Preconditions.checkState(!empty, "can not edit a null fishing operation."); +// boolean newOperation = TuttiEntities.isNew(bean); +// boolean wasModified = fishingOperationMonitor.wasModified(); +// +// // 1) Save any modification of the current fishingOperation +// +// if (wasModified) { +// save(); +// } +// +// ui.getSpeciesTabContent().getHandler().clearTableSelection(); +//// ui.getBenthosTabContent().getHandler().clearTableSelection(); +//// ui.getPlanktonTabContent().getHandler().clearTableSelection(); +//// ui.getMacroWasteTabContent().getHandler().clearTableSelection(); +//// ui.getAccidentalTabContent().getHandler().clearTableSelection(); +// +// // 2) Use new selected fishingOperation +// +// EditCatchesUIModel catchesUIModel = getModel(); +// +// boolean otherOperation = +// ObjectUtils.notEqual(bean, catchesUIModel.getFishingOperation()); +// +// if (empty || newOperation || otherOperation || wasModified) { +// +// CatchBatch batch; +// +// if (empty || newOperation) { +// +// // create a new CatchBatch +// if (log.isInfoEnabled()) { +// log.info("Create a new CatchBatch"); +// } +// batch = new CatchBatch(); +// batch.setFishingOperation(bean); +// +// } else { +// +// String operationId = bean.getId(); +// +// if (log.isInfoEnabled()) { +// log.info("Load existing CatchBatch from operation id: " + +// operationId); +// } +// +// batch = persistenceService.getCatchBatchFromFishingOperation( +// operationId); +// +//// model.setCatchBatch(batch); +//// model.setFishingOperation(bean); +// } +// +// catchesUIModel.setCatchBatch(batch); +// catchesUIModel.setFishingOperation(bean); +// +// catchesUIModel.fromBean(batch); +// +// catchesUIModel.setModify(false); +// fishingOperationMonitor.clearModified(); +// +// // 3) Propagate title to others tabs +// ui.getCatchesCaracteristicsTabPane().setTitle(fishingOperationText); +// ui.getSpeciesTabFishingOperationReminderLabel().setTitle(fishingOperationText); +//// ui.getBenthosTabFishingOperationReminderLabel().setTitle(fishingOperationText); +//// ui.getPlanktonTabFishingOperationReminderLabel().setTitle(fishingOperationText); +//// ui.getMacroWasteTabFishingOperationReminderLabel().setTitle(fishingOperationText); +//// ui.getAccidentalTabFishingOperationReminderLabel().setTitle(fishingOperationText); +// +// // 4) Propagate new selected fishingoperation to others tabs +// +// ui.getSpeciesTabContent().getHandler().selectFishingOperation(bean); +//// ui.getBenthosTabContent().getHandler().selectFishingOperation(bean); +//// ui.getPlanktonTabContent().getHandler().selectFishingOperation(bean); +//// ui.getMacroWasteTabContent().getHandler().selectFishingOperation(bean); +//// ui.getAccidentalTabContent().getHandler().selectFishingOperation(bean); +// +// ui.getTabPane().repaint(); +// } +// } - CatchBatch catchBatch = beanToSave.toBean(); +// public void save() { +// +// // previous fishingOperation was modified, let's save it +// EditCatchesUIModel beanToSave = catchBatchMonitor.getBean(); +// +// CatchBatch catchBatch = beanToSave.toBean(); +// +// if (log.isInfoEnabled()) { +// log.info("FishingOperation " + catchBatch.getId() + +// " was modified, will save it."); +// } +// +// showInformationMessage( +// "[ Captures - Caractéristiques générales ] " + +// "Sauvegarde des modifications du résumé de la capture."); +// +// persistenceService.saveCatchBatch(catchBatch); +// } - if (log.isInfoEnabled()) { - log.info("FishingOperation " + catchBatch.getId() + - " was modified, will save it."); - } - - showInformationMessage( - "[ Captures - Caractéristiques générales ] " + - "Sauvegarde des modifications du résumé de la capture."); - - persistenceService.saveCatchBatch(catchBatch); - } - protected void registerValidators() { registerValidators(getValidator(), ui.getSpeciesTabContent().getHandler().getValidator()); } @@ -289,17 +289,17 @@ if (CREATE_BATCH_CARD.equals(card)) { tuttiUi = ui.getSpeciesTabCreateBatch(); titlePanel = ui.getSpeciesTabCreateBatchReminderLabel(); - title = "tutti.title.createBatch"; + title = n_("tutti.title.createBatch"); } else if (SPLIT_BATCH_CARD.equals(card)) { tuttiUi = ui.getSpeciesTabSplitBatch(); titlePanel = ui.getSpeciesTabSplitBatchReminderLabel(); - title = "tutti.title.splitBatch"; + title = n_("tutti.title.splitBatch"); } else if (EDIT_FREQUENCY_CARD.equals(card)) { tuttiUi = ui.getSpeciesTabFrequencyEditor(); titlePanel = ui.getSpeciesTabFrequencyEditorReminderLabel(); - title = "tutti.title.editFrequency"; + title = n_("tutti.title.editFrequency"); } if (tuttiUi != null) { Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SaveCatchBatchAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SaveCatchBatchAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SaveCatchBatchAction.java 2013-02-10 15:04:13 UTC (rev 388) @@ -0,0 +1,120 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; +import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * To save a {@link CatchBatch}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class SaveCatchBatchAction extends AbstractTuttiAction<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SaveCatchBatchAction.class); + + + /** + * A flag to update ui after create or save the edit catch batch. + * + * @since 1.0 + */ + protected boolean updateUI; + + public SaveCatchBatchAction(EditCatchesUIHandler handler) { + super(handler, + "saveCatchBatch", + "save", + _("tutti.action.saveCatchBatch"), + _("tutti.action.saveCatchBatch.tip"), + true + ); + } + + public void setUpdateUI(boolean updateUI) { + this.updateUI = updateUI; + } + + @Override + protected void releaseAction(ActionEvent event) { + updateUI = true; + super.releaseAction(event); + } + + @Override + protected void doAction(ActionEvent event) { + + EditCatchesUIHandler handler = getHandler(); + + TuttiBeanMonitor<EditCatchesUIModel> monitor = + handler.getCatchBatchMonitor(); + + // previous fishingOperation was modified, let's save it + EditCatchesUIModel beanToSave = monitor.getBean(); + + // must save when bean is new or was modifiy and is valid + boolean mustSave = (beanToSave.isCreate() || beanToSave.isModify()) && + beanToSave.isValid(); + + if (mustSave) { + + PersistenceService persistenceService = + getService(PersistenceService.class); + + CatchBatch catchBatch = beanToSave.toBean(); + + if (log.isInfoEnabled()) { + log.info("FishingOperation " + catchBatch.getId() + + " was modified, will save it."); + } + + getHandler().showInformationMessage( + "[ Captures - Caractéristiques générales ] " + + "Sauvegarde des modifications du résumé de la capture."); + + persistenceService.saveCatchBatch(catchBatch); + + monitor.clearModified(); + } + + getUI().getSpeciesTabContent().getHandler().clearTableSelection(); + + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SaveCatchBatchAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native