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 3aaa5b75d7ed0c26d7f2ce8728a3161231504c26 Author: Kevin Morin <morin@codelutin.com> Date: Thu Feb 11 17:12:46 2016 +0100 - modification de la prise en compte du sexe pour toutes les lignes d'une meme espece - correction du tri des espèces refs #7930 --- .../CalcifiedPiecesSamplingEditorTableModel.java | 11 - .../CalcifiedPiecesSamplingEditorUIHandler.java | 225 ++++++++++++++++----- .../actions/AddSpeciesAction.java | 16 +- .../actions/DeleteRowAction.java | 3 - .../actions/DeleteSpeciesAction.java | 3 - .../actions/SplitSpeciesAction.java | 49 ++--- .../resources/i18n/tutti-ui-swing_en_GB.properties | 4 + 7 files changed, 205 insertions(+), 106 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/CalcifiedPiecesSamplingEditorTableModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/CalcifiedPiecesSamplingEditorTableModel.java index 18ea6e5..48cee24 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/CalcifiedPiecesSamplingEditorTableModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/CalcifiedPiecesSamplingEditorTableModel.java @@ -95,17 +95,6 @@ public class CalcifiedPiecesSamplingEditorTableModel extends AbstractApplication newRow.setOperationLimitation(0); newRow.setZoneLimitation(0); - newRow.addPropertyChangeListener(CalcifiedPiecesSamplingEditorRowModel.PROPERTY_MIN_SIZE, evt -> { - if (evt.getNewValue() == null) { - newRow.setMinSize(0); - } - }); - newRow.addPropertyChangeListener(CalcifiedPiecesSamplingEditorRowModel.PROPERTY_SAMPLING_INTERVAL, evt -> { - if (evt.getNewValue() == null) { - newRow.setSamplingInterval(0); - } - }); - return newRow; } 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 46372df..881f9b3 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 @@ -1,9 +1,11 @@ package fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling; +import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.TuttiDecorator; import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesAbleBatchRowHelper; +import fr.ifremer.tutti.ui.swing.content.protocol.EditProtocolSpeciesRowModel; import fr.ifremer.tutti.ui.swing.content.protocol.EditProtocolUIModel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.util.TuttiUI; @@ -19,16 +21,21 @@ import org.jdesktop.swingx.table.TableColumnExt; import javax.swing.JComponent; import javax.swing.JLabel; -import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.border.LineBorder; +import javax.swing.event.CellEditorListener; +import javax.swing.event.ChangeEvent; import javax.swing.event.TableModelEvent; import javax.swing.table.JTableHeader; +import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import java.awt.Color; import java.awt.Component; import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import java.util.TreeSet; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -41,6 +48,14 @@ public class CalcifiedPiecesSamplingEditorUIHandler extends AbstractTuttiUIHandl /** Logger. */ private static final Log log = LogFactory.getLog(CalcifiedPiecesSamplingEditorUIHandler.class); + protected Caracteristic sexCaracteristic; + + @Override + public void beforeInit(CalcifiedPiecesSamplingEditorUI ui) { + super.beforeInit(ui); + sexCaracteristic = getPersistenceService().getSexCaracteristic(); + } + @Override public void afterInit(CalcifiedPiecesSamplingEditorUI calcifiedPiecesSamplingEditorUI) { initUI(calcifiedPiecesSamplingEditorUI); @@ -49,58 +64,7 @@ public class CalcifiedPiecesSamplingEditorUIHandler extends AbstractTuttiUIHandl JXTable cpsTable = ui.getCpsTable(); - DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); - - TableColumnExt speciesColumn = addColumnToModel(columnModel, - null, - newTableCellRender(Species.class), - CalcifiedPiecesSamplingEditorTableModel.SPECIES); - DecoratorService.SpeciesDecorator speciesDecorator = new DecoratorService.SpeciesDecorator(); - speciesColumn.putClientProperty(SpeciesAbleBatchRowHelper.SPECIES_DECORATOR, speciesDecorator); - speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); - - // renderer to display infinite instead of null - TableCellRenderer infiniteRenderer = new TableCellRenderer() { - - private final TableCellRenderer tableCellRenderer = cpsTable.getDefaultRenderer(Integer.class); - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - Component result = tableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - if(result instanceof JLabel) { - JLabel jLabel = (JLabel)result; - String decoratedValue = getDecorator(Integer.class, DecoratorService.NULL_INFINITE).toString(value); - jLabel.setText(decoratedValue); - jLabel.setHorizontalTextPosition(SwingConstants.RIGHT); - } - return result; - } - }; - - // table cell number editor - NumberCellEditor editor = JAXXWidgetUtil.newNumberTableCellEditor(Integer.class, false); - editor.getNumberEditor().setSelectAllTextOnError(Boolean.valueOf(true)); - editor.getNumberEditor().getTextField().setBorder(new LineBorder(Color.GRAY, 2)); - editor.getNumberEditor().setNumberPattern(TuttiUI.INT_6_DIGITS_PATTERN); - - addColumnToModel(columnModel, - null, - newTableCellRender(Boolean.class, DecoratorService.MATURITY), - CalcifiedPiecesSamplingEditorTableModel.MATURITY); - - addBooleanColumnToModel(columnModel, CalcifiedPiecesSamplingEditorTableModel.SEX, cpsTable); - - addIntegerColumnToModel(columnModel, CalcifiedPiecesSamplingEditorTableModel.MIN_SIZE, TuttiUI.INT_6_DIGITS_PATTERN, cpsTable); - - addColumnToModel(columnModel, null, infiniteRenderer, CalcifiedPiecesSamplingEditorTableModel.MAX_SIZE); - - addColumnToModel(columnModel, editor, infiniteRenderer, CalcifiedPiecesSamplingEditorTableModel.MAX_BY_LENGHT_STEP); - - addIntegerColumnToModel(columnModel, CalcifiedPiecesSamplingEditorTableModel.SAMPLING_INTERVAL, TuttiUI.INT_6_DIGITS_PATTERN, cpsTable); - - addColumnToModel(columnModel, editor, infiniteRenderer, CalcifiedPiecesSamplingEditorTableModel.OPERATION_LIMITATION); - addColumnToModel(columnModel, editor, infiniteRenderer, CalcifiedPiecesSamplingEditorTableModel.ZONE_LIMITATION); - + DefaultTableColumnModelExt columnModel = initTableColumnModel(); final CalcifiedPiecesSamplingEditorTableModel tableModel = new CalcifiedPiecesSamplingEditorTableModel(columnModel); @@ -165,7 +129,7 @@ public class CalcifiedPiecesSamplingEditorUIHandler extends AbstractTuttiUIHandl SpeciesAbleBatchRowHelper.installSpeciesColumnComparatorPopup( cpsTable, - speciesColumn, + columnModel.getColumnExt(0), null, t("tutti.species.refTaxCode.tip"), t("tutti.species.name.tip") @@ -177,6 +141,97 @@ public class CalcifiedPiecesSamplingEditorUIHandler extends AbstractTuttiUIHandl tableModel.setRows(rows); } + protected DefaultTableColumnModelExt initTableColumnModel() { + + NumberCellEditor numberCellEditor = JAXXWidgetUtil.newNumberTableCellEditor(Integer.class, false); + numberCellEditor.getNumberEditor().setSelectAllTextOnError(Boolean.valueOf(true)); + numberCellEditor.getNumberEditor().getTextField().setBorder(new LineBorder(Color.GRAY, 2)); + numberCellEditor.getNumberEditor().setNumberPattern(TuttiUI.INT_6_DIGITS_PATTERN); + + // renderer to display the infinite symbol instead of null + TableCellRenderer infiniteRenderer = (table, value, isSelected, hasFocus, row, column) -> { + + Component result = table.getDefaultRenderer(Integer.class) + .getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (result instanceof JLabel) { + JLabel jLabel = (JLabel) result; + String decoratedValue = getDecorator(Integer.class, DecoratorService.NULL_INFINITE).toString(value); + jLabel.setText(decoratedValue); + jLabel.setHorizontalTextPosition(SwingConstants.RIGHT); + } + return result; + }; + + // sex cell listener to update the sex value of other rows with the same species + CellEditorListener sexEditorListener = new CellEditorListener() { + + @Override + public void editingStopped(ChangeEvent e) { + + int selectedRow = getUI().getCpsTable().getSelectedRow(); + + List<CalcifiedPiecesSamplingEditorRowModel> cpsRows = getModel().getCpsRows(); + CalcifiedPiecesSamplingEditorRowModel row = cpsRows.get(selectedRow); + + List<CalcifiedPiecesSamplingEditorRowModel> rowsToChangeSex = + cpsRows.stream().filter(r -> r.getSpecies().equals(row.getSpecies())).collect(Collectors.toList()); + + rowsToChangeSex.forEach(r -> r.setSex(row.isSex())); + + TreeSet<Integer> indexesToUpdate = + new TreeSet<>(rowsToChangeSex.stream().map(cpsRows::indexOf).collect(Collectors.toSet())); + + CalcifiedPiecesSamplingEditorTableModel tableModel = + (CalcifiedPiecesSamplingEditorTableModel) getUI().getCpsTable().getModel(); + tableModel.fireTableRowsUpdated(indexesToUpdate.first(), indexesToUpdate.last()); + } + + @Override + public void editingCanceled(ChangeEvent e) { + // do nothing + } + }; + + JXTable cpsTable = ui.getCpsTable(); + + DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); + + TableColumnExt speciesColumn = addColumnToModel(columnModel, + null, + newTableCellRender(Species.class), + CalcifiedPiecesSamplingEditorTableModel.SPECIES); + DecoratorService.SpeciesDecorator speciesDecorator = new DecoratorService.SpeciesDecorator(); + speciesColumn.putClientProperty(SpeciesAbleBatchRowHelper.SPECIES_DECORATOR, speciesDecorator); + speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); + + // renderer to display infinite instead of null + + addColumnToModel(columnModel, + null, + newTableCellRender(Boolean.class, DecoratorService.MATURITY), + CalcifiedPiecesSamplingEditorTableModel.MATURITY); + + TableCellEditor defaultBooleanEditor = cpsTable.getDefaultEditor(Boolean.class); + defaultBooleanEditor.addCellEditorListener(sexEditorListener); + addColumnToModel(columnModel, defaultBooleanEditor, + cpsTable.getDefaultRenderer(Boolean.class), + CalcifiedPiecesSamplingEditorTableModel.SEX); + + addIntegerColumnToModel(columnModel, CalcifiedPiecesSamplingEditorTableModel.MIN_SIZE, TuttiUI.INT_6_DIGITS_PATTERN, cpsTable); + + addColumnToModel(columnModel, null, infiniteRenderer, CalcifiedPiecesSamplingEditorTableModel.MAX_SIZE); + + addColumnToModel(columnModel, numberCellEditor, infiniteRenderer, CalcifiedPiecesSamplingEditorTableModel.MAX_BY_LENGHT_STEP); + + addIntegerColumnToModel(columnModel, CalcifiedPiecesSamplingEditorTableModel.SAMPLING_INTERVAL, TuttiUI.INT_6_DIGITS_PATTERN, cpsTable); + + addColumnToModel(columnModel, numberCellEditor, infiniteRenderer, CalcifiedPiecesSamplingEditorTableModel.OPERATION_LIMITATION); + + addColumnToModel(columnModel, numberCellEditor, infiniteRenderer, CalcifiedPiecesSamplingEditorTableModel.ZONE_LIMITATION); + + return columnModel; + } + @Override protected void beforeOpenPopup(int modelRowIndex, int modelColumnIndex) { super.beforeOpenPopup(modelRowIndex, modelColumnIndex); @@ -186,8 +241,11 @@ public class CalcifiedPiecesSamplingEditorUIHandler extends AbstractTuttiUIHandl boolean rowDeletable = rowSelected; if (rowSelected) { + CalcifiedPiecesSamplingEditorRowModel selectedRow = getModel().getCpsRows().get(modelRowIndex); + Integer minSize = selectedRow.getMinSize(); + splitEnabled = selectedRow.getMaxSize() == null || selectedRow.getMaxSize() - minSize > 1; rowDeletable = minSize > 0; @@ -215,4 +273,63 @@ public class CalcifiedPiecesSamplingEditorUIHandler extends AbstractTuttiUIHandl public SwingValidator<EditProtocolUIModel> getValidator() { return null; } + + + public CalcifiedPiecesSamplingEditorRowModel createNewRow(Species species, + Boolean maturity) { + + Optional<EditProtocolSpeciesRowModel> speciesProtocolRow = getModel().getSpeciesRow() + .stream() + .filter(sp -> species.equals(sp.getSpecies())) + .findFirst(); + + boolean sex = speciesProtocolRow.isPresent() + && speciesProtocolRow.get().containsMandatorySampleCategoryId(sexCaracteristic.getIdAsInt()); + + return createNewRow(species, maturity, sex, 0, null); + } + + public CalcifiedPiecesSamplingEditorRowModel createNewRow(Species species, + Boolean maturity, + boolean sex, + Integer minSize, + Integer maxSize) { + + JXTable cpsTable = getUI().getCpsTable(); + CalcifiedPiecesSamplingEditorTableModel tableModel = (CalcifiedPiecesSamplingEditorTableModel) cpsTable.getModel(); + List<CalcifiedPiecesSamplingEditorRowModel> cpsRows = getModel().getCpsRows(); + + CalcifiedPiecesSamplingEditorRowModel newRow = tableModel.createNewRow(species, maturity, sex, minSize, maxSize); + + 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); + } + }); + + return newRow; + } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/AddSpeciesAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/AddSpeciesAction.java index 57b0181..52e493c 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/AddSpeciesAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/AddSpeciesAction.java @@ -1,6 +1,7 @@ package fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.actions; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.CalcifiedPiecesSamplingEditorRowModel; import fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.CalcifiedPiecesSamplingEditorTableModel; import fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.CalcifiedPiecesSamplingEditorUI; @@ -18,6 +19,8 @@ import java.util.List; */ public class AddSpeciesAction extends SimpleActionSupport<CalcifiedPiecesSamplingEditorUI> { + protected final DecoratorService.SpeciesDecorator speciesDecorator = new DecoratorService.SpeciesDecorator(); + public AddSpeciesAction(CalcifiedPiecesSamplingEditorUI ui) { super(ui); } @@ -27,33 +30,32 @@ public class AddSpeciesAction extends SimpleActionSupport<CalcifiedPiecesSamplin BeanFilterableComboBox<Species> speciesComboBox = ui.getSpeciesComboBox(); Species species = (Species) speciesComboBox.getSelectedItem(); - CalcifiedPiecesSamplingEditorTableModel tableModel = (CalcifiedPiecesSamplingEditorTableModel) ui.getCpsTable().getModel(); - List<CalcifiedPiecesSamplingEditorRowModel> newRows = new ArrayList<>(); if (ui.getMaturityCheckBox().isSelected()) { - CalcifiedPiecesSamplingEditorRowModel newRow = tableModel.createNewRow(species, true, true); + CalcifiedPiecesSamplingEditorRowModel newRow = ui.getHandler().createNewRow(species, true); newRows.add(newRow); - newRow = tableModel.createNewRow(species, false, true); + newRow = ui.getHandler().createNewRow(species, false); newRows.add(newRow); } else { - CalcifiedPiecesSamplingEditorRowModel newRow = tableModel.createNewRow(species, null, true); + CalcifiedPiecesSamplingEditorRowModel newRow = ui.getHandler().createNewRow(species, null); newRows.add(newRow); } List<CalcifiedPiecesSamplingEditorRowModel> cpsRows = ui.getModel().getCpsRows(); cpsRows.addAll(newRows); - cpsRows.sort(Comparator.comparing(row -> row.getSpecies().toString())); + cpsRows.sort(Comparator.comparing(row -> speciesDecorator.toString(row.getSpecies()))); speciesComboBox.removeItem(species); int firstRowIndex = cpsRows.indexOf(newRows.get(0)); int lastRowIndex = cpsRows.indexOf(newRows.get(newRows.size() - 1)); + CalcifiedPiecesSamplingEditorTableModel tableModel = + (CalcifiedPiecesSamplingEditorTableModel) ui.getCpsTable().getModel(); tableModel.fireTableRowsInserted(firstRowIndex, lastRowIndex); - // select this new row SwingUtil.setSelectionInterval(ui.getCpsTable(), firstRowIndex); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/DeleteRowAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/DeleteRowAction.java index 2442005..b058b5e 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/DeleteRowAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/DeleteRowAction.java @@ -35,9 +35,6 @@ public class DeleteRowAction extends SimpleActionSupport<CalcifiedPiecesSampling CalcifiedPiecesSamplingEditorTableModel tableModel = (CalcifiedPiecesSamplingEditorTableModel) cpsTable.getModel(); int selectedRow = cpsTable.getSelectedRow(); - if (log.isInfoEnabled()) { - log.info("selected row " + selectedRow); - } List<CalcifiedPiecesSamplingEditorRowModel> cspRows = ui.getModel().getCpsRows(); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/DeleteSpeciesAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/DeleteSpeciesAction.java index 58a73aa..07911f1 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/DeleteSpeciesAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/DeleteSpeciesAction.java @@ -36,9 +36,6 @@ public class DeleteSpeciesAction extends SimpleActionSupport<CalcifiedPiecesSamp CalcifiedPiecesSamplingEditorTableModel tableModel = (CalcifiedPiecesSamplingEditorTableModel) cpsTable.getModel(); int selectedRow = cpsTable.getSelectedRow(); - if (log.isInfoEnabled()) { - log.info("selected row " + selectedRow); - } List<CalcifiedPiecesSamplingEditorRowModel> cspRows = ui.getModel().getCpsRows(); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/SplitSpeciesAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/SplitSpeciesAction.java index 1e2a7af..ba04fd6 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/SplitSpeciesAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/calcifiedpiecessampling/actions/SplitSpeciesAction.java @@ -1,5 +1,7 @@ package fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.actions; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.CalcifiedPiecesSamplingEditorRowModel; import fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.CalcifiedPiecesSamplingEditorTableModel; import fr.ifremer.tutti.ui.swing.content.protocol.calcifiedpiecessampling.CalcifiedPiecesSamplingEditorUI; @@ -31,14 +33,25 @@ public class SplitSpeciesAction extends SimpleActionSupport<CalcifiedPiecesSampl CalcifiedPiecesSamplingEditorTableModel tableModel = (CalcifiedPiecesSamplingEditorTableModel) cpsTable.getModel(); int selectedRow = cpsTable.getSelectedRow(); - if (log.isInfoEnabled()) { - log.info("selected row " + selectedRow); - } List<CalcifiedPiecesSamplingEditorRowModel> cpsRows = ui.getModel().getCpsRows(); CalcifiedPiecesSamplingEditorRowModel row = cpsRows.get(selectedRow); + if (log.isInfoEnabled()) { + Species speciesToDelete = row.getSpecies(); + String decoratedSpecies = ui.getHandler().getDecorator(Species.class, null).toString(speciesToDelete); + String decoratedRow = decoratedSpecies + " | "; + if (row.getMaturity() != null) { + decoratedRow += ui.getHandler().getDecorator(Boolean.class, DecoratorService.MATURITY).toString(row.getMaturity()) + " | "; + } + + decoratedRow += row.getMinSize() + " | " + + ui.getHandler().getDecorator(Integer.class, DecoratorService.NULL_INFINITE).toString(row.getMaxSize()); + log.info("selected row " + selectedRow + " " + decoratedRow); + log.info("rows : " + cpsRows); + } + int minMinSize = row.getMinSize() + 1; Integer maxMinSize = row.getMaxSize() != null ? row.getMaxSize() - 1 : null; @@ -51,31 +64,11 @@ public class SplitSpeciesAction extends SimpleActionSupport<CalcifiedPiecesSampl Integer exMaxSize = row.getMaxSize(); row.setMaxSize(minSize - 1); - CalcifiedPiecesSamplingEditorRowModel newRow = tableModel.createNewRow(row.getSpecies(), - row.getMaturity(), - row.isSex(), - minSize, - exMaxSize); - - 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(); - // si la nouvelle valeur sort de l'intervalle des deux lignes - if (newValue != null && (newValue <= previousRow.getMinSize() - || newRow.getMaxSize() != null && newValue >= newRow.getMaxSize())) { - newRow.setMinSize((Integer) evt.getOldValue()); - - } else { - previousRow.setMaxSize(newValue - 1); - tableModel.fireTableRowsUpdated(previousRowIndex, newRowIndex); - } - - }); - + CalcifiedPiecesSamplingEditorRowModel newRow = ui.getHandler().createNewRow(row.getSpecies(), + row.getMaturity(), + row.isSex(), + minSize, + exMaxSize); cpsRows.add(selectedRow + 1, newRow); tableModel.fireTableRowsUpdated(selectedRow, selectedRow); diff --git a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties index c3b2fa6..c9de0b2 100644 --- a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties +++ b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties @@ -725,6 +725,10 @@ tutti.editCatchBatch.legend.marineLitter= tutti.editCatchBatch.legend.species= tutti.editCatchBatch.legend.total= tutti.editCatchBatch.svgLoading.error= +tutti.editCps.changeSex.noSex= +tutti.editCps.changeSex.noSex.tip= +tutti.editCps.changeSex.sex= +tutti.editCps.changeSex.sex.tip= tutti.editCps.deleteRow= tutti.editCps.deleteRow.message= tutti.editCps.deleteRow.tip= -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.