branch feature/8147 created (now f95e540)
This is an automated email from the git hooks/post-receive script. New change to branch feature/8147 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git at f95e540 ajout d'un veto quand on change d'écran + avertissement si on quitte l'ecran des observations (fixes #8147) This branch includes the following new commits: new f95e540 ajout d'un veto quand on change d'écran + avertissement si on quitte l'ecran des observations (fixes #8147) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit f95e54022d145cfeafff3991803f7eec602cfdf4 Author: Kevin Morin <morin@codelutin.com> Date: Fri Mar 18 17:44:22 2016 +0100 ajout d'un veto quand on change d'écran + avertissement si on quitte l'ecran des observations (fixes #8147) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/8147 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit f95e54022d145cfeafff3991803f7eec602cfdf4 Author: Kevin Morin <morin@codelutin.com> Date: Fri Mar 18 17:44:22 2016 +0100 ajout d'un veto quand on change d'écran + avertissement si on quitte l'ecran des observations (fixes #8147) --- .../fr/ifremer/tutti/ui/swing/TuttiUIContext.java | 24 +++++++-- .../tutti/ui/swing/content/MainUIHandler.java | 57 +++++++++++++--------- .../actions/AbstractChangeScreenAction.java | 9 +++- .../frequency/SpeciesFrequencyUIHandler.java | 35 +++++++++++++ .../actions/CancelEditSpeciesFrequencyAction.java | 30 +----------- .../tutti/ui/swing/util/TuttiExceptionHandler.java | 4 +- 6 files changed, 99 insertions(+), 60 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java index ca450fa..58bbab6 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java @@ -94,6 +94,7 @@ import javax.swing.JOptionPane; import java.awt.Color; import java.awt.Component; import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -627,6 +628,12 @@ public class TuttiUIContext extends AbstractBean implements Closeable, UIMessage actionUI.getModel().clear(); } setActionUI(null); + + } catch (PropertyVetoException e) { + if (log.isErrorEnabled()) { + log.error("cannot change screen", e); + } + } finally { closed = true; if (lock != null) { @@ -955,8 +962,9 @@ public class TuttiUIContext extends AbstractBean implements Closeable, UIMessage return screen; } - public void setScreen(TuttiScreen screen) { + public void setScreen(TuttiScreen screen) throws PropertyVetoException { Object oldValue = getScreen(); + fireVetoableChange(PROPERTY_SCREEN, oldValue, screen); this.screen = screen; firePropertyChange(PROPERTY_SCREEN, oldValue, screen); } @@ -1141,10 +1149,16 @@ public class TuttiUIContext extends AbstractBean implements Closeable, UIMessage } public void setFallBackScreen() { - if (isDbLoaded()) { - setScreen(TuttiScreen.SELECT_CRUISE); - } else { - setScreen(TuttiScreen.MANAGE_DB); + try { + if (isDbLoaded()) { + setScreen(TuttiScreen.SELECT_CRUISE); + } else { + setScreen(TuttiScreen.MANAGE_DB); + } + } catch (PropertyVetoException e) { + if (log.isErrorEnabled()) { + log.error("cannot change screen", e); + } } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java index 04cc2ac..ad2f818 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java @@ -68,6 +68,7 @@ import java.awt.Cursor; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListenerProxy; +import java.beans.PropertyVetoException; import java.util.Locale; import static org.nuiton.i18n.I18n.t; @@ -211,37 +212,45 @@ public class MainUIHandler extends AbstractTuttiUIHandler<TuttiUIContext, MainUI TuttiUIContext context = getContext(); // remove any screen - context.setScreen(null); - context.removeMessageNotifier(this); - - // clean context - - PropertyChangeListener[] propertyChangeListeners = - context.getPropertyChangeListeners(); - for (PropertyChangeListener listener : propertyChangeListeners) { - if (listener instanceof PropertyChangeListenerProxy) { - PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) listener; - listener = proxy.getListener(); - } - if (listener instanceof RemoveablePropertyChangeListener) { - if (log.isDebugEnabled()) { - log.debug("Remove listener: " + listener); + try { + context.setScreen(null); + context.removeMessageNotifier(this); + + // clean context + + PropertyChangeListener[] propertyChangeListeners = + context.getPropertyChangeListeners(); + for (PropertyChangeListener listener : propertyChangeListeners) { + if (listener instanceof PropertyChangeListenerProxy) { + PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) listener; + listener = proxy.getListener(); + } + if (listener instanceof RemoveablePropertyChangeListener) { + if (log.isDebugEnabled()) { + log.debug("Remove listener: " + listener); + } + context.removePropertyChangeListener(listener); } - context.removePropertyChangeListener(listener); } - } - if (ui != null) { + if (ui != null) { - // clean ui + // clean ui - JAXXBinding[] bindings = ui.getDataBindings(); - for (JAXXBinding binding : bindings) { - SwingUtil.removeDataBinding(ui, binding.getId()); + JAXXBinding[] bindings = ui.getDataBindings(); + for (JAXXBinding binding : bindings) { + SwingUtil.removeDataBinding(ui, binding.getId()); + } + ui.setVisible(false); + ui.dispose(); + } + + } catch (PropertyVetoException e) { + if (log.isErrorEnabled()) { + log.error("cannot change screen", e); } - ui.setVisible(false); - ui.dispose(); } + } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/actions/AbstractChangeScreenAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/actions/AbstractChangeScreenAction.java index d4abeb7..15e0c21 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/actions/AbstractChangeScreenAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/actions/AbstractChangeScreenAction.java @@ -28,6 +28,10 @@ import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.MainUIHandler; import jaxx.runtime.SwingUtil; import jaxx.runtime.context.JAXXContextEntryDef; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.beans.PropertyVetoException; import static org.nuiton.i18n.I18n.t; @@ -43,6 +47,9 @@ import static org.nuiton.i18n.I18n.t; */ public abstract class AbstractChangeScreenAction extends AbstractMainUITuttiAction { + /** Logger. */ + private static final Log log = LogFactory.getLog(AbstractChangeScreenAction.class); + /** * Context entry to keep previous screen. * @@ -110,7 +117,7 @@ public abstract class AbstractChangeScreenAction extends AbstractMainUITuttiActi @Override public void postFailedAction(Throwable error) { - if (error != null) { + if (error != null && !(error instanceof PropertyVetoException)) { getContext().setFallBackScreen(); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java index e6f3a80..69f7b24 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java @@ -93,6 +93,7 @@ import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.nuiton.decorator.Decorator; import org.nuiton.jaxx.application.ApplicationBusinessException; +import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; import javax.swing.JComponent; import javax.swing.JFrame; @@ -116,6 +117,7 @@ import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; @@ -177,6 +179,8 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci protected PropertyChangeListener obsChangedListener; + protected VetoableChangeListener changeScreenListener; + protected Optional<CaracteristicColumnIdentifier> maturityColumnId = Optional.empty(); // Flag to mark when preparing the batch edition @@ -360,6 +364,14 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci }; + this.changeScreenListener = evt -> { + if (getModel().isModify()) { + if (!SpeciesFrequencyUIHandler.this.askCancelEditBeforeLeaving()) { + throw new PropertyVetoException("The user does not want to quit the screen.", evt); + } + } + }; + } //------------------------------------------------------------------------// @@ -823,6 +835,8 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci if (getDataContext().isCruiseSamplingCacheLoaded()) { getDataContext().getCruiseSamplingCache().removeSamplingListener(samplingListener); } + + getContext().removeVetoableChangeListener(TuttiUIContext.PROPERTY_SCREEN, changeScreenListener); } public void editBatch(FrequencyCellEditor editor, Optional<String> optionalTitle) { @@ -1117,11 +1131,32 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci model.setModify(false); + getContext().addVetoableChangeListener(TuttiUIContext.PROPERTY_SCREEN, changeScreenListener); + } finally { initBatchEdition = false; } } + public boolean askCancelEditBeforeLeaving() { + // Ask confirmation to quit screen + String htmlMessage = String.format(AbstractApplicationUIHandler.CONFIRMATION_FORMAT, + t("tutti.askToCancelEditFrequencies.message"), + t("tutti.askToCancelEditFrequencies.help")); + + int saveResponse = JOptionPane.showOptionDialog( + getTopestUI(), + htmlMessage, + t("tutti.askToCancelEditFrequencies.title"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + new String[]{t("tutti.option.continue"), t("tutti.option.cancel")}, + t("tutti.option.cancel")); + + return saveResponse == 0; + } + //TODO maturity public void incrementSampling(CaracteristicQualitativeValue gender, Boolean maturity, float lengthStep) { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/CancelEditSpeciesFrequencyAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/CancelEditSpeciesFrequencyAction.java index 7f97f8d..01806a5 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/CancelEditSpeciesFrequencyAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/CancelEditSpeciesFrequencyAction.java @@ -30,11 +30,6 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.Spe import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; - -import javax.swing.JOptionPane; - -import static org.nuiton.i18n.I18n.t; /** * Created on 1/1/15. @@ -59,30 +54,7 @@ public class CancelEditSpeciesFrequencyAction extends LongActionSupport<SpeciesF if (doAction && getModel().isModify()) { // Ask confirmation to quit screen - doAction = false; - - String htmlMessage = String.format(AbstractApplicationUIHandler.CONFIRMATION_FORMAT, - t("tutti.askToCancelEditFrequencies.message"), - t("tutti.askToCancelEditFrequencies.help")); - - int saveResponse = JOptionPane.showOptionDialog( - getHandler().getTopestUI(), - htmlMessage, - t("tutti.askToCancelEditFrequencies.title"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, - null, - new String[]{t("tutti.option.continue"), t("tutti.option.cancel")}, - t("tutti.option.cancel")); - - switch (saveResponse) { - case 0: - - // confirm - doAction = true; - break; - - } + doAction = getHandler().askCancelEditBeforeLeaving(); } return doAction; diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiExceptionHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiExceptionHandler.java index 1e0968d..72029ec 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiExceptionHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiExceptionHandler.java @@ -31,6 +31,8 @@ import org.nuiton.jaxx.application.swing.action.ApplicationActionException; import org.nuiton.jaxx.application.swing.util.ApplicationErrorHelper; import org.nuiton.jaxx.application.swing.util.ApplicationExceptionHandler; +import java.beans.PropertyVetoException; + /** * Tutti global exception handler. * @@ -53,7 +55,7 @@ public class TuttiExceptionHandler extends ApplicationExceptionHandler { @Override public void uncaughtException(Thread t, Throwable ex) { - if (t.getName().startsWith("AWT-EventQueue-")) { + if (t.getName().startsWith("AWT-EventQueue-") || ex.getCause() instanceof PropertyVetoException) { // Swallow some ui execption we can't deal with // See https://forge.codelutin.com/issues/7489 -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm