From fdesbois@users.forge.codelutin.com Mon Sep 10 17:53:25 2012
From: fdesbois@users.forge.codelutin.com
To: sammoa-commits@list.forge.codelutin.com
Subject: [Sammoa-commits] r567 - in
	trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight:	action
 effort
Date: Mon, 10 Sep 2012 17:53:25 +0200
Message-ID: <20120910155325.3EE4415AE0@nuiton.codelutin.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============2587786334974903295=="

--===============2587786334974903295==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

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/V=
alidRouteAction.java
   trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/V=
alidTransectAction.java
   trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/E=
ffortPanelHandler.java

Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/a=
ction/ValidRouteAction.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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 @@
=20
                     validatorIsAdjusting =3D true;
=20
-                    getModel().setCurrentRoute(routeChanged);
                     getModel().setRouteEditBean(routeChanged);
=20
                     getModel().setObservationEditBean(null);

Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/a=
ction/ValidTransectAction.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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 @@
=20
                         // Keep the route selected
                         if (routeEditBean !=3D null && !routeEditBean.isDele=
ted()) {
-                            getModel().setCurrentRoute(routeEditBean);
                             getModel().setRouteEditBean(routeEditBean);
                         }
=20

Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/e=
ffort/EffortPanelHandler.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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 @@
=20
                 // FlightController # change current route
                 getModel().addPropertyChangeListener(
-                        FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN,
-                        new PropertyChangeListener() {
+                        FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new Property=
ChangeListener() {
=20
-                            @Override
-                            public void propertyChange(PropertyChangeEvent e=
vt) {
-                                Route route =3D (Route) evt.getNewValue();
-                                getParentUI().getHandler().getFlightControll=
er().setCurrentRoute(route);
+                    @Override
+                    public void propertyChange(PropertyChangeEvent evt) {
+                        onRouteChangedForValidation(
+                                (Route) evt.getOldValue(),
+                                (Route) evt.getNewValue());
+                    }
+                });
=20
-                                if (route =3D=3D null) {
-                                    // no unselect but ensure valid button (=
a select will cause a loop)
-                                    getModel().setObservationEditBean(null);
-
-                                } else {
-
-                                    // Set audio position
-                                    setAudioReaderPositionDate(route.getBegi=
nTime());
-
-                                    // Remove observationEditBean if not in =
route
-                                    Observation previousObservation =3D getM=
odel().getObservationEditBean();
-                                    if (previousObservation !=3D null
-                                        && !Observations.inRoute(previousObs=
ervation, route, getModel().getRoutes(), true)) {
-
-                                        // no unselect but ensure valid butt=
on (a select will cause a loop)
-                                        getModel().setObservationEditBean(nu=
ll);
-                                    }
-                                }
-                            }
-                        }
-                );
-
                 // Refresh matching routes from selected transectFlight
                 getModel().addPropertyChangeListener(
                         FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, ne=
w PropertyChangeListener() {
=20
                     @Override
                     public void propertyChange(PropertyChangeEvent evt) {
-
-                        TransectFlightModel oldValue =3D (TransectFlightMode=
l) evt.getOldValue();
-                        if (oldValue !=3D null) {
-                            fireRoutesUpdated(oldValue, false);
-                        }
-                        TransectFlightModel newValue =3D (TransectFlightMode=
l) evt.getNewValue();
-                        if (newValue !=3D null) {
-                            fireRoutesUpdated(newValue, true);
-                        }
+                        onTransectFlightChangedForValidation(
+                                (TransectFlightModel) evt.getOldValue(),
+                                (TransectFlightModel) evt.getNewValue());
                     }
                 });
             }
@@ -549,53 +523,28 @@
=20
             // Refresh matching observations from selected route
             getModel().addPropertyChangeListener(
-                    FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN,
-                    new PropertyChangeListener() {
+                    FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new PropertyChan=
geListener() {
=20
-                        @Override
-                        public void propertyChange(PropertyChangeEvent evt) {
+                @Override
+                public void propertyChange(PropertyChangeEvent evt) {
+                    onRouteChanged((Route) evt.getOldValue(),
+                                   (Route) evt.getNewValue());
+                }
+            });
=20
-                            Route oldValue =3D (Route) evt.getOldValue();
-                            if (oldValue !=3D null) {
-                                fireObservationsUpdated(oldValue, false);
-                            }
-                            Route newValue =3D (Route) evt.getNewValue();
-                            if (newValue !=3D null) {
-                                fireObservationsUpdated(newValue, true);
-                            }
-                        }
-                    });
-
             if (getModel().isValidationMode()) {
=20
-                // For validation, time change is listening to properly sele=
ct the route
                 getModel().addPropertyChangeListener(
-                        FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN,
-                        new PropertyChangeListener() {
+                        FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, new Pr=
opertyChangeListener() {
=20
-                            @Override
-                            public void propertyChange(PropertyChangeEvent e=
vt) {
+                    @Override
+                    public void propertyChange(PropertyChangeEvent evt) {
+                        onObservationChangedForValidation(
+                                (Observation) evt.getOldValue(),
+                                (Observation) evt.getNewValue());
+                    }
+                });
=20
-                                Observation oldValue =3D (Observation) evt.g=
etNewValue();
-                                if (oldValue !=3D null) {
-                                    oldValue.removePropertyChangeListener(
-                                            Observation.PROPERTY_OBSERVATION=
_TIME,
-                                            observationTimeChangeListener);
-                                }
-                                Observation newValue =3D (Observation) evt.g=
etNewValue();
-                                if (newValue !=3D null) {
-                                    newValue.addPropertyChangeListener(
-                                            Observation.PROPERTY_OBSERVATION=
_TIME,
-                                            observationTimeChangeListener);
-
-                                    selectRouteByObservation(newValue);
-
-                                    // Set audio position
-                                    setAudioReaderPositionDate(newValue.getO=
bservationTime());
-                                }
-                            }
-                        });
-
             } else {
                 flightController.getDeviceManager(GpsHandler.class).addDevic=
eStateListener(this);
                 flightController.getDeviceManager(AudioRecorder.class).addDe=
viceStateListener(this);
@@ -840,6 +789,72 @@
         SammoaUtil.selectTableRow(ui.getRouteTable(), routeIndex);
     }
=20
+    private void onRouteChanged(Route oldValue, Route newValue) {
+
+        if (oldValue !=3D null) {
+            fireObservationsUpdated(oldValue, false);
+        }
+        if (newValue !=3D null) {
+            fireObservationsUpdated(newValue, true);
+        }
+    }
+
+    private void onTransectFlightChangedForValidation(TransectFlightModel ol=
dValue,
+                                                      TransectFlightModel ne=
wValue) {
+        if (oldValue !=3D null) {
+            fireRoutesUpdated(oldValue, false);
+        }
+        if (newValue !=3D null) {
+            fireRoutesUpdated(newValue, true);
+        }
+    }
+
+    private void onRouteChangedForValidation(Route oldValue,
+                                             Route newValue) {
+
+        getParentUI().getHandler().getFlightController().setCurrentRoute(new=
Value);
+
+        if (newValue =3D=3D null) {
+            // no unselect but ensure valid button (a select will cause a lo=
op)
+            getModel().setObservationEditBean(null);
+
+        } else {
+
+            // Set audio position
+            setAudioReaderPositionDate(newValue.getBeginTime());
+
+            // Remove observationEditBean if not in route
+            Observation previousObservation =3D getModel().getObservationEdi=
tBean();
+            if (previousObservation !=3D null
+                && !Observations.inRoute(previousObservation, newValue, getM=
odel().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 !=3D null) {
+            oldValue.removePropertyChangeListener(
+                    Observation.PROPERTY_OBSERVATION_TIME,
+                    observationTimeChangeListener);
+        }
+
+        if (newValue !=3D null) {
+            newValue.addPropertyChangeListener(
+                    Observation.PROPERTY_OBSERVATION_TIME,
+                    observationTimeChangeListener);
+
+            selectRouteByObservation(newValue);
+
+            // Set audio position
+            setAudioReaderPositionDate(newValue.getObservationTime());
+        }
+    }
+
     private PropertyChangeListener observationTimeChangeListener =3D new Pro=
pertyChangeListener() {
=20
         @Override


--===============2587786334974903295==--


