Commit 1ab2ade2 authored by PECQUOT's avatar PECQUOT

[enh] Upgrade quadrige3-core to version 3.6.13

[fix] Rework the calculation of individual ids on grouped measurements, now use table sorting if possible (Mantis #51520)
Signed-off-by: PECQUOT's avatarlp1ee9d <ludovic.pecquot@e-is.pro>
parent a4f3127e
......@@ -171,7 +171,7 @@
<maven.compiler.debug>true</maven.compiler.debug>
<!-- Quadrige3 Core version -->
<quadrige3-core.version>3.6.11</quadrige3-core.version>
<quadrige3-core.version>3.6.13</quadrige3-core.version>
<!-- Last ReefDb launcher version -->
<launcherVersion>3.0.3</launcherVersion>
......
......@@ -252,7 +252,7 @@ public class OperationsTableUIHandler extends AbstractReefDbTableUIHandler<Opera
}
// save actual table context before loading new survey
getContext().saveComponentInSwingSession(getTable(), getTableModel().getStateContext());
saveTableState();
// affect new selected survey
getModel().setSurvey(survey);
......@@ -739,7 +739,7 @@ public class OperationsTableUIHandler extends AbstractReefDbTableUIHandler<Opera
forceRevalidateModel();
// restore table state from swing session
getContext().restoreComponentFromSwingSession(getTable());
restoreTableState();
// hide analyst column if no pmfm (Mantis #42619)
// forceColumnVisibleAtLastPosition(OperationsTableModel.ANALYST, notEmpty);
......
......@@ -151,7 +151,7 @@ public class OperationMeasurementsGroupedTableUIHandler
getUI().processDataBinding(OperationMeasurementsGroupedTableUI.BINDING_INIT_DATA_GRID_BUTTON_ENABLED);
break;
// TODO ? force sort on sampling operation and transition column
// TODO ? force sort on sampling operation and transition column
// case OperationMeasurementsGroupedTableUIModel.PROPERTY_PIT_TRANSITION_LENGTH_PMFM_ID:
//
// // Try to apply sort on sampling operation and transition column
......@@ -201,11 +201,10 @@ public class OperationMeasurementsGroupedTableUIHandler
@Override
protected List<? extends MeasurementAware> getMeasurementAwareModels() {
List<SamplingOperationDTO> samplingOperations = Lists.newArrayList(getModel().getSamplingOperations());
// sort by name
samplingOperations.sort(Comparator.comparing(SamplingOperationDTO::getName));
return samplingOperations;
return getModel().getSamplingOperations().stream()
// sort by name
.sorted(Comparator.comparing(SamplingOperationDTO::getName))
.collect(Collectors.toList());
}
@Override
......@@ -221,12 +220,13 @@ public class OperationMeasurementsGroupedTableUIHandler
@Override
protected void onRowModified(int rowIndex, OperationMeasurementsGroupedRowModel row, String propertyName, Integer propertyIndex, Object oldValue, Object newValue) {
// update individual id when sampling operation changes
// when sampling operation changes
if (OperationMeasurementsGroupedRowModel.PROPERTY_SAMPLING_OPERATION.equals(propertyName)) {
// remove measurement from old sampling
if (oldValue != null) {
SamplingOperationDTO oldSamplingOperation = (SamplingOperationDTO) oldValue;
// fixme: il rest edes mesures dans le operation !!!!!!!!!!!!!!
oldSamplingOperation.removeAllIndividualMeasurements(row.getIndividualMeasurements());
oldSamplingOperation.setDirty(true);
......
......@@ -170,7 +170,7 @@ public class OperationMeasurementsUngroupedTableUIHandler extends AbstractReefDb
filterSamplingOperations();
// restore table from swing session
getContext().restoreComponentFromSwingSession(getTable());
restoreTableState();
// hide analyst if no pmfm
// forceColumnVisibleAtLastPosition(OperationMeasurementsUngroupedTableModel.ANALYST, notEmpty);
......
......@@ -30,6 +30,7 @@ import com.google.common.collect.Maps;
import fr.ifremer.quadrige3.core.dao.technical.Assert;
import fr.ifremer.quadrige3.core.dao.technical.factorization.pmfm.AllowedQualitativeValuesMap;
import fr.ifremer.quadrige3.ui.core.dto.DirtyAware;
import fr.ifremer.quadrige3.ui.swing.table.SwingTable;
import fr.ifremer.quadrige3.ui.swing.table.editor.ExtendedComboBoxCellEditor;
import fr.ifremer.reefdb.decorator.DecoratorService;
import fr.ifremer.reefdb.dto.ErrorDTO;
......@@ -50,6 +51,7 @@ import fr.ifremer.reefdb.dto.referential.TaxonGroupDTO;
import fr.ifremer.reefdb.dto.referential.pmfm.PmfmDTO;
import fr.ifremer.reefdb.dto.referential.pmfm.QualitativeValueDTO;
import fr.ifremer.reefdb.ui.swing.content.observation.operation.measurement.grouped.OperationMeasurementsGroupedRowModel;
import fr.ifremer.reefdb.ui.swing.util.OneShotListener;
import fr.ifremer.reefdb.ui.swing.util.ReefDbUI;
import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableUIHandler;
import fr.ifremer.reefdb.ui.swing.util.table.PmfmTableColumn;
......@@ -95,6 +97,14 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
super(properties);
}
@Override
protected String[] getRowPropertiesToIgnore() {
return new String[]{
AbstractMeasurementsGroupedRowModel.PROPERTY_INPUT_TAXON_ID,
AbstractMeasurementsGroupedRowModel.PROPERTY_INPUT_TAXON_NAME
};
}
@Override
public void beforeInit(UI ui) {
super.beforeInit(ui);
......@@ -288,7 +298,7 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
filterMeasurements();
// restore table from swing session
getContext().restoreComponentFromSwingSession(getTable());
restoreTableState();
// hide analyst if no pmfm
// forceColumnVisibleAtLastPosition(AbstractMeasurementsGroupedTableModel.ANALYST, notEmpty);
......@@ -315,8 +325,6 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
for (MeasurementAware bean : measurementAwareBeans) {
List<MeasurementDTO> measurements = bean.getIndividualMeasurements().stream()
// Filter measurement to exclude negative ids (not saved from previous save action) (see Mantis #51520)
.filter(measurement -> measurement.getId() != null && measurement.getId() > 0)
// sort by individual id
.sorted(Comparator.comparingInt(MeasurementDTO::getIndividualId))
.collect(Collectors.toList());
......@@ -444,8 +452,12 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
// set default analyst from pmfm strategies (Mantis #42619)
setDefaultAnalyst(newRow);
// now calculate individual id
calculateIndividualIds(newRow);
// now calculate individual id after table is sorted
if (getTable().getRowSorter().getSortKeys().isEmpty()) {
calculateIndividualIds(newRow);
} else {
OneShotListener.create(getTable(), SwingTable.PROPERTY_SORTED, propertyChangeEvent -> calculateIndividualIds(newRow));
}
// reset the cell editors
resetCellEditors();
......@@ -481,25 +493,26 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
protected void calculateIndividualIds(R rowToUpdate) {
MeasurementAware bean = getMeasurementAwareModelForRow(rowToUpdate);
calculateIndividualIds(getMeasurementAwareModelForRow(rowToUpdate));
}
protected void calculateIndividualIds(MeasurementAware bean) {
if (bean == null) return;
// Don't "push" all individual ids, use only the next unused number (see Mantis #51520)
Predicate<? super R> predicate = getRowForBeanPredicate(bean);
AtomicInteger individualId = new AtomicInteger();
incrementNextIndividualId(bean, individualId);
rowToUpdate.setIndividualId(individualId.get());
rowToUpdate.getIndividualMeasurements().forEach(measurement -> measurement.setIndividualId(individualId.get()));
// iterate over all ordered rows and set incremental individualId
// getModel().getRows().stream().filter(getRowForBeanPredicate(bean)).forEach(row -> {
// row.setIndividualId(individualId.incrementAndGet());
// // update all individual measurements
// if (CollectionUtils.isNotEmpty(row.getIndividualMeasurements())) {
// for (MeasurementDTO individualMeasurement : row.getIndividualMeasurements()) {
// individualMeasurement.setIndividualId(individualId.get());
// }
// }
// });
// iterate over sorted rows and set incremental individualId (see Mantis #51520)
for (int i = 0; i < getTable().getRowCount(); i++) {
R row = getTableModel().getEntry(getTable().convertRowIndexToModel(i));
if (predicate.test(row)) {
// increment and set row individual id
row.setIndividualId(individualId.incrementAndGet());
// update all individual measurements
row.getIndividualMeasurements().forEach(measurement -> measurement.setIndividualId(individualId.get()));
}
}
setDirty(bean);
}
......@@ -507,7 +520,7 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
/**
* Increment the nextIndividualId to next unused individual id in rows
*
* @param bean the current bean
* @param bean the current bean
* @param nextIndividualId the counter to increment
*/
protected void incrementNextIndividualId(MeasurementAware bean, AtomicInteger nextIndividualId) {
......@@ -677,12 +690,20 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
if (askBeforeDelete(t("reefdb.action.delete.survey.measurement.titre"), t("reefdb.action.delete.survey.measurement.message"))) {
// Get distinct models to update after rows removed
Collection<MeasurementAware> modelsToUpdate = getModel().getSelectedRows().stream()
.map(this::getMeasurementAwareModelForRow)
.collect(Collectors.toSet());
// Remove from table
getModel().deleteSelectedRows();
// Remove from model
removeIndividualMeasurements(measurementToDelete);
// Recalculate individual ids
modelsToUpdate.forEach(this::calculateIndividualIds);
recomputeRowsValidState();
}
......@@ -1193,7 +1214,7 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
*/
protected void editSelectedMeasurements(JDialog dialog) {
// save current table state to be able to restore it in dialog's table
saveTableInSwingSession();
saveTableState();
Assert.isInstanceOf(ReefDbUI.class, dialog);
ReefDbUI<?, ?> multiEditUI = (ReefDbUI<?, ?>) dialog;
......
......@@ -172,7 +172,7 @@ public class SurveyMeasurementsUngroupedTableUIHandler
recomputeRowsValidState();
// restore table from swing session
getContext().restoreComponentFromSwingSession(getTable());
restoreTableState();
// hide analyst if no pmfm
// forceColumnVisibleAtLastPosition(SurveyMeasurementsUngroupedTableModel.ANALYST, notEmpty);
......
package fr.ifremer.reefdb.ui.swing.util;
import javax.annotation.Nonnull;
import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.function.Consumer;
/**
* a PropertyChangeListener that auto remove after fired
*
* @author peck7 on 20/03/2020.
*/
public class OneShotListener implements PropertyChangeListener {
private final Component parent;
private final String propertyName;
private final Consumer<PropertyChangeEvent> consumer;
/**
* Create and add to parent object
*
* @param parent the component on which this listener will be added
* @param propertyName the property to listen to
* @param consumer the consumer function
*/
public static void create(@Nonnull Component parent, @Nonnull String propertyName, @Nonnull Consumer<PropertyChangeEvent> consumer) {
OneShotListener listener = new OneShotListener(parent, propertyName, consumer);
parent.addPropertyChangeListener(propertyName, listener);
}
private OneShotListener(Component parent, String propertyName, Consumer<PropertyChangeEvent> consumer) {
this.parent = parent;
this.propertyName = propertyName;
this.consumer = consumer;
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
consumer.accept(evt);
parent.removePropertyChangeListener(propertyName, this);
}
}
......@@ -33,7 +33,10 @@
<release version="3.9.7" date="2020-03-19" description="Stable release">
<action dev="ludovic.pecquot@e-is.pro" type="fix" issue="51520">
Filter individual measurements when building rows to exclude measurements with negative id
Rework the calculation of individual ids on grouped measurements, now use table sorting if possible
</action>
<action dev="ludovic.pecquot@e-is.pro" type="add">
Upgrade quadrige3-core to version 3.6.13
</action>
</release>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment