Author: fdesbois Date: 2012-09-10 17:53:25 +0200 (Mon, 10 Sep 2012) New Revision: 567 Url: http://forge.codelutin.com/repositories/revision/sammoa/567 Log: little cleaning Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java 2012-09-10 13:33:34 UTC (rev 566) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java 2012-09-10 15:53:25 UTC (rev 567) @@ -93,7 +93,6 @@ validatorIsAdjusting = true; - getModel().setCurrentRoute(routeChanged); getModel().setRouteEditBean(routeChanged); getModel().setObservationEditBean(null); Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java 2012-09-10 13:33:34 UTC (rev 566) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java 2012-09-10 15:53:25 UTC (rev 567) @@ -129,7 +129,6 @@ // Keep the route selected if (routeEditBean != null && !routeEditBean.isDeleted()) { - getModel().setCurrentRoute(routeEditBean); getModel().setRouteEditBean(routeEditBean); } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-10 13:33:34 UTC (rev 566) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-10 15:53:25 UTC (rev 567) @@ -360,51 +360,25 @@ // FlightController # change current route getModel().addPropertyChangeListener( - FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, - new PropertyChangeListener() { + FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Route route = (Route) evt.getNewValue(); - getParentUI().getHandler().getFlightController().setCurrentRoute(route); + @Override + public void propertyChange(PropertyChangeEvent evt) { + onRouteChangedForValidation( + (Route) evt.getOldValue(), + (Route) evt.getNewValue()); + } + }); - if (route == null) { - // no unselect but ensure valid button (a select will cause a loop) - getModel().setObservationEditBean(null); - - } else { - - // Set audio position - setAudioReaderPositionDate(route.getBeginTime()); - - // Remove observationEditBean if not in route - Observation previousObservation = getModel().getObservationEditBean(); - if (previousObservation != null - && !Observations.inRoute(previousObservation, route, getModel().getRoutes(), true)) { - - // no unselect but ensure valid button (a select will cause a loop) - getModel().setObservationEditBean(null); - } - } - } - } - ); - // Refresh matching routes from selected transectFlight getModel().addPropertyChangeListener( FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - - TransectFlightModel oldValue = (TransectFlightModel) evt.getOldValue(); - if (oldValue != null) { - fireRoutesUpdated(oldValue, false); - } - TransectFlightModel newValue = (TransectFlightModel) evt.getNewValue(); - if (newValue != null) { - fireRoutesUpdated(newValue, true); - } + onTransectFlightChangedForValidation( + (TransectFlightModel) evt.getOldValue(), + (TransectFlightModel) evt.getNewValue()); } }); } @@ -549,53 +523,28 @@ // Refresh matching observations from selected route getModel().addPropertyChangeListener( - FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, - new PropertyChangeListener() { + FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { + @Override + public void propertyChange(PropertyChangeEvent evt) { + onRouteChanged((Route) evt.getOldValue(), + (Route) evt.getNewValue()); + } + }); - Route oldValue = (Route) evt.getOldValue(); - if (oldValue != null) { - fireObservationsUpdated(oldValue, false); - } - Route newValue = (Route) evt.getNewValue(); - if (newValue != null) { - fireObservationsUpdated(newValue, true); - } - } - }); - if (getModel().isValidationMode()) { - // For validation, time change is listening to properly select the route getModel().addPropertyChangeListener( - FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, - new PropertyChangeListener() { + FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { + @Override + public void propertyChange(PropertyChangeEvent evt) { + onObservationChangedForValidation( + (Observation) evt.getOldValue(), + (Observation) evt.getNewValue()); + } + }); - 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); - - selectRouteByObservation(newValue); - - // Set audio position - setAudioReaderPositionDate(newValue.getObservationTime()); - } - } - }); - } else { flightController.getDeviceManager(GpsHandler.class).addDeviceStateListener(this); flightController.getDeviceManager(AudioRecorder.class).addDeviceStateListener(this); @@ -840,6 +789,72 @@ SammoaUtil.selectTableRow(ui.getRouteTable(), routeIndex); } + private void onRouteChanged(Route oldValue, Route newValue) { + + if (oldValue != null) { + fireObservationsUpdated(oldValue, false); + } + if (newValue != null) { + fireObservationsUpdated(newValue, true); + } + } + + private void onTransectFlightChangedForValidation(TransectFlightModel oldValue, + TransectFlightModel newValue) { + if (oldValue != null) { + fireRoutesUpdated(oldValue, false); + } + if (newValue != null) { + fireRoutesUpdated(newValue, true); + } + } + + private void onRouteChangedForValidation(Route oldValue, + Route newValue) { + + getParentUI().getHandler().getFlightController().setCurrentRoute(newValue); + + if (newValue == null) { + // no unselect but ensure valid button (a select will cause a loop) + getModel().setObservationEditBean(null); + + } else { + + // Set audio position + setAudioReaderPositionDate(newValue.getBeginTime()); + + // Remove observationEditBean if not in route + Observation previousObservation = getModel().getObservationEditBean(); + if (previousObservation != null + && !Observations.inRoute(previousObservation, newValue, getModel().getRoutes(), true)) { + + // no unselect but ensure valid button (a select will cause a loop) + getModel().setObservationEditBean(null); + } + } + } + + private void onObservationChangedForValidation(Observation oldValue, + Observation newValue) { + + if (oldValue != null) { + oldValue.removePropertyChangeListener( + Observation.PROPERTY_OBSERVATION_TIME, + observationTimeChangeListener); + } + + if (newValue != null) { + newValue.addPropertyChangeListener( + Observation.PROPERTY_OBSERVATION_TIME, + observationTimeChangeListener); + + selectRouteByObservation(newValue); + + // Set audio position + setAudioReaderPositionDate(newValue.getObservationTime()); + } + } + private PropertyChangeListener observationTimeChangeListener = new PropertyChangeListener() { @Override