r510 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util sammoa-ui-swing/src/main/resources/i18n
Author: fdesbois Date: 2012-09-03 16:57:07 +0200 (Mon, 03 Sep 2012) New Revision: 510 Url: http://forge.codelutin.com/repositories/revision/sammoa/510 Log: fixes #1372 : - add new DeleteTransectAction - support addAll in TableDataChangeListener - support checkbox in ButtonActionTableCellEditorRenderer - add transectFlightEditBean matching selection in FlightUIModel Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/DeleteTransectAction.java Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ValidationService.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextTransectAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/SammoaAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidObservationAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidRouteAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidTransectAction.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/flight/FlightUI.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectTableModel.java 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/util/ButtonActionTableCellEditorRenderer.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TableDataChangeListener.java trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties 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-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-09-03 14:57:07 UTC (rev 510) @@ -305,6 +305,38 @@ } } + public void deleteTansectFlight(Flight flight, + TransectFlight transectFlight) { + + TopiaContext tx = beginTransaction(); + try { + + deleteTansectFlight(tx, flight, transectFlight); + + tx.commitTransaction(); + + } catch (TopiaException ex) { + throw new TopiaRuntimeException(ex); + } finally { + endTransaction(tx); + } + } + + protected void deleteTansectFlight(TopiaContext tx, + Flight flight, + TransectFlight transectFlight) + throws TopiaException { + + SammoaDAOHelper.getObserverPositionDAO(tx).deleteAll( + transectFlight.getObserverPosition()); + + flight.removeTransectFlight(transectFlight); + + SammoaDAOHelper.getTransectFlightDAO(tx).delete(transectFlight); + + SammoaDAOHelper.getFlightDAO(tx).update(flight); + } + /** * Remove the given flight from db and storage. * Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ValidationService.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ValidationService.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ValidationService.java 2012-09-03 14:57:07 UTC (rev 510) @@ -51,27 +51,22 @@ TopiaContext tx = beginTransaction(); try { + TransectFlight result; - TransectFlightDAO transectFlightDAO = SammoaDAOHelper.getTransectFlightDAO(tx); - TransectFlight result = transectFlightDAO.findByTopiaId(transectFlight.getTopiaId()); - boolean valid = !transectFlight.isValid(); if (transectFlight.isDeleted()) { -// ObserverPositionDAO observerPositionDAO = SammoaDAOHelper.getObserverPositionDAO(tx); -// observerPositionDAO.deleteAll(transectFlightExists.getObserverPosition()); -// -// FlightDAO flightDAO = SammoaDAOHelper.getFlightDAO(tx); -// Flight flightExists = flightDAO.findByTopiaId(flight.getTopiaId()); -// -// flightExists.removeTransectFlight(transectFlightExists); -// -// // XXX-fdesbois-2012-08-23 : maybe useless with cascade on delete ? -// transectFlightDAO.delete(transectFlightExists); + // Use FlightService for delete + context.getService(FlightService.class).deleteTansectFlight(tx, flight, transectFlight); + result = null; + } else { + TransectFlightDAO transectFlightDAO = SammoaDAOHelper.getTransectFlightDAO(tx); + result = transectFlightDAO.findByTopiaId(transectFlight.getTopiaId()); + RouteDAO routeDAO = SammoaDAOHelper.getRouteDAO(tx); List<Route> routes = routeDAO.findAllByTransectFlight(result); @@ -153,7 +148,6 @@ if (route.isDeleted()) { - // TODO-fdesbois-2012-08-23 : manage observerPosition attached to observations ObserverPositionDAO observerPositionDAO = SammoaDAOHelper.getObserverPositionDAO(tx); observerPositionDAO.deleteAll(route.getObserverPosition()); Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/DeleteTransectAction.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/DeleteTransectAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/DeleteTransectAction.java 2012-09-03 14:57:07 UTC (rev 510) @@ -0,0 +1,78 @@ +package fr.ulr.sammoa.ui.swing.action; + +import fr.ulr.sammoa.application.FlightService; +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.ui.swing.flight.FlightUI; +import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel; +import fr.ulr.sammoa.ui.swing.util.SammoaUtil; +import jaxx.runtime.JAXXContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.Action; +import javax.swing.JComponent; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/09/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class DeleteTransectAction extends SammoaAction { + + /** Logger. */ + private static final Logger logger = LoggerFactory.getLogger(DeleteTransectAction.class); + + public static final String CLIENT_PROPERTY_TRANSECT_FLIGHT = "transectFlight"; + + public DeleteTransectAction(JAXXContext context) { + super((String) null, context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.deleteTransect.tip")); + } + + @Override + public void actionPerformed(ActionEvent e) { + Object source = e.getSource(); + if (source instanceof JComponent) { + JComponent comp = (JComponent) source; + + final TransectFlightModel transectFlight = + (TransectFlightModel) comp.getClientProperty(CLIENT_PROPERTY_TRANSECT_FLIGHT); + + if (logger.isDebugEnabled()) { + logger.debug("Change transect {} deleted flag to {}", + transectFlight.getSource().getTransect().getName(), + !transectFlight.isDeleted()); + } + + transectFlight.setDeleted(!transectFlight.isDeleted()); + + // #1372: If flight isn't started, we propose to delete definitely the transect + if (FlightState.WAITING == getModel().getFlightState() && transectFlight.isDeleted()) { + + if (SammoaUtil.askQuestion((FlightUI) context, _("sammoa.confirmDialog.deleteTransect.message"))) { + + FlightService service = + getSammoaUIContext().getService(FlightService.class); + service.deleteTansectFlight(getModel().getFlight(), transectFlight.getSource()); + + if (logger.isDebugEnabled()) { + logger.debug("Delete transect {} ", + transectFlight.getSource().getTransect().getName()); + } + + // Update model + int index = getModel().indexOfTransectFlights(transectFlight); + getModel().removeTransectFlight(index); + } + } + } + } + + @Override + protected boolean checkEnabled() { + return true; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/DeleteTransectAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextTransectAction.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextTransectAction.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextTransectAction.java 2012-09-03 14:57:07 UTC (rev 510) @@ -52,11 +52,10 @@ @Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); - TransectFlightModel transectFlight = null; - if (source instanceof JComponent) { JComponent component = (JComponent) e.getSource(); - transectFlight = (TransectFlightModel) component.getClientProperty(CLIENT_PROPERTY_TRANSECT_FLIGHT); + TransectFlightModel transectFlight = + (TransectFlightModel) component.getClientProperty(CLIENT_PROPERTY_TRANSECT_FLIGHT); getFlightController().setNextTransect(transectFlight.getSource()); } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/SammoaAction.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/SammoaAction.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/SammoaAction.java 2012-09-03 14:57:07 UTC (rev 510) @@ -24,6 +24,7 @@ package fr.ulr.sammoa.ui.swing.action; import fr.ulr.sammoa.application.flightController.FlightController; +import fr.ulr.sammoa.ui.swing.SammoaUIContext; import fr.ulr.sammoa.ui.swing.flight.FlightUIHandler; import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; import jaxx.runtime.JAXXContext; @@ -69,6 +70,10 @@ return context.getContextValue(FlightUIHandler.class).getModel(); } + protected SammoaUIContext getSammoaUIContext() { + return context.getContextValue(SammoaUIContext.class); + } + protected void bindModelProperties(String... properties) { for (String property : properties) { getModel().addPropertyChangeListener(property, enabledListener); Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidAction.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidAction.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidAction.java 2012-09-03 14:57:07 UTC (rev 510) @@ -31,6 +31,7 @@ import fr.ulr.sammoa.persistence.Validable; import fr.ulr.sammoa.ui.swing.SammoaUIContext; import jaxx.runtime.JAXXContext; +import org.jdesktop.beans.AbstractBean; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.Resource; import org.nuiton.validator.bean.list.BeanListValidator; @@ -108,8 +109,8 @@ return getValidator(Observation.class); } - protected <E extends TopiaEntity & Validable> void bindValidableModel(String propertyName, - Class<E> propertyClass) { + protected <E extends TopiaEntity & Validable> void bindValidableEntity(String propertyName, + Class<E> propertyClass) { getModel().addPropertyChangeListener(propertyName, new PropertyChangeListener() { @@ -129,4 +130,26 @@ } }); } + + protected <E extends AbstractBean & Validable> void bindValidableModel(String propertyName, + Class<E> propertyClass) { + + getModel().addPropertyChangeListener(propertyName, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + AbstractBean oldValue = (AbstractBean) evt.getOldValue(); + if (oldValue != null) { + oldValue.removePropertyChangeListener( + "deleted", enabledListener); + } + AbstractBean newValue = (AbstractBean) evt.getNewValue(); + if (newValue != null) { + newValue.addPropertyChangeListener( + "deleted", enabledListener); + } + enabledListener.propertyChange(evt); + } + }); + } } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidObservationAction.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidObservationAction.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidObservationAction.java 2012-09-03 14:57:07 UTC (rev 510) @@ -50,7 +50,7 @@ public ValidObservationAction(JAXXContext context) { super(_("sammoa.action.validObservation"), context); putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.validObservation.tip")); - bindValidableModel(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, Observation.class); + bindValidableEntity(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, Observation.class); } @Override Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidRouteAction.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidRouteAction.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidRouteAction.java 2012-09-03 14:57:07 UTC (rev 510) @@ -27,7 +27,6 @@ import fr.ulr.sammoa.persistence.Observation; import fr.ulr.sammoa.persistence.Route; import fr.ulr.sammoa.persistence.Routes; -import fr.ulr.sammoa.ui.swing.SammoaUIContext; import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; import jaxx.runtime.JAXXContext; import org.slf4j.Logger; @@ -55,8 +54,8 @@ public ValidRouteAction(JAXXContext context) { super(_("sammoa.action.validRoute"), context); putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.validRoute.tip")); - bindValidableModel(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, Observation.class); - bindValidableModel(FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, Route.class); + bindValidableEntity(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, Observation.class); + bindValidableEntity(FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, Route.class); } @Override @@ -89,7 +88,7 @@ // Reload all observations FlightService service = - context.getContextValue(SammoaUIContext.class).getService(FlightService.class); + getSammoaUIContext().getService(FlightService.class); getModel().clearObservation(); getModel().addAllObservation(service.getObservations(getModel().getFlight())); Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidTransectAction.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidTransectAction.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidTransectAction.java 2012-09-03 14:57:07 UTC (rev 510) @@ -28,7 +28,6 @@ import fr.ulr.sammoa.persistence.Route; import fr.ulr.sammoa.persistence.TransectFlight; import fr.ulr.sammoa.persistence.TransectFlights; -import fr.ulr.sammoa.ui.swing.SammoaUIContext; import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel; import jaxx.runtime.JAXXContext; @@ -57,21 +56,21 @@ public ValidTransectAction(JAXXContext context) { super(_("sammoa.action.validTransect"), context); putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.validTransect.tip")); - bindValidableModel(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, Observation.class); - bindValidableModel(FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, Route.class); + bindValidableEntity(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, Observation.class); + bindValidableEntity(FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, Route.class); + bindValidableModel(FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, TransectFlightModel.class); } @Override public void actionPerformed(ActionEvent e) { - Route route = getModel().getRouteEditBean(); + TransectFlightModel bean = getModel().getTransectFlightEditBean(); - if (route != null && route.getTransectFlight() != null) { + if (bean != null) { - TransectFlight transectFlight = route.getTransectFlight(); + TransectFlight transectFlight = bean.getSource(); - int index = TransectFlightModel.indexOfTransectFlight( - getModel().getTransectFlights(), transectFlight); + int index = getModel().indexOfTransectFlights(bean); if (logger.isDebugEnabled()) { logger.debug("Validation for transectFlight {} : {}", @@ -91,18 +90,20 @@ validatorIsAdjusting = true; + Route routeEditBean = getModel().getRouteEditBean(); + getModel().setRouteEditBean(null); // Reload all routes FlightService service = - context.getContextValue(SammoaUIContext.class).getService(FlightService.class); + getSammoaUIContext().getService(FlightService.class); getModel().clearRoute(); getModel().addAllRoute(service.getRoutes(getModel().getFlight())); // Keep the route selected - if (!route.isDeleted()) { - getModel().setCurrentRoute(route); - getModel().setRouteEditBean(route); + if (routeEditBean != null && !routeEditBean.isDeleted()) { + getModel().setCurrentRoute(routeEditBean); + getModel().setRouteEditBean(routeEditBean); } getModel().setObservationEditBean(null); @@ -120,11 +121,11 @@ protected boolean checkEnabled() { boolean result = isEnabled(); if (!validatorIsAdjusting) { - Route route = getModel().getRouteEditBean(); - if (route != null) { - TransectFlight bean = route.getTransectFlight(); - result = bean != null - && TransectFlights.isValid(bean, + TransectFlightModel bean = getModel().getTransectFlightEditBean(); + if (bean != null) { + TransectFlight transectflight = bean.getSource(); + result = transectflight != null + && TransectFlights.isValid(transectflight, getRouteValidator(), getObservationValidator()); } 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-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.css 2012-09-03 14:57:07 UTC (rev 510) @@ -144,6 +144,9 @@ #transectTable { model:{transectTableModel}; selectionModel:{transectFlightSelectionModel}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; } #startButton { Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx 2012-09-03 14:57:07 UTC (rev 510) @@ -28,6 +28,7 @@ <import> java.awt.BorderLayout java.awt.Dimension + java.awt.Color javax.swing.ListSelectionModel javax.swing.DefaultListSelectionModel Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-03 14:57:07 UTC (rev 510) @@ -79,6 +79,7 @@ import fr.ulr.sammoa.persistence.Observations; import fr.ulr.sammoa.persistence.Observer; import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.persistence.Routes; import fr.ulr.sammoa.persistence.Strate; import fr.ulr.sammoa.persistence.Transect; import fr.ulr.sammoa.persistence.TransectFlight; @@ -91,6 +92,7 @@ import fr.ulr.sammoa.ui.swing.action.BeginAction; import fr.ulr.sammoa.ui.swing.action.CenterObservationAction; import fr.ulr.sammoa.ui.swing.action.CircleBackAction; +import fr.ulr.sammoa.ui.swing.action.DeleteTransectAction; import fr.ulr.sammoa.ui.swing.action.EndAction; import fr.ulr.sammoa.ui.swing.action.LeftObservationAction; import fr.ulr.sammoa.ui.swing.action.NextAction; @@ -112,6 +114,8 @@ import fr.ulr.sammoa.ui.swing.util.ColorTableCellRenderer; import fr.ulr.sammoa.ui.swing.util.DeletedRowHighlightPredicate; import fr.ulr.sammoa.ui.swing.util.SammoaUtil; +import fr.ulr.sammoa.ui.swing.util.SelectionModelAdapter; +import fr.ulr.sammoa.ui.swing.util.TableDataChangeListener; import fr.ulr.sammoa.ui.swing.util.ValidRowHighlightPredicate; import jaxx.runtime.JAXXObject; import jaxx.runtime.SwingUtil; @@ -128,6 +132,7 @@ import javax.swing.ActionMap; import javax.swing.DefaultCellEditor; import javax.swing.InputMap; +import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; @@ -138,7 +143,6 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; -import java.awt.Color; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.ItemEvent; @@ -186,6 +190,8 @@ protected FlightController flightController; + protected boolean transectFlightSelectionIsAdjusting; + public FlightUIHandler(SammoaUIContext context, FlightUI ui) { this.context = context; this.ui = ui; @@ -416,53 +422,79 @@ TransectTableModel tableModel = ui.getTransectTableModel(); -// if (getModel().isValidationMode()) { -// -// table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); -// -// SammoaUtil.addTableSelectionListener( -// table, new SelectionModelAdapter<TransectFlightModel>() { -// -// @Override -// public List<TransectFlightModel> getElements() { -// return getModel().getTransectFlights(); -// } -// -// @Override -// public void setSelectedElement(TransectFlightModel element) { -// getModel().setTransectFlightEditBean(element); -// } -// }); -// -// getModel().addPropertyChangeListener( -// FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new PropertyChangeListener() { -// -// @Override -// public void propertyChange(PropertyChangeEvent evt) { -// -// int index = -1; -// -// if (evt.getNewValue() != null) { -// -// Route route = (Route) evt.getNewValue(); -// -// index = TransectFlightModel.indexOfTransectFlight( -// getModel().getTransectFlights(), route.getTransectFlight()); -// } -// -// // Unselect all -// if (index == -1) { -// -//// SammoaUtil.unselectAll(ui.getTransectTable()); -// -// // Select the corresponding transectFlight -// } else { -// ui.getTransectFlightSelectionModel().setSelectionInterval(index, index); -// } -// } -// }); -// } + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_TRANSECT_FLIGHTS, + new TableDataChangeListener(table, TableDataChangeListener.NO_COLUMN_INDEX_TO_EDIT_ON_INSERT)); + if (getModel().isValidationMode()) { + + table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + SammoaUtil.addTableSelectionListener( + table, new SelectionModelAdapter<TransectFlightModel>() { + + @Override + public List<TransectFlightModel> getElements() { + return getModel().getTransectFlights(); + } + + @Override + public void setSelectedElement(TransectFlightModel element) { + getModel().setTransectFlightEditBean(element); + } + }); + + // Select the first route matching the transectFlight + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + TransectFlightModel transectFlight = (TransectFlightModel) evt.getNewValue(); + if (!transectFlightSelectionIsAdjusting && transectFlight != null) { + + transectFlightSelectionIsAdjusting = true; + + Route route = FluentIterable + .from(getModel().getRoutes()) + .filter(Routes.withTransectFlight(transectFlight.getSource())) + .first() + .orNull(); + + getModel().setRouteEditBean(route); + + transectFlightSelectionIsAdjusting = false; + } + } + }); + + // Select the transectFlight matching the route + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + if (!transectFlightSelectionIsAdjusting && evt.getNewValue() != null) { + + transectFlightSelectionIsAdjusting = true; + + Route route = (Route) evt.getNewValue(); + + if (route.getTransectFlight() != null) { + + int index = TransectFlightModel.indexOfTransectFlight( + getModel().getTransectFlights(), route.getTransectFlight()); + ui.getTransectFlightSelectionModel().setSelectionInterval(index, index); + } + + transectFlightSelectionIsAdjusting = false; + } + } + }); + } + NumberCellEditor<Integer> numberCellEditor = JAXXWidgetUtil.newNumberTableCellEditor(Integer.class, false); table.setDefaultEditor(Integer.class, numberCellEditor); table.setDefaultEditor(int.class, numberCellEditor); @@ -513,12 +545,48 @@ column.setHeaderRenderer(new ColorTableCellRenderer(stringRenderer, SammoaColors.POSITION_RIGHT_COLOR)); } - // ACTION column (Next Transect) + // ACTION deleted column { + int columnIndex = TransectTableModel.TransectColumn.DELETED.ordinal(); + TableColumn column = table.getColumnModel().getColumn(columnIndex); + ButtonActionTableCellEditorRenderer editorRenderer = new ButtonActionTableCellEditorRenderer( + NextTransectAction.CLIENT_PROPERTY_TRANSECT_FLIGHT, + JCheckBox.class, + new Supplier<Action>() { + + @Override + public Action get() { + Action result = getActionMap().get("deleteTransect"); + return result; + } + }, + new Predicate<Object>() { + + @Override + public boolean apply(Object input) { + TransectFlight transectFlight = + ((TransectFlightModel) input).getSource(); + + // Enabled only if no route match the transectFlight + // Note : the deleted route case is too complex, the user must delete routes before transect + boolean result = FluentIterable + .from(getModel().getRoutes()) + .anyMatch(Routes.withTransectFlight(transectFlight)); + return !result; + } + }); + + column.setCellEditor(editorRenderer); + column.setCellRenderer(editorRenderer); + } + + // ACTION nextTransect column + { int columnIndex = TransectTableModel.TransectColumn.ACTION.ordinal(); TableColumn column = table.getColumnModel().getColumn(columnIndex); ButtonActionTableCellEditorRenderer editorRenderer = new ButtonActionTableCellEditorRenderer( NextTransectAction.CLIENT_PROPERTY_TRANSECT_FLIGHT, + JButton.class, new Supplier<Action>() { @Override @@ -539,10 +607,6 @@ column.setCellRenderer(editorRenderer); } - table.setSortable(false); - table.setSelectionBackground(null); - table.setSelectionForeground(Color.BLACK); - table.addHighlighter(SammoaUtil.newBackgroundColorHighlighter( new CurrentTransectHighlightPredicate(tableModel), SammoaColors.CURRENT_TRANSECT_ROW_COLOR) @@ -733,10 +797,7 @@ List<TransectFlightModel> newTransectFlights = prepareTransectFlights(getModel(), transectFlights); - getModel().getTransectFlights().addAll(fromIndex, newTransectFlights); - - int toIndex = fromIndex + newTransectFlights.size() - 1; - ui.getTransectTableModel().fireTableRowsInserted(fromIndex, toIndex); + getModel().addAllTransectFlights(fromIndex, newTransectFlights); } } @@ -766,15 +827,17 @@ if (logger.isDebugEnabled()) { logger.debug("Select transectFlights {}", event.getFirstIndex()); } + if (event.getFirstIndex() != -1) { - for (int i = event.getFirstIndex(), - transectFlightsize = getModel().getTransectFlights().size(); - i <= event.getLastIndex() && i < transectFlightsize; i++) { + for (int i = event.getFirstIndex(), + transectFlightsize = getModel().getTransectFlights().size(); + i <= event.getLastIndex() && i < transectFlightsize; i++) { - TransectFlightModel model = getModel().getTransectFlights().get(i); + TransectFlightModel model = getModel().getTransectFlights().get(i); - boolean selected = selectionModel.isSelectedIndex(i); - model.getTransect().setSelectedInFlight(selected); + boolean selected = selectionModel.isSelectedIndex(i); + model.getTransect().setSelectedInFlight(selected); + } } } @@ -791,6 +854,7 @@ putAction("centerObservation", new CenterObservationAction(ui)); putAction("rightObservation", new RightObservationAction(ui)); putAction("circleBack", new CircleBackAction(ui)); + putAction("deleteTransect", new DeleteTransectAction(ui)); if (getModel().isValidationMode()) { putAction("validObservation", new ValidObservationAction(ui)); putAction("validRoute", new ValidRouteAction(ui)); Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIModel.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIModel.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIModel.java 2012-09-03 14:57:07 UTC (rev 510) @@ -70,7 +70,7 @@ public static final String PROPERTY_ROUTE_EDIT_BEAN = "routeEditBean"; -// public static final String PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN = "transectFlightEditBean"; + public static final String PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN = "transectFlightEditBean"; public static final String PROPERTY_FLIGHT_OBSERVER_FOR_POSITIONS = "flightObserverForPositions"; @@ -123,7 +123,7 @@ */ protected Route routeEditBean; -// protected TransectFlightModel transectFlightEditBean; + protected TransectFlightModel transectFlightEditBean; /** * La liste des observateurs du vol, sans les pilotes avec l'observateur null @@ -351,17 +351,17 @@ this.routeEditBean = routeEditBean; firePropertyChange(PROPERTY_ROUTE_EDIT_BEAN, oldRouteEditBean, routeEditBean); } -// -// public TransectFlightModel getTransectFlightEditBean() { -// return transectFlightEditBean; -// } -// -// public void setTransectFlightEditBean(TransectFlightModel transectFlightEditBean) { -// TransectFlightModel oldValue = this.transectFlightEditBean; -// this.transectFlightEditBean = transectFlightEditBean; -// firePropertyChange(PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, oldValue, transectFlightEditBean); -// } + public TransectFlightModel getTransectFlightEditBean() { + return transectFlightEditBean; + } + + public void setTransectFlightEditBean(TransectFlightModel transectFlightEditBean) { + TransectFlightModel oldValue = this.transectFlightEditBean; + this.transectFlightEditBean = transectFlightEditBean; + firePropertyChange(PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, oldValue, transectFlightEditBean); + } + public List<Observer> getFlightObserverForPositions() { if (flightObserverForPositions == null) { flightObserverForPositions = Lists.newArrayList(); @@ -370,7 +370,8 @@ } public void setFlightObserverForPositions(List<Observer> flightObserverForPositions) { - List<Observer> oldValue = ImmutableList.copyOf(getFlightObserverForPositions()); + // Note: Can't use ImmutableList for copy, the list contains the null observer + List<Observer> oldValue = Lists.newArrayList(getFlightObserverForPositions()); this.flightObserverForPositions = flightObserverForPositions; firePropertyChange(PROPERTY_FLIGHT_OBSERVER_FOR_POSITIONS, oldValue, flightObserverForPositions); } @@ -398,19 +399,6 @@ public StrateModel getStrateAll() { return !getStrates().isEmpty() ? getStrates().get(0) : null; } -// -// public List<Transect> getTransects() { -// if (transects == null) { -// transects = Lists.newArrayList(); -// } -// return transects; -// } -// -// public void setTransects(List<Transect> transects) { -// List<Transect> oldValue = Lists.newArrayList(getTransects()); -// this.transects = transects; -// firePropertyChange(PROPERTY_TRANSECTS, oldValue, transects); -// } public List<StrateModel> getStrates() { if (strates == null) { @@ -448,12 +436,22 @@ return transectFlights; } + public int indexOfTransectFlights(TransectFlightModel transectFlight) { + return getTransectFlights().indexOf(transectFlight); + } + public void setTransectFlights(List<TransectFlightModel> transectFlights) { List<TransectFlightModel> oldValue = ImmutableList.copyOf(getTransectFlights()); this.transectFlights = transectFlights; firePropertyChange(PROPERTY_TRANSECT_FLIGHTS, oldValue, transectFlights); } + public void addAllTransectFlights(int index, Collection<TransectFlightModel> transectFlights) { + List<TransectFlightModel> oldValue = ImmutableList.copyOf(getTransectFlights()); + getTransectFlights().addAll(index, transectFlights); + fireIndexedPropertyChange(PROPERTY_TRANSECT_FLIGHTS, index, oldValue, getTransectFlights()); + } + public void removeTransectFlight(int index) { List<TransectFlightModel> oldValue = ImmutableList.copyOf(getTransectFlights()); getTransectFlights().remove(index); Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectTableModel.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectTableModel.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectTableModel.java 2012-09-03 14:57:07 UTC (rev 510) @@ -51,10 +51,6 @@ this.reference = reference; } - public FlightUIModel getReference() { - return reference; - } - public Flight getFlight() { return reference.getFlight(); } @@ -270,9 +266,17 @@ DELETED( _("sammoa.flightPanel.table.column.deleted"), true, - Boolean.class, - TransectFlightModel.PROPERTY_DELETED - ), + TransectFlightModel.class + ) { + @Override + public Object getValue(int index, TransectFlightModel bean) { + return bean; + } + + @Override + public void setValue(TransectFlightModel bean, Object value, TransectTableModel model) { + } + }, ACTION( _("sammoa.flightPanel.table.column.action"), true, 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-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-09-03 14:57:07 UTC (rev 510) @@ -48,6 +48,7 @@ import fr.ulr.sammoa.ui.swing.flight.FlightUI; import fr.ulr.sammoa.ui.swing.flight.FlightUIHandler; import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel; import fr.ulr.sammoa.ui.swing.observations.action.MoveToNextEditableCellAction; import fr.ulr.sammoa.ui.swing.observations.action.MoveToNextRowEditableAction; import fr.ulr.sammoa.ui.swing.observations.action.MoveToPreviousEditableCellAction; @@ -83,6 +84,7 @@ import javax.swing.Action; import javax.swing.DefaultCellEditor; +import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JTable; import javax.swing.JTextField; @@ -115,8 +117,6 @@ private static final Logger logger = LoggerFactory.getLogger(EffortPanelHandler.class); - public static final String ERROR_TABLE = "errorTable"; - protected static final Color DEVICE_ERROR_BACKGROUND_COLOR = Color.RED; public static final String ROUTE_VALIDATOR_CONTEXT_VALUE = @@ -356,6 +356,8 @@ ); if (flightUIModel.isValidationMode()) { + + // FlightController # change current route flightUIModel.addPropertyChangeListener( FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new PropertyChangeListener() { @@ -370,6 +372,24 @@ } } ); + + // Refresh matching routes from selected transectFlight + flightUIModel.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); + } + } + }); } } @@ -407,6 +427,10 @@ // Highlighters { + table.addHighlighter(SammoaUtil.newBackgroundColorHighlighter( + new RouteForSelectedTransectFlightHighlightPredicate(flightUIModel), + SammoaColors.OBSERVATION_FOR_ROUTE_ROW_COLOR) + ); table.addHighlighter(SammoaUtil.newForegroundColorHighlighter( new RouteNoModificationHighlightPredicate(tableModel), SammoaColors.ROUTE_NO_MODIFICATION_ROW_COLOR) @@ -507,7 +531,7 @@ } }); - // For highlighting depends on selected route + // Refresh matching observations from selected route flightUIModel.addPropertyChangeListener( FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new PropertyChangeListener() { @@ -642,6 +666,7 @@ int circleBack = ObservationTableModel.ObservationColumn.CIRCLE_BACK.ordinal(); ButtonActionTableCellEditorRenderer editorRenderer = new ButtonActionTableCellEditorRenderer( CircleBackAction.CLIENT_PROPERTY_OBSERVATION, + JButton.class, new Supplier<Action>() { @Override @@ -768,30 +793,26 @@ FlightUIModel model = ui.getFlightUIModel(); - Iterable<Observation> observations = - Observations.filterInRoute(model.getObservations(), route, model.getRoutes(), true); + Iterable<Observation> observations = Observations.filterInRoute( + model.getObservations(), route, model.getRoutes(), true); - if (Iterables.isEmpty(observations)) { - // nothing to do + SammoaUtil.fireTableRowsUpdated(ui.getObservationTable(), + model.getObservations(), + observations, + scrollToFirst); + } - } else { + protected void fireRoutesUpdated(TransectFlightModel transectFlight, boolean scrollToFirst) { - int firstIndex = -1; - int lastIndex = -1; - for (Observation observation : observations) { - int index = model.indexOfObservations(observation); - if (firstIndex == -1 || firstIndex > index) { - firstIndex = index; - } - if (lastIndex == -1 || lastIndex < index) { - lastIndex = index; - } - } - ui.getObservationTableModel().fireTableRowsUpdated(firstIndex, lastIndex); - if (scrollToFirst) { - ui.getObservationTable().scrollRowToVisible(firstIndex); - } - } + FlightUIModel model = ui.getFlightUIModel(); + + Iterable<Route> routes = Iterables.filter( + model.getRoutes(), Routes.withTransectFlight(transectFlight.getSource())); + + SammoaUtil.fireTableRowsUpdated(ui.getRouteTable(), + model.getRoutes(), + routes, + scrollToFirst); } protected void selectRouteByObservation(Observation observation) { @@ -945,6 +966,38 @@ // } // } + public static class RouteForSelectedTransectFlightHighlightPredicate extends AbstractRowHighlightPredicate { + + protected FlightUIModel UIModel; + + public RouteForSelectedTransectFlightHighlightPredicate(FlightUIModel UIModel) { + this.UIModel = UIModel; + } + + @Override + protected boolean isHighlighted(int rowIndex) { + + TransectFlightModel selectedTransectFlight = UIModel.getTransectFlightEditBean(); + + boolean result; + if (selectedTransectFlight != null) { + + Route route = getValueAt(rowIndex); + + result = selectedTransectFlight.getSource().equals(route.getTransectFlight()); + + } else { + result = false; + } + return result; + } + + @Override + protected Route getValueAt(int rowIndex) { + return UIModel.getRoutes().get(rowIndex); + } + } + public static class ObservationForSelectedRouteHighlightPredicate extends AbstractRowHighlightPredicate { protected FlightUIModel UIModel; Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/ButtonActionTableCellEditorRenderer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/ButtonActionTableCellEditorRenderer.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/ButtonActionTableCellEditorRenderer.java 2012-09-03 14:57:07 UTC (rev 510) @@ -25,12 +25,16 @@ import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.base.Throwables; import com.google.common.collect.Maps; -import javax.swing.*; +import javax.swing.AbstractButton; +import javax.swing.AbstractCellEditor; +import javax.swing.Action; +import javax.swing.JTable; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; -import java.awt.*; +import java.awt.Component; import java.util.Map; /** @@ -47,13 +51,17 @@ protected Predicate<Object> enabledPredicate; - protected Map<Object, JButton> cache; + protected Map<Object, AbstractButton> cache; + protected Class<? extends AbstractButton> buttonClass; + public ButtonActionTableCellEditorRenderer(String actionPropertyName, + Class<? extends AbstractButton> buttonClass, Supplier<Action> actionSupplier, Predicate<Object> enabledPredicate) { this.actionPropertyName = actionPropertyName; + this.buttonClass = buttonClass; this.actionSupplier = actionSupplier; this.enabledPredicate = enabledPredicate; this.cache = Maps.newHashMap(); @@ -82,11 +90,17 @@ return result; } - protected JButton getButton(Object bean) { - JButton result = cache.get(bean); + protected AbstractButton getButton(Object bean) { + AbstractButton result = cache.get(bean); if (result == null) { - result = new JButton(); + try { + result = buttonClass.newInstance(); + } catch (InstantiationException ex) { + throw Throwables.propagate(ex); + } catch (IllegalAccessException ex) { + throw Throwables.propagate(ex); + } result.putClientProperty(actionPropertyName, bean); result.setAction(actionSupplier.get()); Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-09-03 14:57:07 UTC (rev 510) @@ -25,11 +25,14 @@ package fr.ulr.sammoa.ui.swing.util; import com.google.common.base.Joiner; +import com.google.common.base.Predicates; import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import org.apache.commons.beanutils.NestedNullException; import org.apache.commons.beanutils.PropertyUtils; +import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.decorator.HighlightPredicate; import org.jdesktop.swingx.decorator.Highlighter; import org.nuiton.util.FileUtil; @@ -45,6 +48,7 @@ import javax.swing.JTable; import javax.swing.KeyStroke; import javax.swing.UIManager; +import javax.swing.table.AbstractTableModel; import java.awt.Color; import java.awt.Component; import java.awt.Cursor; @@ -67,10 +71,31 @@ // never instanciate util class } - public static void unselectAll(JTable table) { - int size = table.getRowCount(); - if (size > 0) { - table.removeRowSelectionInterval(0, size - 1); + public static <T> void fireTableRowsUpdated(JXTable table, + Iterable<T> references, + Iterable<T> updated, + boolean scrollToFirst) { + + if (Iterables.isEmpty(updated)) { + // nothing to do + + } else { + + int firstIndex = -1; + int lastIndex = -1; + for (T element : updated) { + int index = Iterables.indexOf(references, Predicates.equalTo(element)); + if (firstIndex == -1 || firstIndex > index) { + firstIndex = index; + } + if (lastIndex == -1 || lastIndex < index) { + lastIndex = index; + } + } + ((AbstractTableModel) table.getModel()).fireTableRowsUpdated(firstIndex, lastIndex); + if (scrollToFirst) { + table.scrollRowToVisible(firstIndex); + } } } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TableDataChangeListener.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TableDataChangeListener.java 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TableDataChangeListener.java 2012-09-03 14:57:07 UTC (rev 510) @@ -65,7 +65,8 @@ if (evt.getOldValue() == null) { tableModel.fireTableDataChanged(); - // UPDATE : we use null newValue to fire update + // UPDATE : we use null newValue to fire update because no + // event is fired if the size is the same and all elements equals } else if (evt.getNewValue() == null) { int oldSize = ((Collection) evt.getOldValue()).size(); @@ -111,9 +112,10 @@ } } else { - tableModel.fireTableRowsInserted(rowIndex, rowIndex); + // use diff between size for multiple insert (addAll) + int diff = newSize - oldSize; + tableModel.fireTableRowsInserted(rowIndex, rowIndex + diff - 1); -// int columnIndex = getFirstEditableColumn(rowIndex); if (firstEditableColumn != NO_COLUMN_INDEX_TO_EDIT_ON_INSERT) { table.changeSelection(rowIndex, firstEditableColumn, false, false); table.editCellAt(rowIndex, firstEditableColumn); @@ -130,7 +132,9 @@ } } else { - tableModel.fireTableRowsDeleted(rowIndex, rowIndex); + // use diff between size for multiple delete (removeAll) + int diff = oldSize - newSize; + tableModel.fireTableRowsDeleted(rowIndex, rowIndex + diff - 1); } // UPDATE @@ -145,16 +149,4 @@ } } } -// -// protected int getFirstEditableColumn(int rowIndex) { -// for (int columnIndex = 0; columnIndex < tableModel.getColumnCount(); columnIndex++) { -// -// boolean editable = tableModel.isCellEditable(rowIndex, columnIndex); -// -// if (editable) { -// return columnIndex; -// } -// } -// return NO_COLUMN_INDEX_TO_EDIT_ON_INSERT; -// } } Modified: trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties =================================================================== --- trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties 2012-09-01 10:23:12 UTC (rev 509) +++ trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties 2012-09-03 14:57:07 UTC (rev 510) @@ -15,6 +15,7 @@ sammoa.action.configuration=Configuration sammoa.action.configuration.tip=Configuration sammoa.action.create=Create +sammoa.action.deleteTransect.tip=Mark transect as deleted sammoa.action.edit=Edit sammoa.action.end=End sammoa.action.end.tip=END \: end effort and create a new TRANSIT route @@ -55,6 +56,7 @@ sammoa.action.validTransect=Transect sammoa.action.validTransect.tip=Validate the selected transect and all its routes and observations sammoa.action.validation=Validation +sammoa.askQuestion.deleteTransect.message= sammoa.config.category.applications=Application sammoa.config.category.applications.description=Application sammoa.config.category.gps=GPS @@ -63,6 +65,7 @@ sammoa.config.category.other.description=Other sammoa.config.category.shortcuts=Shortcuts sammoa.config.category.shortcuts.description=List of all the shortcuts +sammoa.confirmDialog.deleteTransect.message=The flight is not started, do you want to definetely delete this flight's transect ? sammoa.confirmDialog.flightInProgress.message.exit=A flight is in progress, are you sure you want to quit ? sammoa.confirmDialog.flightInProgress.message.showHome=A flight is in progress, are you sure you want to go back to the home screen ? sammoa.confirmDialog.flightInProgress.title=Flight in progress
participants (1)
-
fdesbois@users.forge.codelutin.com