This is an automated email from the git hooks/post-receive script. New commit to branch feature/8238 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 2f13607bef0a24b72f2bc46e8398096e923f9ebb Author: Kevin Morin <morin@codelutin.com> Date: Mon Apr 25 17:48:36 2016 +0200 - Quand on supprime des lignes d'espece ou benthos du protocole, on enlève leur maturité des maturités utilisées. - On met à jour l'état des boutons de la double liste de maturité quand on arrive sur l'onglet des caractéristiques. Sinon, si la maturité sélectionné a été ajoutée ou supprimée, le bouton n'est plus dans le bon état. fixes #8238 --- .../protocol/EditProtocolSpeciesTableModel.java | 42 ++++++++++++++++------ .../content/protocol/EditProtocolUIHandler.java | 16 ++++++++- .../actions/RemoveBenthosProtocolAction.java | 5 +++ .../actions/RemoveSpeciesProtocolAction.java | 5 +++ 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java index 3c0ab77..936aab4 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java @@ -95,15 +95,6 @@ public class EditProtocolSpeciesTableModel extends AbstractApplicationTableModel this.sampleCategoryModel = sampleCategoryModel; setNoneEditableCols(SPECIES_ID); -// addTableModelListener(new TableModelListener() { -// -// @Override -// public void tableChanged(TableModelEvent e) { -// if (e.getType() == TableModelEvent.DELETE) { -// e.getFirstRow(); -// } -// } -// }); } public static EditProtocolSpeciesRowModel newRow(SampleCategoryModel sampleCategoryModel) { @@ -135,11 +126,12 @@ public class EditProtocolSpeciesTableModel extends AbstractApplicationTableModel //FIXME gérer les maturités des lignes suprpimées result.addPropertyChangeListener(EditProtocolSpeciesRowModel.PROPERTY_MATURITY_PMFM, evt -> { + // update the used maturities if (evt.getOldValue() != null) { - maturitiesUsed.remove(evt.getOldValue()); + removeUsedMaturity((Caracteristic) evt.getOldValue()); } if (evt.getNewValue() != null) { - maturitiesUsed.add((Caracteristic) evt.getNewValue()); + addUsedMaturity((Caracteristic) evt.getNewValue()); } }); @@ -197,7 +189,35 @@ public class EditProtocolSpeciesTableModel extends AbstractApplicationTableModel return result; } + // operations on the used maturities + + public static void addUsedMaturity(Caracteristic maturity) { + maturitiesUsed.add(maturity); + } + + public static void removeUsedMaturity(Caracteristic maturity) { + maturitiesUsed.remove(maturity); + } + + public static void removeUsedMaturities(Collection<Caracteristic> maturities) { + maturitiesUsed.removeAll(maturities); + } + + /** + * Check if the caracteristics are used in the maturity caracteristics of the species or benthos + * @param caracteristics the list of caracteristics to check + * @return true if none of the maturities are used + */ public static boolean isNoneOfTheMaturitiesUsed(Collection<Caracteristic> caracteristics) { return maturitiesUsed.stream().noneMatch(caracteristics::contains); } + + /** + * Check if the caracteristic is used in the maturity caracteristics of the species or benthos + * @param caracteristic the caracteristic to check + * @return true if the maturity is used + */ + public static boolean isMaturityUsed(Caracteristic caracteristic) { + return maturitiesUsed.contains(caracteristic); + } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java index ef52875..58ea42d 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java @@ -554,6 +554,15 @@ public class EditProtocolUIHandler extends AbstractTuttiUIHandler<EditProtocolUI maturityList.getModel().addCanRemoveItemsPredicate( input -> EditProtocolSpeciesTableModel.isNoneOfTheMaturitiesUsed(maturityList.getSelectedList().getSelectedValuesList())); + // update maturity list button states when the user goes back to the caracteristic panel + // to update the remove state in case the selected maturity has been added or removed from the species or benthos + ui.getTabPanel().addChangeListener(e -> { + JTabbedPane source = (JTabbedPane) e.getSource(); + if (ui.getCaracteristicPanel().equals(source.getSelectedComponent())) { + maturityList.getHandler().recomputeButtonStates(); + } + }); + JMenuItem editMaturity = ui.getEditMaturityCaracteristicAction(); maturityList.getSelectedListPopup().add(editMaturity); @@ -1657,6 +1666,8 @@ public class EditProtocolUIHandler extends AbstractTuttiUIHandler<EditProtocolUI private Color invalidColor = getConfig().getColorRowInvalid(); + private Color notRemovableColor = getConfig().getColorWarningRow(); + MaturityCaracteristicCellRenderer(ListCellRenderer defaultRenderer) { this.defaultRenderer = defaultRenderer; } @@ -1667,7 +1678,10 @@ public class EditProtocolUIHandler extends AbstractTuttiUIHandler<EditProtocolUI Caracteristic maturityCaracteristic = (Caracteristic) value; Color backgroud; - if (!EditProtocolUIHandler.this.getModel().isMaturityValid(maturityCaracteristic)) { + if (isSelected && EditProtocolSpeciesTableModel.isMaturityUsed((Caracteristic) value)) { + backgroud= notRemovableColor; + + } else if (!EditProtocolUIHandler.this.getModel().isMaturityValid(maturityCaracteristic)) { backgroud= invalidColor; } else { backgroud = validColor; diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/actions/RemoveBenthosProtocolAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/actions/RemoveBenthosProtocolAction.java index ea0a8d5..0568fe2 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/actions/RemoveBenthosProtocolAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/actions/RemoveBenthosProtocolAction.java @@ -153,6 +153,11 @@ public class RemoveBenthosProtocolAction extends LongActionSupport<EditProtocolU // remove all rows from model getModel().getBenthosRow().removeAll(removedRows); + // remove the maturities of the rows from the used maturities + EditProtocolSpeciesTableModel.removeUsedMaturities(removedRows.stream() + .map(EditProtocolSpeciesRowModel::getMaturityPmfm) + .collect(Collectors.toList())); + // remove the protocolSpecies from the cps table or combobox if (!cpsRowsToDelete.isEmpty()) { handler.deleteCpsRows(cpsRowsToDelete); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/actions/RemoveSpeciesProtocolAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/actions/RemoveSpeciesProtocolAction.java index e9bff10..049f602 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/actions/RemoveSpeciesProtocolAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/actions/RemoveSpeciesProtocolAction.java @@ -150,6 +150,11 @@ public class RemoveSpeciesProtocolAction extends LongActionSupport<EditProtocolU // remove all rows from model getModel().getSpeciesRow().removeAll(removedRows); + // remove the maturities of the rows from the used maturities + EditProtocolSpeciesTableModel.removeUsedMaturities(removedRows.stream() + .map(EditProtocolSpeciesRowModel::getMaturityPmfm) + .collect(Collectors.toList())); + // remove the protocolSpecies from the cps table or combobox if (!cpsRowsToDelete.isEmpty()) { handler.deleteCpsRows(cpsRowsToDelete); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.