Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe Commits: 117a98c1 by Tony Chemit at 2021-01-20T10:52:24+01:00 Problème dans la gestion des onglets du formulaire 'Avançon' - Closes #1756 (on v7) - - - - - 17 changed files: - client-core/pom.xml - client-core/src/main/i18n/getters/java.getter - client-core/src/main/i18n/getters/jaxx.getter - client-core/src/main/java/fr/ird/observe/client/ui/ObserveCommon.jcss - client-core/src/main/java/fr/ird/observe/client/ui/content/ContentUIInitializer.java - client-core/src/main/java/fr/ird/observe/client/ui/content/data/longline/CatchLonglineUI.jaxx - client-core/src/main/java/fr/ird/observe/client/ui/content/data/longline/CatchLonglineUI.jcss - client-core/src/main/java/fr/ird/observe/client/ui/content/data/longline/CatchLonglineUIHandler.java - client-core/src/main/java/fr/ird/observe/client/ui/content/data/longline/CatchLonglineUIModel.java - + client-core/src/main/java/fr/ird/observe/client/ui/util/time/UnlimitedTimeEditor.jaxx - + client-core/src/main/java/fr/ird/observe/client/ui/util/time/UnlimitedTimeEditor.jcss - + client-core/src/main/java/fr/ird/observe/client/ui/util/time/UnlimitedTimeEditorHandler.java - + client-core/src/main/java/fr/ird/observe/client/ui/util/time/UnlimitedTimeEditorModel.java - + client-core/src/main/java/fr/ird/observe/client/ui/util/time/actions/UnlimitedTimeEditorResetAction.java - observe-i18n/src/main/i18n/translations/observe_en_GB.properties - observe-i18n/src/main/i18n/translations/observe_es_ES.properties - observe-i18n/src/main/i18n/translations/observe_fr_FR.properties Changes: ===================================== client-core/pom.xml ===================================== @@ -372,6 +372,10 @@ <artifactId>class-mapping</artifactId> </dependency> + <dependency> + <groupId>io.ultreia.java4all</groupId> + <artifactId>java-bean</artifactId> + </dependency> <dependency> <groupId>io.ultreia.java4all</groupId> <artifactId>java-lang</artifactId> @@ -380,6 +384,7 @@ <dependency> <groupId>io.ultreia.java4all</groupId> <artifactId>java-util</artifactId> + <scope>runtime</scope> </dependency> <!-- jaxx dependencies --> ===================================== client-core/src/main/i18n/getters/java.getter ===================================== @@ -1,3 +1,4 @@ +DateTimeEditor.action.reset.tip aboutframe.changelog observe.action.about observe.action.about.tip ===================================== client-core/src/main/i18n/getters/jaxx.getter ===================================== @@ -1,3 +1,4 @@ +TimeEditor.H observe.action.apply observe.action.auto.copy.to.clipboard observe.action.auto.copy.to.clipboard.tip ===================================== client-core/src/main/java/fr/ird/observe/client/ui/ObserveCommon.jcss ===================================== @@ -55,6 +55,10 @@ TimeEditor { i18nProperty:""; } +UnlimitedTimeEditor { + i18nProperty:""; +} + NumberEditor { autoPopup:{config.isAutoPopupNumberEditor()}; showPopupButton:{config.isShowNumberEditorButton()}; ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/ContentUIInitializer.java ===================================== @@ -38,6 +38,7 @@ import fr.ird.observe.client.ui.actions.content.GoToTab6UIAction; import fr.ird.observe.client.ui.actions.content.GoToTabUIActionSupport; import fr.ird.observe.client.ui.util.BooleanEditor; import fr.ird.observe.client.ui.util.UIHelper; +import fr.ird.observe.client.ui.util.time.UnlimitedTimeEditor; import fr.ird.observe.client.ui.util.tripMap.ObserveMapPane; import fr.ird.observe.client.validation.ObserveSwingValidator; import fr.ird.observe.dto.I18nEnumHelper; @@ -314,6 +315,8 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> } if (o instanceof TemperatureEditor) { init((TemperatureEditor) o); + }if (o instanceof UnlimitedTimeEditor) { + init((UnlimitedTimeEditor) o); } } @@ -353,6 +356,9 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> editor.setLabelFor((Component) objectById); } } + private void init(UnlimitedTimeEditor editor) { + editor.init(); + } protected void initBlockLayerUI(String... doNotBlockComponentIds) { // ui.getBlockLayerUI().setAcceptedComponentTypes(UIHelper.ACCEPTABLE_COMPONENTS_TYPE); ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/longline/CatchLonglineUI.jaxx ===================================== @@ -50,6 +50,7 @@ fr.ird.observe.client.ui.util.JComment fr.ird.observe.client.ui.actions.content.CatchSetDefaultTimerTimeOnBoard + fr.ird.observe.client.ui.util.time.UnlimitedTimeEditor org.nuiton.jaxx.widgets.number.NumberEditor io.ultreia.java4all.jaxx.widgets.combobox.JaxxComboBox @@ -391,14 +392,14 @@ <tab id='branchlineTab' i18nProperty=""> - <JPanel layout="{new BorderLayout()}"> - <Table id='branchlineForm' fill='both' insets='3' constraints='BorderLayout.NORTH'> + <JPanel id='branchlinePanel' layout="{new BorderLayout()}"> + <Table id='branchlineForm' fill='both' constraints='BorderLayout.NORTH'> <!-- depthRecorder --> <!-- hookLost --> <!-- traceCutOff --> <row> - <cell columns="3"> + <cell columns="2"> <JPanel layout="{new GridLayout()}"> <JCheckBox id='depthRecorder'/> <JCheckBox id='hookLost'/> @@ -414,16 +415,15 @@ <cell anchor='east'> <JCheckBox id='timer'/> </cell> - <cell columns="2"> - <TimeEditor id='timeSinceContact' constructorParams='this'/> + <cell> + <UnlimitedTimeEditor id='timeSinceContact'/> </cell> </row> <!-- timerTimeOnBoard --> <row> + <cell/> <cell> - </cell> - <cell columns="3"> <DateTimeEditor id='timerTimeOnBoard' constructorParams='this'/> </cell> </row> @@ -433,22 +433,15 @@ <cell anchor='west'> <JLabel id='baitHaulingStatusLabel'/> </cell> - <cell anchor='east' weightx="1" fill="both" columns="2"> - <JaxxComboBox id='baitHaulingStatus' constructorParams='this' - genericType='BaitHaulingStatusReference'/> + <cell anchor='east' weightx="1" fill="both"> + <JaxxComboBox id='baitHaulingStatus' constructorParams='this' genericType='BaitHaulingStatusReference'/> </cell> </row> - - <row> - <cell columns="3"> - <JPanel id='branchlineActions' layout="{new GridLayout()}"> - <JButton id='resetBranchline' onActionPerformed='getHandler().resetBranchline()'/> - <JButton id='saveBranchline' onActionPerformed='getHandler().saveBranchline()'/> - </JPanel> - </cell> - </row> - </Table> + <JPanel id='branchlineActions' layout="{new GridLayout()}" constraints='BorderLayout.SOUTH'> + <JButton id='resetBranchline' onActionPerformed='getHandler().resetBranchline()'/> + <JButton id='saveBranchline' onActionPerformed='getHandler().saveBranchline()'/> + </JPanel> </JPanel> </tab> ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/longline/CatchLonglineUI.jcss ===================================== @@ -293,11 +293,15 @@ JCheckBox { enabled:{!tableModel.isCreate() && tableEditBean.getBranchline() != null}; } -#branchlineForm { +#branchlinePanel { border:{new TitledBorder( (String) null)}; visible:{!tableModel.isCreate() && tableEditBean.getBranchline() != null}; } +#branchlineForm { + visible:{!tableModel.isCreate() && tableEditBean.getBranchline() != null}; +} + #depthRecorder { horizontalTextPosition:{JCheckBox.LEFT}; _branchlineBeanPropertyName:{BranchlineDto.PROPERTY_DEPTH_RECORDER}; @@ -327,7 +331,7 @@ JCheckBox { bean:{model}; enabled:{BooleanUtils.isTrue(branchlineBean.getTimer())}; time:{model.getBranchlineTimeSinceContact()}; - showTimeEditorSlider:false; + showReset:true; } #timerTimeOnBoard { @@ -335,6 +339,7 @@ JCheckBox { propertyDate: {BranchlineDto.PROPERTY_TIMER_TIME_ON_BOARD}; bean:{branchlineBean}; showTimeEditorSlider:false; + showReset:true; } #baitHaulingStatus { ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/longline/CatchLonglineUIHandler.java ===================================== @@ -60,7 +60,6 @@ import fr.ird.observe.dto.referential.longline.CatchFateLonglineReference; import fr.ird.observe.dto.referential.longline.HealthStatusReference; import fr.ird.observe.dto.result.SaveResultDto; import fr.ird.observe.spi.DtoModelHelper; -import io.ultreia.java4all.util.Dates; import org.apache.commons.lang3.BooleanUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -69,7 +68,6 @@ import org.nuiton.jaxx.runtime.spi.UIHandler; import org.nuiton.jaxx.validator.swing.SwingValidator; import org.nuiton.jaxx.validator.swing.SwingValidatorMessage; import org.nuiton.jaxx.validator.swing.SwingValidatorMessageTableModel; -import org.nuiton.util.DateUtil; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -82,9 +80,7 @@ import java.awt.Component; import java.awt.Container; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Calendar; import java.util.Collections; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -102,27 +98,45 @@ import static io.ultreia.java4all.i18n.I18n.t; */ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCatchDto, CatchLonglineDto, CatchLonglineUI> implements UIHandler<CatchLonglineUI> { - /** Logger */ + /** + * Logger + */ private static final Logger log = LogManager.getLogger(CatchLonglineUIHandler.class); - + private static final String GROUPED_TRIP_TYPE_ID = "fr.ird.observe.entities.referentiel.longline.TripType#1239832686136#0.1"; // Compute valid state of tab from the error table protected final TableModelListener computeTabValidStateListener; - private final PropertyChangeListener catchFateChanged; - private final PropertyChangeListener branchlineChanged; - private final PropertyChangeListener depredatedChanged; private final PropertyChangeListener timerChanged; - private final PropertyChangeListener sizeTableModelModified; - private final PropertyChangeListener weightTableModelModified; - private final JAXXContextEntryDef<LonglinePositionHelper<CatchLonglineDto>> POSITION_HELPER_ENTRY = UIHelper.newContextEntryDef("CatchLonglineUI-positionHelper", LonglinePositionHelper.class); - private static final String GROUPED_TRIP_TYPE_ID = "fr.ird.observe.entities.referentiel.longline.TripType#1239832686136#0.1"; + static class TablePopupSupport extends AutotSelectRowAndShowPopupActionSupport { + + private final CatchLonglineUI ui; + + TablePopupSupport(CatchLonglineUI ui) { + super(ui.getTableScrollPane(), ui.getTable(), ui.getTablePopup()); + this.ui = ui; + } + + @Override + protected void beforeOpenPopup(int modelRowIndex, int modelColumnIndex) { + + CatchLonglineTableModel model = (CatchLonglineTableModel) getTable().getModel(); + + boolean canMoveUp = !ui.getModel().isCanSaveRow() && modelRowIndex > 0; + boolean canMoveDown = !ui.getModel().isCanSaveRow() && modelRowIndex < model.getRowCount() - 1; + + ui.getMoveUp().setEnabled(canMoveUp); + ui.getMoveDown().setEnabled(canMoveDown); + + } + + } CatchLonglineUIHandler() { super(DataContextType.SetLongline); @@ -236,7 +250,9 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat evt -> ui.getBranchlineValidator().setChanged(true)); ui.getTimerTimeOnBoard().getSliderHidorToolBar().setVisible(true); + ui.getTimerTimeOnBoard().getSliderHidor().setVisible(false); ui.getTimerTimeOnBoard().getSliderHidorToolBar().add(ui.getSetDefaultTimerTimeOnBoard()); +// ui.getTimeSinceContact().getReset().setVisible(true); } @Override @@ -248,9 +264,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat super.openUI(); - getUi().getTimeSinceContact().getSliderHidor().setVisible(false); - getUi().getTimerTimeOnBoard().getSliderHidor().setVisible(false); - // Reset all sections LonglinePositionHelper<CatchLonglineDto> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); getUi().getSection().setData(positionHelper.getSections()); @@ -276,36 +289,34 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat public void saveBranchline() { - if (log.isInfoEnabled()) { - log.info("Saved modified branchline"); - } + log.info("Saved modified branchline"); CatchLonglineUI ui = getUi(); BranchlineDto branchline = ui.getBranchlineBean(); + CatchLonglineUIModel model = getModel(); if (BooleanUtils.isTrue(branchline.getTimer())) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(getModel().getBranchlineTimeSinceContact()); - int minutes = calendar.get(Calendar.MINUTE); - int hours = calendar.get(Calendar.HOUR_OF_DAY); - branchline.setTimeSinceContact(minutes + 60L * hours); + Integer branchlineTimeSinceContact = model.getBranchlineTimeSinceContact(); + branchline.setTimeSinceContact(branchlineTimeSinceContact == null ? null : branchlineTimeSinceContact.longValue()); } else { branchline.setTimeSinceContact(null); } - if (log.isInfoEnabled()) { - log.info("Time since contact: " + branchline.getTimeSinceContact()); - } + log.info(String.format("Save with time since contact: %d", branchline.getTimeSinceContact())); String openSetLonglineId = getDataContext().getSelectedSetLonglineId(); SaveResultDto saveResult = getBranchlineService().save(openSetLonglineId, branchline); saveResult.toDto(branchline); + boolean modified = model.isModified(); // on recopie le last update car c'est le laste update de SetLongline qui est renvoyé. getBean().setLastUpdateDate(saveResult.getLastUpdateDate()); getUi().getBranchlineValidator().setChanged(false); - + if (!modified) { + ui.getValidator().setChanged(false); + model.setModified(false); + } } void updateCatchAcquisitionMode(CatchAcquisitionMode newMode) { @@ -488,7 +499,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat ui.getMainTabbedPane().setSelectedIndex(0); NavigationTree treeHelper = getNavigationTree(); - NavigationTreeNodeSupport selectedNode = treeHelper.getSelectedNode(); + NavigationTreeNodeSupport<?> selectedNode = treeHelper.getSelectedNode(); while (!(selectedNode instanceof TripLonglineNavigationTreeNode)) { selectedNode = selectedNode.getParent(); } @@ -825,9 +836,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat return; } - //tchemit-20191104 there is a bug on time editor, need to reset by hand the hour and minute editor - ui.getTimeSinceContact().reset(); - CatchLonglineUI ui = getUi(); BranchlineDto branchline = ui.getBranchlineBean(); @@ -836,9 +844,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat CatchLonglineUIModel model = getModel(); if (newValue == null) { - if (log.isInfoEnabled()) { - log.info("Remove branchline"); - } + log.info("Remove branchline"); branchline.removePropertyChangeListener(BranchlineDto.PROPERTY_TIMER, timerChanged); branchlineValidator.setBean(null); branchline.clear(); @@ -846,9 +852,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat } else { - if (log.isInfoEnabled()) { - log.info("Use branchline: " + newValue); - } + log.info(String.format("Use branchline: %s", newValue)); branchline.addPropertyChangeListener(BranchlineDto.PROPERTY_TIMER, timerChanged); String setLonglineId = getDataContext().getSelectedSetLonglineId(); @@ -859,18 +863,12 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat ui.getValidator().setBean(getBean()); } - Date timeSinceContactDate = null; + Long timeSinceContact=null; if (Objects.equals(true, branchline.getTimer())) { - Long timeSinceContact = branchline.getTimeSinceContact(); - if (timeSinceContact != null) { - timeSinceContactDate = DateUtil.createDate(0, (int) (timeSinceContact % 60), (int) (timeSinceContact / 60f), 0, 0, 0); - } - } - if (timeSinceContactDate == null) { - timeSinceContactDate = DateUtil.createDate(0, 0, 0, 0, 0, 0); + timeSinceContact = branchline.getTimeSinceContact(); } - log.info("Set time since contact: " + timeSinceContactDate); - model.setBranchlineTimeSinceContact(timeSinceContactDate); + log.info(String.format("Set time since contact: %d", timeSinceContact)); + model.setBranchlineTimeSinceContact(timeSinceContact==null?null:timeSinceContact.intValue()); branchlineValidator.setBean(branchline); } @@ -943,7 +941,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat } - private void onSizeTableModelModified(Boolean newValue) { if (newValue) { @@ -1042,41 +1039,19 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat model.setBranchlineTabValid(branchlineTabValid); } + void onTimerChanged(Boolean newValue) { if (Objects.equals(true, newValue)) { // with timer - ui.getModel().setBranchlineTimeSinceContact(Dates.createDate(0, 0, 0, 0, 0, 0)); + ui.getModel().setBranchlineTimeSinceContact(0); } else { // without timer ui.getModel().setBranchlineTimeSinceContact(null); } } + @Override protected CatchLonglineTableModel getTableModel() { return (CatchLonglineTableModel) super.getTableModel(); } - - static class TablePopupSupport extends AutotSelectRowAndShowPopupActionSupport { - - private final CatchLonglineUI ui; - - TablePopupSupport(CatchLonglineUI ui) { - super(ui.getTableScrollPane(), ui.getTable(), ui.getTablePopup()); - this.ui = ui; - } - - @Override - protected void beforeOpenPopup(int modelRowIndex, int modelColumnIndex) { - - CatchLonglineTableModel model = (CatchLonglineTableModel) getTable().getModel(); - - boolean canMoveUp = !ui.getModel().isCanSaveRow() && modelRowIndex > 0; - boolean canMoveDown = !ui.getModel().isCanSaveRow() && modelRowIndex < model.getRowCount() - 1; - - ui.getMoveUp().setEnabled(canMoveUp); - ui.getMoveDown().setEnabled(canMoveDown); - - } - - } } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/longline/CatchLonglineUIModel.java ===================================== @@ -111,7 +111,7 @@ public class CatchLonglineUIModel extends ContentTableUIModel<SetLonglineCatchDt protected boolean branchlineTabValid; - protected Date branchlineTimeSinceContact; + protected Integer branchlineTimeSinceContact; public CatchLonglineUIModel(CatchLonglineUI ui) { super(SetLonglineCatchDto.class, CatchLonglineDto.class); @@ -189,31 +189,19 @@ public class CatchLonglineUIModel extends ContentTableUIModel<SetLonglineCatchDt firePropertyChange(PROPERTY_BRANCHLINE_TAB_VALID, null, branchlineTabValid); } - public Date getBranchlineTimeSinceContact() { + public Integer getBranchlineTimeSinceContact() { return branchlineTimeSinceContact; } - public void setBranchlineTimeSinceContact(Date branchlineTimeSinceContact) { - Date oldValue = getBranchlineTimeSinceContact(); + public void setBranchlineTimeSinceContact(Integer branchlineTimeSinceContact) { + Integer oldValue = getBranchlineTimeSinceContact(); this.branchlineTimeSinceContact = branchlineTimeSinceContact; firePropertyChange(PROPERTY_BRANCHLINE_TIME_SINCE_CONTACT, oldValue, branchlineTimeSinceContact); - } @Override protected CatchLonglineTableModel createTableModel(ObserveContentTableUI<SetLonglineCatchDto, CatchLonglineDto, ?> ui, List<ContentTableMeta<CatchLonglineDto>> contentTableMetas) { return new CatchLonglineTableModel(ui, contentTableMetas); } -// -// @Override -// protected BinderModelBuilder<CatchLonglineDto, CatchLonglineDto> prepareChildLoador(String binderName) { -// -// BinderModelBuilder<CatchLonglineDto, CatchLonglineDto> builder = super.prepareChildLoador(binderName); -// -// builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, CatchLonglineDto.PROPERTY_PREDATOR); -// -// return builder; -// -// } } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/util/time/UnlimitedTimeEditor.jaxx ===================================== @@ -0,0 +1,78 @@ +<!-- + #%L + JAXX :: Widgets DateTime + %% + Copyright (C) 2008 - 2020 Code Lutin, 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% + --> + +<JPanel layout='{new BorderLayout()}' implements='org.nuiton.jaxx.runtime.bean.BeanScopeAware'> + + <import> + java.util.Calendar + java.util.Date + java.awt.BorderLayout + </import> + + <!-- model --> + <UnlimitedTimeEditorModel id='model'/> + + <!-- spinner hour editor --> + <SpinnerNumberModel id="hourModel" constructorParams="0, 0, 100, 1"/> + + <!-- spinner minute editor --> + <SpinnerNumberModel id="minuteModel" constructorParams="0, 0, 59, 1"/> + + <!-- flag to show or hide reset button --> + <Boolean id='showReset' javaBean='false'/> + + <script><![CDATA[ +public void init() { handler.init(this); } + +@Override +public Object getBean() { return model.getBean(); } + +@Override +public void setBean(Object bean) { model.setBean(bean); } + +public void setPropertyTime(String property) { model.setPropertyTime(property); } + +public void setTime(Integer time) { model.setTime(time); } + +public void setLabel(String label) { timeLabel.setText(label); } + +public void reset() { handler.reset(); } +]]> + </script> + + <BeanValidator id='validator' autoField='true' bean='model'> + <field name='time' component='editorPanel'/> + </BeanValidator> + <JPanel id='leftPanel' constraints='BorderLayout.WEST' layout='{new BorderLayout()}'> + <JLabel id='timeLabel' constraints='BorderLayout.WEST'/> + <JToolBar id='toolbarReset' constraints='BorderLayout.CENTER'> + <JButton id='reset'/> + </JToolBar> + </JPanel> + <JPanel id='editorPanel' constraints='BorderLayout.EAST'> + <JSpinner id='hourEditor' onStateChanged='model.setHours((Integer)((JSpinner)event.getSource()).getValue())'/> + <JLabel id='labelH'/> + <JSpinner id='minuteEditor' onStateChanged='model.setMinutes((Integer)((JSpinner)event.getSource()).getValue())'/> + <JToolBar id="sliderHidorToolBar"/> + </JPanel> + +</JPanel> ===================================== client-core/src/main/java/fr/ird/observe/client/ui/util/time/UnlimitedTimeEditor.jcss ===================================== @@ -0,0 +1,69 @@ +/* + * #%L + * JAXX :: Widgets DateTime + * %% + * Copyright (C) 2008 - 2014 CodeLutin + * %% + * 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% + */ + +JToolBar { + borderPainted:false; + floatable:false; + focusable:false; + opaque:false; +} + +JButton { + borderPainted:false; + opaque:false; + focusable:false; +} + +#title { + horizontalAlignment:center; +} + +#hourModel { + value:{model.getHours()}; +} + +#hourEditor { + model:{hourModel}; + enabled:{isEnabled()}; +} + +#labelH { + text:"TimeEditor.H"; + horizontalAlignment:center; +} + +#minuteModel { + value:{model.getMinutes()}; +} + +#minuteEditor { + model:{minuteModel}; + enabled:{isEnabled()}; +} + +#toolbarReset { + visible:{isShowReset()}; +} + +#reset { + enabled:{isEnabled()}; +} ===================================== client-core/src/main/java/fr/ird/observe/client/ui/util/time/UnlimitedTimeEditorHandler.java ===================================== @@ -0,0 +1,82 @@ +package fr.ird.observe.client.ui.util.time; + +/*- + * #%L + * ObServe :: Client core + * %% + * Copyright (C) 2008 - 2021 IRD, Code Lutin, 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 fr.ird.observe.client.ui.util.time.actions.UnlimitedTimeEditorResetAction; +import io.ultreia.java4all.lang.Setters; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.nuiton.jaxx.runtime.spi.UIHandler; +import org.nuiton.jaxx.widgets.MutateOnConditionalPropertyChangeListener; + +import java.lang.reflect.Method; +import java.util.Objects; +import java.util.function.Predicate; + +/** + * Created on 20/01/2021. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 7.6.7 + */ +public class UnlimitedTimeEditorHandler implements UIHandler<UnlimitedTimeEditor> { + + private static final Logger log = LogManager.getLogger(UnlimitedTimeEditorHandler.class); + private UnlimitedTimeEditor ui; + + @Override + public void afterInit(UnlimitedTimeEditor ui) { + this.ui = Objects.requireNonNull(ui); + UnlimitedTimeEditorResetAction.init(ui, ui.getReset(), UnlimitedTimeEditorResetAction.class); + } + + public void init(UnlimitedTimeEditor ui) { + log.debug(String.format("%s - init UnlimitedTimeEditor", ui.getName())); + UnlimitedTimeEditorModel model = ui.getModel(); + String property = model.getPropertyTime(); + if (property == null || property.isEmpty()) { + ui.setPropertyTime(ui.getName()); + } + ui.setEnabled(true); + Predicate<UnlimitedTimeEditorModel> predicate = model.canUpdateBeanValuePredicate(); + + Object bean = ui.getBean(); + if (property != null && bean != null) { + + Method mutator = Setters.getMutator(bean, property); + Objects.requireNonNull(mutator, "could not find mutator for " + property); + + // When model time date changed, let's push it back in bean + model.addPropertyChangeListener( + UnlimitedTimeEditorModel.PROPERTY_TIME, + new MutateOnConditionalPropertyChangeListener<>(model, mutator, predicate)); + } + } + + public void reset() { + ui.getHourEditor().setValue(0); + ui.getMinuteEditor().setValue(0); + ui.getModel().setTime(null); + } + +} ===================================== client-core/src/main/java/fr/ird/observe/client/ui/util/time/UnlimitedTimeEditorModel.java ===================================== @@ -0,0 +1,166 @@ +package fr.ird.observe.client.ui.util.time; + +/*- + * #%L + * ObServe :: Client core + * %% + * Copyright (C) 2008 - 2021 IRD, Code Lutin, 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 com.google.common.base.Preconditions; +import io.ultreia.java4all.bean.AbstractJavaBean; +import org.nuiton.jaxx.widgets.ModelToBean; + +import java.util.function.Predicate; + +/** + * Created on 20/01/2021. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 7.6.7 + */ +public class UnlimitedTimeEditorModel extends AbstractJavaBean implements ModelToBean { + + public static final String PROPERTY_TIME = "time"; + public static final String PROPERTY_HOURS = "hours"; + public static final String PROPERTY_MINUTES = "minutes"; + public static final String PROPERTY_VALUE_IS_ADJUSTING = "valueIsAdjusting"; + /** + * State to be able to custom the model. will be pass to {@code false} by the {@link UnlimitedTimeEditorHandler#init(UnlimitedTimeEditor)}. + */ + protected final boolean fillState = true; + /** + * Optional bean where to push back dates. + */ + protected Object bean; + /** + * Optional bean property where to push back the time date. + */ + protected String propertyTime; + /** + * Time in minutes. + */ + protected Integer time = null; + /** + * To stop propagate events when we are doing some modifications on the model. + */ + protected boolean valueIsAdjusting; + + public String getPropertyTime() { + return propertyTime; + } + + public void setPropertyTime(String propertyTime) { + Preconditions.checkState(fillState, "cant change *propertyTimeDate* property once the fillState is off."); + this.propertyTime = propertyTime; + } + + @Override + public Object getBean() { + return bean; + } + + public void setBean(Object bean) { + Preconditions.checkState(fillState, "cant change *bean* property once the fillState is off."); + this.bean = bean; + } + + public Integer getTime() { + return time; + } + + public void setTime(Integer time) { + if (!isValueIsAdjusting()) { + Integer oldHours = getHours(); + Integer oldMinutes = getMinutes(); + setTime(getHours(time), getMinutes(time)); + firePropertyChange(PROPERTY_HOURS, oldHours, getHours()); + firePropertyChange(PROPERTY_MINUTES, oldMinutes, getMinutes()); + } + } + + public int getHours() { + return getHours(time); + } + + public void setHours(Integer hour) { + if (!isValueIsAdjusting()) { + Integer oldValue = getHours(); + setTime(hour, getMinutes()); + firePropertyChange(PROPERTY_HOURS, oldValue, hour); + + } + } + + public int getMinutes() { + return getMinutes(time); + } + + public void setMinutes(Integer minutes) { + if (!isValueIsAdjusting()) { + Integer oldValue = getMinutes(); + setTime(getHours(), minutes); + firePropertyChange(PROPERTY_MINUTES, oldValue, minutes); + } + } + + public boolean isValueIsAdjusting() { + return valueIsAdjusting; + } + + public void setValueIsAdjusting(boolean valueIsAdjusting) { + boolean oldValue = isValueIsAdjusting(); + this.valueIsAdjusting = valueIsAdjusting; + fireValueIsAdjusting(oldValue); + } + + public int getHours(Integer time) { + return time == null ? 0 : time / 60; + } + + public int getMinutes(Integer time) { + return time == null ? 0 : time % 60; + } + + protected void setTime(Integer hour, Integer minute) { + Integer oldTime = getTime(); + setValueIsAdjusting(true); + try { + if (hour == null || minute == null) { + this.time = null; + } else { + this.time = hour * 60 + minute; + } + } finally { + setValueIsAdjusting(false); + fireTime(oldTime); + } + } + + protected void fireTime(Integer oldTime) { + firePropertyChange(PROPERTY_TIME, oldTime, getTime()); + } + + protected void fireValueIsAdjusting(boolean oldValue) { + firePropertyChange(PROPERTY_VALUE_IS_ADJUSTING, oldValue, isValueIsAdjusting()); + } + + protected Predicate<UnlimitedTimeEditorModel> canUpdateBeanValuePredicate() { + return input -> !isValueIsAdjusting(); + } +} ===================================== client-core/src/main/java/fr/ird/observe/client/ui/util/time/actions/UnlimitedTimeEditorResetAction.java ===================================== @@ -0,0 +1,54 @@ +package fr.ird.observe.client.ui.util.time.actions; + +/*- + * #%L + * ObServe :: Client core + * %% + * Copyright (C) 2008 - 2021 IRD, Code Lutin, 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 fr.ird.observe.client.ui.util.time.UnlimitedTimeEditor; +import org.nuiton.jaxx.runtime.swing.SwingUtil; +import org.nuiton.jaxx.runtime.swing.action.JComponentActionSupport; + +import java.awt.event.ActionEvent; + +import static io.ultreia.java4all.i18n.I18n.n; + +/** + * Created on 20/01/2021. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 7.6.7 + */ +public class UnlimitedTimeEditorResetAction extends JComponentActionSupport<UnlimitedTimeEditor> { + + public UnlimitedTimeEditorResetAction() { + super(null, n("DateTimeEditor.action.reset.tip"), "combobox-reset", SwingUtil.findKeyStroke("beancombobox.reset", "ctrl pressed D")); + } + + @Override + protected void doActionPerformed(ActionEvent e, UnlimitedTimeEditor ui) { + ui.reset(); + } + + @Override + public void init() { + defaultInit(ui.getInputMap(UnlimitedTimeEditor.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT), ui.getActionMap()); + } +} ===================================== observe-i18n/src/main/i18n/translations/observe_en_GB.properties ===================================== @@ -1,5 +1,6 @@ ClientConfig.description=ObServe configuration ObserveWebApplicationConfig.description=ObServe Web configuration +TimeEditor.H=H observe.action.about=About observe.action.about.tip=About ObServe... observe.action.admin.cancel=Cancel wizard ===================================== observe-i18n/src/main/i18n/translations/observe_es_ES.properties ===================================== @@ -1,5 +1,6 @@ ClientConfig.description=Configuración de ObServe ObserveWebApplicationConfig.description=Configuración de Observe web +TimeEditor.H=H observe.action.about=Acerca de observe.action.about.tip=Acerca de ObServe... observe.action.admin.cancel=Anular el asistente ===================================== observe-i18n/src/main/i18n/translations/observe_fr_FR.properties ===================================== @@ -1,5 +1,6 @@ ClientConfig.description=Configuration d'ObServe ObserveWebApplicationConfig.description=Observe web Configuration +TimeEditor.H=H observe.action.about=À propos observe.action.about.tip=À propos d'ObServe... observe.action.admin.cancel=Annulation de l'assistant View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/117a98c11ab5df423cb4000809... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/117a98c11ab5df423cb4000809... You're receiving this email because of your account on gitlab.com.