Author: tchemit Date: 2013-10-14 20:41:57 +0200 (Mon, 14 Oct 2013) New Revision: 1301 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1301 Log: refs #3328: [ERGO] Tri du tableau des esp?\195?\168ces (need more tests...) Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java 2013-10-14 18:41:57 UTC (rev 1301) @@ -0,0 +1,87 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * 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 fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.DecoratorService; +import org.jdesktop.swingx.JXTable; + +import static org.nuiton.i18n.I18n._; + +/** + * To decorate some {@link SpeciesAbleBatch} as a {@link Species}. + * <p/> + * Used to be able to keep the hole speciesBatch in the cell. + * + * @since 2.8 + */ +public class SpeciesBatchDecorator<R extends SpeciesAbleBatch> extends DecoratorService.SpeciesFromProtocolDecorator { + + private static final long serialVersionUID = 1L; + + public static <R extends SpeciesAbleBatch> SpeciesBatchDecorator<R> newDecorator(JXTable table) { + return new SpeciesBatchDecorator<R>(table); + } + + public SpeciesBatchDecorator(JXTable table) throws IllegalArgumentException, NullPointerException { + super(); + + // use special comparator + for (Context context : contexts) { + TuttiDecoratorComparator comparator = (TuttiDecoratorComparator<?>) context.getComparator(0); + context.setComparator(new SpeciesBatchDecoratorComparator<R>(comparator.getExpression(), table)); + } + } + + @Override + public String toString(Object bean) { + if (bean instanceof SpeciesAbleBatch) { + bean = ((SpeciesAbleBatch) bean).getSpecies(); + } + return super.toString(bean); + } + + @Override + protected Object getValue(Species bean, String token) { + Object result = super.getValue(bean, token); + if (Species.PROPERTY_SURVEY_CODE.equals(token) && result == null) { + result = bean.getRefTaxCode(); + } + return result; + } + + @Override + protected Object onNullValue(Species bean, String token) { + Object result; + if (Species.PROPERTY_SURVEY_CODE.equals(token)) { + result = _("tutti.propety.no.species.speciesCode"); + + } else { + result = super.onNullValue(bean, token); + } + return result; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java 2013-10-14 18:41:57 UTC (rev 1301) @@ -0,0 +1,110 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * 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 fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.service.TuttiDecorator; +import org.jdesktop.swingx.JXTable; +import org.nuiton.decorator.JXPathDecorator; + +import javax.swing.SortOrder; +import java.util.List; + +/** + * To decorate a {@link SpeciesAbleBatch} as a species + keeping the logic of batchs childs. + * <p/> + * first sort on species, then always keep the row index order. + * <p/> + * Created on 10/11/13. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.8 + */ +public class SpeciesBatchDecoratorComparator<R extends SpeciesAbleBatch> extends TuttiDecorator.TuttiDecoratorComparator<R> { + + static class RowComparatorContext implements Comparable<RowComparatorContext> { + + private final String speciesText; + + private final int rowIndex; + + private final JXTable table; + + RowComparatorContext(JXTable table, + String speciesText, + int rowIndex) { + this.table = table; + this.speciesText = speciesText; + this.rowIndex = rowIndex; + } + + @Override + public int compareTo(RowComparatorContext o) { + // first compare on speciesText + int result = speciesText.compareTo(o.speciesText); + if (result == 0) { + + int sortedColumnIndex = table.getSortedColumnIndex(); + SortOrder sortOrder = table.getSortOrder(sortedColumnIndex); + + switch (sortOrder) { + case UNSORTED: + case ASCENDING: + + // respect natural order + result = rowIndex - o.rowIndex; + break; + case DESCENDING: + result = o.rowIndex - rowIndex; + break; + } + } + return result; + } + } + + private static final long serialVersionUID = 1L; + + JXTable table; + + public SpeciesBatchDecoratorComparator(String expression, JXTable table) { + super(expression); + this.table = table; + } + + @Override + public void init(JXPathDecorator<R> decorator, List<R> datas) { + clear(); + + int index = 0; + for (R data : datas) { + + String speciesText = decorator.toString(data); + Comparable value = new RowComparatorContext(table, speciesText, index++); + valueCache.put(data, value); + + } + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-10-14 18:36:22 UTC (rev 1300) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-10-14 18:41:57 UTC (rev 1301) @@ -36,12 +36,12 @@ import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryAble; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.BenthosFrequencyRowModel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import fr.ifremer.tutti.service.WeightUnit; import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; @@ -66,6 +66,8 @@ private static final long serialVersionUID = 1L; + public static final String PROPERTY_SPECIES_ROW = "speciesRow"; + public static final String PROPERTY_SPECIES_TO_CONFIRM = "speciesToConfirm"; public static final String PROPERTY_SPECIES = "species"; @@ -228,6 +230,10 @@ Collections.sort(frequency); } + public BenthosBatchRowModel getSpeciesRow() { + return this; + } + //------------------------------------------------------------------------// //-- AbstractTuttiBeanUIModel --// //------------------------------------------------------------------------// Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-10-14 18:36:22 UTC (rev 1300) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-10-14 18:41:57 UTC (rev 1301) @@ -59,7 +59,7 @@ LogFactory.getLog(BenthosBatchTableModel.class); public static final ColumnIdentifier<BenthosBatchRowModel> SPECIES = ColumnIdentifier.newId( - BenthosBatchRowModel.PROPERTY_SPECIES, + BenthosBatchRowModel.PROPERTY_SPECIES_ROW, n_("tutti.editBenthosBatch.table.header.species"), n_("tutti.editBenthosBatch.table.header.species.tip")); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-10-14 18:36:22 UTC (rev 1300) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-10-14 18:41:57 UTC (rev 1301) @@ -57,6 +57,7 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.BenthosFrequencyRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.split.SplitBenthosBatchUI; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchDecorator; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; @@ -68,7 +69,6 @@ import fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataTableCell; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUI; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUIModel; -import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.editor.NumberEditor; @@ -422,7 +422,7 @@ Highlighter evenHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( new HighlightPredicate.AndHighlightPredicate( HighlightPredicate.EVEN, - new HighlightPredicate.NotHighlightPredicate(HighlightPredicate.READ_ONLY)), + HighlightPredicate.EDITABLE), Color.WHITE); table.addHighlighter(evenHighlighter); @@ -434,10 +434,11 @@ Highlighter confirmHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( new HighlightPredicate.AndHighlightPredicate( new HighlightPredicate.NotHighlightPredicate(HighlightPredicate.IS_SELECTED), + HighlightPredicate.EDITABLE, new HighlightPredicate() { public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - BenthosBatchRowModel row = getTableModel().getEntry(adapter.row); + BenthosBatchRowModel row = getTableModel().getEntry(adapter.convertRowIndexToModel(adapter.row)); return row.isSpeciesToConfirm(); } @@ -446,14 +447,17 @@ // paint the cell in dark orange if the row is to confirm and the cell is not editable Highlighter confirmNotEditableHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( - new HighlightPredicate() { + new HighlightPredicate.AndHighlightPredicate( + new HighlightPredicate.NotHighlightPredicate(HighlightPredicate.IS_SELECTED), + HighlightPredicate.READ_ONLY, + new HighlightPredicate() { - public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - BenthosBatchRowModel row = getTableModel().getEntry(adapter.row); - return row.isSpeciesToConfirm() && !adapter.isEditable(); - } + public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { + BenthosBatchRowModel row = getTableModel().getEntry(adapter.convertRowIndexToModel(adapter.row)); + return row.isSpeciesToConfirm(); + } - }, toConfirmColor.darker()); + }), toConfirmColor.darker()); table.addHighlighter(confirmNotEditableHighlighter); } @@ -620,7 +624,7 @@ JXTable table = getTable(); // can add species to a melag if several root are selected - int[] selectedRows = table.getSelectedRows(); + int[] selectedRows = SwingUtil.getSelectedModelRows(table); for (int selectedRowIndex : selectedRows) { BenthosBatchRowModel selectedRow = tableModel.getEntry(selectedRowIndex); @@ -719,8 +723,9 @@ null, null, BenthosBatchTableModel.SPECIES); -// speciesColumn.setSortable(true); - DecoratorService.SpeciesFromProtocolDecorator speciesDecorator = new DecoratorService.SpeciesFromProtocolDecorator(); + speciesColumn.setSortable(true); + SpeciesBatchDecorator<BenthosBatchRowModel> speciesDecorator = + SpeciesBatchDecorator.newDecorator(table); speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); } @@ -841,12 +846,12 @@ e.getLastRow() == Integer.MAX_VALUE) { // get column comparator - TuttiDecorator.TuttiDecoratorComparator<Species> comparator = - (TuttiDecorator.TuttiDecoratorComparator<Species>) + TuttiDecorator.TuttiDecoratorComparator<BenthosBatchRowModel> comparator = + (TuttiDecorator.TuttiDecoratorComparator<BenthosBatchRowModel>) speciesColumn.getComparator(); // get column comparator - TuttiDecorator<Species> decorator = + TuttiDecorator<BenthosBatchRowModel> decorator = TuttiUIUtil.getSpeciesColumnDecorator(speciesColumn); boolean comparatorNull = comparator == null; @@ -857,7 +862,7 @@ } // init comparator with model species list - comparator.init(decorator, tableModel.getSpeciesList()); + comparator.init(decorator, tableModel.getRows()); if (comparatorNull) { @@ -923,7 +928,7 @@ saveRow(newRow); tableModel.addNewRow(newRow); - AbstractSelectTableAction.doSelectCell(getTable(), tableModel.getRowCount() - 1, 0); + TuttiUIUtil.selectFirstCellOnLastRow(getTable()); // update speciesUsed addToSpeciesUsed(newRow); @@ -944,13 +949,13 @@ JXTable table = getTable(); - int rowIndex = table.getSelectedRow(); + int rowIndex = SwingUtil.getSelectedModelRow(table); TableColumnModelExt columnModel = (TableColumnModelExt) getTable().getColumnModel(); int columnIndex = columnModel.getColumnIndex(BenthosBatchTableModel.COMPUTED_NUMBER); - AbstractSelectTableAction.doSelectCell(getTable(), rowIndex, columnIndex); + TuttiUIUtil.doSelectCell(getTable(), rowIndex, columnIndex); BenthosFrequencyCellComponent.FrequencyCellEditor cellEditor = (BenthosFrequencyCellComponent.FrequencyCellEditor) @@ -963,7 +968,7 @@ JXTable table = getTable(); // get selected row - int rowIndex = table.getSelectedRow(); + int rowIndex = SwingUtil.getSelectedModelRow(table); Preconditions.checkState(rowIndex != -1, "Cant split batch if no batch selected"); @@ -1010,12 +1015,12 @@ BenthosBatchTableModel tableModel = getTableModel(); // get selected row - int rowIndex = getTable().getSelectedRow(); + int rowIndex = SwingUtil.getSelectedModelRow(getTable()); Preconditions.checkState(rowIndex != -1, "Cant split batch if no batch selected"); // get selected column - int columnIndex = getTable().getSelectedColumn(); + int columnIndex = SwingUtil.getSelectedModelColumn(getTable()); Preconditions.checkState(columnIndex != -1, "Cant split batch if no batch selected"); @@ -1053,10 +1058,10 @@ BenthosBatchTableModel tableModel = getTableModel(); // get selected row - int rowIndex = getTable().getSelectedRow(); + int rowIndex = SwingUtil.getSelectedModelRow(getTable()); // get selected column - int columnIndex = getTable().getSelectedColumn(); + int columnIndex = SwingUtil.getSelectedModelColumn(getTable()); // get selected row BenthosBatchRowModel selectedRow = tableModel.getEntry(rowIndex); @@ -1171,7 +1176,7 @@ JXTable table = getTable(); // get selected row - int insertRow = table.getSelectedRow(); + int insertRow = SwingUtil.getSelectedModelRow(table); BenthosBatchTableModel tableModel = getTableModel(); BenthosBatchRowModel parentBatch = tableModel.getEntry(insertRow); @@ -1274,7 +1279,7 @@ model.setLeafNumber(model.getLeafNumber() + newBatches.size() - 1); // update columns for the parent shell - tableModel.updateShell(shell, getTable().getSelectedColumn()); + tableModel.updateShell(shell, SwingUtil.getSelectedModelColumn(getTable())); } public void updateTotalFromFrequencies(BenthosBatchRowModel row) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-10-14 18:36:22 UTC (rev 1300) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-10-14 18:41:57 UTC (rev 1301) @@ -66,6 +66,8 @@ private static final long serialVersionUID = 1L; + public static final String PROPERTY_SPECIES_ROW = "speciesRow"; + public static final String PROPERTY_SAMPLE_CATEGORY = "sampleCategory"; public static final String PROPERTY_SAMPLE_CATEGORY_VALUE = "sampleCategoryValue"; @@ -179,6 +181,10 @@ computedOrNotNumber.addPropagateListener(PROPERTY_COMPUTED_NUMBER, this); } + public SpeciesBatchRowModel getSpeciesRow() { + return this; + } + public SpeciesBatchRowModel(WeightUnit weightUnit, SampleCategoryModel sampleCategoryModel, SpeciesBatch aBatch, Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-10-14 18:36:22 UTC (rev 1300) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-10-14 18:41:57 UTC (rev 1301) @@ -59,7 +59,7 @@ LogFactory.getLog(SpeciesBatchTableModel.class); public static final ColumnIdentifier<SpeciesBatchRowModel> SPECIES = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_SPECIES, + SpeciesBatchRowModel.PROPERTY_SPECIES_ROW, n_("tutti.editSpeciesBatch.table.header.species"), n_("tutti.editSpeciesBatch.table.header.species")); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-10-14 18:36:22 UTC (rev 1300) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-10-14 18:41:57 UTC (rev 1301) @@ -50,6 +50,7 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryColumnIdentifier; import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryComponent; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchDecorator; import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.create.CreateSpeciesBatchUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.create.CreateSpeciesBatchUIModel; @@ -67,7 +68,6 @@ import fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataTableCell; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUI; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUIModel; -import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.editor.NumberEditor; @@ -430,7 +430,7 @@ Highlighter evenHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( new HighlightPredicate.AndHighlightPredicate( HighlightPredicate.EVEN, - new HighlightPredicate.NotHighlightPredicate(HighlightPredicate.READ_ONLY)), + HighlightPredicate.EDITABLE), Color.WHITE); table.addHighlighter(evenHighlighter); @@ -442,10 +442,11 @@ Highlighter confirmHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( new HighlightPredicate.AndHighlightPredicate( new HighlightPredicate.NotHighlightPredicate(HighlightPredicate.IS_SELECTED), + HighlightPredicate.EDITABLE, new HighlightPredicate() { public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - SpeciesBatchRowModel row = getTableModel().getEntry(adapter.row); + SpeciesBatchRowModel row = getTableModel().getEntry(adapter.convertRowIndexToModel(adapter.row)); return row.isSpeciesToConfirm(); } @@ -454,14 +455,17 @@ // paint the cell in dark orange if the row is to confirm and the cell is not editable Highlighter confirmNotEditableHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( - new HighlightPredicate() { + new HighlightPredicate.AndHighlightPredicate( + new HighlightPredicate.NotHighlightPredicate(HighlightPredicate.IS_SELECTED), + HighlightPredicate.READ_ONLY, + new HighlightPredicate() { - public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - SpeciesBatchRowModel row = getTableModel().getEntry(adapter.row); - return row.isSpeciesToConfirm() && !adapter.isEditable(); - } + public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { + SpeciesBatchRowModel row = getTableModel().getEntry(adapter.convertRowIndexToModel(adapter.row)); + return row.isSpeciesToConfirm() && !adapter.isEditable(); + } - }, toConfirmColor.darker()); + }), toConfirmColor.darker()); table.addHighlighter(confirmNotEditableHighlighter); } @@ -628,7 +632,7 @@ JXTable table = getTable(); // can add species to a melag if several root are selected - int[] selectedRows = table.getSelectedRows(); + int[] selectedRows = SwingUtil.getSelectedModelRows(table); for (int selectedRowIndex : selectedRows) { SpeciesBatchRowModel selectedRow = tableModel.getEntry(selectedRowIndex); @@ -727,8 +731,9 @@ null, null, SpeciesBatchTableModel.SPECIES); -// speciesColumn.setSortable(true); - DecoratorService.SpeciesFromProtocolDecorator speciesDecorator = new DecoratorService.SpeciesFromProtocolDecorator(); + speciesColumn.setSortable(true); + SpeciesBatchDecorator<SpeciesBatchRowModel> speciesDecorator = + SpeciesBatchDecorator.newDecorator(table); speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); } @@ -850,12 +855,12 @@ e.getLastRow() == Integer.MAX_VALUE) { // get column comparator - TuttiDecorator.TuttiDecoratorComparator<Species> comparator = - (TuttiDecorator.TuttiDecoratorComparator<Species>) + TuttiDecorator.TuttiDecoratorComparator<SpeciesBatchRowModel> comparator = + (TuttiDecorator.TuttiDecoratorComparator<SpeciesBatchRowModel>) speciesColumn.getComparator(); // get column comparator - TuttiDecorator<Species> decorator = + TuttiDecorator<SpeciesBatchRowModel> decorator = TuttiUIUtil.getSpeciesColumnDecorator(speciesColumn); boolean comparatorNull = comparator == null; @@ -866,7 +871,7 @@ } // init comparator with model species list - comparator.init(decorator, tableModel.getSpeciesList()); + comparator.init(decorator, tableModel.getRows()); if (comparatorNull) { @@ -931,7 +936,7 @@ saveRow(newRow); tableModel.addNewRow(newRow); - AbstractSelectTableAction.doSelectCell(getTable(), tableModel.getRowCount() - 1, 0); + TuttiUIUtil.selectFirstCellOnLastRow(getTable()); // update speciesUsed addToSpeciesUsed(newRow); @@ -952,13 +957,13 @@ JXTable table = getTable(); - int rowIndex = table.getSelectedRow(); + int rowIndex = SwingUtil.getSelectedModelRow(table); TableColumnModelExt columnModel = (TableColumnModelExt) getTable().getColumnModel(); int columnIndex = columnModel.getColumnIndex(SpeciesBatchTableModel.COMPUTED_NUMBER); - AbstractSelectTableAction.doSelectCell(getTable(), rowIndex, columnIndex); + TuttiUIUtil.doSelectCell(getTable(), rowIndex, columnIndex); SpeciesFrequencyCellComponent.FrequencyCellEditor cellEditor = (SpeciesFrequencyCellComponent.FrequencyCellEditor) @@ -971,7 +976,7 @@ JXTable table = getTable(); // get selected row - int rowIndex = table.getSelectedRow(); + int rowIndex = SwingUtil.getSelectedModelRow(table); Preconditions.checkState(rowIndex != -1, "Cant split batch if no batch selected"); @@ -1018,12 +1023,12 @@ SpeciesBatchTableModel tableModel = getTableModel(); // get selected row - int rowIndex = getTable().getSelectedRow(); + int rowIndex = SwingUtil.getSelectedModelRow(getTable()); Preconditions.checkState(rowIndex != -1, "Cant split batch if no batch selected"); // get selected column - int columnIndex = getTable().getSelectedColumn(); + int columnIndex = SwingUtil.getSelectedModelColumn(getTable()); Preconditions.checkState(columnIndex != -1, "Cant split batch if no batch selected"); @@ -1061,10 +1066,10 @@ SpeciesBatchTableModel tableModel = getTableModel(); // get selected row - int rowIndex = getTable().getSelectedRow(); + int rowIndex = SwingUtil.getSelectedModelRow(getTable()); // get selected column - int columnIndex = getTable().getSelectedColumn(); + int columnIndex = SwingUtil.getSelectedModelColumn(getTable()); // get selected row SpeciesBatchRowModel selectedRow = tableModel.getEntry(rowIndex); @@ -1178,7 +1183,7 @@ JXTable table = getTable(); // get selected row - int insertRow = table.getSelectedRow(); + int insertRow = SwingUtil.getSelectedModelRow(table); SpeciesBatchTableModel tableModel = getTableModel(); SpeciesBatchRowModel parentBatch = tableModel.getEntry(insertRow); @@ -1208,7 +1213,7 @@ newBatches.add(newBatch); tableModel.addNewRow(++insertRow, newBatch); - AbstractSelectTableAction.doSelectCell(getTable(), insertRow, 0); + TuttiUIUtil.selectFirstCellOnRow(getTable(), insertRow, false); } } @@ -1282,7 +1287,7 @@ model.setLeafNumber(model.getLeafNumber() + newBatches.size() - 1); // update columns for the parent shell - tableModel.updateShell(shell, getTable().getSelectedColumn()); + tableModel.updateShell(shell, SwingUtil.getSelectedModelColumn(getTable())); } public void updateTotalFromFrequencies(SpeciesBatchRowModel row) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-10-14 18:36:22 UTC (rev 1300) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-10-14 18:41:57 UTC (rev 1301) @@ -441,7 +441,13 @@ if (rowIndex == -1) { source.clearSelection(); } else if (!ArrayUtils.contains(selectedRows, rowIndex)) { - source.setRowSelectionInterval(rowIndex, rowIndex); + if (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION == source.getSelectionMode()) { + // add to selection + source.addRowSelectionInterval(rowIndex, rowIndex); + } else { + // set selection + source.setRowSelectionInterval(rowIndex, rowIndex); + } } // select column (could empty selection) @@ -453,8 +459,12 @@ if (rightClick) { - beforeOpenPopup(rowIndex, columnIndex); + // use now model coordinate + int modelRowIndex = source.convertRowIndexToModel(rowIndex); + int modelColumnIndex = source.convertColumnIndexToModel(columnIndex); + beforeOpenPopup(modelRowIndex, modelColumnIndex); + // on right click show popup popup.show(source, e.getX(), e.getY()); } @@ -472,7 +482,9 @@ boolean result = false; if (adapter.isEditable()) { AbstractTuttiTableModel model = (AbstractTuttiTableModel) table.getModel(); - AbstractTuttiBeanUIModel row = (AbstractTuttiBeanUIModel) model.getEntry(adapter.row); + int viewRow = adapter.row; + int modelRow = adapter.convertRowIndexToModel(viewRow); + AbstractTuttiBeanUIModel row = (AbstractTuttiBeanUIModel) model.getEntry(modelRow); result = !row.isValid(); } return result; @@ -534,7 +546,7 @@ HighlightPredicate.ODD, notSelectedPredicate, rowIsValidPredicate, - new HighlightPredicate.NotHighlightPredicate(HighlightPredicate.READ_ONLY)), + HighlightPredicate.EDITABLE), getConfig().getColorAlternateRow()); table.addHighlighter(evenNotReadOnlyHighlighter); @@ -544,7 +556,7 @@ HighlightPredicate.ODD, HighlightPredicate.IS_SELECTED, rowIsValidPredicate, - new HighlightPredicate.NotHighlightPredicate(HighlightPredicate.READ_ONLY)), + HighlightPredicate.EDITABLE), getConfig().getColorSelectedRow()); table.addHighlighter(evenSelectedHighlighter); @@ -606,7 +618,10 @@ if (canContinue) { - beforeOpenPopup(lowestRow, selectedColumn); + // use now model coordinate + int rowIndex = source.convertRowIndexToModel(lowestRow); + int columnIndex = source.convertColumnIndexToModel(selectedColumn); + beforeOpenPopup(rowIndex, columnIndex); popup.show(source, p.x, p.y); } Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-10-14 18:36:22 UTC (rev 1300) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-10-14 18:41:57 UTC (rev 1301) @@ -1363,6 +1363,7 @@ tutti.property.refTaxCode= tutti.property.set.error= tutti.property.surveycode= +tutti.propety.no.species.speciesCode= tutti.reimport.step.backupDb= tutti.reimport.step.closeDb= tutti.reimport.step.reloadApplication= Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-10-14 18:36:22 UTC (rev 1300) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-10-14 18:41:57 UTC (rev 1301) @@ -1140,7 +1140,7 @@ tutti.flash.info.benthos.imported.in.protocol=Benthos importés dans le protocole depuis le fichier <strong>%s</strong>. tutti.flash.info.benthos.imported.in.protocol.oneReplaced=Benthos importés dans le protocole depuis le fichier <strong>%s</strong>. 1 remplacée par son référent. tutti.flash.info.benthos.imported.in.protocol.severalReplaced=Benthos importés dans le protocole depuis le fichier <strong>%s</strong>. %s remplacées par leur référent. -tutti.flash.info.benthos.remove.from.protocol=Le benthos <strong>%s</strong> a été retiré du protocole. +tutti.flash.info.benthos.remove.from.protocol=Les benthos ont été retirés du protocole. tutti.flash.info.benthos.replaced=Le benthos <strong>%s</strong> a été remplacé par son référent <strong>%s</strong>. tutti.flash.info.caracteristic.imported.in.protocol=Caractéristiques importées dans le protocole depuis le fichier <strong>%s</strong>. tutti.flash.info.caractristic.exported.from.protocol=Caractéristiques du protocole exportées dans le fichier <strong>%s</strong>. @@ -1163,7 +1163,7 @@ tutti.flash.info.species.imported.in.protocol=Espèces importées dans le protocole depuis le fichier <strong>%s</strong>. tutti.flash.info.species.imported.in.protocol.oneReplaced=Espèces importées dans le protocole depuis le fichier <strong>%s</strong>. 1 remplacée par son référent. tutti.flash.info.species.imported.in.protocol.severalReplaced=Espèces importées dans le protocole depuis le fichier <strong>%s</strong>. %s remplacées par leur référent. -tutti.flash.info.species.remove.from.protocol=L'espèce <strong>%s</strong> a été retirée du protocole. +tutti.flash.info.species.remove.from.protocol=Les espèces ont été retirées du protocole. tutti.flash.info.species.replaced=L'espèce <strong>%s</strong> a été remplacée par son référent <strong>%s</strong>. tutti.gear.noCaracteristics=Pas de caractéristiques. tutti.gear.withCaracteristics=Caractéristiques de l'engin %s @@ -1361,6 +1361,7 @@ tutti.property.refTaxCode= tutti.property.set.error=Propriété %1s non trouvée sur l'objet de type %2s tutti.property.surveycode= +tutti.propety.no.species.speciesCode= tutti.reimport.step.backupDb=Sauvegarde de la base dans l'archive %s tutti.reimport.step.closeDb=Fermeture de la base tutti.reimport.step.reloadApplication=Redémarrage de l'application...