r497 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence sammoa-persistence/src/main/xmi sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observatio
Author: fdesbois Date: 2012-08-30 15:28:13 +0200 (Thu, 30 Aug 2012) New Revision: 497 Url: http://forge.codelutin.com/repositories/revision/sammoa/497 Log: fixes #1419 : allow change time, do not keep milliseconds Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TimeCellEditor.java Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/FlightDAOImpl.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointDAOImpl.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointImpl.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/ObservationDAOImpl.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteDAOImpl.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Routes.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/TransectDAOImpl.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/TransectFlightDAOImpl.java trunk/sammoa-persistence/src/main/xmi/sammoa.properties trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/GeoPointsTest.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.css trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TextCellEditor.java Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-08-30 13:28:13 UTC (rev 497) @@ -843,7 +843,10 @@ RouteDAO dao = SammoaDAOHelper.getRouteDAO(transaction); // Create the new Route - Route result = dao.createByNaturalId(beginTime, type, flight); + Route result = dao.create(); + result.setBeginTime(beginTime); + result.setRouteType(type); + result.setFlight(flight); // Copy previous data if (previousRoute != null) { Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java 2012-08-30 13:28:13 UTC (rev 497) @@ -29,6 +29,7 @@ import fr.ulr.sammoa.persistence.GeoPoint; import fr.ulr.sammoa.persistence.GeoPointImpl; import fr.ulr.sammoa.persistence.GeoPoints; +import org.apache.commons.lang3.time.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -133,13 +134,13 @@ GeoPoint result; if (currentLocation == null) { result = new GeoPointImpl(GeoPoints.EMPTY_COORDINATE, GeoPoints.EMPTY_COORDINATE); - result.setRecordTime(new Date()); + result.setRecordTime(getDate()); } else if (currentLocation.getTopiaId() != null) { result = new GeoPointImpl(currentLocation.getLatitude(), currentLocation.getLongitude()); result.setAltitude(currentLocation.getAltitude()); result.setSpeed(currentLocation.getSpeed()); - result.setRecordTime(new Date()); + result.setRecordTime(getDate()); } else { result = currentLocation; @@ -171,11 +172,17 @@ longitude += random.nextDouble() - 0.5; currentLocation = new GeoPointImpl(latitude, longitude); - currentLocation.setRecordTime(new Date()); + currentLocation.setRecordTime(getDate()); count--; } } } + protected Date getDate() { + Date result = new Date(); + result = DateUtils.setMilliseconds(result, 0); + return result; + } + } Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java 2012-08-30 13:28:13 UTC (rev 497) @@ -31,6 +31,7 @@ import fr.ulr.sammoa.persistence.GeoPointImpl; import fr.ulr.sammoa.persistence.GeoPoints; import gnu.io.CommPortIdentifier; +import org.apache.commons.lang3.time.DateUtils; import org.dinopolis.gpstool.gpsinput.GPSDataProcessor; import org.dinopolis.gpstool.gpsinput.GPSDevice; import org.dinopolis.gpstool.gpsinput.GPSException; @@ -173,15 +174,17 @@ // } double latitude = lastPosition != null - ? lastPosition.getLatitude() : GeoPoints.EMPTY_COORDINATE; + ? lastPosition.getLatitude() + : GeoPoints.EMPTY_COORDINATE; + double longitude = lastPosition != null - ? lastPosition.getLongitude() : GeoPoints.EMPTY_COORDINATE; + ? lastPosition.getLongitude() + : GeoPoints.EMPTY_COORDINATE; GeoPoint result = new GeoPointImpl(latitude, longitude); result.setAltitude(lastAltitude); result.setSpeed(lastSpeed); - // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp - result.setRecordTime(new Date()); + result.setRecordTime(getDate()); if (logger.isWarnEnabled() && lastPosition == null) { logger.warn("Retrieve a location without any coordinates : {}", result); @@ -255,6 +258,13 @@ super.finalize(); } + protected Date getDate() { + // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp + Date result = new Date(); + result = DateUtils.setMilliseconds(result, 0); + return result; + } + /** * Si l'on recoit des evenements, c'est que le gps fonctionne. * Il sont envoyé par le traitement des flux NMEA et propagé par le Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-08-30 13:28:13 UTC (rev 497) @@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory; import java.io.File; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -102,30 +103,33 @@ Date newTime; if (position > 0) { - newTime = DateUtils.addMilliseconds(previousTime, (int) position); + newTime = DateUtils.addSeconds(previousTime, (int) position); } else { - // Arbitrary add 1 second for the newTime - newTime = DateUtils.addMilliseconds(previousTime, 1000); + newTime = new Date(); + newTime.setTime(previousTime.getTime()); - // Ensure that newTime is before nextRoute time - Route nextRoute = Routes.findNext(routes, currentRoute); - if (nextRoute != null) { - - logger.debug(String.format("Next route %1$s at %2$tH:%2$tM:%2$tS.%2$tL", - nextRoute.getRouteType(), - nextRoute.getBeginTime()) - ); - - // If greater or equals than the nextRoute, we use the middle - // time between previous and next route - if (newTime.after(nextRoute.getBeginTime()) - || newTime.equals(nextRoute.getBeginTime())) { - - newTime = Routes.getMiddleTime(currentRoute, nextRoute); - } - } +// // Arbitrary add 1 second for the newTime +// newTime = DateUtils.addMilliseconds(previousTime, 1000); +// +// // Ensure that newTime is before nextRoute time +// Route nextRoute = Routes.findNext(routes, currentRoute); +// if (nextRoute != null) { +// +// logger.debug(String.format("Next route %1$s at %2$tH:%2$tM:%2$tS.%2$tL", +// nextRoute.getRouteType(), +// nextRoute.getBeginTime()) +// ); +// +// // If greater or equals than the nextRoute, we use the middle +// // time between previous and next route +// if (newTime.after(nextRoute.getBeginTime()) +// || newTime.equals(nextRoute.getBeginTime())) { +// +// newTime = Routes.getMiddleTime(currentRoute, nextRoute); +// } +// } } if (logger.isDebugEnabled()) { @@ -140,12 +144,16 @@ // Create a new location if no one is available for the newTime if (!location.getRecordTime().equals(newTime)) { - // Note that the captureDelay is keeped but maybe we need to update it - // depends on modified time ? result = new GeoPointImpl(location.getLatitude(), location.getLongitude()); result.setSpeed(location.getSpeed()); result.setAltitude(location.getAltitude()); - result.setCaptureDelay(location.getCaptureDelay()); + + // Ensure captureDelay of the new recording time + long locationSeconds = DateUtils.getFragmentInSeconds(location.getRecordTime(), Calendar.MINUTE); + long newSeconds = DateUtils.getFragmentInSeconds(newTime, Calendar.MINUTE); + int captureDelay = (int) newSeconds - (int) locationSeconds; + result.setCaptureDelay(captureDelay); + result.setFlight(flight); result.setRecordTime(newTime); SammoaDAOHelper.getGeoPointDAO(tx).create(result); Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/FlightDAOImpl.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/FlightDAOImpl.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/FlightDAOImpl.java 2012-08-30 13:28:13 UTC (rev 497) @@ -92,23 +92,4 @@ } } -// public List<Flight> findAllByCampaignOrderedByBeginDateDesc(Campaign campaign) { -// -// List<Flight> result; -// -// String ql = String.format("FROM %1$s WHERE %2$s = :campaign ORDER BY %3$s DESC", -// FlightImpl.class.getSimpleName(), -// Flight.PROPERTY_CAMPAIGN, -// Flight.PROPERTY_BEGIN_DATE -// ); -// -// try { -// result = context.findAll(ql, "campaign", campaign); -// -// } catch (TopiaException e) { -// throw new TopiaRuntimeException(e); -// } -// return result; -// } - } Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointDAOImpl.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointDAOImpl.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointDAOImpl.java 2012-08-30 13:28:13 UTC (rev 497) @@ -32,11 +32,9 @@ public List<E> findAllByFlightOrderedByRecordTime(Flight flight) { - String ql = String.format("FROM %1$s WHERE %2$s = :flight ORDER BY %3$s", - GeoPointImpl.class.getSimpleName(), - GeoPoint.PROPERTY_FLIGHT, - GeoPoint.PROPERTY_RECORD_TIME - ); + String ql = "FROM GeoPointImpl " + + "WHERE flight = :flight " + + "ORDER BY recordTime"; try { List<E> result = findAllByQuery(ql, "flight", flight); Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointImpl.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointImpl.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointImpl.java 2012-08-30 13:28:13 UTC (rev 497) @@ -52,6 +52,7 @@ .append(PROPERTY_ALTITUDE, altitude) .append(PROPERTY_SPEED, speed) .append(PROPERTY_RECORD_TIME, recordTime) + .append(PROPERTY_CAPTURE_DELAY, captureDelay) .build(); } } Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java 2012-08-30 13:28:13 UTC (rev 497) @@ -101,7 +101,7 @@ for (Date date : dates) { // We continue starting from the previous index to avoid loop on all the date list - index = getClosestDateIndex(index > 0 ? index - 1 : 0, geoPointDates, date); + index = getBeforeDateIndex(index > 0 ? index - 1 : 0, geoPointDates, date); result.add(geoPoints.get(index)); } @@ -120,41 +120,44 @@ List<Date> geoPointDates = Lists.transform(source, toDate()); - int index = getClosestDateIndex(0, geoPointDates, date); + int index = getBeforeDateIndex(0, geoPointDates, date); result = geoPoints.get(index); } return result; } - protected static int getClosestDateIndex(int startIndex, List<Date> source, Date date) { + protected static int getBeforeDateIndex(int startIndex, List<Date> source, Date date) { int size = source.size(); for (int index = startIndex; index < size; index++) { int nextIndex = index + 1; if (nextIndex < size) { - Date before = source.get(index); - Date after = source.get(nextIndex); + Date end = source.get(nextIndex); - // If the date is equal or before we take the current index - if (date.equals(before) || date.before(before)) { + if (date.before(end)) { return index; + } - // If the date is before the next date, we check which one - // of the before and after is the nearest value and we return - // its index - } else if (date.before(after)) { - - long diffBefore = date.getTime() - before.getTime(); - long diffAfter = after.getTime() - date.getTime(); - - if (diffBefore <= diffAfter) { - return index; - - } else { - return nextIndex; - } - } +// // If the date is equal or before we take the current index +// if (date.equals(before) || date.before(before)) { +// return index; +// +// // If the date is before the next date, we check which one +// // of the before and after is the nearest value and we return +// // its index +// } else if (date.before(after)) { +// +// long diffBefore = date.getTime() - before.getTime(); +// long diffAfter = after.getTime() - date.getTime(); +// +// if (diffBefore <= diffAfter) { +// return index; +// +// } else { +// return nextIndex; +// } +// } } } // We loop over the whole list, we return the last index Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/ObservationDAOImpl.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/ObservationDAOImpl.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/ObservationDAOImpl.java 2012-08-30 13:28:13 UTC (rev 497) @@ -81,7 +81,9 @@ public List<E> findAllByFlightOrderedByObservationTime(Flight flight) { - String ql = "FROM ObservationImpl WHERE flight = :flight ORDER BY observationTime"; + String ql = "FROM ObservationImpl " + + "WHERE flight = :flight " + + "ORDER BY observationTime, topiaCreateDate"; try { List<E> result = findAllByQuery(ql, "flight", flight); @@ -93,7 +95,9 @@ public int findLastObservationNumber(Flight flight) { - String ql = "SELECT max(observationNumber) FROM ObservationImpl WHERE flight = :flight"; + String ql = "SELECT max(observationNumber) " + + "FROM ObservationImpl " + + "WHERE flight = :flight"; try { Integer queryResult = findByQuery(Integer.class, ql, "flight", flight); Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteDAOImpl.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteDAOImpl.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteDAOImpl.java 2012-08-30 13:28:13 UTC (rev 497) @@ -39,7 +39,7 @@ String ql = "FROM RouteImpl " + "WHERE flight = :flight " + - "ORDER BY beginTime"; + "ORDER BY beginTime, topiaCreateDate"; try { List<E> result = findAllByQuery(ql, "flight", flight); @@ -54,7 +54,7 @@ String ql = "FROM RouteImpl " + "WHERE flight = :flight " + "AND deleted = :deleted " + - "ORDER BY beginTime DESC"; + "ORDER BY beginTime DESC, topiaCreateDate DESC"; try { List<E> queryResults = findAllByQueryWithBound( @@ -75,7 +75,7 @@ "AND routeType = :type " + "AND beginTime <= :date " + "AND deleted = :deleted " + - "ORDER BY beginTime DESC"; + "ORDER BY beginTime DESC, topiaCreateDate DESC"; try { List<E> queryResults = findAllByQueryWithBound( @@ -100,7 +100,7 @@ "WHERE flight = :flight " + "AND beginTime <= :date " + "AND deleted = :deleted " + - "ORDER BY beginTime DESC"; + "ORDER BY beginTime DESC, topiaCreateDate DESC"; try { List<E> queryResults = findAllByQueryWithBound( Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Routes.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Routes.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Routes.java 2012-08-30 13:28:13 UTC (rev 497) @@ -28,6 +28,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.collect.ComparisonChain; import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; @@ -94,31 +95,38 @@ boolean result = Objects.equal(o1.getRouteType(), o2.getRouteType()); - result &= Objects.equal(o1.getTransectFlight(), o2.getTransectFlight()); - result &= Objects.equal(o1.getCircleBackCause(), o2.getCircleBackCause()); + // We assume that time equality for a same routeType is an equivalence + if (result && Objects.equal(o1.getBeginTime(), o2.getBeginTime())) { + result = true; - result &= Objects.equal(o1.isDeleted(), o2.isDeleted()); + } else { - result &= Objects.equal(o1.getSeaState(), o2.getSeaState()); - result &= Objects.equal(o1.getSwell(), o2.getSwell()); - result &= Objects.equal(o1.getTurbidity(), o2.getTurbidity()); - result &= Objects.equal(o1.getCloudCover(), o2.getCloudCover()); - result &= Objects.equal(o1.getSkyGlint(), o2.getSkyGlint()); - result &= Objects.equal(o1.getGlareFrom(), o2.getGlareFrom()); - result &= Objects.equal(o1.getGlareTo(), o2.getGlareTo()); - result &= Objects.equal(o1.isGlareUnder(), o2.isGlareUnder()); - result &= Objects.equal(o1.getGlareSeverity(), o2.getGlareSeverity()); - result &= Objects.equal(o1.getSubjectiveConditions(), o2.getSubjectiveConditions()); + result &= Objects.equal(o1.getTransectFlight(), o2.getTransectFlight()); + result &= Objects.equal(o1.getCircleBackCause(), o2.getCircleBackCause()); - result &= o1.getObserverPosition().size() == o2.getObserverPosition().size(); + result &= Objects.equal(o1.isDeleted(), o2.isDeleted()); - if (result) { + result &= Objects.equal(o1.getSeaState(), o2.getSeaState()); + result &= Objects.equal(o1.getSwell(), o2.getSwell()); + result &= Objects.equal(o1.getTurbidity(), o2.getTurbidity()); + result &= Objects.equal(o1.getCloudCover(), o2.getCloudCover()); + result &= Objects.equal(o1.getSkyGlint(), o2.getSkyGlint()); + result &= Objects.equal(o1.getGlareFrom(), o2.getGlareFrom()); + result &= Objects.equal(o1.getGlareTo(), o2.getGlareTo()); + result &= Objects.equal(o1.isGlareUnder(), o2.isGlareUnder()); + result &= Objects.equal(o1.getGlareSeverity(), o2.getGlareSeverity()); + result &= Objects.equal(o1.getSubjectiveConditions(), o2.getSubjectiveConditions()); - for (ObserverPosition position1 : o1.getObserverPosition()) { - ObserverPosition position2 = - o2.getObserverPositionByPosition(position1.getPosition()); + result &= o1.getObserverPosition().size() == o2.getObserverPosition().size(); - result &= Objects.equal(position1.getObserver(), position2.getObserver()); + if (result) { + + for (ObserverPosition position1 : o1.getObserverPosition()) { + ObserverPosition position2 = + o2.getObserverPositionByPosition(position1.getPosition()); + + result &= Objects.equal(position1.getObserver(), position2.getObserver()); + } } } return result; @@ -160,15 +168,15 @@ return Iterables.find(routes, new WithObservationPredicate(observation, routes, ignoreDeleted), null); } - public static Date getMiddleTime(Route previousRoute, Route nextRoute) { - Date previousTime = previousRoute.getBeginTime(); - Date nextTime = nextRoute.getBeginTime(); +// public static Date getMiddleTime(Route previousRoute, Route nextRoute) { +// Date previousTime = previousRoute.getBeginTime(); +// Date nextTime = nextRoute.getBeginTime(); +// +// long diff = nextTime.getTime() - previousTime.getTime(); +// Date result = new Date(nextTime.getTime() - diff / 2); +// return result; +// } - long diff = nextTime.getTime() - previousTime.getTime(); - Date result = new Date(nextTime.getTime() - diff / 2); - return result; - } - public static Predicate<Route> isDeleted() { return IS_DELETED_PREDICATE; } @@ -181,12 +189,12 @@ @Override public int compare(Route o1, Route o2) { -// int result = ComparisonChain -// .start() -// .compare(o1.getBeginTime(), o2.getBeginTime()) -// .compare(o1.getTopiaCreateDate(), o2.getTopiaCreateDate()) -// .result(); - return o1.getBeginTime().compareTo(o2.getBeginTime()); + int result = ComparisonChain + .start() + .compare(o1.getBeginTime(), o2.getBeginTime()) + .compare(o1.getTopiaCreateDate(), o2.getTopiaCreateDate()) + .result(); + return result; } }; Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/TransectDAOImpl.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/TransectDAOImpl.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/TransectDAOImpl.java 2012-08-30 13:28:13 UTC (rev 497) @@ -32,13 +32,9 @@ public List<E> findAllByCampaignOrderedByName(Campaign campaign) { - String ql = String.format("FROM %1$s WHERE %2$s.%3$s.%4$s = :campaign ORDER BY %5$s", - TransectImpl.class.getSimpleName(), - Transect.PROPERTY_STRATE, - Strate.PROPERTY_SECTOR, - Sector.PROPERTY_CAMPAIGN, - Transect.PROPERTY_NAME - ); + String ql = "FROM TransectImpl " + + "WHERE strate.sector.campaign = :campaign " + + "ORDER BY name"; try { List<E> result = findAllByQuery(ql, "campaign", campaign); Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/TransectFlightDAOImpl.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/TransectFlightDAOImpl.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/TransectFlightDAOImpl.java 2012-08-30 13:28:13 UTC (rev 497) @@ -35,7 +35,8 @@ public Map<Transect, Long> countAllByTransect() { - String ql = "SELECT transect, count(*) FROM TransectFlightImpl " + + String ql = "SELECT transect, count(*) " + + "FROM TransectFlightImpl " + "GROUP BY transect"; try { @@ -55,8 +56,10 @@ public Map<Transect, Long> countAllByTransects(Collection<Transect> transects) { - String ql = "SELECT transect, count(*) FROM TransectFlightImpl " + - "WHERE transect IN (:transects) GROUP BY transect"; + String ql = "SELECT transect, count(*) " + + "FROM TransectFlightImpl " + + "WHERE transect IN (:transects) " + + "GROUP BY transect"; try { List<Object[]> queryResults = findAllByQuery( @@ -86,23 +89,5 @@ getContext().executeSQL(builder.toString()); } -// public Long countByTransect(Transect transect) { -// -// Long result; -// -// String ql = String.format("SELECT count(*) FROM %1$s WHERE %2$s = :transect", -// TransectFlightImpl.class.getSimpleName(), -// TransectFlight.PROPERTY_TRANSECT -// ); -// -// try { -// result = (Long) context.findUnique(ql, "transect", transect); -// -// } catch (TopiaException e) { -// throw new TopiaRuntimeException(e); -// } -// return result; -// } - } Modified: trunk/sammoa-persistence/src/main/xmi/sammoa.properties =================================================================== --- trunk/sammoa-persistence/src/main/xmi/sammoa.properties 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/main/xmi/sammoa.properties 2012-08-30 13:28:13 UTC (rev 497) @@ -112,10 +112,10 @@ ############## ROUTE -fr.ulr.sammoa.persistence.Route.class.tagvalue.naturalIdMutable=true -fr.ulr.sammoa.persistence.Route.attribute.routeType.tagvalue.naturalId=true -fr.ulr.sammoa.persistence.Route.attribute.flight.tagvalue.naturalId=true -fr.ulr.sammoa.persistence.Route.attribute.beginTime.tagvalue.naturalId=true +#fr.ulr.sammoa.persistence.Route.class.tagvalue.naturalIdMutable=true +#fr.ulr.sammoa.persistence.Route.attribute.routeType.tagvalue.naturalId=true +#fr.ulr.sammoa.persistence.Route.attribute.flight.tagvalue.naturalId=true +#fr.ulr.sammoa.persistence.Route.attribute.beginTime.tagvalue.naturalId=true # transectFlight is not a collection (EAGER load) fr.ulr.sammoa.persistence.Route.attribute.transectFlight.tagvalue.lazy=false Modified: trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/GeoPointsTest.java =================================================================== --- trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/GeoPointsTest.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/GeoPointsTest.java 2012-08-30 13:28:13 UTC (rev 497) @@ -55,7 +55,7 @@ Assert.assertEquals(3, result.size()); Assert.assertEquals(4000, result.get(0).getRecordTime().getTime()); - Assert.assertEquals(6000, result.get(1).getRecordTime().getTime()); + Assert.assertEquals(5000, result.get(1).getRecordTime().getTime()); Assert.assertEquals(85000, result.get(2).getRecordTime().getTime()); } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.css =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.css 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.css 2012-08-30 13:28:13 UTC (rev 497) @@ -85,7 +85,7 @@ #beginDatePicker { patternLayout:{_("sammoa.dateTimePattern")}; showPopupButton:false; - editable:false; + editable:{model.isValidationMode()}; date:{bean.getBeginDate()}; } @@ -96,7 +96,7 @@ #endDatePicker { patternLayout:{_("sammoa.dateTimePattern")}; showPopupButton:false; - editable:false; + editable:{model.isValidationMode()}; date:{bean.getEndDate()}; } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-30 13:28:13 UTC (rev 497) @@ -58,9 +58,11 @@ import fr.ulr.sammoa.ui.swing.util.SammoaUtil; import fr.ulr.sammoa.ui.swing.util.TableDataChangeListener; import fr.ulr.sammoa.ui.swing.util.TextCellEditor; +import fr.ulr.sammoa.ui.swing.util.TimeCellEditor; import fr.ulr.sammoa.ui.swing.util.ValidRowHighlightPredicate; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.JAXXDatePicker; import jaxx.runtime.swing.JAXXWidgetUtil; import jaxx.runtime.swing.editor.cell.NumberCellEditor; import jaxx.runtime.validator.swing.SwingListValidatorDataLocator; @@ -154,7 +156,6 @@ ui.getConavComboBox().setRenderer(observeCellRenderer); JTable errorTable = ui.getErrorTable(); - SwingListValidatorMessageTableModel errorTableModel = ui.getErrorTableModel(); // prepare error table ui SwingValidatorUtil.installUI( @@ -170,139 +171,282 @@ } ); - FlightUIModel flightUIModel = ui.getFlightUIModel(); - String validatorContext = flightUIModel.isValidationMode() ? "validation" : "onBoard"; + initRouteTable(); - // init route section - { - JXTable table = ui.getRouteTable(); + initObservationTable(); + } - RouteTableModel tableModel = ui.getRouteTableModel(); - BeanListValidator<Route> validator = ui.getRouteValidator(); - validator.setContext(validatorContext); - getParentUI().setContextValue(validator, ROUTE_VALIDATOR_CONTEXT_VALUE); + /** + * Add hightlighters on the editor of beans. + * + * @param validator the validator where to find bean states + * @param editor the editor of beans + * @param dataLocator the data locator + * @param scopes scopes to hightlight + * @param <O> type of bean to validate + * @since 2.5.3 + */ + public static <O> void addHightLighterOnEditor(BeanListValidator<O> validator, + JXTable editor, + SwingListValidatorDataLocator<O> dataLocator, + NuitonValidatorScope... scopes) { - init(table, new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { + for (NuitonValidatorScope scope : scopes) { - if (!e.getValueIsAdjusting()) { + SwingListValidatorHighlightPredicate<O> predicate = SwingListValidatorHighlightPredicate.newPredicate( + scope, + validator, dataLocator + ); - ListSelectionModel listSelectionModel = - (ListSelectionModel) e.getSource(); - int firstIndex = e.getFirstIndex(); - int lastIndex = e.getLastIndex(); - Integer newSelectedRow = null; + Highlighter highlighter = SammoaUtil.newBackgroundColorHighlighter( + predicate, SwingValidatorUtil.getColor(scope)); + editor.addHighlighter(highlighter); + } + } - if (listSelectionModel.isSelectionEmpty()) { + public Observer getObserverByPosition(Route route, Position position) { + Observer result; + if (route != null) { + ObserverPosition observerPosition = + route.getObserverPositionByPosition(position); + result = observerPosition.getObserver(); - // no selection - } else if (listSelectionModel.isSelectedIndex(firstIndex)) { + } else { + result = null; + } + return result; + } - // use first index - newSelectedRow = firstIndex; - } else if (listSelectionModel.isSelectedIndex(lastIndex)) { + public void setObserverByPosition(Observer newValue, Position position) { + if (!comboIsAdjusting) { - // use last index - newSelectedRow = lastIndex; - } - FlightUIModel flightUIModel = ui.getFlightUIModel(); - List<Route> routes = flightUIModel.getRoutes(); - Route route = null; + FlightUIModel flightUIModel = ui.getFlightUIModel(); - if (newSelectedRow != null && - newSelectedRow < routes.size()) { - route = routes.get(newSelectedRow); + Route route = flightUIModel.getRouteEditBean(); + if (route != null) { - if (logger.isInfoEnabled()) { - logger.info("Select route from index {}", newSelectedRow); - } + if (logger.isDebugEnabled()) { + logger.debug(String.format("Set observer %s for position %s", newValue, position)); + } - if (flightUIModel.isValidationMode()) { - getParentUI().getHandler().getFlightController().setCurrentRoute(route); - } + FlightService flightService = context.getService(FlightService.class); + flightService.setRouteObserverByPosition(route, newValue, position); - } else { - if (logger.isInfoEnabled()) { - logger.info("No route selected"); - } + // the method setObserverByPosition could update other positions + // so we need to refresh all comboboxes + comboIsAdjusting = true; + + try { + if (Position.NAVIGATOR != position) { + ObserverPosition navPosition = route.getObserverPositionByPosition(Position.NAVIGATOR); + ui.getNavComboBox().setSelectedItem(navPosition.getObserver()); + } + + if (Position.FRONT_LEFT != position) { + ObserverPosition leftPosition = route.getObserverPositionByPosition(Position.FRONT_LEFT); + ui.getLeftComboBox().setSelectedItem(leftPosition.getObserver()); + } + + if (Position.FRONT_RIGHT != position) { + ObserverPosition rightPosition = route.getObserverPositionByPosition(Position.FRONT_RIGHT); + ui.getRightComboBox().setSelectedItem(rightPosition.getObserver()); + } + + if (Position.CO_NAVIGATOR != position) { + ObserverPosition conavPosition = route.getObserverPositionByPosition(Position.CO_NAVIGATOR); + ui.getConavComboBox().setSelectedItem(conavPosition.getObserver()); + } + } finally { + + comboIsAdjusting = false; + } + + // Fire on TableModel to update the row (highlighting) + // ensureRowIndex in case of new route, otherwise the size is + // not updated yet in tableModel and an IndexOutOfBounds appears + int index = flightUIModel.indexOfRoutes(route); + SwingUtil.ensureRowIndex(ui.getRouteTableModel(), index); + ui.getRouteTableModel().fireTableRowsUpdated(index, index); + + // Update observation table to ensure observer's name during validation + if (flightUIModel.isValidationMode()) { + fireObservationsUpdated(route, false); + } + } + } + } + + @Override + public void stateChanged(DeviceStateEvent event) { + DeviceState state = event.getNewValue(); + if (DeviceState.ERROR == state) { + ui.getObservationTable().setBackground(DEVICE_ERROR_BACKGROUND_COLOR); + + } else { + ui.getObservationTable().setBackground(Color.WHITE); + } + } + + public void initRouteTable() { + + FlightUIModel flightUIModel = ui.getFlightUIModel(); + + JXTable table = ui.getRouteTable(); + RouteTableModel tableModel = ui.getRouteTableModel(); + + SwingUtil.setI18nTableHeaderRenderer( + table, + n_("sammoa.observations.routeTable.column.effortNumber"), + n_("sammoa.observations.routeTable.column.effortNumber.tip"), + n_("sammoa.observations.routeTable.column.beginTime"), + n_("sammoa.observations.routeTable.column.beginTime.tip"), + n_("sammoa.observations.routeTable.column.routeType"), + n_("sammoa.observations.routeTable.column.routeType.tip"), + n_("sammoa.observations.routeTable.column.transect"), + n_("sammoa.observations.routeTable.column.transect.tip"), + n_("sammoa.observations.routeTable.column.seaState"), + n_("sammoa.observations.routeTable.column.seaState.tip"), + n_("sammoa.observations.routeTable.column.swell"), + n_("sammoa.observations.routeTable.column.swell.tip"), + n_("sammoa.observations.routeTable.column.turbidity"), + n_("sammoa.observations.routeTable.column.turbidity.tip"), + n_("sammoa.observations.routeTable.column.skyGlint"), + n_("sammoa.observations.routeTable.column.skyGlint.tip"), + n_("sammoa.observations.routeTable.column.glareFrom"), + n_("sammoa.observations.routeTable.column.glareFrom.tip"), + n_("sammoa.observations.routeTable.column.glareTo"), + n_("sammoa.observations.routeTable.column.glareTo.tip"), + n_("sammoa.observations.routeTable.column.glareSeverity"), + n_("sammoa.observations.routeTable.column.glareSeverity.tip"), + n_("sammoa.observations.routeTable.column.glareUnder"), + n_("sammoa.observations.routeTable.column.glareUnder.tip"), + n_("sammoa.observations.routeTable.column.cloudCover"), + n_("sammoa.observations.routeTable.column.cloudCover.tip"), + n_("sammoa.observations.routeTable.column.subjectiveConditions"), + n_("sammoa.observations.routeTable.column.subjectiveConditions.tip"), + n_("sammoa.observations.routeTable.column.unexpectedLeft"), + n_("sammoa.observations.routeTable.column.unexpectedLeft.tip"), + n_("sammoa.observations.routeTable.column.unexpectedRight"), + n_("sammoa.observations.routeTable.column.unexpectedRight.tip"), + n_("sammoa.observations.routeTable.column.comment"), + n_("sammoa.observations.routeTable.column.comment.tip"), + n_("sammoa.observations.routeTable.column.deleted"), + n_("sammoa.observations.routeTable.column.deleted.tip") + ); + + init(table, new ListSelectionListener() { + + @Override + public void valueChanged(ListSelectionEvent e) { + + if (!e.getValueIsAdjusting()) { + + ListSelectionModel listSelectionModel = + (ListSelectionModel) e.getSource(); + int firstIndex = e.getFirstIndex(); + int lastIndex = e.getLastIndex(); + Integer newSelectedRow = null; + + if (listSelectionModel.isSelectionEmpty()) { + + // no selection + } else if (listSelectionModel.isSelectedIndex(firstIndex)) { + + // use first index + newSelectedRow = firstIndex; + } else if (listSelectionModel.isSelectedIndex(lastIndex)) { + + // use last index + newSelectedRow = lastIndex; + } + FlightUIModel flightUIModel = ui.getFlightUIModel(); + List<Route> routes = flightUIModel.getRoutes(); + Route route = null; + + if (newSelectedRow != null && + newSelectedRow < routes.size()) { + route = routes.get(newSelectedRow); + + if (logger.isInfoEnabled()) { + logger.info("Select route from index {}", newSelectedRow); } - // set new route in model to validate - flightUIModel.setRouteEditBean(route); + } else { + if (logger.isInfoEnabled()) { + logger.info("No route selected"); + } } + + // set new route in model to validate + flightUIModel.setRouteEditBean(route); } - }); + } + }); - SwingUtil.setI18nTableHeaderRenderer( - table, - n_("sammoa.observations.routeTable.column.effortNumber"), - n_("sammoa.observations.routeTable.column.effortNumber.tip"), - n_("sammoa.observations.routeTable.column.beginTime"), - n_("sammoa.observations.routeTable.column.beginTime.tip"), - n_("sammoa.observations.routeTable.column.routeType"), - n_("sammoa.observations.routeTable.column.routeType.tip"), - n_("sammoa.observations.routeTable.column.transect"), - n_("sammoa.observations.routeTable.column.transect.tip"), - n_("sammoa.observations.routeTable.column.seaState"), - n_("sammoa.observations.routeTable.column.seaState.tip"), - n_("sammoa.observations.routeTable.column.swell"), - n_("sammoa.observations.routeTable.column.swell.tip"), - n_("sammoa.observations.routeTable.column.turbidity"), - n_("sammoa.observations.routeTable.column.turbidity.tip"), - n_("sammoa.observations.routeTable.column.skyGlint"), - n_("sammoa.observations.routeTable.column.skyGlint.tip"), - n_("sammoa.observations.routeTable.column.glareFrom"), - n_("sammoa.observations.routeTable.column.glareFrom.tip"), - n_("sammoa.observations.routeTable.column.glareTo"), - n_("sammoa.observations.routeTable.column.glareTo.tip"), - n_("sammoa.observations.routeTable.column.glareSeverity"), - n_("sammoa.observations.routeTable.column.glareSeverity.tip"), - n_("sammoa.observations.routeTable.column.glareUnder"), - n_("sammoa.observations.routeTable.column.glareUnder.tip"), - n_("sammoa.observations.routeTable.column.cloudCover"), - n_("sammoa.observations.routeTable.column.cloudCover.tip"), - n_("sammoa.observations.routeTable.column.subjectiveConditions"), - n_("sammoa.observations.routeTable.column.subjectiveConditions.tip"), - n_("sammoa.observations.routeTable.column.unexpectedLeft"), - n_("sammoa.observations.routeTable.column.unexpectedLeft.tip"), - n_("sammoa.observations.routeTable.column.unexpectedRight"), - n_("sammoa.observations.routeTable.column.unexpectedRight.tip"), - n_("sammoa.observations.routeTable.column.comment"), - n_("sammoa.observations.routeTable.column.comment.tip"), - n_("sammoa.observations.routeTable.column.deleted"), - n_("sammoa.observations.routeTable.column.deleted.tip") - ); - + // Listeners + { int columnToEditOnInsert = RouteTableModel.RouteColumn.SEA_STATE.ordinal(); flightUIModel.addPropertyChangeListener( FlightUIModel.PROPERTY_ROUTES, new TableDataChangeListener(table, columnToEditOnInsert) ); - // Highlighter for no modification - table.addHighlighter( - SammoaUtil.newForegroundColorHighlighter( - new RouteNoModificationHighlightPredicate(tableModel), - SammoaColors.ROUTE_NO_MODIFICATION_ROW_COLOR) - ); + if (flightUIModel.isValidationMode()) { + flightUIModel.addPropertyChangeListener( + FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, + new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Route route = (Route) evt.getNewValue(); + getParentUI().getHandler().getFlightController().setCurrentRoute(route); + } + } + ); + } + } + + // Validation + { + JTable errorTable = ui.getErrorTable(); + SwingListValidatorMessageTableModel errorTableModel = ui.getErrorTableModel(); + + BeanListValidator<Route> validator = ui.getRouteValidator(); + validator.setContext(getValidatorContext()); + getParentUI().setContextValue(validator, ROUTE_VALIDATOR_CONTEXT_VALUE); + RouteValidatorDataLocator dataLocator = new RouteValidatorDataLocator(); SwingValidatorUtil.registerListValidator( validator, errorTableModel, table, - errorTable, dataLocator); + errorTable, + dataLocator + ); addHightLighterOnEditor( - validator, table, dataLocator, + validator, + table, + dataLocator, NuitonValidatorScope.ERROR, - NuitonValidatorScope.WARNING); + NuitonValidatorScope.WARNING + ); + for (Route route : tableModel.getBean()) { + validator.addBean(route); + } + } + + // Highlighters + { table.addHighlighter(SammoaUtil.newForegroundColorHighlighter( + new RouteNoModificationHighlightPredicate(tableModel), + SammoaColors.ROUTE_NO_MODIFICATION_ROW_COLOR) + ); + table.addHighlighter(SammoaUtil.newForegroundColorHighlighter( new DeletedRowHighlightPredicate(flightUIModel.getRoutes()), SammoaColors.DELETED_ROW_COLOR) ); @@ -310,32 +454,106 @@ new ValidRowHighlightPredicate(flightUIModel.getRoutes()), SammoaColors.VALID_ROW_COLOR) ); - - for (Route route : tableModel.getBean()) { - validator.addBean(route); - } } + } - // init observation section - { - JXTable table = ui.getObservationTable(); + public void initObservationTable() { - BeanListValidator<Observation> validator = ui.getObservationValidator(); - validator.setContext(validatorContext); - getParentUI().setContextValue(validator, OBSERVATION_VALIDATOR_CONTEXT_VALUE); + FlightUIModel flightUIModel = ui.getFlightUIModel(); - FlightController flightController = - getParentUI().getHandler().getFlightController(); + JXTable table = ui.getObservationTable(); + ObservationTableModel tableModel = ui.getObservationTableModel(); - if (flightUIModel.isValidationMode()) { + SwingUtil.setI18nTableHeaderRenderer( + table, + n_("sammoa.observations.observationTable.column.observationNumber"), + n_("sammoa.observations.observationTable.column.observationNumber.tip"), + n_("sammoa.observations.observationTable.column.observationTime"), + n_("sammoa.observations.observationTable.column.observationTime.tip"), + n_("sammoa.observations.observationTable.column.position"), + n_("sammoa.observations.observationTable.column.position.tip"), + n_("sammoa.observations.observationTable.column.podSize"), + n_("sammoa.observations.observationTable.column.podSize.tip"), + n_("sammoa.observations.observationTable.column.species"), + n_("sammoa.observations.observationTable.column.species.tip"), + n_("sammoa.observations.observationTable.column.age"), + n_("sammoa.observations.observationTable.column.age.tip"), + n_("sammoa.observations.observationTable.column.decAngle"), + n_("sammoa.observations.observationTable.column.decAngle.tip"), + n_("sammoa.observations.observationTable.column.cue"), + n_("sammoa.observations.observationTable.column.cue.tip"), + n_("sammoa.observations.observationTable.column.behaviour"), + n_("sammoa.observations.observationTable.column.behaviour.tip"), + n_("sammoa.observations.observationTable.column.swimDir"), + n_("sammoa.observations.observationTable.column.swimDir.tip"), + n_("sammoa.observations.observationTable.column.calves"), + n_("sammoa.observations.observationTable.column.calves.tip"), + n_("sammoa.observations.observationTable.column.photo"), + n_("sammoa.observations.observationTable.column.photo.tip"), + n_("sammoa.observations.observationTable.column.comment"), + n_("sammoa.observations.observationTable.column.comment.tip"), + n_("sammoa.observations.observationTable.column.observationStatus"), + n_("sammoa.observations.observationTable.column.observationStatus.tip"), + n_("sammoa.observations.observationTable.column.deleted"), + n_("sammoa.observations.observationTable.column.deleted.tip"), + n_("sammoa.observations.observationTable.column.circleback"), + n_("sammoa.observations.observationTable.column.circleback.tip") + ); - // nothing for the moment + init(table, new ListSelectionListener() { - } else { - flightController.getDeviceManager(GpsHandler.class).addDeviceStateListener(this); - flightController.getDeviceManager(AudioRecorder.class).addDeviceStateListener(this); + @Override + public void valueChanged(ListSelectionEvent e) { + + FlightUIModel flightUIModel = ui.getFlightUIModel(); + + if (!e.getValueIsAdjusting()) { + + ListSelectionModel listSelectionModel = + (ListSelectionModel) e.getSource(); + int firstIndex = e.getFirstIndex(); + int lastIndex = e.getLastIndex(); + Integer newSelectedRow = null; + + if (listSelectionModel.isSelectionEmpty()) { + + // no selection + } else if (listSelectionModel.isSelectedIndex(firstIndex)) { + + // use first index + newSelectedRow = firstIndex; + } else if (listSelectionModel.isSelectedIndex(lastIndex)) { + + // use last index + newSelectedRow = lastIndex; + } + List<Observation> observations = flightUIModel.getObservations(); + Observation observation = null; + + if (newSelectedRow != null && + newSelectedRow < observations.size()) { + observation = observations.get(newSelectedRow); + + if (logger.isInfoEnabled()) { + logger.info("Select observation from index {}", newSelectedRow); + } + + } else { + if (logger.isInfoEnabled()) { + logger.info("No observation selected"); + } + } + + // set new observation in model to validate + flightUIModel.setObservationEditBean(observation); + } } + }); + // Listeners + { + FlightController flightController = + getParentUI().getHandler().getFlightController(); int columnToEditOnInsert = ObservationTableModel.ObservationColumn.POD_SIZE.ordinal(); flightUIModel.addPropertyChangeListener( @@ -345,107 +563,118 @@ // For CircleBack buttons flightUIModel.addPropertyChangeListener( - FlightUIModel.PROPERTY_FLIGHT_STATE, observationUpdateListener); + FlightUIModel.PROPERTY_FLIGHT_STATE, + new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + FlightUIModel model = (FlightUIModel) evt.getSource(); + + if (model.sizeObservations() > 0) { + + ui.getObservationTableModel().fireTableRowsUpdated( + 0, model.sizeObservations() - 1); + } + } + }); + // For highlighting depends on selected route flightUIModel.addPropertyChangeListener( - FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, observationUpdateListener); + FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, + new PropertyChangeListener() { - SwingUtil.setI18nTableHeaderRenderer( - table, - n_("sammoa.observations.observationTable.column.observationNumber"), - n_("sammoa.observations.observationTable.column.observationNumber.tip"), - n_("sammoa.observations.observationTable.column.observationTime"), - n_("sammoa.observations.observationTable.column.observationTime.tip"), - n_("sammoa.observations.observationTable.column.position"), - n_("sammoa.observations.observationTable.column.position.tip"), - n_("sammoa.observations.observationTable.column.podSize"), - n_("sammoa.observations.observationTable.column.podSize.tip"), - n_("sammoa.observations.observationTable.column.species"), - n_("sammoa.observations.observationTable.column.species.tip"), - n_("sammoa.observations.observationTable.column.age"), - n_("sammoa.observations.observationTable.column.age.tip"), - n_("sammoa.observations.observationTable.column.decAngle"), - n_("sammoa.observations.observationTable.column.decAngle.tip"), - n_("sammoa.observations.observationTable.column.cue"), - n_("sammoa.observations.observationTable.column.cue.tip"), - n_("sammoa.observations.observationTable.column.behaviour"), - n_("sammoa.observations.observationTable.column.behaviour.tip"), - n_("sammoa.observations.observationTable.column.swimDir"), - n_("sammoa.observations.observationTable.column.swimDir.tip"), - n_("sammoa.observations.observationTable.column.calves"), - n_("sammoa.observations.observationTable.column.calves.tip"), - n_("sammoa.observations.observationTable.column.photo"), - n_("sammoa.observations.observationTable.column.photo.tip"), - n_("sammoa.observations.observationTable.column.comment"), - n_("sammoa.observations.observationTable.column.comment.tip"), - n_("sammoa.observations.observationTable.column.observationStatus"), - n_("sammoa.observations.observationTable.column.observationStatus.tip"), - n_("sammoa.observations.observationTable.column.deleted"), - n_("sammoa.observations.observationTable.column.deleted.tip"), - n_("sammoa.observations.observationTable.column.circleback"), - n_("sammoa.observations.observationTable.column.circleback.tip") - ); - -// init(dataTable, new ObservationTableListSelectionListener(ui.getFlightUIModel())); - init(table, new ListSelectionListener() { @Override - public void valueChanged(ListSelectionEvent e) { + public void propertyChange(PropertyChangeEvent evt) { - FlightUIModel flightUIModel = ui.getFlightUIModel(); + Route oldValue = (Route) evt.getOldValue(); + if (oldValue != null) { + fireObservationsUpdated(oldValue, false); + } + Route newValue = (Route) evt.getNewValue(); + if (newValue != null) { + fireObservationsUpdated(newValue, true); + } + } + }); - if (!e.getValueIsAdjusting()) { + if (flightUIModel.isValidationMode()) { - ListSelectionModel listSelectionModel = - (ListSelectionModel) e.getSource(); - int firstIndex = e.getFirstIndex(); - int lastIndex = e.getLastIndex(); - Integer newSelectedRow = null; + // For validation, time change is listening to properly select the route + flightUIModel.addPropertyChangeListener( + FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, + new PropertyChangeListener() { - if (listSelectionModel.isSelectionEmpty()) { + @Override + public void propertyChange(PropertyChangeEvent evt) { - // no selection - } else if (listSelectionModel.isSelectedIndex(firstIndex)) { + Observation oldValue = (Observation) evt.getNewValue(); + if (oldValue != null) { + oldValue.removePropertyChangeListener( + Observation.PROPERTY_OBSERVATION_TIME, + observationTimeChangeListener); + } + Observation newValue = (Observation) evt.getNewValue(); + if (newValue != null) { + newValue.addPropertyChangeListener( + Observation.PROPERTY_OBSERVATION_TIME, + observationTimeChangeListener); - // use first index - newSelectedRow = firstIndex; - } else if (listSelectionModel.isSelectedIndex(lastIndex)) { - - // use last index - newSelectedRow = lastIndex; + selectRouteByObservation(newValue); } - List<Observation> observations = flightUIModel.getObservations(); - Observation observation = null; + } + }); - if (newSelectedRow != null && - newSelectedRow < observations.size()) { - observation = observations.get(newSelectedRow); + } else { + flightController.getDeviceManager(GpsHandler.class).addDeviceStateListener(this); + flightController.getDeviceManager(AudioRecorder.class).addDeviceStateListener(this); + } + } - if (logger.isInfoEnabled()) { - logger.info("Select observation from index {}", newSelectedRow); - } + table.addHighlighter( + SammoaUtil.newBackgroundColorHighlighter( + new ObservationForSelectedRouteHighlightPredicate(flightUIModel), + SammoaColors.OBSERVATION_FOR_ROUTE_ROW_COLOR) + ); - // We need to auto-select the route in validation mode - if (flightUIModel.isValidationMode()) { - Route route = Routes.findWithObservation( - flightUIModel.getRoutes(), observation, true); + // Validation + { + JTable errorTable = ui.getErrorTable(); + SwingListValidatorMessageTableModel errorTableModel = ui.getErrorTableModel(); - int routeIndex = flightUIModel.indexOfRoutes(route); - ui.getRouteTable().getSelectionModel().setSelectionInterval(routeIndex, routeIndex); - } + BeanListValidator<Observation> validator = ui.getObservationValidator(); + validator.setContext(getValidatorContext()); + getParentUI().setContextValue(validator, OBSERVATION_VALIDATOR_CONTEXT_VALUE); - } else { - if (logger.isInfoEnabled()) { - logger.info("No observation selected"); - } - } + ObservationValidatorDataLocator dataLocator = + new ObservationValidatorDataLocator(); - // set new observation in model to validate - flightUIModel.setObservationEditBean(observation); - } - } - }); + SwingValidatorUtil.registerListValidator( + validator, + errorTableModel, + table, + errorTable, + dataLocator + ); + addHightLighterOnEditor( + validator, + table, + dataLocator, + NuitonValidatorScope.ERROR, + NuitonValidatorScope.WARNING + ); + + for (Observation observation : tableModel.getBean()) { + validator.addBean(observation); + } + } + + // Renderers/Editors/Highlighters + { + UIDecoratorService decoratorService = + context.getService(UIDecoratorService.class); + TableCellRenderer stringRenderer = table.getDefaultRenderer(String.class); // ObservationStatus @@ -499,26 +728,6 @@ column.setCellRenderer(editorRenderer); } - ObservationValidatorDataLocator dataLocator = - new ObservationValidatorDataLocator(); - - SwingValidatorUtil.registerListValidator( - validator, - errorTableModel, - table, - errorTable, dataLocator); - - table.addHighlighter( - SammoaUtil.newBackgroundColorHighlighter( - new ObservationForSelectedRouteHighlightPredicate(flightUIModel), - SammoaColors.OBSERVATION_FOR_ROUTE_ROW_COLOR) - ); - - addHightLighterOnEditor( - validator, table, dataLocator, - NuitonValidatorScope.ERROR, - NuitonValidatorScope.WARNING); - table.addHighlighter(SammoaUtil.newForegroundColorHighlighter( new DeletedRowHighlightPredicate(flightUIModel.getObservations()), SammoaColors.DELETED_ROW_COLOR) @@ -527,139 +736,12 @@ new ValidRowHighlightPredicate(flightUIModel.getObservations()), SammoaColors.VALID_ROW_COLOR) ); - - ObservationTableModel tableModel = ui.getObservationTableModel(); - for (Observation observation : tableModel.getBean()) { - validator.addBean(observation); - } } } - - /** - * Add hightlighters on the editor of beans. - * - * @param validator the validator where to find bean states - * @param editor the editor of beans - * @param dataLocator the data locator - * @param scopes scopes to hightlight - * @param <O> type of bean to validate - * @since 2.5.3 - */ - public static <O> void addHightLighterOnEditor(BeanListValidator<O> validator, - JXTable editor, - SwingListValidatorDataLocator<O> dataLocator, - NuitonValidatorScope... scopes) { - - for (NuitonValidatorScope scope : scopes) { - - SwingListValidatorHighlightPredicate<O> predicate = SwingListValidatorHighlightPredicate.newPredicate( - scope, - validator, dataLocator - ); - - Highlighter highlighter = SammoaUtil.newBackgroundColorHighlighter( - predicate, SwingValidatorUtil.getColor(scope)); - editor.addHighlighter(highlighter); - } - } - - public Observer getObserverByPosition(Route route, Position position) { - Observer result; - if (route != null) { - ObserverPosition observerPosition = - route.getObserverPositionByPosition(position); - result = observerPosition.getObserver(); - - } else { - result = null; - } - return result; - } - - public void setObserverByPosition(Observer newValue, Position position) { - if (!comboIsAdjusting) { - - FlightUIModel flightUIModel = ui.getFlightUIModel(); - - Route route = flightUIModel.getRouteEditBean(); - if (route != null) { - - if (logger.isDebugEnabled()) { - logger.debug(String.format("Set observer %s for position %s", newValue, position)); - } - - FlightService flightService = context.getService(FlightService.class); - flightService.setRouteObserverByPosition(route, newValue, position); - - // the method setObserverByPosition could update other positions - // so we need to refresh all comboboxes - comboIsAdjusting = true; - - try { - if (Position.NAVIGATOR != position) { - ObserverPosition navPosition = route.getObserverPositionByPosition(Position.NAVIGATOR); - ui.getNavComboBox().setSelectedItem(navPosition.getObserver()); - } - - if (Position.FRONT_LEFT != position) { - ObserverPosition leftPosition = route.getObserverPositionByPosition(Position.FRONT_LEFT); - ui.getLeftComboBox().setSelectedItem(leftPosition.getObserver()); - } - - if (Position.FRONT_RIGHT != position) { - ObserverPosition rightPosition = route.getObserverPositionByPosition(Position.FRONT_RIGHT); - ui.getRightComboBox().setSelectedItem(rightPosition.getObserver()); - } - - if (Position.CO_NAVIGATOR != position) { - ObserverPosition conavPosition = route.getObserverPositionByPosition(Position.CO_NAVIGATOR); - ui.getConavComboBox().setSelectedItem(conavPosition.getObserver()); - } - } finally { - - comboIsAdjusting = false; - } - - // Fire on TableModel to update the row (highlighting) - // ensureRowIndex in case of new route, otherwise the size is - // not updated yet in tableModel and an IndexOutOfBounds appears - int index = flightUIModel.indexOfRoutes(route); - SwingUtil.ensureRowIndex(ui.getRouteTableModel(), index); - ui.getRouteTableModel().fireTableRowsUpdated(index, index); - - // Update observation table to ensure observer's name during validation - if (flightUIModel.isValidationMode()) { - updateObservationTable(route, false); - } - } - } - } - - @Override - public void stateChanged(DeviceStateEvent event) { - DeviceState state = event.getNewValue(); - if (DeviceState.ERROR == state) { - ui.getObservationTable().setBackground(DEVICE_ERROR_BACKGROUND_COLOR); - - } else { - ui.getObservationTable().setBackground(Color.WHITE); - } - } - public void init(final JXTable table, - ListSelectionListener selectionListener) { + ListSelectionListener selectionListener) { - // make tab key to focus only next editable cell -// table.setSelectionModel(new ForceSelectionSelectionModel()); -// table.setSelectionBackground(null); -// table.setSelectionForeground(Color.BLACK); -// -//// table.setSortable(context.isValidationMode()); -// table.setSortable(false); - -// table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); - final Action moveToNextEditableCell = new MoveToNextEditableCellAction(table); final Action moveToPreviousEditableCell = new MoveToPreviousEditableCellAction(table); final Action moveToPreviousRowEditableCell = new MoveToPreviousRowEditableAction(table); @@ -674,6 +756,7 @@ // Key adapter à ajouter sur les éditeurs où l'on souhaite gérer les // touches "entrer", "gauche", "doite" de facon personnalisée. KeyListener goNextCellAdapter = new KeyAdapter() { + @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER || @@ -693,7 +776,7 @@ } }; - // TextCellEditor + // Text { TextCellEditor editor = new TextCellEditor(); JTextField textField = editor.getComponent(); @@ -702,7 +785,8 @@ // textField.setBorder(BasicBorders.getTextFieldBorder()); table.setDefaultEditor(String.class, editor); } - // NumberCellEditor + + // Number { NumberCellEditor<Integer> editor = JAXXWidgetUtil.newNumberTableCellEditor(Integer.class, false); @@ -715,48 +799,41 @@ table.setDefaultEditor(Integer.class, editor); } - // Boolean editor + // Boolean { + TableCellRenderer renderer = table.getDefaultRenderer(Boolean.class); + table.setDefaultRenderer(boolean.class, renderer); + TableCellEditor editor = table.getDefaultEditor(Boolean.class); table.setDefaultEditor(boolean.class, editor); - TableCellRenderer renderer = table.getDefaultRenderer(Boolean.class); - table.setDefaultRenderer(boolean.class, renderer); } - // Renderers - TableCellRenderer defaultDateCellRenderer = table.getDefaultRenderer(Date.class); - table.setDefaultRenderer(Date.class, JAXXWidgetUtil.newDateTableCellRenderer(defaultDateCellRenderer, _("sammoa.timePattern"))); + // Date + { + TableCellRenderer defaultDateCellRenderer = table.getDefaultRenderer(Date.class); + TableCellRenderer renderer = JAXXWidgetUtil.newDateTableCellRenderer( + defaultDateCellRenderer, _("sammoa.timePattern")); + table.setDefaultRenderer(Date.class, renderer); + JAXXDatePicker datePicker = new JAXXDatePicker(); + datePicker.setShowPopupButton(false); + datePicker.setPatternLayout(_("sammoa.timePattern")); + JTextField textField = datePicker.getEditor(); +// textField.addKeyListener(goNextCellAdapter); + textField.setBorder(new LineBorder(Color.GRAY, 2)); + table.setDefaultEditor(Date.class, new TimeCellEditor(datePicker)); + } + table.getSelectionModel().addListSelectionListener(selectionListener); SwingUtil.scrollToTableSelection(table); + } -// table.getModel().addTableModelListener(new TableModelListener() { -// @Override -// public void tableChanged(TableModelEvent e) { -// switch (e.getType()) { -// case TableModelEvent.INSERT: -// -// // auto select new added line -// table.getSelectionModel().setSelectionInterval(e.getFirstRow(), e.getFirstRow()); -// Rectangle rect = table.getCellRect(e.getFirstRow(), 0, true); -// table.scrollRectToVisible(rect); -// break; -// -// case TableModelEvent.DELETE: -// case TableModelEvent.UPDATE: -// -// // auto select first line ? -// if (table.getSelectedRow() < 0 && table.getRowCount() > 0) { -// table.getSelectionModel().setSelectionInterval(0, 0); -// } -// break; -// } -// } -// }); + protected String getValidatorContext() { + return ui.getFlightUIModel().isValidationMode() ? "validation" : "onBoard"; } - protected void updateObservationTable(Route route, boolean scrollToFirst) { + protected void fireObservationsUpdated(Route route, boolean scrollToFirst) { FlightUIModel model = ui.getFlightUIModel(); @@ -786,31 +863,22 @@ } } - private PropertyChangeListener observationUpdateListener = new PropertyChangeListener() { + protected void selectRouteByObservation(Observation observation) { - @Override - public void propertyChange(PropertyChangeEvent evt) { + FlightUIModel flightUIModel = ui.getFlightUIModel(); -// int selectedRow = ui.getObservationTable().getSelectedRow(); + Route route = Routes.findWithObservation( + flightUIModel.getRoutes(), observation, true); -// ui.getObservationTableModel().fireTableDataChanged(); + int routeIndex = flightUIModel.indexOfRoutes(route); + ui.getRouteTable().getSelectionModel().setSelectionInterval(routeIndex, routeIndex); + } - if (FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN.equals(evt.getPropertyName())) { + private PropertyChangeListener observationTimeChangeListener = new PropertyChangeListener() { - Route oldValue = (Route) evt.getOldValue(); - if (oldValue != null) { - updateObservationTable(oldValue, false); - } - Route newValue = (Route) evt.getNewValue(); - if (newValue != null) { - updateObservationTable(newValue, true); - } - - } else if (ui.getFlightUIModel().sizeObservations() > 0) { - - ui.getObservationTableModel().fireTableRowsUpdated( - 0, ui.getFlightUIModel().sizeObservations() - 1); - } + @Override + public void propertyChange(PropertyChangeEvent evt) { + selectRouteByObservation((Observation) evt.getSource()); } }; Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java 2012-08-30 13:28:13 UTC (rev 497) @@ -79,7 +79,7 @@ public boolean isCellEditable(int row, int column) { Observation observation = getBean(row); ObservationColumn observationColumn = ObservationColumn.valueOf(column); - boolean result = observationColumn.isEditable(observation); + boolean result = observationColumn.isEditable(observation, flightUIModel.isValidationMode()); return result; } @@ -133,7 +133,13 @@ public enum ObservationColumn { OBSERVATION_NUMBER(false, int.class, Observation.PROPERTY_OBSERVATION_NUMBER), - OBSERVATION_TIME(false, Date.class, Observation.PROPERTY_OBSERVATION_TIME), + OBSERVATION_TIME(true, Date.class, Observation.PROPERTY_OBSERVATION_TIME) { + + @Override + public boolean isEditable(Observation bean, boolean validationMode) { + return super.isEditable(bean, validationMode) && validationMode; + } + }, POSITION(true, Position.class, Observation.PROPERTY_POSITION), POD_SIZE(true, int.class, Observation.PROPERTY_POD_SIZE), SPECIES(true, String.class, Observation.PROPERTY_SPECIES, Species.PROPERTY_CODE) { @@ -231,7 +237,7 @@ } } - public boolean isEditable(Observation bean) { + public boolean isEditable(Observation bean, boolean validationMode) { boolean result = !bean.isValid() && editable; return result; } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java 2012-08-30 13:28:13 UTC (rev 497) @@ -82,7 +82,7 @@ public boolean isCellEditable(int row, int column) { Route route = getRow(row); RouteColumn routeColumn = RouteColumn.valueOf(column); - boolean result = routeColumn.isEditable(route); + boolean result = routeColumn.isEditable(route, flightUIModel.isValidationMode()); return result; } @@ -129,7 +129,13 @@ protected enum RouteColumn { EFFORT_NUMBER(false, Integer.class, Route.PROPERTY_EFFORT_NUMBER), - BEGIN_TIME(false, Date.class, Route.PROPERTY_BEGIN_TIME), + BEGIN_TIME(true, Date.class, Route.PROPERTY_BEGIN_TIME) { + + @Override + public boolean isEditable(Route bean, boolean validationMode) { + return super.isEditable(bean, validationMode) && validationMode; + } + }, ROUTE_TYPE(false, RouteType.class, Route.PROPERTY_ROUTE_TYPE), TRANSECT(false, String.class, Route.PROPERTY_TRANSECT_FLIGHT, @@ -209,7 +215,7 @@ } } - public boolean isEditable(Route bean) { + public boolean isEditable(Route bean, boolean validationMode) { boolean result = !bean.isValid() && editable; return result; } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TextCellEditor.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TextCellEditor.java 2012-08-30 13:27:48 UTC (rev 496) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TextCellEditor.java 2012-08-30 13:28:13 UTC (rev 497) @@ -42,7 +42,11 @@ private static final long serialVersionUID = 1L; public TextCellEditor() { - super(new JTextField()); + this(new JTextField()); + } + + public TextCellEditor(JTextField textField) { + super(textField); setClickCountToStart(1); getComponent().addFocusListener(new FocusListener() { Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TimeCellEditor.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TimeCellEditor.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TimeCellEditor.java 2012-08-30 13:28:13 UTC (rev 497) @@ -0,0 +1,90 @@ +package fr.ulr.sammoa.ui.swing.util; +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * 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 jaxx.runtime.swing.JAXXDatePicker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.JTable; +import javax.swing.table.TableCellEditor; +import java.awt.Component; +import java.util.Calendar; +import java.util.Date; + +/** + * Created: 17/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class TimeCellEditor extends TextCellEditor implements TableCellEditor { + + /** Logger. */ + private static final Logger logger = LoggerFactory.getLogger(TimeCellEditor.class); + + private static final long serialVersionUID = 1L; + + protected JAXXDatePicker datePicker; + + protected Calendar referenceCalendar; + + public TimeCellEditor(JAXXDatePicker datePicker) { + super(datePicker.getEditor()); + this.datePicker = datePicker; + this.referenceCalendar = Calendar.getInstance(); + } + + @Override + public Component getTableCellEditorComponent(JTable table, + Object value, + boolean isSelected, + int row, + int column) { + Date date = (Date) value; + referenceCalendar.setTime(date); + + if (logger.isDebugEnabled()) { + logger.debug(String.format("Set editor date: %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", date)); + } + + datePicker.setDate(date); + return datePicker; + } + + @Override + public Object getCellEditorValue() { + + Calendar editCalendar = Calendar.getInstance(); + editCalendar.setTime(datePicker.getDate()); + editCalendar.set(Calendar.DATE, referenceCalendar.get(Calendar.DATE)); + editCalendar.set(Calendar.MONTH, referenceCalendar.get(Calendar.MONTH)); + editCalendar.set(Calendar.YEAR, referenceCalendar.get(Calendar.YEAR)); + + if (logger.isDebugEnabled()) { + logger.debug(String.format("Get editor date: %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", editCalendar.getTime())); + } + + return editCalendar.getTime(); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TimeCellEditor.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
fdesbois@users.forge.codelutin.com