Author: tchemit Date: 2014-01-08 13:34:01 +0100 (Wed, 08 Jan 2014) New Revision: 1479 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1479 Log: fixes #4073: [ERGO] Tri du tableau des esp?\195?\168ces Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchRowHelper.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortMode.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortableRowModel.java trunk/tutti-ui-swing/src/main/resources/icons/action-sort.png Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 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 trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx 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/BenthosBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 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/SpeciesBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.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 Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties =================================================================== --- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2014-01-08 12:34:01 UTC (rev 1479) @@ -1,5 +1,5 @@ #Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo -#Mon Dec 09 15:37:05 CET 2013 +#Wed Jan 08 12:42:32 CET 2014 tutti.config.help=config.html tutti.createAccidentalBatch.action.cancel.help=editFishingOperation.html\#captureCapturesAccidentellesActions tutti.createAccidentalBatch.action.saveAndClose.help=editFishingOperation.html\#captureCapturesAccidentellesActions @@ -85,6 +85,9 @@ tutti.editBenthosBatch.field.benthosTotalSortedWeight.help=editFishingOperation.html\#captureBenthosFields tutti.editBenthosBatch.field.benthosTotalUnsortedWeight.help=editFishingOperation.html\#captureBenthosFields tutti.editBenthosBatch.field.benthosTotalWeight.help=editFishingOperation.html\#captureBenthosFields +tutti.editBenthosBatch.field.speciesSortMode.asc.help=editFishingOperation.html\#captureBenthosFields +tutti.editBenthosBatch.field.speciesSortMode.desc.help=editFishingOperation.html\#captureBenthosFields +tutti.editBenthosBatch.field.speciesSortMode.none.help=editFishingOperation.html\#captureBenthosFields tutti.editBenthosBatch.field.speciesTotalInertWeight.help=editFishingOperation.html\#captureBenthosFields tutti.editBenthosBatch.field.speciesTotalLivingNotItemizedWeight.help=editFishingOperation.html\#captureBenthosFields tutti.editBenthosBatch.field.speciesTotalSampleSortedWeight.help=editFishingOperation.html\#captureBenthosFields @@ -93,6 +96,7 @@ tutti.editBenthosBatch.field.speciesTotalWeight.help=editFishingOperation.html\#captureBenthosFields tutti.editBenthosBatch.filterBatch.help=editFishingOperation.html\#captureBenthosFields tutti.editBenthosBatch.help=editFishingOperation.html\#captureBenthos +tutti.editBenthosBatch.sortSpeciesBatch.help=editFishingOperation.html\#captureBenthosFields tutti.editBenthosFrequencies.action.addLengthStepCaracteristic.help=editFishingOperation.html\#captureBenthosActions tutti.editBenthosFrequencies.action.cancel.help=editFishingOperation.html\#captureBenthosActions tutti.editBenthosFrequencies.action.generate.help=editFishingOperation.html\#captureBenthosActions @@ -252,6 +256,9 @@ tutti.editSpeciesBatch.action.removeSubBatch.help=editFishingOperation.html\#captureEspecesActions tutti.editSpeciesBatch.action.renameBatch.help=editFishingOperation.html\#captureEspecesActions tutti.editSpeciesBatch.action.splitBatch.help=editFishingOperation.html\#captureEspecesActions +tutti.editSpeciesBatch.field.speciesSortMode.asc.help=editFishingOperation.html\#captureEspecesFields +tutti.editSpeciesBatch.field.speciesSortMode.desc.help=editFishingOperation.html\#captureEspecesFields +tutti.editSpeciesBatch.field.speciesSortMode.none.help=editFishingOperation.html\#captureEspecesFields tutti.editSpeciesBatch.field.speciesTotalInertWeight.help=editFishingOperation.html\#captureEspecesFields tutti.editSpeciesBatch.field.speciesTotalLivingNotItemizedWeight.help=editFishingOperation.html\#captureEspecesFields tutti.editSpeciesBatch.field.speciesTotalSampleSortedWeight.help=editFishingOperation.html\#captureEspecesFields @@ -260,6 +267,7 @@ tutti.editSpeciesBatch.field.speciesTotalWeight.help=editFishingOperation.html\#captureEspecesFields tutti.editSpeciesBatch.filterSpeciesBatch.help=editFishingOperation.html\#captureEspecesFields tutti.editSpeciesBatch.help=editFishingOperation.html\#captureEspeces +tutti.editSpeciesBatch.sortSpeciesBatch.help=editFishingOperation.html\#captureEspecesFields tutti.editSpeciesFrequencies.action.addLengthStepCaracteristic.help=editFishingOperation.html\#captureEspecesMensurationActions tutti.editSpeciesFrequencies.action.cancel.help=editFishingOperation.html\#captureEspecesMensurationActions tutti.editSpeciesFrequencies.action.generate.help=editFishingOperation.html\#captureEspecesMensurationActions Modified: 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 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -27,7 +27,6 @@ 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._; @@ -42,17 +41,23 @@ private static final long serialVersionUID = 1L; - public static <R extends SpeciesAbleBatch> SpeciesBatchDecorator<R> newDecorator(JXTable table) { - return new SpeciesBatchDecorator<R>(table); + public static <R extends SpeciesAbleBatch> SpeciesBatchDecorator<R> newDecorator() { + return new SpeciesBatchDecorator<R>(); } - public SpeciesBatchDecorator(JXTable table) throws IllegalArgumentException, NullPointerException { + protected final TuttiDecoratorComparator[] originalComparators; + + public SpeciesBatchDecorator() throws IllegalArgumentException, NullPointerException { super(); - // use special comparator - for (Context context : contexts) { + int nbContext = getNbContext(); + originalComparators = new TuttiDecoratorComparator[nbContext]; + + for (int i = 0; i < nbContext; i++) { TuttiDecoratorComparator comparator = (TuttiDecoratorComparator<?>) context.getComparator(0); - context.setComparator(new SpeciesBatchDecoratorComparator<R>(comparator.getExpression(), table)); + originalComparators[i] = comparator; + Context context = contexts[i]; + context.setComparator(new SpeciesBatchDecoratorComparator<R>(comparator.getExpression())); } } @@ -84,4 +89,20 @@ } return result; } + + public TuttiDecoratorComparator getOriginalComparator() { + return originalComparators[contextIndex]; + } + + protected int contextIndex = 0; + + @Override + public void setContextIndex(int index) { + super.setContextIndex(index); + this.contextIndex = index; + } + + public int getContextIndex() { + return contextIndex; + } } Modified: 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 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -26,10 +26,8 @@ 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; /** @@ -44,18 +42,14 @@ */ public class SpeciesBatchDecoratorComparator<R extends SpeciesAbleBatch> extends TuttiDecorator.TuttiDecoratorComparator<R> { - static class RowComparatorContext implements Comparable<RowComparatorContext> { + class RowComparatorContext implements Comparable<RowComparatorContext> { private final String speciesText; private final int rowIndex; - private final JXTable table; - - RowComparatorContext(JXTable table, - String speciesText, + RowComparatorContext(String speciesText, int rowIndex) { - this.table = table; this.speciesText = speciesText; this.rowIndex = rowIndex; } @@ -63,23 +57,11 @@ @Override public int compareTo(RowComparatorContext o) { // first compare on speciesText - int result = speciesText.compareTo(o.speciesText); + int result = sortSign * 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; - } + // respect natural order + result = rowIndex - o.rowIndex; } return result; } @@ -87,11 +69,21 @@ private static final long serialVersionUID = 1L; - JXTable table; + SpeciesSortMode speciesSortMode; - public SpeciesBatchDecoratorComparator(String expression, JXTable table) { + int sortSign; + + public void setSpeciesSortMode(SpeciesSortMode speciesSortMode) { + this.speciesSortMode = speciesSortMode; + if (speciesSortMode == SpeciesSortMode.DESC) { + sortSign = -1; + } else { + sortSign = 1; + } + } + + public SpeciesBatchDecoratorComparator(String expression) { super(expression); - this.table = table; } @Override @@ -102,7 +94,7 @@ for (R data : datas) { String speciesText = decorator.toString(data); - Comparable value = new RowComparatorContext(table, speciesText, index++); + Comparable value = new RowComparatorContext(speciesText, index++); valueCache.put(data, value); } Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchRowHelper.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchRowHelper.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchRowHelper.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -0,0 +1,296 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import fr.ifremer.shared.application.swing.table.AbstractApplicationTableModel; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.TuttiDecorator; +import jaxx.runtime.SwingUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.table.TableColumnExt; +import org.nuiton.decorator.DecoratorUtil; + +import javax.swing.ButtonGroup; +import javax.swing.JLabel; +import javax.swing.JPopupMenu; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JSeparator; +import javax.swing.SwingUtilities; +import javax.swing.table.JTableHeader; +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.Serializable; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import static org.nuiton.i18n.I18n._; + +/** + * Helper methods aroun sorting species rows. + * Created on 1/8/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SpeciesBatchRowHelper { + + /** Logger. */ + private static final Log log = LogFactory.getLog(SpeciesBatchRowHelper.class); + + public static final String SPECIES_DECORATOR = "decorator"; + + public static final String SPECIES_DECORATOR_INDEX = "decoratorIndex"; + + public static <E extends SpeciesAbleBatch> int getIndexToInsert(List<E> rows, + E newRow, + SpeciesSortMode sortMode, + SpeciesBatchDecorator decorator) { + + int result; + + int rowsSize = rows.size(); + if (sortMode == SpeciesSortMode.NONE) { + // after the last row + result = rowsSize; + } else { + + // get the universe of species + Set<Species> speciesSet = Sets.newHashSet(); + for (E row : rows) { + speciesSet.add(row.getSpecies()); + } + Species newSpecies = newRow.getSpecies(); + + boolean speciestoAdd = speciesSet.add(newSpecies); + + int nbSpecies = speciesSet.size(); + + // sort it + List<Species> speciesList = Lists.newArrayList(speciesSet); + TuttiDecorator.TuttiDecoratorComparator<Species> comparator = decorator.getOriginalComparator(); + comparator.init(decorator, speciesList); + Collections.sort(speciesList, comparator); + if (sortMode == SpeciesSortMode.DESC) { + + // reserve order + Collections.reverse(speciesList); + } + + int indexOf = speciesList.indexOf(newSpecies); + + if (!speciestoAdd) { + // add after all rows of the species + indexOf++; + } + + if (indexOf == 0) { + + // limit case: first row + result = 0; + } else if (indexOf >= nbSpecies) { + + // limit case: last row + result = rowsSize; + } else { + + // must insert before this species + Species beforeSpecies; + if (speciestoAdd) { + beforeSpecies = speciesList.get(indexOf + 1); + } else { + beforeSpecies = speciesList.get(indexOf); + } + result = 0; + for (E row : rows) { + Species species = row.getSpecies(); + if (beforeSpecies.equals(species)) { + break; + } + result++; + } + } + } + return result; + } + + public static TuttiDecorator<Species> getSpeciesColumnDecorator(TableColumnExt tableColumn) { + TuttiDecorator<Species> decorator = (TuttiDecorator<Species>) tableColumn.getClientProperty(SPECIES_DECORATOR); + return decorator; + } + + public static <R extends Serializable, T extends AbstractApplicationTableModel<R>> void installSpeciesColumnComparatorPopup(JXTable table, + TableColumnExt speciesColumn, + SpeciesSortableRowModel optionalModel, + String... tips) { + + ButtonGroup buttonGroup = new ButtonGroup(); + + SpeciesDecoratorListener<R, T> speciesDecoratorListener = + new SpeciesDecoratorListener<R, T>(table, buttonGroup, optionalModel); + + TuttiDecorator<Species> decorator = + getSpeciesColumnDecorator(speciesColumn); + + JPopupMenu popup = new JPopupMenu(); + popup.add(new JLabel(_("tutti.ui.change.species.decorator"))); + popup.add(new JSeparator()); + + for (int i = 0, nbContext = decorator.getNbContext(); i < nbContext; i++) { + String property = decorator.getProperty(i); + + String i18nName = "tutti.property." + property; + speciesColumn.putClientProperty(i18nName, tips[i]); + JRadioButtonMenuItem item = new JRadioButtonMenuItem(tips[i]); + item.putClientProperty(SPECIES_DECORATOR_INDEX, i); + item.addActionListener(speciesDecoratorListener); + if (i == 0) { + // select the first property (as it is the + item.setSelected(true); + } + buttonGroup.add(item); + popup.add(item); + } + + // recompute the header tip using the decorator + speciesDecoratorListener.recomputeSpeciesColumnTip(); + + // listen when to show popup menu on cell header + table.getTableHeader().addMouseListener( + new ShowSpeciesDecoratorPopupListener(popup)); + + } + + public static <R extends SpeciesAbleBatch> void sortSpeciesRows(SpeciesBatchDecoratorComparator comparator, + SpeciesBatchDecorator decorator, + List<R> rows, + SpeciesSortMode speciesSortMode) { + comparator.setSpeciesSortMode(speciesSortMode); + comparator.init(decorator, rows); + + switch (speciesSortMode) { + + case NONE: + // nothing special to do + break; + case ASC: + case DESC: + // sort + DecoratorUtil.sort(decorator, rows, decorator.getContextIndex()); + break; + } + } + + protected static class SpeciesDecoratorListener<R extends Serializable, T extends AbstractApplicationTableModel<R>> implements ActionListener { + + protected final JXTable table; + + protected final ButtonGroup buttonGroup; + + protected final SpeciesSortableRowModel optionalModel; + + protected final TuttiDecorator<Species> decorator; + + protected final TableColumnExt column; + + public SpeciesDecoratorListener(JXTable table, + ButtonGroup buttonGroup, + SpeciesSortableRowModel optionalModel) { + this.table = table; + this.buttonGroup = buttonGroup; + this.optionalModel = optionalModel; + this.column = (TableColumnExt) table.getColumn(0); + this.decorator = getSpeciesColumnDecorator(column); + } + + @Override + public void actionPerformed(ActionEvent e) { + + JRadioButtonMenuItem source = (JRadioButtonMenuItem) e.getSource(); + buttonGroup.setSelected(source.getModel(), true); + + Integer index = + (Integer) source.getClientProperty(SPECIES_DECORATOR_INDEX); + + if (log.isInfoEnabled()) { + log.info("Selected decorator context index: " + index); + } + + // do the decoration from here + decorator.setContextIndex(index); + + column.setComparator(decorator.getCurrentComparator()); + + // recompute the header tip + recomputeSpeciesColumnTip(); + + if (optionalModel != null) { + + // set new index in model + optionalModel.setSpeciesDecoratorContextIndex(index); + } else { + + // reload table data + T tableModel = (T) table.getModel(); + + // keep selected rows + List<R> rowsToReSelect = Lists.newArrayList(); + for (int rowIndex : SwingUtil.getSelectedModelRows(table)) { + R row = tableModel.getEntry(rowIndex); + rowsToReSelect.add(row); + } + + // fire model (will reload the comparator) + tableModel.fireTableDataChanged(); + + // reselect rows + for (R row : rowsToReSelect) { + int modelRowIndex = tableModel.getRowIndex(row); + SwingUtil.addRowSelectionInterval(table, modelRowIndex); + } + } + } + + public void recomputeSpeciesColumnTip() { + List<String> tips = Lists.newArrayList(); + for (int i = 0, nbContext = decorator.getNbContext(); i < nbContext; i++) { + String property = decorator.getProperty(i); + + String i18nName = "tutti.property." + property; + String tip = (String) column.getClientProperty(i18nName); + tips.add(tip); + } + String tip = Joiner.on(" - ").join(tips); + column.setToolTipText(tip); + } + } + + protected static class ShowSpeciesDecoratorPopupListener extends MouseAdapter { + + private final JPopupMenu popup; + + public ShowSpeciesDecoratorPopupListener(JPopupMenu popup) { + this.popup = popup; + } + + @Override + public void mouseClicked(MouseEvent e) { + JTableHeader source = (JTableHeader) e.getSource(); + Point point = e.getPoint(); + int columnIndex = source.columnAtPoint(point); + + boolean rightClick = SwingUtilities.isRightMouseButton(e); + if (columnIndex == 0 && rightClick) { + e.consume(); + popup.show(source, e.getX(), e.getY()); + } + } + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchRowHelper.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortMode.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortMode.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortMode.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -0,0 +1,14 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +/** + * Created on 1/7/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since XXX + */ +public enum SpeciesSortMode { + + NONE, + ASC, + DESC +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortMode.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortableRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortableRowModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortableRowModel.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -0,0 +1,34 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +/** + * Created on 1/8/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 3.0 + */ +public interface SpeciesSortableRowModel { + + String PROPERTY_SPECIES_SORT_MODE = "speciesSortMode"; + + String PROPERTY_SPECIES_SORT_MODE_NONE = "speciesSortModeNone"; + + String PROPERTY_SPECIES_SORT_MODE_ASC = "speciesSortModeAsc"; + + String PROPERTY_SPECIES_SORT_MODE_DESC = "speciesSortModeDesc"; + + String PROPERTY_SPECIES_DECORATOR_CONTEXT_INDEX = "speciesDecoratorContextIndex"; + + SpeciesSortMode getSpeciesSortMode(); + + void setSpeciesSortMode(SpeciesSortMode speciesSortMode); + + boolean isSpeciesSortModeNone(); + + boolean isSpeciesSortModeAsc(); + + boolean isSpeciesSortModeDesc(); + + int getSpeciesDecoratorContextIndex(); + + void setSpeciesDecoratorContextIndex(int speciesDecoratorContextIndex); +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesSortableRowModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css 2014-01-08 12:34:01 UTC (rev 1479) @@ -141,6 +141,10 @@ border: {new TitledBorder(null, "")}; } +#speciesSortTablePane { + border: {new TitledBorder(null, "")}; +} + #filterBenthosBatchLabel { actionIcon: filter; text: "tutti.editBenthosBatch.filterBatch"; @@ -149,30 +153,14 @@ _help: {"tutti.editBenthosBatch.filterBatch.help"}; } -#filterBenthosBatchAllButton { - text: "tutti.editBenthosBatch.filterBatch.mode.all"; - toolTipText: "tutti.editBenthosBatch.filterBatch.mode.all.tip"; - value: "all"; - selected: {model.isTableViewModeAll()}; - buttonGroup: "filterBenthosBatchMode"; +#speciesSortBatchLabel { + actionIcon: sort; + text: "tutti.editBenthosBatch.sortSpeciesBatch"; + toolTipText: "tutti.editBenthosBatch.sortSpeciesBatch.tip"; + _strongStyle: true; + _help: {"tutti.editBenthosBatch.sortSpeciesBatch.help"}; } -#filterBenthosBatchLeafButton { - text: "tutti.editBenthosBatch.filterBatch.mode.leaf"; - toolTipText: "tutti.editBenthosBatch.filterBatch.mode.leaf.tip"; - value: "leaf"; - selected: {model.isTableViewModeLeaf()}; - buttonGroup: "filterBenthosBatchMode"; -} - -#filterBenthosBatchRootButton { - text: {handler.getFilterBenthosBatchRootButtonText(model.getRootNumber())}; - toolTipText: "tutti.editBenthosBatch.filterBatch.mode.root.tip"; - value: "root"; - selected: {model.isTableViewModeRoot()}; - buttonGroup: "filterBenthosBatchMode"; -} - #splitBenthosBatchMenu { actionIcon: batch-split; text: "tutti.editBenthosBatch.action.splitBatch"; @@ -249,6 +237,30 @@ _help: {"tutti.editBenthosBatch.action.editFrequencies.help"}; } +#filterBenthosBatchAllButton { + text: "tutti.editBenthosBatch.filterBatch.mode.all"; + toolTipText: "tutti.editBenthosBatch.filterBatch.mode.all.tip"; + value: "all"; + selected: {model.isTableViewModeAll()}; + buttonGroup: "filterBenthosBatchMode"; +} + +#filterBenthosBatchLeafButton { + text: "tutti.editBenthosBatch.filterBatch.mode.leaf"; + toolTipText: "tutti.editBenthosBatch.filterBatch.mode.leaf.tip"; + value: "leaf"; + selected: {model.isTableViewModeLeaf()}; + buttonGroup: "filterBenthosBatchMode"; +} + +#filterBenthosBatchRootButton { + text: {handler.getFilterBenthosBatchRootButtonText(model.getRootNumber())}; + toolTipText: "tutti.editBenthosBatch.filterBatch.mode.root.tip"; + value: "root"; + selected: {model.isTableViewModeRoot()}; + buttonGroup: "filterBenthosBatchMode"; +} + #importMultiPostButton { actionIcon: import; text: "tutti.editBenthosBatch.action.importMultiPost"; @@ -274,3 +286,30 @@ i18nMnemonic: "tutti.editBenthosBatch.action.createBatch.mnemonic"; _help: {"tutti.editBenthosBatch.action.createBatch.help"}; } + +#speciesSortModeNoneButton { + text: "tutti.editBenthosBatch.speciesSortMode.none"; + toolTipText: "tutti.editBenthosBatch.speciesSortMode.none.tip"; + _help: {"tutti.editBenthosBatch.field.speciesSortMode.none.help"}; + value: "NONE"; + selected: {model.isSpeciesSortModeNone()}; + buttonGroup: "speciesSort"; +} + +#speciesSortModeAscButton { + text: "tutti.editBenthosBatch.speciesSortMode.asc"; + toolTipText: "tutti.editBenthosBatch.speciesSortMode.asc.tip"; + _help: {"tutti.editBenthosBatch.field.speciesSortMode.asc.help"}; + value: "ASC"; + selected: {model.isSpeciesSortModeAsc()}; + buttonGroup: "speciesSort"; +} + +#speciesSortModeDescButton { + text: "tutti.editBenthosBatch.speciesSortMode.desc"; + toolTipText: "tutti.editBenthosBatch.speciesSortMode.desc.tip"; + _help: {"tutti.editBenthosBatch.field.speciesSortMode.desc.help"}; + value: "DESC"; + selected: {model.isSpeciesSortModeDesc()}; + buttonGroup: "speciesSort"; +} Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx 2014-01-08 12:34:01 UTC (rev 1479) @@ -28,7 +28,7 @@ <import><![CDATA[ fr.ifremer.tutti.ui.swing.TuttiHelpBroker fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode - + fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesSortMode fr.ifremer.tutti.ui.swing.util.TuttiUI fr.ifremer.tutti.ui.swing.util.TuttiUIUtil fr.ifremer.shared.application.swing.computable.ComputableDataEditor @@ -143,14 +143,25 @@ <JButton id='createBenthosBatchButton' onActionPerformed='handler.createBatch()'/> </JPanel> - <JPanel id='filterTablePane' constraints='BorderLayout.CENTER'> - <JLabel id='filterBenthosBatchLabel'/> - <JRadioButton id='filterBenthosBatchAllButton' - onActionPerformed='model.setTableViewMode(TableViewMode.ALL)'/> - <JRadioButton id='filterBenthosBatchLeafButton' - onActionPerformed='model.setTableViewMode(TableViewMode.LEAF)'/> - <JRadioButton id='filterBenthosBatchRootButton' - onActionPerformed='model.setTableViewMode(TableViewMode.ROOT)'/> + <JPanel constraints='BorderLayout.CENTER' layout='{new GridLayout()}'> + <JPanel id='filterTablePane'> + <JLabel id='filterBenthosBatchLabel'/> + <JRadioButton id='filterBenthosBatchAllButton' + onActionPerformed='model.setTableViewMode(TableViewMode.ALL)'/> + <JRadioButton id='filterBenthosBatchLeafButton' + onActionPerformed='model.setTableViewMode(TableViewMode.LEAF)'/> + <JRadioButton id='filterBenthosBatchRootButton' + onActionPerformed='model.setTableViewMode(TableViewMode.ROOT)'/> + </JPanel> + <JPanel id='speciesSortTablePane'> + <JLabel id='speciesSortBatchLabel'/> + <JRadioButton id='speciesSortModeNoneButton' + onActionPerformed='model.setSpeciesSortMode(SpeciesSortMode.NONE)'/> + <JRadioButton id='speciesSortModeAscButton' + onActionPerformed='model.setSpeciesSortMode(SpeciesSortMode.ASC)'/> + <JRadioButton id='speciesSortModeDescButton' + onActionPerformed='model.setSpeciesSortMode(SpeciesSortMode.DESC)'/> + </JPanel> </JPanel> </JPanel> </cell> @@ -164,8 +175,4 @@ onKeyPressed='handler.openRowMenu(event, tablePopup)'/> </JScrollPane> - <!--JPanel constraints='BorderLayout.SOUTH' - minimumSize="{new Dimension(10,30)}" - maximumSize="{new Dimension(10,30)}" - preferredSize="{new Dimension(10,30)}"/--> </JPanel> 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 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -43,7 +43,6 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.service.TuttiDecorator; import fr.ifremer.tutti.service.ValidationService; import fr.ifremer.tutti.ui.swing.content.operation.catches.AbstractTuttiBatchTableUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; @@ -52,6 +51,9 @@ 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.SpeciesBatchDecoratorComparator; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchRowHelper; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesSortMode; import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.create.CreateBenthosBatchUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.create.CreateBenthosBatchUIModel; @@ -263,6 +265,16 @@ } } } + + SpeciesBatchDecorator decorator = getSpeciesColumnDecorator(); + + SpeciesSortMode speciesSortMode = model.getSpeciesSortMode(); + SpeciesBatchDecoratorComparator comparator = getSpeciesRowComparator(); + + SpeciesBatchRowHelper.sortSpeciesRows(comparator, + decorator, + rows, + speciesSortMode); } model.setRows(rows); @@ -714,6 +726,7 @@ BenthosBatchUIModel model = new BenthosBatchUIModel(catchesUIModel); model.setTableViewMode(TableViewMode.ALL); + model.setSpeciesSortMode(SpeciesSortMode.NONE); ui.setContextValue(model); } @@ -761,8 +774,8 @@ BenthosBatchTableModel.SPECIES); speciesColumn.setSortable(true); SpeciesBatchDecorator<BenthosBatchRowModel> speciesDecorator = - SpeciesBatchDecorator.newDecorator(table); - speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); + SpeciesBatchDecorator.newDecorator(); + speciesColumn.putClientProperty(SpeciesBatchRowHelper.SPECIES_DECORATOR, speciesDecorator); speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); } @@ -855,6 +868,39 @@ getTable().setRowFilter(filter); } }); + + // when species sort mode change, must reload the firshing operation + // and applying the sort on model + getModel().addPropertyChangeListener(BenthosBatchUIModel.PROPERTY_SPECIES_SORT_MODE, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + SpeciesSortMode newValue = (SpeciesSortMode) evt.getNewValue(); + if (log.isInfoEnabled()) { + log.info("New species sort mode: " + newValue); + } + + // must reload fishing operation + selectFishingOperation(getModel().getFishingOperation()); + } + }); + + // when species sort mode change, must reload the firshing operation + // and applying the sort on model + getModel().addPropertyChangeListener(BenthosBatchUIModel.PROPERTY_SPECIES_DECORATOR_CONTEXT_INDEX, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + int newValue = (int) evt.getNewValue(); + if (log.isInfoEnabled()) { + log.info("New species decorator context index: " + newValue); + } + + // update the decorator context index + getSpeciesColumnDecorator().setContextIndex(newValue); + + // reload fishing operation + selectFishingOperation(getModel().getFishingOperation()); + } + }); } @Override @@ -885,37 +931,22 @@ e.getLastRow() == Integer.MAX_VALUE) { // get column comparator - TuttiDecorator.TuttiDecoratorComparator<BenthosBatchRowModel> comparator = - (TuttiDecorator.TuttiDecoratorComparator<BenthosBatchRowModel>) - speciesColumn.getComparator(); + SpeciesBatchDecoratorComparator<BenthosBatchRowModel> comparator = getSpeciesRowComparator(); - // get column comparator - TuttiDecorator<BenthosBatchRowModel> decorator = - TuttiUIUtil.getSpeciesColumnDecorator(speciesColumn); + // get column decorator + SpeciesBatchDecorator<BenthosBatchRowModel> decorator = getSpeciesColumnDecorator(); - boolean comparatorNull = comparator == null; - if (comparatorNull) { - - // first time coming here, add the comparator - comparator = decorator.getCurrentComparator(); - } - // init comparator with model species list - comparator.init(decorator, tableModel.getRows()); - - if (comparatorNull) { - - // affect it to colum - speciesColumn.setComparator(comparator); - } + comparator.init((SpeciesBatchDecorator) decorator, tableModel.getRows()); } } }); // create popup to change species decorator - TuttiUIUtil.<BenthosBatchRowModel, BenthosBatchTableModel>installSpeciesColumnComparatorPopup( + SpeciesBatchRowHelper.installSpeciesColumnComparatorPopup( table, speciesColumn, + getModel(), _("tutti.species.surveyCode.tip"), _("tutti.species.name.tip") ); @@ -966,8 +997,16 @@ saveRow(newRow); - tableModel.addNewRow(newRow); - TuttiUIUtil.selectFirstCellOnLastRow(getTable()); + int insertIndex = SpeciesBatchRowHelper.getIndexToInsert( + tableModel.getRows(), + newRow, + getModel().getSpeciesSortMode(), + getSpeciesColumnDecorator()); + if (log.isDebugEnabled()) { + log.debug("Will insert at index: " + insertIndex); + } + tableModel.addNewRow(insertIndex, newRow); + TuttiUIUtil.doSelectCell(getTable(), insertIndex, 0); // update speciesUsed addToSpeciesUsed(newRow); @@ -1669,4 +1708,36 @@ } return usedValues; } + + protected SpeciesBatchDecoratorComparator<BenthosBatchRowModel> getSpeciesRowComparator() { + TableColumnExt speciesColumn = + (TableColumnExt) getTable().getColumns().get(0); + + SpeciesBatchDecoratorComparator<BenthosBatchRowModel> comparator = + (SpeciesBatchDecoratorComparator<BenthosBatchRowModel>) speciesColumn.getComparator(); + + SpeciesBatchDecorator<BenthosBatchRowModel> decorator = getSpeciesColumnDecorator(); + + boolean comparatorNull = comparator == null; + if (comparatorNull) { + + // first time coming here, add the comparator + comparator = (SpeciesBatchDecoratorComparator) decorator.getCurrentComparator(); + } + + if (comparatorNull) { + + // affect it to colum + speciesColumn.setComparator(comparator); + } + return comparator; + } + + protected SpeciesBatchDecorator<BenthosBatchRowModel> getSpeciesColumnDecorator() { + TableColumnExt speciesColumn = + (TableColumnExt) getTable().getColumns().get(0); + SpeciesBatchDecorator<BenthosBatchRowModel> decorator = + (SpeciesBatchDecorator<BenthosBatchRowModel>) SpeciesBatchRowHelper.getSpeciesColumnDecorator(speciesColumn); + return decorator; + } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIModel.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -25,13 +25,15 @@ */ import com.google.common.collect.Multimap; +import fr.ifremer.shared.application.swing.computable.ComputableData; +import fr.ifremer.shared.application.swing.tab.TabContentModel; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.content.operation.catches.AbstractTuttiBatchUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesSortMode; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesSortableRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode; -import fr.ifremer.shared.application.swing.tab.TabContentModel; -import fr.ifremer.shared.application.swing.computable.ComputableData; import org.apache.commons.collections.CollectionUtils; import static org.nuiton.i18n.I18n.n_; @@ -41,7 +43,7 @@ * @since 0.1 */ public class BenthosBatchUIModel extends AbstractTuttiBatchUIModel<BenthosBatchRowModel, BenthosBatchUIModel> - implements TabContentModel { + implements TabContentModel, SpeciesSortableRowModel { private static final long serialVersionUID = 1L; @@ -142,6 +144,20 @@ /** @since 1.0 */ protected int leafNumber; + /** + * How to sort table. + * + * @since 3.0 + */ + protected SpeciesSortMode speciesSortMode; + + /** + * Which decorator index for species column decorate. + * + * @since 3.0 + */ + protected int speciesDecoratorContextIndex; + public BenthosBatchUIModel(EditCatchesUIModel catchesUIModel) { super(catchesUIModel, EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, @@ -375,4 +391,50 @@ this.editFrequenciesEnabled = editFrequenciesEnabled; firePropertyChange(PROPERTY_EDIT_FREQUENCIES_ENABLED, null, editFrequenciesEnabled); } + + //------------------------------------------------------------------------// + //-- SpeciesSortableRowModel --// + //------------------------------------------------------------------------// + + @Override + public SpeciesSortMode getSpeciesSortMode() { + return speciesSortMode; + } + + @Override + public void setSpeciesSortMode(SpeciesSortMode speciesSortMode) { + Object oldValue = getSpeciesSortMode(); + this.speciesSortMode = speciesSortMode; + firePropertyChange(PROPERTY_SPECIES_SORT_MODE, oldValue, speciesSortMode); + firePropertyChange(PROPERTY_SPECIES_SORT_MODE_NONE, null, isSpeciesSortModeNone()); + firePropertyChange(PROPERTY_SPECIES_SORT_MODE_ASC, null, isSpeciesSortModeAsc()); + firePropertyChange(PROPERTY_SPECIES_SORT_MODE_DESC, null, isSpeciesSortModeDesc()); + } + + @Override + public boolean isSpeciesSortModeNone() { + return SpeciesSortMode.NONE.equals(speciesSortMode); + } + + @Override + public boolean isSpeciesSortModeAsc() { + return SpeciesSortMode.ASC.equals(speciesSortMode); + } + + @Override + public boolean isSpeciesSortModeDesc() { + return SpeciesSortMode.DESC.equals(speciesSortMode); + } + + @Override + public int getSpeciesDecoratorContextIndex() { + return speciesDecoratorContextIndex; + } + + @Override + public void setSpeciesDecoratorContextIndex(int speciesDecoratorContextIndex) { + int oldValue = getSpeciesDecoratorContextIndex(); + this.speciesDecoratorContextIndex = speciesDecoratorContextIndex; + firePropertyChange(PROPERTY_SPECIES_DECORATOR_CONTEXT_INDEX, oldValue, speciesDecoratorContextIndex); + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2014-01-08 12:34:01 UTC (rev 1479) @@ -141,6 +141,10 @@ border: {new TitledBorder(null, "")}; } +#speciesSortTablePane { + border: {new TitledBorder(null, "")}; +} + #filterSpeciesBatchLabel { actionIcon: filter; text: "tutti.editSpeciesBatch.filterBatch"; @@ -149,6 +153,14 @@ _help: {"tutti.editSpeciesBatch.filterSpeciesBatch.help"}; } +#speciesSortBatchLabel { + actionIcon: sort; + text: "tutti.editSpeciesBatch.sortSpeciesBatch"; + toolTipText: "tutti.editSpeciesBatch.sortSpeciesBatch.tip"; + _strongStyle: true; + _help: {"tutti.editSpeciesBatch.sortSpeciesBatch.help"}; +} + #splitSpeciesBatchMenu { actionIcon: batch-split; text: "tutti.editSpeciesBatch.action.splitBatch"; @@ -283,3 +295,30 @@ i18nMnemonic: "tutti.editSpeciesBatch.action.createBatch.mnemonic"; _help: {"tutti.editSpeciesBatch.action.createBatch.help"}; } + +#speciesSortModeNoneButton { + text: "tutti.editSpeciesBatch.speciesSortMode.none"; + toolTipText: "tutti.editSpeciesBatch.speciesSortMode.none.tip"; + _help: {"tutti.editSpeciesBatch.field.speciesSortMode.none.help"}; + value: "NONE"; + selected: {model.isSpeciesSortModeNone()}; + buttonGroup: "speciesSort"; +} + +#speciesSortModeAscButton { + text: "tutti.editSpeciesBatch.speciesSortMode.asc"; + toolTipText: "tutti.editSpeciesBatch.speciesSortMode.asc.tip"; + _help: {"tutti.editSpeciesBatch.field.speciesSortMode.asc.help"}; + value: "ASC"; + selected: {model.isSpeciesSortModeAsc()}; + buttonGroup: "speciesSort"; +} + +#speciesSortModeDescButton { + text: "tutti.editSpeciesBatch.speciesSortMode.desc"; + toolTipText: "tutti.editSpeciesBatch.speciesSortMode.desc.tip"; + _help: {"tutti.editSpeciesBatch.field.speciesSortMode.desc.help"}; + value: "DESC"; + selected: {model.isSpeciesSortModeDesc()}; + buttonGroup: "speciesSort"; +} \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2014-01-08 12:34:01 UTC (rev 1479) @@ -27,8 +27,8 @@ <import><![CDATA[ fr.ifremer.tutti.ui.swing.TuttiHelpBroker - fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode + fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesSortMode fr.ifremer.tutti.ui.swing.util.TuttiUI fr.ifremer.tutti.ui.swing.util.TuttiUIUtil fr.ifremer.shared.application.swing.computable.ComputableDataEditor @@ -45,7 +45,7 @@ <script><![CDATA[ -public SpeciesBatchUI(EditCatchesUI parentUI) { +public SpeciesBatchUI(TuttiUI<?,?> parentUI) { TuttiUIUtil.setParentUI(this, parentUI); } ]]></script> @@ -145,14 +145,25 @@ <JButton id='createSpeciesBatchButton' onActionPerformed='handler.createBatch()'/> </JPanel> - <JPanel id='filterTablePane' constraints='BorderLayout.CENTER'> - <JLabel id='filterSpeciesBatchLabel'/> - <JRadioButton id='filterSpeciesBatchAllButton' - onActionPerformed='model.setTableViewMode(TableViewMode.ALL)'/> - <JRadioButton id='filterSpeciesBatchLeafButton' - onActionPerformed='model.setTableViewMode(TableViewMode.LEAF)'/> - <JRadioButton id='filterSpeciesBatchRootButton' - onActionPerformed='model.setTableViewMode(TableViewMode.ROOT)'/> + <JPanel constraints='BorderLayout.CENTER' layout='{new GridLayout()}'> + <JPanel id='filterTablePane'> + <JLabel id='filterSpeciesBatchLabel'/> + <JRadioButton id='filterSpeciesBatchAllButton' + onActionPerformed='model.setTableViewMode(TableViewMode.ALL)'/> + <JRadioButton id='filterSpeciesBatchLeafButton' + onActionPerformed='model.setTableViewMode(TableViewMode.LEAF)'/> + <JRadioButton id='filterSpeciesBatchRootButton' + onActionPerformed='model.setTableViewMode(TableViewMode.ROOT)'/> + </JPanel> + <JPanel id='speciesSortTablePane'> + <JLabel id='speciesSortBatchLabel'/> + <JRadioButton id='speciesSortModeNoneButton' + onActionPerformed='model.setSpeciesSortMode(SpeciesSortMode.NONE)'/> + <JRadioButton id='speciesSortModeAscButton' + onActionPerformed='model.setSpeciesSortMode(SpeciesSortMode.ASC)'/> + <JRadioButton id='speciesSortModeDescButton' + onActionPerformed='model.setSpeciesSortMode(SpeciesSortMode.DESC)'/> + </JPanel> </JPanel> </JPanel> </cell> @@ -166,18 +177,4 @@ onKeyPressed='handler.openRowMenu(event, tablePopup)'/> </JScrollPane> - <!--JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER' columnHeaderView="{table.getTableHeader()}"> - <JPanel layout='{new BorderLayout()}'> - <JXTable id='table' constraints='BorderLayout.CENTER' - onMouseClicked='handler.autoSelectRowInTable(event, tablePopup)' - onKeyPressed='handler.openRowMenu(event, tablePopup)'/> - <JLabel constraints='BorderLayout.SOUTH' - preferredSize="{new Dimension(10,100)}"/> - </JPanel> - - </JScrollPane--> - - - <!--background="{Color.WHITE}"/>--> - </JPanel> 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 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -43,7 +43,6 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.service.TuttiDecorator; import fr.ifremer.tutti.service.ValidationService; import fr.ifremer.tutti.ui.swing.content.operation.catches.AbstractTuttiBatchTableUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; @@ -52,6 +51,9 @@ 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.SpeciesBatchDecoratorComparator; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchRowHelper; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesSortMode; 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; @@ -216,6 +218,16 @@ } } } + + SpeciesBatchDecorator decorator = getSpeciesColumnDecorator(); + + SpeciesSortMode speciesSortMode = model.getSpeciesSortMode(); + SpeciesBatchDecoratorComparator comparator = getSpeciesRowComparator(); + + SpeciesBatchRowHelper.sortSpeciesRows(comparator, + decorator, + rows, + speciesSortMode); } model.setRows(rows); @@ -669,6 +681,7 @@ SpeciesBatchUIModel model = new SpeciesBatchUIModel(catchesUIModel); model.setTableViewMode(TableViewMode.ALL); + model.setSpeciesSortMode(SpeciesSortMode.NONE); ui.setContextValue(model); } @@ -716,8 +729,8 @@ SpeciesBatchTableModel.SPECIES); speciesColumn.setSortable(true); SpeciesBatchDecorator<SpeciesBatchRowModel> speciesDecorator = - SpeciesBatchDecorator.newDecorator(table); - speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); + SpeciesBatchDecorator.newDecorator(); + speciesColumn.putClientProperty(SpeciesBatchRowHelper.SPECIES_DECORATOR, speciesDecorator); speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); } @@ -811,6 +824,39 @@ getTable().setRowFilter(filter); } }); + + // when species sort mode change, must reload the firshing operation + // and applying the sort on model + getModel().addPropertyChangeListener(SpeciesBatchUIModel.PROPERTY_SPECIES_SORT_MODE, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + SpeciesSortMode newValue = (SpeciesSortMode) evt.getNewValue(); + if (log.isInfoEnabled()) { + log.info("New species sort mode: " + newValue); + } + + // must reload fishing operation + selectFishingOperation(getModel().getFishingOperation()); + } + }); + + // when species sort mode change, must reload the firshing operation + // and applying the sort on model + getModel().addPropertyChangeListener(SpeciesBatchUIModel.PROPERTY_SPECIES_DECORATOR_CONTEXT_INDEX, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + int newValue = (int) evt.getNewValue(); + if (log.isInfoEnabled()) { + log.info("New species decorator context index: " + newValue); + } + + // update the decorator context index + getSpeciesColumnDecorator().setContextIndex(newValue); + + // reload fishing operation + selectFishingOperation(getModel().getFishingOperation()); + } + }); } @Override @@ -839,40 +885,28 @@ int type = e.getType(); if (type == TableModelEvent.DELETE || type == TableModelEvent.INSERT || + type == TableModelEvent.INSERT || e.getLastRow() == Integer.MAX_VALUE) { // get column comparator - TuttiDecorator.TuttiDecoratorComparator<SpeciesBatchRowModel> comparator = - (TuttiDecorator.TuttiDecoratorComparator<SpeciesBatchRowModel>) - speciesColumn.getComparator(); + SpeciesBatchDecoratorComparator<SpeciesBatchRowModel> comparator = + getSpeciesRowComparator(); - // get column comparator - TuttiDecorator<SpeciesBatchRowModel> decorator = - TuttiUIUtil.getSpeciesColumnDecorator(speciesColumn); + // get column decorator + SpeciesBatchDecorator<SpeciesBatchRowModel> decorator = + getSpeciesColumnDecorator(); - boolean comparatorNull = comparator == null; - if (comparatorNull) { - - // first time coming here, add the comparator - comparator = decorator.getCurrentComparator(); - } - // init comparator with model species list - comparator.init(decorator, tableModel.getRows()); - - if (comparatorNull) { - - // affect it to colum - speciesColumn.setComparator(comparator); - } + comparator.init((SpeciesBatchDecorator) decorator, tableModel.getRows()); } } }); // create popup to change species decorator - TuttiUIUtil.<SpeciesBatchRowModel, SpeciesBatchTableModel>installSpeciesColumnComparatorPopup( + SpeciesBatchRowHelper.installSpeciesColumnComparatorPopup( table, speciesColumn, + getModel(), _("tutti.species.surveyCode.tip"), _("tutti.species.name.tip") ); @@ -922,9 +956,18 @@ saveRow(newRow); - tableModel.addNewRow(newRow); - TuttiUIUtil.selectFirstCellOnLastRow(getTable()); + int insertIndex = SpeciesBatchRowHelper.getIndexToInsert( + tableModel.getRows(), + newRow, + getModel().getSpeciesSortMode(), + getSpeciesColumnDecorator()); + if (log.isDebugEnabled()) { + log.debug("Will insert at index: " + insertIndex); + } + tableModel.addNewRow(insertIndex, newRow); + TuttiUIUtil.doSelectCell(getTable(), insertIndex, 0); + // update speciesUsed addToSpeciesUsed(newRow); @@ -1626,4 +1669,37 @@ } return usedValues; } + + protected SpeciesBatchDecoratorComparator<SpeciesBatchRowModel> getSpeciesRowComparator() { + TableColumnExt speciesColumn = + (TableColumnExt) getTable().getColumns().get(0); + + SpeciesBatchDecoratorComparator<SpeciesBatchRowModel> comparator = + (SpeciesBatchDecoratorComparator<SpeciesBatchRowModel>) speciesColumn.getComparator(); + + SpeciesBatchDecorator<SpeciesBatchRowModel> decorator = getSpeciesColumnDecorator(); + + boolean comparatorNull = comparator == null; + if (comparatorNull) { + + // first time coming here, add the comparator + comparator = (SpeciesBatchDecoratorComparator) decorator.getCurrentComparator(); + } + + if (comparatorNull) { + + // affect it to colum + speciesColumn.setComparator(comparator); + } + return comparator; + } + + protected SpeciesBatchDecorator<SpeciesBatchRowModel> getSpeciesColumnDecorator() { + TableColumnExt speciesColumn = + (TableColumnExt) getTable().getColumns().get(0); + SpeciesBatchDecorator<SpeciesBatchRowModel> decorator = + (SpeciesBatchDecorator<SpeciesBatchRowModel>) SpeciesBatchRowHelper.getSpeciesColumnDecorator(speciesColumn); + return decorator; + } + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -27,15 +27,17 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; +import fr.ifremer.shared.application.swing.computable.ComputableData; +import fr.ifremer.shared.application.swing.tab.TabContentModel; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.content.operation.catches.AbstractTuttiBatchUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesSortMode; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesSortableRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel; -import fr.ifremer.shared.application.swing.tab.TabContentModel; -import fr.ifremer.shared.application.swing.computable.ComputableData; import org.apache.commons.collections.CollectionUtils; import java.util.List; @@ -48,7 +50,7 @@ * @since 0.1 */ public class SpeciesBatchUIModel extends AbstractTuttiBatchUIModel<SpeciesBatchRowModel, SpeciesBatchUIModel> - implements TabContentModel { + implements TabContentModel, SpeciesSortableRowModel { private static final long serialVersionUID = 1L; @@ -149,6 +151,20 @@ /** @since 1.0 */ protected int leafNumber; + /** + * How to sort table. + * + * @since 3.0 + */ + protected SpeciesSortMode speciesSortMode; + + /** + * Which decorator index for species column decorate. + * + * @since 3.0 + */ + protected int speciesDecoratorContextIndex; + public SpeciesBatchUIModel(EditCatchesUIModel catchesUIModel) { super(catchesUIModel, EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, @@ -442,4 +458,50 @@ } return result; } + + //------------------------------------------------------------------------// + //-- SpeciesSortableRowModel --// + //------------------------------------------------------------------------// + + @Override + public SpeciesSortMode getSpeciesSortMode() { + return speciesSortMode; + } + + @Override + public void setSpeciesSortMode(SpeciesSortMode speciesSortMode) { + Object oldValue = getSpeciesSortMode(); + this.speciesSortMode = speciesSortMode; + firePropertyChange(PROPERTY_SPECIES_SORT_MODE, oldValue, speciesSortMode); + firePropertyChange(PROPERTY_SPECIES_SORT_MODE_NONE, null, isSpeciesSortModeNone()); + firePropertyChange(PROPERTY_SPECIES_SORT_MODE_ASC, null, isSpeciesSortModeAsc()); + firePropertyChange(PROPERTY_SPECIES_SORT_MODE_DESC, null, isSpeciesSortModeDesc()); + } + + @Override + public boolean isSpeciesSortModeNone() { + return SpeciesSortMode.NONE.equals(speciesSortMode); + } + + @Override + public boolean isSpeciesSortModeAsc() { + return SpeciesSortMode.ASC.equals(speciesSortMode); + } + + @Override + public boolean isSpeciesSortModeDesc() { + return SpeciesSortMode.DESC.equals(speciesSortMode); + } + + @Override + public int getSpeciesDecoratorContextIndex() { + return speciesDecoratorContextIndex; + } + + @Override + public void setSpeciesDecoratorContextIndex(int speciesDecoratorContextIndex) { + int oldValue = getSpeciesDecoratorContextIndex(); + this.speciesDecoratorContextIndex = speciesDecoratorContextIndex; + firePropertyChange(PROPERTY_SPECIES_DECORATOR_CONTEXT_INDEX, oldValue, speciesDecoratorContextIndex); + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -42,8 +42,8 @@ import fr.ifremer.tutti.ui.swing.action.CloneProtocolAction; import fr.ifremer.tutti.ui.swing.action.EditProtocolAction; import fr.ifremer.tutti.ui.swing.action.ImportProtocolAction; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchRowHelper; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUI; import fr.ifremer.tutti.ui.swing.util.species.SelectSpeciesUIModel; import jaxx.runtime.SwingUtil; @@ -299,7 +299,7 @@ EditProtocolSpeciesTableModel.SPECIES_ID); speciesColumn.setSortable(true); DecoratorService.SpeciesDecorator speciesDecorator = new DecoratorService.SpeciesDecorator(); - speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); + speciesColumn.putClientProperty(SpeciesBatchRowHelper.SPECIES_DECORATOR, speciesDecorator); speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); TableColumnExt speciesSurveyCodeColumn = addColumnToModel(columnModel, @@ -358,7 +358,7 @@ EditProtocolSpeciesTableModel.SPECIES_ID); speciesColumn.setSortable(true); DecoratorService.SpeciesDecorator speciesDecorator = new DecoratorService.SpeciesDecorator(); - speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); + speciesColumn.putClientProperty(SpeciesBatchRowHelper.SPECIES_DECORATOR, speciesDecorator); speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); TableColumnExt speciesSurveyCodeColumn = addColumnToModel(columnModel, @@ -716,7 +716,7 @@ // get column comparator TuttiDecorator<Species> decorator = - TuttiUIUtil.getSpeciesColumnDecorator(tableColumn); + SpeciesBatchRowHelper.getSpeciesColumnDecorator(tableColumn); boolean comparatorNull = comparator == null; if (comparatorNull) { @@ -739,9 +739,10 @@ // create popup to change species decorator - TuttiUIUtil.<EditProtocolSpeciesRowModel, EditProtocolSpeciesTableModel>installSpeciesColumnComparatorPopup( + SpeciesBatchRowHelper.installSpeciesColumnComparatorPopup( table, speciesColumn, + null, _("tutti.species.refTaxCode.tip"), _("tutti.species.name.tip") ); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java 2014-01-08 12:34:01 UTC (rev 1479) @@ -24,41 +24,19 @@ * #L% */ -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; import fr.ifremer.shared.application.ApplicationBusinessException; -import fr.ifremer.shared.application.swing.table.AbstractApplicationTableModel; import fr.ifremer.shared.application.swing.util.ApplicationUIUtil; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.service.TuttiDecorator; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import jaxx.runtime.JAXXObject; import jaxx.runtime.JAXXUtil; -import jaxx.runtime.SwingUtil; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.table.TableColumnExt; -import javax.swing.ButtonGroup; -import javax.swing.JLabel; -import javax.swing.JPopupMenu; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JSeparator; -import javax.swing.SwingUtilities; -import javax.swing.table.JTableHeader; -import java.awt.Point; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.io.InputStream; -import java.io.Serializable; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; -import java.util.List; import static org.nuiton.i18n.I18n._; @@ -70,10 +48,6 @@ */ public final class TuttiUIUtil extends ApplicationUIUtil { - public static final String SPECIES_DECORATOR = "decorator"; - - public static final String SPECIES_DECORATOR_INDEX = "decoratorIndex"; - /** Logger. */ private static final Log log = LogFactory.getLog(TuttiUIUtil.class); @@ -135,143 +109,4 @@ } } - public static <E> TuttiDecorator<E> getSpeciesColumnDecorator(TableColumnExt tableColumn) { - TuttiDecorator<E> decorator = (TuttiDecorator<E>) - tableColumn.getClientProperty(SPECIES_DECORATOR); - return decorator; - } - - public static <R extends Serializable, T extends AbstractApplicationTableModel<R>> void installSpeciesColumnComparatorPopup(JXTable table, - TableColumnExt speciesColumn, - String... tips) { - - ButtonGroup buttonGroup = new ButtonGroup(); - - SpeciesDecoratorListener<R, T> speciesDecoratorListener = - new SpeciesDecoratorListener<R, T>(table, buttonGroup); - - TuttiDecorator<Species> decorator = - getSpeciesColumnDecorator(speciesColumn); - - JPopupMenu popup = new JPopupMenu(); - popup.add(new JLabel(_("tutti.ui.change.species.decorator"))); - popup.add(new JSeparator()); - - for (int i = 0, nbContext = decorator.getNbContext(); i < nbContext; i++) { - String property = decorator.getProperty(i); - - String i18nName = "tutti.property." + property; - speciesColumn.putClientProperty(i18nName, tips[i]); - JRadioButtonMenuItem item = new JRadioButtonMenuItem(tips[i]); - item.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR_INDEX, i); - item.addActionListener(speciesDecoratorListener); - if (i == 0) { - // select the first property (as it is the - item.setSelected(true); - } - buttonGroup.add(item); - popup.add(item); - } - - // recompute the header tip using the decorator - speciesDecoratorListener.recomputeSpeciesColumnTip(); - - // listen when to show popup menu on cell header - table.getTableHeader().addMouseListener( - new ShowSpeciesDecoratorPopupListener(popup)); - - } - - protected static class SpeciesDecoratorListener<R extends Serializable, T extends AbstractApplicationTableModel<R>> implements ActionListener { - - protected final JXTable table; - - protected final ButtonGroup buttonGroup; - - protected final TuttiDecorator<Species> decorator; - - protected final TableColumnExt column; - - public SpeciesDecoratorListener(JXTable table, - ButtonGroup buttonGroup) { - this.table = table; - this.buttonGroup = buttonGroup; - this.column = (TableColumnExt) table.getColumn(0); - this.decorator = TuttiUIUtil.getSpeciesColumnDecorator(column); - } - - @Override - public void actionPerformed(ActionEvent e) { - - JRadioButtonMenuItem source = (JRadioButtonMenuItem) e.getSource(); - buttonGroup.setSelected(source.getModel(), true); - - Integer index = - (Integer) source.getClientProperty(TuttiUIUtil.SPECIES_DECORATOR_INDEX); - - if (log.isInfoEnabled()) { - log.info("Selected decorator context index: " + index); - } - - decorator.setContextIndex(index); - - column.setComparator(decorator.getCurrentComparator()); - - // recompute the header tip - recomputeSpeciesColumnTip(); - - T tableModel = (T) table.getModel(); - - // keep selected rows - List<R> rowsToReSelect = Lists.newArrayList(); - for (int rowIndex : SwingUtil.getSelectedModelRows(table)) { - R row = tableModel.getEntry(rowIndex); - rowsToReSelect.add(row); - } - - // fire model (will reload the comparator) - tableModel.fireTableDataChanged(); - - // reselect rows - for (R row : rowsToReSelect) { - int modelRowIndex = tableModel.getRowIndex(row); - SwingUtil.addRowSelectionInterval(table, modelRowIndex); - } - } - - public void recomputeSpeciesColumnTip() { - List<String> tips = Lists.newArrayList(); - for (int i = 0, nbContext = decorator.getNbContext(); i < nbContext; i++) { - String property = decorator.getProperty(i); - - String i18nName = "tutti.property." + property; - String tip = (String) column.getClientProperty(i18nName); - tips.add(tip); - } - String tip = Joiner.on(" - ").join(tips); - column.setToolTipText(tip); - } - } - - protected static class ShowSpeciesDecoratorPopupListener extends MouseAdapter { - - private final JPopupMenu popup; - - public ShowSpeciesDecoratorPopupListener(JPopupMenu popup) { - this.popup = popup; - } - - @Override - public void mouseClicked(MouseEvent e) { - JTableHeader source = (JTableHeader) e.getSource(); - Point point = e.getPoint(); - int columnIndex = source.columnAtPoint(point); - - boolean rightClick = SwingUtilities.isRightMouseButton(e); - if (columnIndex == 0 && rightClick) { - e.consume(); - popup.show(source, e.getX(), e.getY()); - } - } - } } 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 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2014-01-08 12:34:01 UTC (rev 1479) @@ -54,6 +54,13 @@ tutti.caracteristicMapEditor.none.tip= tutti.caracteristicMapEditorTable.table.header.key= tutti.caracteristicMapEditorTable.table.header.value= +tutti.catches.action.cancel= +tutti.catches.sortSpecies.action.accept= +tutti.catches.sortSpecies.action.accept.mnemonic= +tutti.catches.sortSpecies.action.accept.tip= +tutti.catches.sortSpecies.action.cancel.mnemonic= +tutti.catches.sortSpecies.action.cancel.tip= +tutti.catches.sortSpecies.title= tutti.commentEditor.action.close.tip= tutti.commentEditor.action.tip= tutti.commentEditor.none.tip= @@ -429,6 +436,14 @@ tutti.editBenthosBatch.filterBatch.mode.root= tutti.editBenthosBatch.filterBatch.mode.root.tip= tutti.editBenthosBatch.filterBatch.tip= +tutti.editBenthosBatch.sortSpeciesBatch= +tutti.editBenthosBatch.sortSpeciesBatch.tip= +tutti.editBenthosBatch.speciesSortMode.asc= +tutti.editBenthosBatch.speciesSortMode.asc.tip= +tutti.editBenthosBatch.speciesSortMode.desc= +tutti.editBenthosBatch.speciesSortMode.desc.tip= +tutti.editBenthosBatch.speciesSortMode.none= +tutti.editBenthosBatch.speciesSortMode.none.tip= tutti.editBenthosBatch.split.weightNotNull.help= tutti.editBenthosBatch.split.weightNotNull.message= tutti.editBenthosBatch.split.weightNotNull.title= @@ -998,6 +1013,14 @@ tutti.editSpeciesBatch.filterBatch.mode.root= tutti.editSpeciesBatch.filterBatch.mode.root.tip= tutti.editSpeciesBatch.filterSpeciesBatch.tip= +tutti.editSpeciesBatch.sortSpeciesBatch= +tutti.editSpeciesBatch.sortSpeciesBatch.tip= +tutti.editSpeciesBatch.speciesSortMode.asc= +tutti.editSpeciesBatch.speciesSortMode.asc.tip= +tutti.editSpeciesBatch.speciesSortMode.desc= +tutti.editSpeciesBatch.speciesSortMode.desc.tip= +tutti.editSpeciesBatch.speciesSortMode.none= +tutti.editSpeciesBatch.speciesSortMode.none.tip= tutti.editSpeciesBatch.split.weightNotNull.help= tutti.editSpeciesBatch.split.weightNotNull.message= tutti.editSpeciesBatch.split.weightNotNull.title= 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 2014-01-07 14:16:06 UTC (rev 1478) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2014-01-08 12:34:01 UTC (rev 1479) @@ -429,6 +429,14 @@ tutti.editBenthosBatch.filterBatch.mode.root=Parents (%s) tutti.editBenthosBatch.filterBatch.mode.root.tip=Voir uniquement les lots *parents* tutti.editBenthosBatch.filterBatch.tip=Pour filtrer les lots +tutti.editBenthosBatch.sortSpeciesBatch=Tri +tutti.editBenthosBatch.sortSpeciesBatch.tip=Trier les lignes selon les espèces +tutti.editBenthosBatch.speciesSortMode.asc=Ascendant +tutti.editBenthosBatch.speciesSortMode.asc.tip=Utiliser l'ordre ascendant +tutti.editBenthosBatch.speciesSortMode.desc=Descendant +tutti.editBenthosBatch.speciesSortMode.desc.tip=Utiliser l'ordre descendant +tutti.editBenthosBatch.speciesSortMode.none=Saisie +tutti.editBenthosBatch.speciesSortMode.none.tip=Utiliser l'ordre de saisie tutti.editBenthosBatch.split.weightNotNull.help=Que voulez-vous faire ? <ul><li><strong>Annuler</strong> pour ne pas catégoriser le lot et garder le poids sous-échantilloné</li><li><strong>OK</strong> pour catégoriser le lot et supprimer le poids sous-échantillonné</li></ul>. tutti.editBenthosBatch.split.weightNotNull.message=Pour catégoriser un lot, il ne doit pas avoir de poids sous-échantillonné. tutti.editBenthosBatch.split.weightNotNull.title=Poids sous-échantillonné non nul @@ -998,6 +1006,14 @@ tutti.editSpeciesBatch.filterBatch.mode.root=Parents (%s) tutti.editSpeciesBatch.filterBatch.mode.root.tip=Voir uniquement les lots *parents* tutti.editSpeciesBatch.filterSpeciesBatch.tip=Pour filtrer les lots +tutti.editSpeciesBatch.sortSpeciesBatch=Tri +tutti.editSpeciesBatch.sortSpeciesBatch.tip=Trier les lignes selon les espèces +tutti.editSpeciesBatch.speciesSortMode.asc=Ascendant +tutti.editSpeciesBatch.speciesSortMode.asc.tip=Utiliser l'ordre ascendant +tutti.editSpeciesBatch.speciesSortMode.desc=Descendant +tutti.editSpeciesBatch.speciesSortMode.desc.tip=Utiliser l'ordre descendant +tutti.editSpeciesBatch.speciesSortMode.none=Saisie +tutti.editSpeciesBatch.speciesSortMode.none.tip=Utiliser l'ordre de saisie tutti.editSpeciesBatch.split.weightNotNull.help=Que voulez-vous faire ? <ul><li><strong>Annuler</strong> pour ne pas catégoriser le lot et garder le poids sous-échantilloné</li><li><strong>OK</strong> pour catégoriser le lot et supprimer le poids sous-échantillonné</li></ul>. tutti.editSpeciesBatch.split.weightNotNull.message=Pour catégoriser un lot, il ne doit pas avoir de poids sous-échantillonné tutti.editSpeciesBatch.split.weightNotNull.title=Poids sous-échantillonné non nul Added: trunk/tutti-ui-swing/src/main/resources/icons/action-sort.png =================================================================== (Binary files differ) Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-sort.png ___________________________________________________________________ Added: svn:mime-type + image/png