Author: tchemit Date: 2012-12-10 14:33:13 +0100 (Mon, 10 Dec 2012) New Revision: 39 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/39 Log: introduce SimpleTimeEditor (will be later in jaxx ?) use it for fishingOperation Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorModel.java Modified: trunk/tutti-persistence/src/main/xmi/tutti-persistence.zargo trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationsUIHandler.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties trunk/tutti-ui-swing/src/main/resources/icons/action-reset.png Modified: trunk/tutti-persistence/src/main/xmi/tutti-persistence.zargo =================================================================== (Binary files differ) Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2012-12-10 06:59:02 UTC (rev 38) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2012-12-10 13:33:13 UTC (rev 39) @@ -32,9 +32,9 @@ import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.ui.swing.config.TuttiConfig; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.util.editor.SimpleTimeEditor; import jaxx.runtime.swing.OneClicListSelectionModel; import jaxx.runtime.swing.editor.NumberEditor; -import jaxx.runtime.swing.editor.TimeEditor; import jaxx.runtime.swing.editor.bean.BeanComboBox; import jaxx.runtime.swing.editor.bean.BeanListHeader; import jaxx.runtime.swing.renderer.DecoratorListCellRenderer; @@ -142,8 +142,8 @@ initNumberEditor((NumberEditor) component); } else if (component instanceof JXDatePicker) { initDatePicker((JXDatePicker) component); - } else if (component instanceof TimeEditor) { - initTimeEditor((TimeEditor) component); + } else if (component instanceof SimpleTimeEditor) { + initTimeEditor((SimpleTimeEditor) component); } } } @@ -230,10 +230,10 @@ } } - protected void initTimeEditor(TimeEditor editor) { + protected void initTimeEditor(SimpleTimeEditor editor) { if (log.isDebugEnabled()) { log.debug("init time editor " + editor.getName() + - " for property " + editor.getProperty()); + " for property " + editor.getModel().getProperty()); } editor.init(); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUI.css 2012-12-10 06:59:02 UTC (rev 38) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUI.css 2012-12-10 13:33:13 UTC (rev 39) @@ -49,6 +49,10 @@ showReset: true; } +SimpleTimeEditor { + bean: {model}; +} + #stationNumberLabel { text: "tutti.label.fishingOperation.stationNumber"; labelFor: {stationNumberField}; @@ -150,7 +154,8 @@ } #gearShootingStartTimeField { - text: {getStringValue(model.getGearShootingStartTime())}; + property: "gearShootingStartDate"; + date: {model.getGearShootingStartDate()}; } #gearShootingEndLongitudeField { @@ -167,7 +172,8 @@ } #gearShootingEndTimeField { - text: {getStringValue(model.getGearShootingEndTime())}; + property: "gearShootingEndDate"; + date: {model.getGearShootingEndDate()}; } #fishingOperationValidPanel { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUI.jaxx 2012-12-10 06:59:02 UTC (rev 38) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUI.jaxx 2012-12-10 13:33:13 UTC (rev 39) @@ -31,9 +31,12 @@ fr.ifremer.tutti.persistence.entities.data.FishingOperation fr.ifremer.tutti.persistence.entities.referential.Person + fr.ifremer.tutti.ui.swing.util.editor.SimpleTimeEditor + jaxx.runtime.swing.editor.bean.BeanComboBox jaxx.runtime.swing.editor.bean.BeanListHeader jaxx.runtime.swing.editor.NumberEditor + jaxx.runtime.swing.editor.TimeEditor jaxx.runtime.validator.swing.SwingValidatorUtil jaxx.runtime.validator.swing.SwingValidatorMessageTableModel @@ -179,8 +182,8 @@ onActionPerformed='handler.setDate(event, "gearShootingStartDate")'/> </cell> <cell> - <JTextField id='gearShootingStartTimeField' - onKeyReleased='handler.setGearShootingStartTime(((JTextField)event.getSource()).getText())'/> + <SimpleTimeEditor id='gearShootingStartTimeField' + constructorParams='this'/> </cell> </row> <row> @@ -200,8 +203,8 @@ onActionPerformed='handler.setDate(event, "gearShootingEndDate")'/> </cell> <cell> - <JTextField id='gearShootingEndTimeField' - onKeyReleased='handler.setGearShootingEndTime(((JTextField)event.getSource()).getText())'/> + <SimpleTimeEditor id='gearShootingEndTimeField' + constructorParams='this'/> </cell> </row> </Table> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUIHandler.java 2012-12-10 06:59:02 UTC (rev 38) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUIHandler.java 2012-12-10 13:33:13 UTC (rev 39) @@ -224,9 +224,9 @@ getModel().setGearShootingStartLongitude(Float.valueOf(text)); } - public void setGearShootingStartTime(String text) { - getModel().setGearShootingStartTime(Integer.valueOf(text)); - } +// public void setGearShootingStartTime(String text) { +// getModel().setGearShootingStartTime(Integer.valueOf(text)); +// } public void setGearShootingEndLatitude(String text) { getModel().setGearShootingEndLatitude(Float.valueOf(text)); @@ -236,7 +236,7 @@ getModel().setGearShootingEndLongitude(Float.valueOf(text)); } - public void setGearShootingEndTime(String text) { - getModel().setGearShootingEndTime(Integer.valueOf(text)); - } +// public void setGearShootingEndTime(String text) { +// getModel().setGearShootingEndTime(Integer.valueOf(text)); +// } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUIModel.java 2012-12-10 06:59:02 UTC (rev 38) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationTabUIModel.java 2012-12-10 13:33:13 UTC (rev 39) @@ -65,16 +65,12 @@ public static final String PROPERTY_GEAR_SHOOTING_START_DATE = "gearShootingStartDate"; - public static final String PROPERTY_GEAR_SHOOTING_START_TIME = "gearShootingStartTime"; - public static final String PROPERTY_GEAR_SHOOTING_START_DEPTH = "gearShootingStartDepth"; public static final String PROPERTY_GEAR_SHOOTING_END_LATITUDE = "gearShootingEndLatitude"; public static final String PROPERTY_GEAR_SHOOTING_END_LONGITUDE = "gearShootingEndLongitude"; - public static final String PROPERTY_GEAR_SHOOTING_END_TIME = "gearShootingEndTime"; - public static final String PROPERTY_GEAR_SHOOTING_END_DATE = "gearShootingEndDate"; public static final String PROPERTY_GEAR_SHOOTING_END_DEPTH = "gearShootingEndDepth"; @@ -326,16 +322,6 @@ firePropertyChange(PROPERTY_GEAR_SHOOTING_START_DATE, oldValue, gearShootingStartDate); } - public Integer getGearShootingStartTime() { - return gearShootingStartTime; - } - - public void setGearShootingStartTime(Integer gearShootingStartTime) { - Object oldValue = getGearShootingStartTime(); - this.gearShootingStartTime = gearShootingStartTime; - firePropertyChange(PROPERTY_GEAR_SHOOTING_START_TIME, oldValue, gearShootingStartTime); - } - public Float getGearShootingStartDepth() { return gearShootingStartDepth; } @@ -376,16 +362,6 @@ firePropertyChange(PROPERTY_GEAR_SHOOTING_END_DATE, oldValue, gearShootingEndDate); } - public Integer getGearShootingEndTime() { - return gearShootingEndTime; - } - - public void setGearShootingEndTime(Integer gearShootingEndTime) { - Object oldValue = getGearShootingEndTime(); - this.gearShootingEndTime = gearShootingEndTime; - firePropertyChange(PROPERTY_GEAR_SHOOTING_END_TIME, oldValue, gearShootingEndTime); - } - public Float getGearShootingEndDepth() { return gearShootingEndDepth; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationsUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationsUIHandler.java 2012-12-10 06:59:02 UTC (rev 38) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/FishingOperationsUIHandler.java 2012-12-10 13:33:13 UTC (rev 39) @@ -30,6 +30,7 @@ import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.TuttiUIContext; +import org.apache.commons.lang.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -138,7 +139,15 @@ // use a new empty fishingOperation FishingOperation newFishingOperation = new FishingOperation(); newFishingOperation.setScientificCruise(getModel().getScientificCruise()); - newFishingOperation.setDate(new Date()); + + // by default use the current day with no time information + Date currentDate = new Date(); + currentDate = DateUtils.setHours(currentDate, 0); + currentDate = DateUtils.setMinutes(currentDate, 0); + + newFishingOperation.setDate(currentDate); + newFishingOperation.setGearShootingStartDate(currentDate); + newFishingOperation.setGearShootingEndDate(currentDate); selectFishingOperation(newFishingOperation); } Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.css 2012-12-10 13:33:13 UTC (rev 39) @@ -0,0 +1,45 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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% + */ + +#hour { + value:{model.getTimeModel() / 60}; + enabled:{isEnabled()}; + model:{new SpinnerNumberModel(0, 0, 23, 1)}; +} + +#labelH { + text:"tutti.timeeditor.H"; + horizontalAlignment:center; +} + +#minuteModel { + calendarField:{java.util.Calendar.MINUTE}; + value:{handler.setMinuteModel(model.getDate())}; +} + +#minute { + enabled:{isEnabled()}; + model:{minuteModel}; +} + Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.jaxx 2012-12-10 13:33:13 UTC (rev 39) @@ -0,0 +1,62 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 Ifremer + %% + 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% + --> +<Table constraints='BorderLayout.NORTH' fill='horizontal' insets='0'> + <import> + java.io.Serializable + java.util.Date + java.awt.BorderLayout + javax.swing.SpinnerNumberModel + javax.swing.DefaultBoundedRangeModel + </import> + + <!-- ui handler --> + <SimpleTimeEditorModel id='model'/> + + <!-- spinner minute editor --> + <SpinnerDateModel id="minuteModel"/> + + <SimpleTimeEditorHandler id='handler' constructorParams='this'/> + + <script><![CDATA[ +public void init() { handler.init(); } +public void setBean(Serializable bean) { model.setBean(bean); } +public void setProperty(String property ) { model.setProperty(property); } +public void setDate(Date date) { model.setDate(date); } +]]> + </script> + + <row> + <cell weightx='0.5'> + <JSpinner id='hour' + onStateChanged='handler.updateTimeModelFromHour((Integer)hour.getValue())'/> + </cell> + <cell> + <JLabel id='labelH'/> + </cell> + <cell weightx='0.5'> + <JSpinner id='minute' + onStateChanged='handler.updateTimeModelFromMinute(minuteModel.getDate())'/> + </cell> + </row> +</Table> \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditor.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorHandler.java 2012-12-10 13:33:13 UTC (rev 39) @@ -0,0 +1,271 @@ +package fr.ifremer.tutti.ui.swing.util.editor; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JSpinner; +import javax.swing.SpinnerDateModel; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; +import java.util.Calendar; +import java.util.Date; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since TODO + */ +public class SimpleTimeEditorHandler { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SimpleTimeEditorHandler.class); + + private final SimpleTimeEditor editor; + + private final SimpleTimeEditorModel model; + + /** the mutator method on the property of boxed bean in the editor */ + protected Method mutator; + + protected final Calendar calendarDate; + + protected final Calendar calendarMinute; + + protected final Calendar calendarHour; + + public SimpleTimeEditorHandler(SimpleTimeEditor editor) { + this.editor = editor; + this.model = editor.getModel(); + this.calendarMinute = Calendar.getInstance(); + this.calendarHour = Calendar.getInstance(); + this.calendarDate = Calendar.getInstance(); + } + + public void init() { + + if (model.getBean() == null) { + throw new NullPointerException("can not have a null bean in ui " + editor); + } + + editor.getMinute().setEditor(new JSpinner.DateEditor(editor.getMinute(), "mm")); +// editor.getHour().setEditor(new JSpinner.DateEditor(editor.getHour(), "HH")); + + +// TuttiUIUtil.autoSelectOnFocus(minuteEditor.getTextField()); +// JSpinner.NumberEditor hourEditor = (JSpinner.NumberEditor) editor.getHour().getEditor(); +// TuttiUIUtil.autoSelectOnFocus(hourEditor.getTextField()); + + // listen when date changes (should come from outside) + model.addPropertyChangeListener(SimpleTimeEditorModel.PROPERTY_DATE, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + Date date = (Date) evt.getNewValue(); + + if (date != null) { + calendarDate.setTime(date); + int hours = calendarDate.get(Calendar.HOUR_OF_DAY); + int minutes = calendarDate.get(Calendar.MINUTE); + if (log.isDebugEnabled()) { + log.debug("date changed : new value " + hours + ":" + minutes); + } + model.setTimeModel(hours * 60 + minutes); + } + + } + }); + + // When time model change, let's push it back in bean + model.addPropertyChangeListener(SimpleTimeEditorModel.PROPERTY_TIME_MODEL, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + Integer time = (Integer) evt.getNewValue(); + + int hours = time / 60; + int minutes = time % 60; + + calendarDate.set(Calendar.HOUR_OF_DAY, hours); + calendarDate.set(Calendar.MINUTE, minutes); + + // push it back into the bean + + Date newValue = calendarDate.getTime(); + + if (log.isDebugEnabled()) { + log.debug(model.getProperty() + " on " + model.getBean().getClass() + " :: " + newValue); + } + + try { + getMutator().invoke(model.getBean(), newValue); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + } + + public SimpleTimeEditor getEditor() { + return editor; + } + + protected Date setMinuteModel(Date incomingDate) { + if (incomingDate == null) { + incomingDate = new Date(); + calendarMinute.setTime(incomingDate); + calendarMinute.set(Calendar.HOUR_OF_DAY, 0); + calendarMinute.set(Calendar.MINUTE, 0); + } else { + calendarMinute.setTime(incomingDate); + calendarMinute.set(Calendar.HOUR_OF_DAY, 0); + } + incomingDate = calendarMinute.getTime(); + return incomingDate; + } + + public void updateTimeModelFromHour(Integer hour) { + model.setTimeModel(hour * 60 + model.getMinute()); + } + + public void updateTimeModelFromMinute(Date minuteDate) { + + calendarMinute.setTime(minuteDate); + int newHour = calendarMinute.get(Calendar.HOUR_OF_DAY); + int newMinute = calendarMinute.get(Calendar.MINUTE); + + int oldHour = model.getHour(); + int oldMinute = model.getMinute(); + + if (oldHour == newHour && oldMinute == newMinute) { + + // do nothing, same data + if (log.isDebugEnabled()) { + log.debug("Do not update time model , stay on same time = " + oldHour + ":" + oldMinute); + } + return; + } + + // by default stay on same hour + int hour = oldHour; + + // by default, use the new minute data + int minute = newMinute; + + if (log.isDebugEnabled()) { + log.debug("hh:mm (old from dateModel) = " + oldHour + ":" + oldMinute); + log.debug("hh:mm (new from minuteModel) = " + newHour + ":" + newMinute); + } + + SpinnerDateModel minuteModel = editor.getMinuteModel(); + + if (newMinute == 0) { + + // minute pass to zero (check if a new hour is required) + if (newHour == 1) { + + if (oldHour == 23) { + + // can't pass from 23:59 to 0:00, stay on 23:59 + if (log.isDebugEnabled()) { + log.debug("Do not update time model , stay on hh:mm = " + oldHour + ":" + oldMinute); + } + minuteModel.setValue(minuteModel.getPreviousValue()); + return; + } + hour = (oldHour + 1) % 24; + } + } else if (newMinute == 59) { + + // minute pass to 59 (check if a new hour is required) + + if (newHour == 23) { + + if (oldHour == 0) { + + // can't pass from 0:00 to 23:59, stay on 0:00 + if (log.isDebugEnabled()) { + log.debug("Do not update time model , stay on hh:mm = " + oldHour + ":" + oldMinute); + } + minuteModel.setValue(minuteModel.getNextValue()); + return; + } + + // decrease hour + hour = (oldHour - 1) % 24; + } + } + + // date has changed + if (log.isDebugEnabled()) { + log.debug("Update time model to hh:mm = " + hour + ":" + minute); + } + model.setTimeModel(hour * 60 + minute); + } + + protected void setDate(Date oldValue, Date newValue) { + if (model.getBean() != null) { + + if (log.isDebugEnabled()) { + log.debug(model.getProperty() + " on " + model.getBean().getClass() + " :: " + oldValue + " to " + newValue); + } + + try { + getMutator().invoke(model.getBean(), newValue); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + protected Method getMutator() { + if (mutator == null) { + Object bean = model.getBean(); + if (bean == null) { + throw new NullPointerException("could not find bean in " + editor); + } + String property = model.getProperty(); + if (property == null) { + throw new NullPointerException("could not find property in " + editor); + } + + try { + PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(bean, property); + mutator = descriptor.getWriteMethod(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + return mutator; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorModel.java 2012-12-10 13:33:13 UTC (rev 39) @@ -0,0 +1,111 @@ +package fr.ifremer.tutti.ui.swing.util.editor; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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.jdesktop.beans.AbstractSerializableBean; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class SimpleTimeEditorModel extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_DATE = "date"; + + public static final String PROPERTY_TIME_MODEL = "timeModel"; + + public static final String PROPERTY_PROPERTY = "property"; + + public static final String PROPERTY_BEAN = "bean"; + + /** Bean where to push data. */ + protected Serializable bean; + + /** Property of the bean to use. */ + protected String property; + + /** Time model in minutes. */ + protected Integer timeModel = 0; + + /** Real date which contains the edited time. */ + protected Date date; + + public Serializable getBean() { + return bean; + } + + public void setBean(Serializable bean) { + Object oldValue = getBean(); + this.bean = bean; + firePropertyChange(PROPERTY_BEAN, oldValue, bean); + } + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + Object oldValue = getProperty(); + this.property = property; + firePropertyChange(PROPERTY_PROPERTY, oldValue, property); + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + Object oldValue = getDate(); + this.date = date; + firePropertyChange(PROPERTY_DATE, oldValue, date); + } + + public Integer getTimeModel() { + return timeModel; + } + + public void setTimeModel(Integer timeModel) { + if (timeModel == null) { + timeModel = 0; + } + Object oldValue = getTimeModel(); + this.timeModel = timeModel; + firePropertyChange(PROPERTY_TIME_MODEL, oldValue, timeModel); + } + + public int getMinute() { + return timeModel % 60; + } + + public int getHour() { + return timeModel / 60; + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/SimpleTimeEditorModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2012-12-10 06:59:02 UTC (rev 38) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2012-12-10 13:33:13 UTC (rev 39) @@ -186,6 +186,7 @@ tutti.table.species.frequency.header.lengthStep=Classe de taille tutti.table.species.frequency.header.number=Nombre tutti.table.species.frequency.header.weight=Poids observé +tutti.timeeditor.H=H tutti.title.about=À propos de Tutti tutti.title.create.program=Créer une nouvelle série de campagne tutti.title.create.scientificCruise=Créer une nouvelle campagne Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-reset.png ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL