This is an automated email from the git hooks/post-receive script. New commit to branch feature/21 in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit 6f4d06e02896a1b3377e7a2762f4050cada4156b Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Dec 21 18:11:59 2016 +0100 Lorsqu'on traverse un champ date, le formulaire est modifié (Closes #21) --- .../swing/ui/content/ContentUIInitializer.java | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIInitializer.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIInitializer.java index b135e5e..2158706 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIInitializer.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIInitializer.java @@ -97,6 +97,7 @@ import java.awt.event.ItemEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -474,15 +475,22 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> addAutoSelectOnFocus((JSpinner.DateEditor) editor.getMinuteEditor().getEditor()); addAutoSelectOnFocus(editor.getDayDateEditor().getEditor()); editor.getDayDateEditor().getEditor().addFocusListener(new FocusAdapter() { + + private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + @Override public void focusLost(FocusEvent e) { JFormattedTextField source = (JFormattedTextField) e.getSource(); if (source.isEditValid()) { try { - editor.getDayDateEditor().commitEdit(); - if (log.isInfoEnabled()) { - log.info("quit date editor, commit value: " + source.getValue()); + Date newDate = simpleDateFormat.parse(editor.getDayDateEditor().getEditor().getText()); + Object oldValue = JavaBeanObjectUtil.getProperty(editor.getModel().getBean(), editor.getModel().getPropertyDayDate()); + if (!Objects.equals(oldValue, newDate)) { + editor.getDayDateEditor().commitEdit(); + if (log.isInfoEnabled()) { + log.info("quit date editor, commit value: " + source.getValue()); + } } } catch (ParseException e1) { // l'édition est valide donc pas de problème ici @@ -521,6 +529,12 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> public void keyReleased(KeyEvent e) { JTextField source = (JTextField) e.getSource(); String text = source.getText(); + text = text.isEmpty() ? null : text; + if (text == null && JavaBeanObjectUtil.getProperty(getBean(), propertyName) == null) { + // On n'envoie pas la demande, car cela va modifier ensuite le formulaire + // car avec oldValue=null et newValue=null, les pcs sont déclanchés... + return; + } JavaBeanObjectUtil.setProperty(getBean(), propertyName, text); } }); @@ -607,6 +621,11 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> picker.addActionListener(e -> { JXDatePicker source = (JXDatePicker) e.getSource(); Date date = source.getDate(); + if (Objects.equals(date, JavaBeanObjectUtil.getProperty(getBean(), propertyName))) { + // On n'envoie pas la demande, car cela va modifier ensuite le formulaire + // car avec oldValue=null et newValue=null, les pcs sont déclanchés... + return; + } JavaBeanObjectUtil.setProperty(getBean(), propertyName, date); }); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.