Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 585e7e3c by Tony Chemit at 2024-08-30T13:13:46+02:00 Make sure form is never modified on opening in updating mode - See #2928 - - - - - 338b09b9 by Tony Chemit at 2024-08-30T13:13:46+02:00 Never alter modified state when changing format (this code is actually not working, but will soon...) - See #2928 - - - - - fb1673ec by Tony Chemit at 2024-08-30T13:14:02+02:00 Le changement de format des éditeurs de température ou de longueur altère l'état «modifié» du formulaire - Closes #2927 - - - - - 7e46fe94 by Tony Chemit at 2024-08-30T13:14:02+02:00 Add TemperatureEditorState state - - - - - f6dc862f by Tony Chemit at 2024-08-30T13:14:02+02:00 Add NauticalLengthEditorState state - - - - - b0b52a85 by Tony Chemit at 2024-08-30T13:14:02+02:00 Add CoordinatesEditorState state - - - - - bd320372 by Tony Chemit at 2024-08-30T13:14:02+02:00 use new states in ObserveSwingSession - - - - - df95fe00 by Tony Chemit at 2024-08-30T13:14:10+02:00 Merge branch 'feature/issue-2901' into develop Permettre à l’utilisateur de sauvegarder les unités choisies (longueur, température et coordonnées) - Closes #2901 - - - - - 8 changed files: - + client/configuration/src/main/java/fr/ird/observe/client/CoordinatesEditorState.java - + client/configuration/src/main/java/fr/ird/observe/client/NauticalLengthEditorState.java - client/configuration/src/main/java/fr/ird/observe/client/ObserveSwingSession.java - + client/configuration/src/main/java/fr/ird/observe/client/TemperatureEditorState.java - client/core/src/main/java/fr/ird/observe/client/util/init/UIInitHelper.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/ContentUIHandler.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/ContentUIInitializer.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/open/ContentOpen.java Changes: ===================================== client/configuration/src/main/java/fr/ird/observe/client/CoordinatesEditorState.java ===================================== @@ -0,0 +1,83 @@ +package fr.ird.observe.client; + +/*- + * #%L + * ObServe Client :: Configuration + * %% + * Copyright (C) 2008 - 2024 IRD, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.nuiton.jaxx.runtime.swing.session.State; +import org.nuiton.jaxx.widgets.gis.CoordinateFormat; +import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor; + +/** + * All states to persist on a {@link CoordinatesEditor}. + * <p> + * Created at 30/08/2024. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 9.3.7 + * <p> + * FIXME Move this back to JAXX + */ +public class CoordinatesEditorState implements State { + + protected CoordinateFormat format; + + public CoordinatesEditorState() { + } + + public CoordinatesEditorState(CoordinateFormat format) { + this.format = format; + } + + public CoordinateFormat getFormat() { + return format; + } + + public void setFormat(CoordinateFormat format) { + this.format = format; + } + + protected CoordinatesEditor checkComponent(Object o) { + if (o == null) { + throw new IllegalArgumentException("null component"); + } + if (!(o instanceof CoordinatesEditor)) { + throw new IllegalArgumentException("invalid component"); + } + return (CoordinatesEditor) o; + } + + @Override + public State getState(Object o) { + CoordinatesEditor ui = checkComponent(o); + return new CoordinatesEditorState(ui.getModel().getFormat()); + } + + @Override + public void setState(Object o, State state) { + if (!(state instanceof CoordinatesEditorState)) { + throw new IllegalArgumentException("invalid state"); + } + CoordinatesEditor ui = checkComponent(o); + CoordinatesEditorState typedState = (CoordinatesEditorState) state; + ui.getModel().setFormat(typedState.getFormat()); + } +} ===================================== client/configuration/src/main/java/fr/ird/observe/client/NauticalLengthEditorState.java ===================================== @@ -0,0 +1,83 @@ +package fr.ird.observe.client; + +/*- + * #%L + * ObServe Client :: Configuration + * %% + * Copyright (C) 2008 - 2024 IRD, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthEditor; +import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthFormat; +import org.nuiton.jaxx.runtime.swing.session.State; + +/** + * All states to persist on a {@link NauticalLengthEditor}. + * <p> + * Created at 30/08/2024. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 9.3.7 + * <p> + * FIXME Move this back to JAXX + */ +public class NauticalLengthEditorState implements State { + + protected NauticalLengthFormat format; + + public NauticalLengthEditorState() { + } + + public NauticalLengthEditorState(NauticalLengthFormat format) { + this.format = format; + } + + public NauticalLengthFormat getFormat() { + return format; + } + + public void setFormat(NauticalLengthFormat format) { + this.format = format; + } + + protected NauticalLengthEditor checkComponent(Object o) { + if (o == null) { + throw new IllegalArgumentException("null component"); + } + if (!(o instanceof NauticalLengthEditor)) { + throw new IllegalArgumentException("invalid component"); + } + return (NauticalLengthEditor) o; + } + + @Override + public State getState(Object o) { + NauticalLengthEditor ui = checkComponent(o); + return new NauticalLengthEditorState(ui.getModel().getFormat()); + } + + @Override + public void setState(Object o, State state) { + if (!(state instanceof NauticalLengthEditorState)) { + throw new IllegalArgumentException("invalid state"); + } + NauticalLengthEditor ui = checkComponent(o); + NauticalLengthEditorState typedState = (NauticalLengthEditorState) state; + ui.getModel().setFormat(typedState.getFormat()); + } +} ===================================== client/configuration/src/main/java/fr/ird/observe/client/ObserveSwingSession.java ===================================== @@ -23,12 +23,15 @@ package fr.ird.observe.client; */ import io.ultreia.java4all.jaxx.widgets.combobox.FilterableComboBox; +import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthEditor; import io.ultreia.java4all.jaxx.widgets.list.DoubleList; import io.ultreia.java4all.jaxx.widgets.list.ListHeader; import io.ultreia.java4all.jaxx.widgets.list.session.DoubleListState; import io.ultreia.java4all.util.SortedProperties; import org.nuiton.jaxx.runtime.swing.session.State; import org.nuiton.jaxx.runtime.swing.session.SwingSession; +import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor; +import org.nuiton.jaxx.widgets.temperature.TemperatureEditor; import java.io.BufferedReader; import java.io.File; @@ -54,7 +57,10 @@ public class ObserveSwingSession extends SwingSession { public ObserveSwingSession(File file, boolean autoSave, File preferencesFile) { super(file, autoSave, Map.of(FilterableComboBox.class, new FilterableComboBoxState(), DoubleList.class, new DoubleListState(), - ListHeader.class, new ListHeaderState() + ListHeader.class, new ListHeaderState(), + TemperatureEditor.class, new TemperatureEditorState(), + NauticalLengthEditor.class, new NauticalLengthEditorState(), + CoordinatesEditor.class, new CoordinatesEditorState() )); this.preferencesFile = preferencesFile; this.preferences = new SortedProperties(); ===================================== client/configuration/src/main/java/fr/ird/observe/client/TemperatureEditorState.java ===================================== @@ -0,0 +1,83 @@ +package fr.ird.observe.client; + +/*- + * #%L + * ObServe Client :: Configuration + * %% + * Copyright (C) 2008 - 2024 IRD, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.nuiton.jaxx.runtime.swing.session.State; +import org.nuiton.jaxx.widgets.temperature.TemperatureEditor; +import org.nuiton.jaxx.widgets.temperature.TemperatureFormat; + +/** + * All states to persist on a {@link TemperatureEditor}. + * <p> + * Created at 30/08/2024. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 9.3.7 + * <p> + * FIXME Move this back to JAXX + */ +public class TemperatureEditorState implements State { + + protected TemperatureFormat format; + + public TemperatureEditorState() { + } + + public TemperatureEditorState(TemperatureFormat format) { + this.format = format; + } + + public TemperatureFormat getFormat() { + return format; + } + + public void setFormat(TemperatureFormat format) { + this.format = format; + } + + protected TemperatureEditor checkComponent(Object o) { + if (o == null) { + throw new IllegalArgumentException("null component"); + } + if (!(o instanceof TemperatureEditor)) { + throw new IllegalArgumentException("invalid component"); + } + return (TemperatureEditor) o; + } + + @Override + public State getState(Object o) { + TemperatureEditor ui = checkComponent(o); + return new TemperatureEditorState(ui.getModel().getFormat()); + } + + @Override + public void setState(Object o, State state) { + if (!(state instanceof TemperatureEditorState)) { + throw new IllegalArgumentException("invalid state"); + } + TemperatureEditor ui = checkComponent(o); + TemperatureEditorState typedState = (TemperatureEditorState) state; + ui.getModel().setFormat(typedState.getFormat()); + } +} ===================================== client/core/src/main/java/fr/ird/observe/client/util/init/UIInitHelper.java ===================================== @@ -23,13 +23,11 @@ package fr.ird.observe.client.util.init; */ import fr.ird.observe.client.datasource.validation.ContentMessageTableRenderer; -import fr.ird.observe.client.datasource.validation.ObserveSwingValidator; import fr.ird.observe.client.datasource.validation.ObserveValidatorMessageMouseListener; import io.ultreia.java4all.jaxx.widgets.combobox.BeanEnumEditor; import io.ultreia.java4all.jaxx.widgets.combobox.FilterableComboBox; import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthEditor; import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthEditorConfig; -import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthEditorModel; import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthFormat; import io.ultreia.java4all.jaxx.widgets.list.DoubleList; import io.ultreia.java4all.jaxx.widgets.list.ListHeader; @@ -197,7 +195,7 @@ public class UIInitHelper { editor.init(); } - public static void init(JAXXObject ui, ObserveSwingValidator<?> validator, TemperatureEditor editor, boolean autoPopupNumberEditor, boolean showPopupButton, TemperatureFormat defaultFormat) { + public static void init(JAXXObject ui, TemperatureEditor editor, boolean autoPopupNumberEditor, boolean showPopupButton, TemperatureFormat defaultFormat) { NumberEditor numberEditor = editor.getEditor(); numberEditor.setShowReset(true); numberEditor.setAutoPopup(autoPopupNumberEditor); @@ -207,14 +205,9 @@ public class UIInitHelper { Objects.requireNonNull(label, "can't find label for temperature editor " + editor); editor.setConfig(new TemperatureEditorConfig(defaultFormat, label.getText(), propertyName)); editor.init(label); - editor.getModel().addPropertyChangeListener("format", e -> { - if (validator.getBean() != null) { - validator.doValidate(); - } - }); } - public static void init(JAXXObject ui, ObserveSwingValidator<?> validator, NauticalLengthEditor editor, boolean autoPopupNumberEditor, boolean showPopupButton,NauticalLengthFormat defaultFormat) { + public static void init(JAXXObject ui, NauticalLengthEditor editor, boolean autoPopupNumberEditor, boolean showPopupButton, NauticalLengthFormat defaultFormat) { NumberEditor numberEditor = editor.getEditor(); numberEditor.setShowReset(true); numberEditor.setAutoPopup(autoPopupNumberEditor); @@ -224,11 +217,7 @@ public class UIInitHelper { Objects.requireNonNull(label, "can't find label for nautical length editor " + editor); editor.setConfig(new NauticalLengthEditorConfig(defaultFormat, label.getText(), propertyName)); editor.init(label); - editor.getModel().addPropertyChangeListener(NauticalLengthEditorModel.PROPERTY_FORMAT, e -> { - if (validator.getBean() != null) { - validator.doValidate(); - } - }); + } public static void init(NumberEditor editor, boolean autoPopupNumberEditor, boolean showPopupButton) { ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/ContentUIHandler.java ===================================== @@ -257,6 +257,11 @@ public abstract class ContentUIHandler<U extends ContentUI> implements ObserveSe } public void onEndOpenUI() { + //FIXME We should remove this code when issue #2928 is fixed + ContentUIModelStates states = ui.getModel().getStates(); + if (!states.isReadingMode()) { + states.setModified(states.isCreatingMode()); + } } public void startEditUI() { ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/ContentUIInitializer.java ===================================== @@ -44,6 +44,7 @@ import io.ultreia.java4all.jaxx.widgets.choice.BooleanEditor; import io.ultreia.java4all.jaxx.widgets.combobox.BeanEnumEditor; import io.ultreia.java4all.jaxx.widgets.combobox.FilterableComboBox; import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthEditor; +import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthEditorModel; import io.ultreia.java4all.jaxx.widgets.list.DoubleList; import io.ultreia.java4all.jaxx.widgets.list.ListHeader; import org.jdesktop.swingx.JXTable; @@ -234,20 +235,41 @@ public class ContentUIInitializer<UI extends ContentUI> extends UIInitializerSup protected void init(TemperatureEditor editor) { initializerContext.checkFirstPass(); - ObserveSwingValidator<?> validator = null; + ObserveSwingValidator<?> validator; if (ui instanceof EditableContentUI) { validator = ((EditableContentUI<?>) ui).getValidator(); + } else { + validator = null; + } + UIInitHelper.init(ui, editor, getClientConfig().isAutoPopupNumberEditor(), getClientConfig().isShowNumberEditorButton(), getClientConfig().getTemperatureFormat()); + if (validator != null) { + editor.getModel().addPropertyChangeListener("format"/*FIXME make TemperatureEditorModel.PROPERTY_FORMAT public*/, e -> onFormatChanged(validator)); } - UIInitHelper.init(ui, validator, editor, getClientConfig().isAutoPopupNumberEditor(), getClientConfig().isShowNumberEditorButton(), getClientConfig().getTemperatureFormat()); } protected void init(NauticalLengthEditor editor) { initializerContext.checkFirstPass(); - ObserveSwingValidator<?> validator = null; + ObserveSwingValidator<?> validator; if (ui instanceof EditableContentUI) { validator = ((EditableContentUI<?>) ui).getValidator(); + } else { + validator = null; + } + UIInitHelper.init(ui, editor, getClientConfig().isAutoPopupNumberEditor(), getClientConfig().isShowNumberEditorButton(), getClientConfig().getNauticalLengthFormat()); + if (validator != null) { + editor.getModel().addPropertyChangeListener(NauticalLengthEditorModel.PROPERTY_FORMAT, e -> onFormatChanged(validator)); + } + } + + private void onFormatChanged(ObserveSwingValidator<?> validator) { + if (validator.getBean() != null) { + ContentUIModelStates states = ui.getModel().getStates(); + boolean modified = states.isModified(); + validator.doValidate(); + if (!modified) { + states.setModified(false); + } } - UIInitHelper.init(ui, validator, editor, getClientConfig().isAutoPopupNumberEditor(), getClientConfig().isShowNumberEditorButton(), getClientConfig().getNauticalLengthFormat()); } protected void init(JToolBar editor) { ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/open/ContentOpen.java ===================================== @@ -655,10 +655,14 @@ public class ContentOpen<U extends ContentUI> { private synchronized void onCoordinateFormatChanged(CoordinateFormat newValue) { if (!coordinateFormatChangedIsChanging) { coordinateFormatChangedIsChanging = true; + boolean modified = ui.getModel().getStates().isModified(); try { coordinateEditors.forEach(e -> e.setFormat(newValue)); } finally { coordinateFormatChangedIsChanging = false; + if (!modified) { + ui.getModel().getStates().setModified(false); + } } } } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/8d17f01ceffa8a653baeb1e98... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/8d17f01ceffa8a653baeb1e98... You're receiving this email because of your account on gitlab.com.