This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 392701e464df81fd20ea0fad0cdb8fcd2ffd8f37 Author: Benjamin POUSSIN <poussin@codelutin.com> Date: Wed Jun 15 15:27:32 2016 +0200 fixes #8329 --- .../actions/ApplySpeciesFrequencyRafaleAction.java | 75 +++++++++++++++++++--- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/ApplySpeciesFrequencyRafaleAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/ApplySpeciesFrequencyRafaleAction.java index e4bfb39..ab68c61 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/ApplySpeciesFrequencyRafaleAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/ApplySpeciesFrequencyRafaleAction.java @@ -34,13 +34,14 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.Spe import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyUIModel; import fr.ifremer.tutti.ui.swing.util.SoundEngine; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.util.Date; +import javax.swing.SwingUtilities; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; -import javax.swing.SwingUtilities; -import java.util.Date; - import static org.nuiton.i18n.I18n.t; /** @@ -96,28 +97,50 @@ public class ApplySpeciesFrequencyRafaleAction { if (model.isAddIndividualObservationOnRafale()) { IndividualObservationBatchTableModel obsTableModel = (IndividualObservationBatchTableModel) ui.getObsTable().getModel(); + // need for https://forge.codelutin.com/issues/8329 + int oldHeight = ui.getObsTable().getHeight(); + if (log.isDebugEnabled()) { + log.debug(String.format( + "DEBUG before **** rowCount: %s oldHeight: %s", + obsTableModel.getRowCount(), oldHeight)); + } + IndividualObservationBatchRowModel obsRow = obsTableModel.addRafaleRow(step); newLogRow.setObsRow(obsRow); int rowIndex = obsTableModel.getRowIndex(obsRow); + SwingUtilities.invokeLater(() -> { + int newHeight = ui.getObsTable().getHeight(); - model.getIndividualObservationModel().getSamplingNotificationZoneModel().setValueAdjusting(true); + if (log.isDebugEnabled()) { + log.debug(String.format( + "DEBUG invokeLater **** rowCount: %s newHeight: %s", + obsTableModel.getRowCount(), newHeight)); + } - try { + // try to detect too early call (table not yet graphicaly modified) + // see https://forge.codelutin.com/issues/8329 + if (oldHeight != newHeight) { + model.getIndividualObservationModel().getSamplingNotificationZoneModel().setValueAdjusting(true); - selectRow(ui.getObsTable(), rowIndex); + try { - } finally { + selectRow(ui.getObsTable(), rowIndex); - model.getIndividualObservationModel().getSamplingNotificationZoneModel().setValueAdjusting(false); + } finally { - } + model.getIndividualObservationModel().getSamplingNotificationZoneModel().setValueAdjusting(false); + } + } else { + log.error("Scroll to added line is not possible, try to use fallback method"); + // fallback to early call, wait JComponent size change + selectRowWhenTableResized(ui.getObsTable(), rowIndex); + } }); - } if (fromIchtyometer) { @@ -135,6 +158,38 @@ public class ApplySpeciesFrequencyRafaleAction { table.setRowSelectionInterval(rowIndex, rowIndex); table.scrollRowToVisible(rowIndex); + + } + + protected void selectRowWhenTableResized(JXTable table, int rowIndex) { + table.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + log.error(String.format("DEBUG ### remove listener: ", this.getClass().getName())); + table.removeComponentListener(this); + ui.getModel().getIndividualObservationModel().getSamplingNotificationZoneModel().setValueAdjusting(true); + + try { + table.setRowSelectionInterval(rowIndex, rowIndex); + table.scrollRowToVisible(rowIndex); +// table.scrollRectToVisible(table.getCellRect(rowIndex, 0, true)); + table.removeComponentListener(this); + + int newHeight = ui.getObsTable().getHeight(); + log.error(String.format( + "DEBUG in selectRowWhenTableResized resized ****" + + " rowCount: %s" + + " newHeight: %s", + table.getRowCount(), + newHeight) + ); + + } finally { + ui.getModel().getIndividualObservationModel().getSamplingNotificationZoneModel().setValueAdjusting(false); + } + + } + }); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.