Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 6a093710 by Tony Chemit at 2024-08-30T11:34:21+02:00 Add FilterableComboBoxState state - - - - - 21265de1 by Tony Chemit at 2024-08-30T11:34:28+02:00 Add ListHeaderState state - - - - - c1d72929 by Tony Chemit at 2024-08-30T11:35:12+02:00 use new states in ObserveSwingSession - - - - - 8d17f01c by Tony Chemit at 2024-08-30T11:48:45+02:00 Merge branch 'feature/issue-2834' into develop Sauvegarde des préférences utilisateur sur le classement des listes : gestion dans l'UI - Closes #2834 - - - - - 3 changed files: - + client/configuration/src/main/java/fr/ird/observe/client/FilterableComboBoxState.java - + client/configuration/src/main/java/fr/ird/observe/client/ListHeaderState.java - client/configuration/src/main/java/fr/ird/observe/client/ObserveSwingSession.java Changes: ===================================== client/configuration/src/main/java/fr/ird/observe/client/FilterableComboBoxState.java ===================================== @@ -0,0 +1,97 @@ +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.combobox.FilterableComboBox; +import org.nuiton.jaxx.runtime.swing.session.State; + +/** + * All states to persist on a {@link FilterableComboBox}. + * <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 FilterableComboBoxState implements State { + + protected int index = 0; + + protected boolean reverseSort = false; + + public FilterableComboBoxState() { + } + + public FilterableComboBoxState(int index, boolean reverseSort) { + this.index = index; + this.reverseSort = reverseSort; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public boolean isReverseSort() { + return reverseSort; + } + + public void setReverseSort(boolean reverseSort) { + this.reverseSort = reverseSort; + } + + protected FilterableComboBox<?> checkComponent(Object o) { + if (o == null) { + throw new IllegalArgumentException("null component"); + } + if (!(o instanceof FilterableComboBox)) { + throw new IllegalArgumentException("invalid component"); + } + return (FilterableComboBox<?>) o; + } + + @Override + public State getState(Object o) { + FilterableComboBox<?> combo = checkComponent(o); + return new FilterableComboBoxState(combo.getModel().getIndex(), combo.getModel().getReverseSort()); + } + + @Override + public void setState(Object o, State state) { + if (!(state instanceof FilterableComboBoxState)) { + throw new IllegalArgumentException("invalid state"); + } + FilterableComboBox<?> ui = checkComponent(o); + FilterableComboBoxState typedState = (FilterableComboBoxState) state; + ui.getModel().setIndex(typedState.getIndex()); + ui.getModel().setReverseSort(typedState.isReverseSort()); + } + + +} + ===================================== client/configuration/src/main/java/fr/ird/observe/client/ListHeaderState.java ===================================== @@ -0,0 +1,99 @@ +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.list.ListHeader; +import org.nuiton.jaxx.runtime.swing.JAXXButtonGroup; +import org.nuiton.jaxx.runtime.swing.session.State; + +/** + * All states to persist on a {@link ListHeader}. + * <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 ListHeaderState implements State { + + protected int index = 0; + + protected boolean reverseSort = false; + + public ListHeaderState() { + } + + public ListHeaderState(int index, boolean reverseSort) { + this.index = index; + this.reverseSort = reverseSort; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public boolean isReverseSort() { + return reverseSort; + } + + public void setReverseSort(boolean reverseSort) { + this.reverseSort = reverseSort; + } + + protected ListHeader<?> checkComponent(Object o) { + if (o == null) { + throw new IllegalArgumentException("null component"); + } + if (!(o instanceof ListHeader)) { + throw new IllegalArgumentException("invalid component"); + } + return (ListHeader<?>) o; + } + + @Override + public State getState(Object o) { + ListHeader<?> combo = checkComponent(o); + return new ListHeaderState(combo.getIndex(), combo.getReverseSort()); + } + + @Override + public void setState(Object o, State state) { + if (!(state instanceof ListHeaderState)) { + throw new IllegalArgumentException("invalid state"); + } + ListHeader<?> ui = checkComponent(o); + ListHeaderState typedState = (ListHeaderState) state; + ui.setIndex(typedState.getIndex()); + ui.setReverseSort(typedState.isReverseSort()); + //FIXME Move this back to JListHeader.setIndex method + JAXXButtonGroup indexes = ui.getIndexes(); + indexes.setSelectedButton(ui.getIndex()); + } + +} ===================================== client/configuration/src/main/java/fr/ird/observe/client/ObserveSwingSession.java ===================================== @@ -22,6 +22,10 @@ package fr.ird.observe.client; * #L% */ +import io.ultreia.java4all.jaxx.widgets.combobox.FilterableComboBox; +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; @@ -46,8 +50,12 @@ public class ObserveSwingSession extends SwingSession { private final File preferencesFile; private final Properties preferences; + public ObserveSwingSession(File file, boolean autoSave, File preferencesFile) { - super(file, autoSave); + super(file, autoSave, Map.of(FilterableComboBox.class, new FilterableComboBoxState(), + DoubleList.class, new DoubleListState(), + ListHeader.class, new ListHeaderState() + )); this.preferencesFile = preferencesFile; this.preferences = new SortedProperties(); loadPreferences(preferencesFile); @@ -68,8 +76,8 @@ public class ObserveSwingSession extends SwingSession { return preferences; } - private void loadPreferences(File preferencesFile) { - if(preferencesFile.exists()) { + private void loadPreferences(File preferencesFile) { + if (preferencesFile.exists()) { try (BufferedReader reader = Files.newBufferedReader(preferencesFile.toPath(), StandardCharsets.UTF_8)) { preferences.load(reader); } catch (IOException e) { View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/b1408eb4a1930e47d445b2036... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/b1408eb4a1930e47d445b2036... You're receiving this email because of your account on gitlab.com.