This is an automated email from the git hooks/post-receive script. New commit to branch feature/7930 in repository tutti. See http://git.codelutin.com/tutti.git commit 273bcf877f1f975ab258651e066286bac695b557 Author: Kevin Morin <morin@codelutin.com> Date: Mon Feb 15 12:17:19 2016 +0100 - ajout des listener à l'initialisation de la liste des lignes - ajout de la modif du model quand on modifie une ligne refs #7930 --- .../content/protocol/EditProtocolUIModel.java | 2 +- .../CalcifiedPiecesSamplingEditorUIHandler.java | 84 ++++++++++++++-------- 2 files changed, 54 insertions(+), 32 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java index eab2c3e..71a86d3 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIModel.java @@ -37,10 +37,10 @@ import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocols; import fr.ifremer.tutti.persistence.entities.protocol.Zone; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.CalcifiedPiecesSamplingEditorRowModel; import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.StrataUIModel; import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.SubStrataUIModel; import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.ZoneUIModel; -import fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.CalcifiedPiecesSamplingEditorRowModel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.logging.Log; diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/CalcifiedPiecesSamplingEditorUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/CalcifiedPiecesSamplingEditorUIHandler.java index 615e7ac..b54737d 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/CalcifiedPiecesSamplingEditorUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/CalcifiedPiecesSamplingEditorUIHandler.java @@ -27,7 +27,10 @@ import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import java.awt.Color; import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.TreeSet; @@ -44,6 +47,48 @@ public class CalcifiedPiecesSamplingEditorUIHandler extends AbstractTuttiUIHandl protected Caracteristic sexCaracteristic; + protected final PropertyChangeListener rowChangeListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + getModel().setModify(true); + + String propertyName = evt.getPropertyName(); + CalcifiedPiecesSamplingEditorRowModel row = (CalcifiedPiecesSamplingEditorRowModel) evt.getSource(); + + if (CalcifiedPiecesSamplingEditorRowModel.PROPERTY_MIN_SIZE.equals(propertyName)) { + + List<CalcifiedPiecesSamplingEditorRowModel> cpsRows = getModel().getCpsRows(); + + int newRowIndex = cpsRows.indexOf(row); + int previousRowIndex = newRowIndex - 1; + CalcifiedPiecesSamplingEditorRowModel previousRow = cpsRows.get(previousRowIndex); + + Integer newValue = (Integer) evt.getNewValue(); + + if (newValue == null) { + row.setMinSize(0); + + } else if (newValue <= previousRow.getMinSize() + || row.getMaxSize() != null && newValue >= row.getMaxSize()) { + // si la nouvelle valeur sort de l'intervalle des deux lignes + row.setMinSize((Integer) evt.getOldValue()); + + } else { + previousRow.setMaxSize(newValue - 1); + CalcifiedPiecesSamplingEditorTableModel model = + (CalcifiedPiecesSamplingEditorTableModel) getUI().getCpsTable().getModel(); + model.fireTableRowsUpdated(previousRowIndex, newRowIndex); + } + + } else if (CalcifiedPiecesSamplingEditorRowModel.PROPERTY_SAMPLING_INTERVAL.equals(propertyName)) { + if (evt.getNewValue() == null) { + row.setSamplingInterval(0); + } + } + } + }; + @Override public void beforeInit(CalcifiedPiecesSamplingEditorUI ui) { super.beforeInit(ui); @@ -100,6 +145,12 @@ public class CalcifiedPiecesSamplingEditorUIHandler extends AbstractTuttiUIHandl // at the very end, set rows to model getModel().addPropertyChangeListener(EditProtocolUIModel.PROPERTY_CSP_ROWS, evt -> { + Collection<CalcifiedPiecesSamplingEditorRowModel> rows = + (Collection<CalcifiedPiecesSamplingEditorRowModel>) evt.getNewValue(); + for (CalcifiedPiecesSamplingEditorRowModel row : rows) { + row.removePropertyChangeListener(rowChangeListener); + row.addPropertyChangeListener(rowChangeListener); + } tableModel.setRows(getModel().getCpsRows()); tableModel.fireTableDataChanged(); }); @@ -277,39 +328,10 @@ public class CalcifiedPiecesSamplingEditorUIHandler extends AbstractTuttiUIHandl JXTable cpsTable = getUI().getCpsTable(); CalcifiedPiecesSamplingEditorTableModel tableModel = (CalcifiedPiecesSamplingEditorTableModel) cpsTable.getModel(); - List<CalcifiedPiecesSamplingEditorRowModel> cpsRows = getModel().getCpsRows(); CalcifiedPiecesSamplingEditorRowModel newRow = tableModel.createNewRow(species, maturity, sex, minSize, maxSize); - - //FIXME il faudrait ajouter ces listener sur les lignes qu'on charge au chargement du protocole - newRow.addPropertyChangeListener(CalcifiedPiecesSamplingEditorRowModel.PROPERTY_MIN_SIZE, evt -> { - - int newRowIndex = cpsRows.indexOf(newRow); - int previousRowIndex = newRowIndex - 1; - CalcifiedPiecesSamplingEditorRowModel previousRow = cpsRows.get(previousRowIndex); - - Integer newValue = (Integer) evt.getNewValue(); - - if (newValue == null) { - newRow.setMinSize(0); - - } else if (newValue <= previousRow.getMinSize() - || newRow.getMaxSize() != null && newValue >= newRow.getMaxSize()) { - // si la nouvelle valeur sort de l'intervalle des deux lignes - newRow.setMinSize((Integer) evt.getOldValue()); - - } else { - previousRow.setMaxSize(newValue - 1); - tableModel.fireTableRowsUpdated(previousRowIndex, newRowIndex); - } - - }); - - newRow.addPropertyChangeListener(CalcifiedPiecesSamplingEditorRowModel.PROPERTY_SAMPLING_INTERVAL, evt -> { - if (evt.getNewValue() == null) { - newRow.setSamplingInterval(0); - } - }); + newRow.removePropertyChangeListener(rowChangeListener); + newRow.addPropertyChangeListener(rowChangeListener); return newRow; } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.