This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit 1984263f6ac60a7fb0dbb9f7dcfa7f5c24874eda Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Mar 12 21:36:45 2015 +0100 chahngement de l'état des onglets sous la captures --- .../catches/AbstractTuttiBatchUIModel.java | 27 ++++- .../content/operation/catches/CatchCustomTab.java | 133 +++++++++++++++++++++ .../operation/catches/EditCatchesUIHandler.java | 31 ++++- 3 files changed, 188 insertions(+), 3 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/AbstractTuttiBatchUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/AbstractTuttiBatchUIModel.java index 5755105..5097395 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/AbstractTuttiBatchUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/AbstractTuttiBatchUIModel.java @@ -26,6 +26,8 @@ import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -39,6 +41,9 @@ import java.util.Set; */ public abstract class AbstractTuttiBatchUIModel<R extends AbstractTuttiBeanUIModel, B extends AbstractTuttiBatchUIModel<R, B>> extends AbstractTuttiTableUIModel<FishingOperation, R, B> { + /** Logger. */ + private static final Log log = LogFactory.getLog(AbstractTuttiBatchUIModel.class); + private static final long serialVersionUID = 1L; /** @@ -63,8 +68,26 @@ public abstract class AbstractTuttiBatchUIModel<R extends AbstractTuttiBeanUIMod catchesUIModel.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - if (propagateProperties.contains(evt.getPropertyName())) { - firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); + String propertyName = evt.getPropertyName(); + + if (propagateProperties.contains(propertyName)) { + if (log.isDebugEnabled()) { + log.debug("Propagates property [" + propertyName + "] change from catch model to " + AbstractTuttiBatchUIModel.this.getClass().getSimpleName()); + } + firePropertyChange(propertyName, evt.getOldValue(), evt.getNewValue()); + EditCatchesUIModel source = (EditCatchesUIModel) evt.getSource(); + if (!source.isLoadingData() && !isModify()) { + setModify(true); + } + } + + if (AbstractTuttiBeanUIModel.PROPERTY_MODIFY.equals(propertyName)) { + + Boolean newValue = (Boolean) evt.getNewValue(); + if (newValue != null && !newValue) { + setModify(false); + } + } } }); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CatchCustomTab.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CatchCustomTab.java new file mode 100644 index 0000000..20a76ea --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CatchCustomTab.java @@ -0,0 +1,133 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import org.nuiton.jaxx.application.ApplicationTechnicalException; +import org.nuiton.jaxx.application.swing.tab.CustomTab; +import org.nuiton.jaxx.application.swing.tab.TabContainerHandler; +import org.nuiton.jaxx.application.swing.tab.TabContentModel; +import org.nuiton.util.beans.BeanMonitor; +import org.nuiton.util.beans.BeanUtil; + +import javax.swing.UIManager; +import java.awt.Font; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Set; + +import static org.nuiton.i18n.I18n.t; + +/** + * Une amélioration de CustomTab pour ne pas utiliser la propriété modify d'un modèle mais un sous ensemble de ses + * propriétés. + * + * De plus on utilise un monitor donc quand plus rien n'est modifié, on peut aussi le savoir. + * + * TODO Il faudrait utiliser cet objet sur tous les onglets une fois un gros travail de nettoyage des listeners effectué + * TODO car là c'est un peu chaotique et le monitor devient rapidemment inconsitent. + * + * Created on 3/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.13.3 + */ +public class CatchCustomTab extends CustomTab { + + private static final long serialVersionUID = 1L; + + private final Set<String> modifyPropertyNames; + + public static CatchCustomTab newCustomTab(TabContentModel model, TabContainerHandler handler, Set<String> modifyPropertyNames) { + + CatchCustomTab customTab = new CatchCustomTab(model, handler, modifyPropertyNames); + customTab.init(); + return customTab; + + } + + protected transient BeanMonitor monitor; + + protected final Font defaultFont; + + protected void init() { + + // init first monitor + // so monitor will be notify before later listener + monitor = new BeanMonitor(modifyPropertyNames.toArray(new String[modifyPropertyNames.size()])); + monitor.setBean(model); + + // listen to the model + try { + BeanUtil.addPropertyChangeListener( + new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + onPropertyChanged(evt.getPropertyName(), evt.getNewValue()); + + } + }, this.model); + } catch (Exception e) { + throw new ApplicationTechnicalException("Could not init listener", e); + } + + } + + void onPropertyChanged(String propertyName, Object value) { + + if (propertyName.equals(AbstractTuttiBeanUIModel.PROPERTY_MODIFY)) { + + Boolean newValue = (Boolean) value; + if (newValue != null && !newValue) { + + // model no more modified, reset the monitor + monitor.clearModified(); + updateTitle2(monitor.wasModified(), model.isEmpty()); + + } + + } else { + + if (modifyPropertyNames.contains(propertyName)) { + + updateTitle2(monitor.wasModified(), model.isEmpty()); + + } + + } + + } + + CatchCustomTab(TabContentModel model, TabContainerHandler handler, Set<String> modifyPropertyNames) { + super(model, handler); + this.modifyPropertyNames = modifyPropertyNames; + this.defaultFont = UIManager.getDefaults().getFont("Label.font"); + } + + @Override + protected void updateTitle() { + // bad method (fire before monitor is notified + fired from constructor, bad, bad, bad!) + } + + protected void updateTitle2(boolean modelModify, boolean modelEmpty) { + + String titleValue = t(model.getTitle()); + + int style; + if (modelModify) { + style = Font.BOLD; + titleValue += "*"; + + } else if (modelEmpty) { + style = Font.ITALIC; + + } else { + style = Font.PLAIN; + } + + title.setText(titleValue); + title.setFont(defaultFont.deriveFont(style)); + + } + +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java index 90d7bf8..c016991 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java @@ -39,6 +39,7 @@ import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTitledPanel; +import org.nuiton.jaxx.application.swing.tab.TabContentModel; import org.nuiton.jaxx.application.swing.tab.TabHandler; import javax.swing.JComponent; @@ -161,7 +162,27 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi changeValidatorContext(model.getValidationContext(), getValidator()); listenValidationTableHasNoFatalError(getValidator(), model); - setCustomTab(0, model); + setCustomTab2(0, model, + Sets.newHashSet(EditCatchesUIModel.PROPERTY_CATCH_TOTAL_WEIGHT, + EditCatchesUIModel.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + EditCatchesUIModel.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT)); + + //FIXME Can't use it with thoses tabs, because of crazy listener usage, the scheme is not clear at all + //FIXME and we need to clarify and sanity this doom :( +// setCustomTab2(1, ui.getSpeciesTabContent().getModel(), +// Sets.newHashSet(EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, +// EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, +// EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT)); +// setCustomTab2(2, ui.getBenthosTabContent().getModel(), +// Sets.newHashSet(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, +// EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_INERT_WEIGHT, +// EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT)); +// +// setCustomTab2(3, ui.getMarineLitterTabContent().getModel(), +// Sets.newHashSet(EditCatchesUIModel.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT)); + setCustomTab(1, ui.getSpeciesTabContent().getModel()); setCustomTab(2, ui.getBenthosTabContent().getModel()); setCustomTab(3, ui.getMarineLitterTabContent().getModel()); @@ -179,6 +200,13 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } + public void setCustomTab2(int index, TabContentModel model, Set<String> modifyPropertyNames) { + + JTabbedPane tabPanel = getTabPanel(); + tabPanel.setTabComponentAt(index, CatchCustomTab.newCustomTab(model, this, modifyPropertyNames)); + + } + public void closeAttachments() { ui.getCatchesCaracteristicsAttachmentsButton().onCloseUI(); ui.getSpeciesTabContent().getSpeciesBatchAttachmentsButton().onCloseUI(); @@ -248,6 +276,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_COMPUTED_WEIGHT, EditCatchesUIModel.PROPERTY_SPECIES_DISTINCT_SORTED_SPECIES_COUNT, EditCatchesUIModel.PROPERTY_BENTHOS_DISTINCT_SORTED_SPECIES_COUNT, + EditCatchesUIModel.PROPERTY_MARINE_LITTER_TOTAL_COMPUTED_WEIGHT, EditCatchesUIModel.PROPERTY_ATTACHMENT, EditCatchesUIModel.PROPERTY_BATCH_UPDATED )); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.