Author: tchemit Date: 2013-03-27 22:44:37 +0100 (Wed, 27 Mar 2013) New Revision: 692 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/692 Log: fixes #2224: [CAPUTRE] Donn?\195?\169es non sauvegard?\195?\169es Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 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/EditCatchesUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-03-27 19:09:49 UTC (rev 691) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-03-27 21:44:37 UTC (rev 692) @@ -317,6 +317,7 @@ text: "tutti.editCatchBatch.action.saveCatchBatch"; toolTipText: "tutti.editCatchBatch.action.saveCatchBatch.tip"; i18nMnemonic: "tutti.editCatchBatch.action.saveCatchBatch.mnemonic"; + enabled: {model.isModify()}; _tuttiAction: {SaveCatchBatchAction.class}; _help: {"tutti.editCatchBatch.action.saveCatchBatch.help"}; } 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-03-27 19:09:49 UTC (rev 691) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-03-27 21:44:37 UTC (rev 692) @@ -87,7 +87,11 @@ this.parentUi = parentUi; this.catchBatchMonitor = new TuttiBeanMonitor<EditCatchesUIModel>( EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT); + EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, + EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, + EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_INERT_WEIGHT, + EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT); } //------------------------------------------------------------------------// Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-03-27 19:09:49 UTC (rev 691) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-03-27 21:44:37 UTC (rev 692) @@ -41,8 +41,6 @@ import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.Collection; import java.util.List; @@ -182,43 +180,24 @@ public EditCatchesUIModel() { super(CatchBatch.class, fromBeanBinder, toBeanBinder); - speciesTotalSortedComputedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, - new PropertyChangeListener() { + speciesTotalSortedComputedOrNotWeight.addPropagateListener( + PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, this); + speciesTotalInertComputedOrNotWeight.addPropagateListener( + PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, this); + speciesTotalLivingNotItemizedComputedOrNotWeight.addPropagateListener( + PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, this); - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - evt.getOldValue(), evt.getNewValue()); - } - }); - benthosTotalSortedComputedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, - new PropertyChangeListener() { + benthosTotalSortedComputedOrNotWeight.addPropagateListener( + PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, this); + benthosTotalInertComputedOrNotWeight.addPropagateListener( + PROPERTY_BENTHOS_TOTAL_INERT_WEIGHT, this); + benthosTotalLivingNotItemizedComputedOrNotWeight.addPropagateListener( + PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, this); - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - evt.getOldValue(), evt.getNewValue()); - } - }); - - catchTotalComputedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_CATCH_TOTAL_WEIGHT, - evt.getOldValue(), evt.getNewValue()); - } - }); - catchTotalRejectedComputedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, - evt.getOldValue(), evt.getNewValue()); - } - }); + catchTotalComputedOrNotWeight.addPropagateListener( + PROPERTY_CATCH_TOTAL_WEIGHT, this); + catchTotalRejectedComputedOrNotWeight.addPropagateListener( + PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, this); } @Override Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-03-27 19:09:49 UTC (rev 691) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-03-27 21:44:37 UTC (rev 692) @@ -42,8 +42,6 @@ import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -242,39 +240,10 @@ maturityCategory = SampleCategory.newSample(SampleCategoryEnum.maturity); ageCategory = SampleCategory.newSample(SampleCategoryEnum.age); - computedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_WEIGHT, evt.getOldValue(), evt.getNewValue()); - } - }); - computedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_COMPUTED_WEIGHT, evt.getOldValue(), evt.getNewValue()); - } - }); - - computedOrNotNumber.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_NUMBER, evt.getOldValue(), evt.getNewValue()); - } - }); - computedOrNotNumber.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_COMPUTED_NUMBER, evt.getOldValue(), evt.getNewValue()); - } - }); + computedOrNotWeight.addPropagateListener(PROPERTY_WEIGHT, this); + computedOrNotWeight.addPropagateListener(PROPERTY_COMPUTED_WEIGHT, this); + computedOrNotNumber.addPropagateListener(PROPERTY_NUMBER, this); + computedOrNotNumber.addPropagateListener(PROPERTY_COMPUTED_NUMBER, this); } public BenthosBatchRowModel(SpeciesBatch aBatch, Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-03-27 19:09:49 UTC (rev 691) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-03-27 21:44:37 UTC (rev 692) @@ -42,8 +42,6 @@ import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -242,39 +240,10 @@ maturityCategory = SampleCategory.newSample(SampleCategoryEnum.maturity); ageCategory = SampleCategory.newSample(SampleCategoryEnum.age); - computedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_WEIGHT, evt.getOldValue(), evt.getNewValue()); - } - }); - computedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_COMPUTED_WEIGHT, evt.getOldValue(), evt.getNewValue()); - } - }); - - computedOrNotNumber.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_NUMBER, evt.getOldValue(), evt.getNewValue()); - } - }); - computedOrNotNumber.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, - new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_COMPUTED_NUMBER, evt.getOldValue(), evt.getNewValue()); - } - }); + computedOrNotWeight.addPropagateListener(PROPERTY_WEIGHT, this); + computedOrNotWeight.addPropagateListener(PROPERTY_COMPUTED_WEIGHT, this); + computedOrNotNumber.addPropagateListener(PROPERTY_NUMBER, this); + computedOrNotNumber.addPropagateListener(PROPERTY_COMPUTED_NUMBER, this); } public SpeciesBatchRowModel(SpeciesBatch aBatch, Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java 2013-03-27 19:09:49 UTC (rev 691) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java 2013-03-27 21:44:37 UTC (rev 692) @@ -119,4 +119,12 @@ public boolean isCreate() { return id == null; } + + public void firePropertyChanged(String propertyName, + Object oldValue, + Object newValue) { + firePropertyChange(propertyName, oldValue, newValue); + } + + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-03-27 19:09:49 UTC (rev 691) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-03-27 21:44:37 UTC (rev 692) @@ -1,8 +1,5 @@ - package fr.ifremer.tutti.ui.swing.util; -import org.jdesktop.beans.AbstractSerializableBean; - /* * #%L * Tutti :: UI @@ -13,20 +10,26 @@ * %% * 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 + * 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 + * + * 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 org.jdesktop.beans.AbstractSerializableBean; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + + /** @author kmorin <kmorin@codelutin.com> */ public class TuttiComputedOrNotData<N extends Number> extends AbstractSerializableBean { @@ -81,4 +84,33 @@ return result; } + /** + * Add a listener to propagate the modification of the + * {@link #PROPERTY_DATA} property to a given {@code propertyName}. + * + * @param propertyName name of the property to fire on given bean + * @param otherBean bean that will fires + * @since 1.2 + */ + public void addPropagateListener(String propertyName, AbstractTuttiBeanUIModel otherBean) { + PropagatePropertyChangeListener listener = new PropagatePropertyChangeListener(propertyName, otherBean); + addPropertyChangeListener(PROPERTY_DATA, listener); + } + + private static class PropagatePropertyChangeListener implements PropertyChangeListener { + + private String propertyName; + + private AbstractTuttiBeanUIModel otherBean; + + public PropagatePropertyChangeListener(String propertyName, AbstractTuttiBeanUIModel otherBean) { + this.propertyName = propertyName; + this.otherBean = otherBean; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + otherBean.firePropertyChanged(propertyName, evt.getOldValue(), evt.getNewValue()); + } + } }