r514 - in trunk: . sammoa-ui-swing sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util
Author: fdesbois Date: 2012-09-04 14:48:41 +0200 (Tue, 04 Sep 2012) New Revision: 514 Url: http://forge.codelutin.com/repositories/revision/sammoa/514 Log: fixes #1416 : use swing-bits for sorting and filtering. Be careful of conversion between model and view indexes in tables. Removed: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectCrossingNumberCellRenderer.java Modified: trunk/pom.xml trunk/sammoa-ui-swing/pom.xml trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 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/effort/EffortPanelHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/AbstractRowHighlightPredicate.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/TableSelectionListener.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-09-04 12:47:21 UTC (rev 513) +++ trunk/pom.xml 2012-09-04 12:48:41 UTC (rev 514) @@ -305,6 +305,12 @@ <version>${swingXVersion}</version> </dependency> + <dependency> + <groupId>com.ezware.oxbow</groupId> + <artifactId>swing-bits</artifactId> + <version>0.5.0</version> + </dependency> + <!-- librairie topia --> <dependency> <groupId>org.nuiton.topia</groupId> Modified: trunk/sammoa-ui-swing/pom.xml =================================================================== --- trunk/sammoa-ui-swing/pom.xml 2012-09-04 12:47:21 UTC (rev 513) +++ trunk/sammoa-ui-swing/pom.xml 2012-09-04 12:48:41 UTC (rev 514) @@ -137,6 +137,11 @@ <artifactId>swingx-common</artifactId> </dependency> + <dependency> + <groupId>com.ezware.oxbow</groupId> + <artifactId>swing-bits</artifactId> + </dependency> + <!-- Validation --> <dependency> <groupId>org.nuiton.jaxx</groupId> Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-09-04 12:47:21 UTC (rev 513) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-09-04 12:48:41 UTC (rev 514) @@ -341,6 +341,8 @@ helper.setOptionCallBack("actions"); helper.addOption(SammoaConfig.SammoaConfigOption.KEY_CIRCLE_BACK); helper.setOptionCallBack("actions"); + helper.addOption(SammoaConfig.SammoaConfigOption.KEY_VALID_TRANSECT); + helper.setOptionCallBack("actions"); helper.addOption(SammoaConfig.SammoaConfigOption.KEY_VALID_OBSERVATION); helper.setOptionCallBack("actions"); helper.addOption(SammoaConfig.SammoaConfigOption.KEY_VALID_ROUTE); 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-04 12:47:21 UTC (rev 513) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-04 12:48:41 UTC (rev 514) @@ -143,6 +143,7 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; +import java.awt.Component; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.ItemEvent; @@ -486,7 +487,7 @@ int index = TransectFlightModel.indexOfTransectFlight( getModel().getTransectFlights(), route.getTransectFlight()); - ui.getTransectFlightSelectionModel().setSelectionInterval(index, index); + SammoaUtil.selectTableRow(ui.getTransectTable(), index); } transectFlightSelectionIsAdjusting = false; @@ -776,7 +777,7 @@ // Retrieve the last selected row from the table JTable table = ui.getTransectTable(); - int fromIndex = SammoaUtil.getLastSelectedRow(table); + int fromIndex = SammoaUtil.getLastSelectedTableRow(table); if (fromIndex == -1) { // Add after the last row fromIndex = table.getRowCount(); @@ -1226,7 +1227,8 @@ Transect transectBean = referentialService.getTransect(transectId); - StrateModel strate = Iterables.find(getModel().getStrates(), StrateModel.withStrate(transectBean.getStrate())); + StrateModel strate = Iterables.find( + getModel().getStrates(), StrateModel.withStrate(transectBean.getStrate())); TransectModel transect = new TransectModel(transectBean); @@ -1235,8 +1237,35 @@ ui.getStrateCombobox().setSelectedItem(strate); - // Maybe auto-scroll ? auto-selection ? + ui.getTransectList().ensureIndexIsVisible(strate.getTransects().size() - 1); } } }; + + private static class TransectCrossingNumberCellRenderer implements TableCellRenderer { + + protected TableCellRenderer delegate; + + protected TransectTableModel model; + + public TransectCrossingNumberCellRenderer(TableCellRenderer delegate, + TransectTableModel model) { + this.delegate = delegate; + this.model = model; + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + + TransectFlightModel transectFlight = model.getRow(table.convertRowIndexToModel(row)); + TransectModel transect = transectFlight.getTransect(); + + int crossingNumber = transectFlight.getCrossingNumber(); + int realNbTimes = transect.getRealNbTimes(); + + String newValue = crossingNumber + " (" + realNbTimes + ")"; + + return delegate.getTableCellRendererComponent(table, newValue, isSelected, hasFocus, row, column); + } + } } Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectCrossingNumberCellRenderer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectCrossingNumberCellRenderer.java 2012-09-04 12:47:21 UTC (rev 513) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectCrossingNumberCellRenderer.java 2012-09-04 12:48:41 UTC (rev 514) @@ -1,60 +0,0 @@ -package fr.ulr.sammoa.ui.swing.flight; -/* - * #%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 javax.swing.JTable; -import javax.swing.table.TableCellRenderer; -import java.awt.Component; - -/** - * Created: 18/07/12 - * - * @author fdesbois <desbois@codelutin.com> - */ -public class TransectCrossingNumberCellRenderer implements TableCellRenderer { - - protected TableCellRenderer delegate; - - protected TransectTableModel model; - - public TransectCrossingNumberCellRenderer(TableCellRenderer delegate, - TransectTableModel model) { - this.delegate = delegate; - this.model = model; - } - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - - TransectFlightModel transectFlight = model.getRow(row); - TransectModel transect = transectFlight.getTransect(); - - int crossingNumber = transectFlight.getCrossingNumber(); - int realNbTimes = transect.getRealNbTimes(); - - String newValue = crossingNumber + " (" + realNbTimes + ")"; - - return delegate.getTableCellRendererComponent(table, newValue, isSelected, hasFocus, row, column); - } -} 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-04 12:47:21 UTC (rev 513) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-04 12:48:41 UTC (rev 514) @@ -23,6 +23,7 @@ * #L% */ +import com.ezware.oxbow.swingbits.table.filter.TableRowFilterSupport; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -264,8 +265,6 @@ } // 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 = getModel().indexOfRoutes(route); SwingUtil.ensureRowIndex(ui.getRouteTableModel(), index); ui.getRouteTableModel().fireTableRowsUpdated(index, index); @@ -572,9 +571,6 @@ selectRouteByObservation(newValue); } -// else { -// SammoaUtil.unselectAll(ui.getObservationTable()); -// } } }); @@ -778,6 +774,10 @@ table.setDefaultEditor(Date.class, new TimeCellEditor(datePicker)); } + if (getModel().isValidationMode()) { + TableRowFilterSupport.forTable(table).searchable(true).apply(); + } + SammoaUtil.addTableSelectionListener(table, selectionModelAdapter); SwingUtil.scrollToTableSelection(table); @@ -789,13 +789,11 @@ protected void fireObservationsUpdated(Route route, boolean scrollToFirst) { - FlightUIModel model = getModel(); - Iterable<Observation> observations = Observations.filterInRoute( - model.getObservations(), route, model.getRoutes(), true); + getModel().getObservations(), route, getModel().getRoutes(), true); SammoaUtil.fireTableRowsUpdated(ui.getObservationTable(), - model.getObservations(), + getModel().getObservations(), observations, scrollToFirst); } @@ -817,7 +815,7 @@ getModel().getRoutes(), observation, true); int routeIndex = getModel().indexOfRoutes(route); - ui.getRouteTable().getSelectionModel().setSelectionInterval(routeIndex, routeIndex); + SammoaUtil.selectTableRow(ui.getRouteTable(), routeIndex); } private PropertyChangeListener observationTimeChangeListener = new PropertyChangeListener() { @@ -847,7 +845,7 @@ @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - Observation observation = model.getBean(row); + Observation observation = model.getBean(table.convertRowIndexToModel(row)); Route route = Routes.findWithObservation(model.getFlightUIModel().getRoutes(), observation, true); Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/AbstractRowHighlightPredicate.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/AbstractRowHighlightPredicate.java 2012-09-04 12:47:21 UTC (rev 513) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/AbstractRowHighlightPredicate.java 2012-09-04 12:48:41 UTC (rev 514) @@ -49,8 +49,8 @@ @Override public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - int columnIndex = adapter.column; - int rowIndex = adapter.row; + int columnIndex = adapter.convertColumnIndexToModel(adapter.column); + int rowIndex = adapter.convertRowIndexToModel(adapter.row); Object object = getValueAt(rowIndex); boolean result; 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-04 12:47:21 UTC (rev 513) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-09-04 12:48:41 UTC (rev 514) @@ -94,14 +94,40 @@ } ((AbstractTableModel) table.getModel()).fireTableRowsUpdated(firstIndex, lastIndex); if (scrollToFirst) { - table.scrollRowToVisible(firstIndex); + table.scrollRowToVisible(table.convertRowIndexToView(firstIndex)); } } } + /** + * Select the row with the model {@code index} in given {@code table}. + * + * @param table Jtable to select the row + * @param index Model index to select + */ + public static void selectTableRow(JTable table, int index) { + int viewIndex = table.convertRowIndexToView(index); + table.setRowSelectionInterval(viewIndex, viewIndex); + } + + public static int getLastSelectedTableRow(JTable table) { + int result; + int nbRows = table.getSelectedRows().length; + if (nbRows > 0) { + int lastRow = table.getSelectedRows()[nbRows - 1]; + result = table.convertRowIndexToModel(lastRow); + + } else { + // No line selected + result = -1; + } + return result; + } + public static <T> TableSelectionListener<T> addTableSelectionListener(JTable table, SelectionModelAdapter<T> selectionModelAdapter) { - TableSelectionListener<T> result = new TableSelectionListener<T>(selectionModelAdapter); + TableSelectionListener<T> result = + new TableSelectionListener<T>(table, selectionModelAdapter); table.getSelectionModel().addListSelectionListener(result); return result; } @@ -305,17 +331,4 @@ JOptionPane.YES_NO_OPTION); return i == JOptionPane.YES_OPTION; } - - public static int getLastSelectedRow(JTable table) { - int result; - int nbRows = table.getSelectedRows().length; - if (nbRows > 0) { - result = table.getSelectedRows()[nbRows - 1]; - - } else { - // No line selected - result = -1; - } - return result; - } } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TableSelectionListener.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TableSelectionListener.java 2012-09-04 12:47:21 UTC (rev 513) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/TableSelectionListener.java 2012-09-04 12:48:41 UTC (rev 514) @@ -27,6 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -41,9 +42,13 @@ private static final Logger logger = LoggerFactory.getLogger(TableSelectionListener.class); + protected JTable table; + protected SelectionModelAdapter<T> selectionModelAdapter; - public TableSelectionListener(SelectionModelAdapter<T> selectionModelAdapter) { + public TableSelectionListener(JTable table, + SelectionModelAdapter<T> selectionModelAdapter) { + this.table = table; this.selectionModelAdapter = selectionModelAdapter; } @@ -64,11 +69,11 @@ } else if (listSelectionModel.isSelectedIndex(firstIndex)) { // use first index - newSelectedRow = firstIndex; + newSelectedRow = table.convertRowIndexToModel(firstIndex); } else if (listSelectionModel.isSelectedIndex(lastIndex)) { // use last index - newSelectedRow = lastIndex; + newSelectedRow = table.convertRowIndexToModel(lastIndex); } List<T> elements = selectionModelAdapter.getElements(); T element = null; @@ -78,7 +83,7 @@ element = elements.get(newSelectedRow); if (logger.isInfoEnabled()) { - logger.info("Select {} from index {}", + logger.info("Select {} at model index {}", element.getClass().getSimpleName(), newSelectedRow); }
participants (1)
-
fdesbois@users.forge.codelutin.com