r1291 - in trunk: tutti-service/src/main/java/fr/ifremer/tutti/service tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/opera
Author: tchemit Date: 2013-10-09 18:27:15 +0200 (Wed, 09 Oct 2013) New Revision: 1291 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1291 Log: refs #3328: [ERGO] Tri du tableau des esp?\195?\168ces Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDecorator.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/AbstractTuttiBatchTableUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.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/BenthosBatchUI.css 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/individualobservation/IndividualObservationBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIHandler.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/SpeciesBatchUI.css 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/protocol/AddBenthosProtocolAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.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/content/protocol/RemoveBenthosProtocolAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.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-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -197,7 +197,7 @@ @Override protected Object onNullValue(Species bean, String token) { Object result = null; - if ("refTaxCode".equals(token)) { + if (Species.PROPERTY_REF_TAX_CODE.equals(token)) { result = _("tutti.propety.no.species.speciesCode"); } return result; @@ -215,7 +215,7 @@ @Override protected Object getValue(Species bean, String token) { Object result = super.getValue(bean, token); - if ("surveyCode".equals(token) && result == null) { + if (Species.PROPERTY_SURVEY_CODE.equals(token) && result == null) { result = bean.getRefTaxCode(); } return result; @@ -224,7 +224,7 @@ @Override protected Object onNullValue(Species bean, String token) { Object result; - if ("surveyCode".equals(token)) { + if (Species.PROPERTY_SURVEY_CODE.equals(token)) { result = _("tutti.propety.no.species.speciesCode"); } else { @@ -245,7 +245,7 @@ @Override protected Object getValue(Program bean, String token) { Object result = super.getValue(bean, token); - if ("zone".equals(token) && result != null) { + if (Program.PROPERTY_ZONE.equals(token) && result != null) { result = ((TuttiLocation) result).getLabel(); } return result; @@ -254,7 +254,7 @@ @Override protected Object onNullValue(Program bean, String token) { Object result = null; - if ("zone".equals(token)) { + if (Program.PROPERTY_ZONE.equals(token)) { result = _("tutti.propety.no.zone"); } return result; @@ -274,7 +274,7 @@ // handle the null internationalRegistrationCode here, // otherwise this will be considered null during sorting Object result = super.getValue(bean, token); - if ("internationalRegistrationCode".equals(token) && result == null) { + if (Vessel.PROPERTY_INTERNATIONAL_REGISTRATION_CODE.equals(token) && result == null) { // use national registration code result = _("tutti.propety.vessel.nation.registrationCode", bean.getRegistrationCode()); } @@ -284,7 +284,7 @@ @Override protected Object onNullValue(Vessel bean, String token) { Object result = null; - if ("name".equals(token)) { + if (Vessel.PROPERTY_NAME.equals(token)) { result = _("tutti.propety.no.vessel.name"); } return result; Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDecorator.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDecorator.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDecorator.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -31,7 +31,6 @@ import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; import org.nuiton.decorator.DecoratorUtil; import org.nuiton.decorator.JXPathDecorator; import org.nuiton.decorator.MultiJXPathDecorator; @@ -41,7 +40,6 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.util.Arrays; -import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Set; @@ -75,8 +73,9 @@ /** * List of tokens to sort using the {@link #sortOnlyOnSelectedContext} mode. + * <p/> + * If the mode is not set, then won't use this. * - * If the mode is not set, then won't use this. * @since 2.8 */ protected Set<String> sortOnlyOnSelectedContextTokens; @@ -100,9 +99,8 @@ separator, separatorReplacement)); tokenMethods = Maps.newHashMap(); - Set<PropertyDescriptor> descriptors = BeanUtil.getDescriptors(type, BeanUtil.IS_READ_DESCRIPTOR); -// PropertyDescriptor[] descriptors = -// PropertyUtils.getPropertyDescriptors(type); + Set<PropertyDescriptor> descriptors = + BeanUtil.getDescriptors(type, BeanUtil.IS_READ_DESCRIPTOR); for (String token : getTokens()) { Method m = null; @@ -113,7 +111,8 @@ } } if (m == null) { - throw new IllegalArgumentException("could not find the property " + token + " in " + type); + throw new IllegalArgumentException( + "could not find the property " + token + " in " + type); } tokenMethods.put(token, m); } @@ -162,8 +161,8 @@ this.sortOnlyOnSelectedContextTokens = sortOnlyOnSelectedContextTokens; } - public Comparator getCurrentComparator() { - return context.getComparator(0); + public TuttiDecoratorComparator<O> getCurrentComparator() { + return (TuttiDecoratorComparator<O>) context.getComparator(0); } @Override @@ -241,7 +240,7 @@ return super.clone(); } - public static class TuttiDecoratorComparator<O> extends JXPathComparator<O> implements Serializable { + public static class TuttiDecoratorComparator<O> extends JXPathComparator<O> implements Serializable, Cloneable { private static final long serialVersionUID = 1L; @@ -258,7 +257,9 @@ TuttiDecorator<O> tuttiDecorator = (TuttiDecorator<O>) decorator; String token = decorator.getTokens()[0]; boolean sortOnlyOnSelectedContext = - tuttiDecorator.isSortOnlyOnSelectedContext() && tuttiDecorator.getSortOnlyOnSelectedContextTokens()!=null && tuttiDecorator.getSortOnlyOnSelectedContextTokens().contains(token); + tuttiDecorator.isSortOnlyOnSelectedContext() && + tuttiDecorator.getSortOnlyOnSelectedContextTokens() != null && + tuttiDecorator.getSortOnlyOnSelectedContextTokens().contains(token); for (O data : datas) { if (sortOnlyOnSelectedContext) { @@ -273,5 +274,14 @@ } } } + + @Override + public TuttiDecoratorComparator<O> clone() { + TuttiDecoratorComparator<O> result = + new TuttiDecoratorComparator<O>(expression); + return result; + } + + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/AbstractTuttiBatchTableUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/AbstractTuttiBatchTableUIHandler.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/AbstractTuttiBatchTableUIHandler.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -38,6 +38,7 @@ import org.jdesktop.swingx.decorator.HighlightPredicate; import org.jdesktop.swingx.decorator.Highlighter; import org.jdesktop.swingx.sort.TableSortController; +import org.jdesktop.swingx.table.TableColumnModelExt; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; @@ -51,7 +52,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public abstract class AbstractTuttiBatchTableUIHandler<R extends AbstractTuttiBeanUIModel, M extends AbstractTuttiBatchUIModel<R, M>, UI extends TuttiUI<M, ?>> extends AbstractTuttiTableUIHandler<R, M, UI> { +public abstract class AbstractTuttiBatchTableUIHandler<R extends AbstractTuttiBeanUIModel, M extends AbstractTuttiBatchUIModel<R, M>, T extends AbstractTuttiTableModel<R>, UI extends TuttiUI<M, ?>> extends AbstractTuttiTableUIHandler<R, M, UI> { protected abstract ColumnIdentifier<R> getCommentIdentifier(); @@ -98,8 +99,8 @@ } protected void initBatchTable(JXTable table, - TableColumnModel columnModel, - AbstractTuttiTableModel<R> tableModel) { + TableColumnModelExt columnModel, + T tableModel) { installTableKeyListener(columnModel, table); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -71,7 +71,7 @@ * @since 0.2 */ public class AccidentalBatchUIHandler - extends AbstractTuttiBatchTableUIHandler<AccidentalBatchRowModel, AccidentalBatchUIModel, AccidentalBatchUI> + extends AbstractTuttiBatchTableUIHandler<AccidentalBatchRowModel, AccidentalBatchUIModel, AccidentalBatchTableModel, AccidentalBatchUI> implements CaracteristicMapColumnUIHandler { /** Logger. */ 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-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -25,6 +25,7 @@ */ import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; @@ -381,6 +382,23 @@ } /** + * Return the list of used species in the table (used to fill the + * comparator cache for species sort) + * + * @return the list of used species in the table. + * @since 2.8 + */ + public List<Species> getSpeciesList() { + List<Species> result = Lists.newArrayList(); + for (BenthosBatchRowModel row : rows) { + if (row.isBatchRoot()) { + result.add(row.getSpecies()); + } + } + return result; + } + + /** * Update all the cells of the given row shell for a given column. * * @param entry the first row to update 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 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.css 2013-10-09 16:27:15 UTC (rev 1291) @@ -133,9 +133,8 @@ #table { selectionMode: {ListSelectionModel.MULTIPLE_INTERVAL_SELECTION}; - /*selectionBackground: {null};*/ selectionForeground: {Color.BLACK}; - sortable: false; + sortable: true; } #filterTablePane { 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-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -40,6 +40,7 @@ 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.service.WeightUnit; import fr.ifremer.tutti.service.catches.ValidateCruiseOperationsService; @@ -82,6 +83,7 @@ import org.jdesktop.swingx.decorator.HighlightPredicate; import org.jdesktop.swingx.decorator.Highlighter; import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import org.jdesktop.swingx.table.TableColumnExt; import org.jdesktop.swingx.table.TableColumnModelExt; import org.nuiton.decorator.Decorator; import org.nuiton.validator.NuitonValidatorResult; @@ -90,6 +92,8 @@ import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.RowFilter; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumnModel; import java.awt.Color; @@ -109,7 +113,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.1 */ -public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<BenthosBatchRowModel, BenthosBatchUIModel, BenthosBatchUI> { +public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<BenthosBatchRowModel, BenthosBatchUIModel, BenthosBatchTableModel, BenthosBatchUI> { /** Logger. */ private static final Log log = @@ -710,10 +714,15 @@ { // Species column - addColumnToModel(columnModel, - null, - newTableCellRender(Species.class, DecoratorService.FROM_PROTOCOL), - BenthosBatchTableModel.SPECIES); + TableColumnExt speciesColumn = addColumnToModel( + columnModel, + null, + null, + BenthosBatchTableModel.SPECIES); +// speciesColumn.setSortable(true); + DecoratorService.SpeciesFromProtocolDecorator speciesDecorator = new DecoratorService.SpeciesFromProtocolDecorator(); + speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); + speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); } // Sample category columns @@ -805,6 +814,70 @@ } @Override + protected void initBatchTable(final JXTable table, + TableColumnModelExt columnModel, + BenthosBatchTableModel tableModel) { + super.initBatchTable(table, + columnModel, + tableModel); + + // by default do not authorize to change column orders + table.getTableHeader().setReorderingAllowed(false); + + // get species column + final TableColumnExt speciesColumn = + (TableColumnExt) table.getColumns().get(0); + + // when model change, then rebuild the species comparator + set model as modified + tableModel.addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + + BenthosBatchTableModel tableModel = + (BenthosBatchTableModel) e.getSource(); + int type = e.getType(); + if (type == TableModelEvent.DELETE || + type == TableModelEvent.INSERT || + e.getLastRow() == Integer.MAX_VALUE) { + + // get column comparator + TuttiDecorator.TuttiDecoratorComparator<Species> comparator = + (TuttiDecorator.TuttiDecoratorComparator<Species>) + speciesColumn.getComparator(); + + // get column comparator + TuttiDecorator<Species> decorator = + TuttiUIUtil.getSpeciesColumnDecorator(speciesColumn); + + 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.getSpeciesList()); + + if (comparatorNull) { + + // affect it to colum + speciesColumn.setComparator(comparator); + } + } + } + }); + + // create popup to change species decorator + TuttiUIUtil.<BenthosBatchRowModel, BenthosBatchTableModel>installSpeciesColumnComparatorPopup( + table, + speciesColumn, + _("tutti.species.surveyCode.tip"), + _("tutti.species.name.tip") + ); + } + + @Override protected JComponent getComponentToFocus() { return getUI().getTable(); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchUIHandler.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchUIHandler.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -82,7 +82,7 @@ * @since 1.4 */ public class IndividualObservationBatchUIHandler - extends AbstractTuttiBatchTableUIHandler<IndividualObservationBatchRowModel, IndividualObservationBatchUIModel, IndividualObservationBatchUI> + extends AbstractTuttiBatchTableUIHandler<IndividualObservationBatchRowModel, IndividualObservationBatchUIModel, IndividualObservationBatchTableModel, IndividualObservationBatchUI> implements CaracteristicMapColumnUIHandler { private static final Log log = Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIHandler.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIHandler.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -64,7 +64,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler<MarineLitterBatchRowModel, MarineLitterBatchUIModel, MarineLitterBatchUI> { +public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler<MarineLitterBatchRowModel, MarineLitterBatchUIModel, MarineLitterBatchTableModel, MarineLitterBatchUI> { private static final Log log = LogFactory.getLog(MarineLitterBatchUIHandler.class); 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-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -25,6 +25,7 @@ */ import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; @@ -380,6 +381,23 @@ } /** + * Return the list of used species in the table (used to fill the + * comparator cache for species sort) + * + * @return the list of used species in the table. + * @since 2.8 + */ + public List<Species> getSpeciesList() { + List<Species> result = Lists.newArrayList(); + for (SpeciesBatchRowModel row : rows) { + if (row.isBatchRoot()) { + result.add(row.getSpecies()); + } + } + return result; + } + + /** * Update all the cells of the given row shell for a given column. * * @param entry the first row to update 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 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2013-10-09 16:27:15 UTC (rev 1291) @@ -133,9 +133,8 @@ #table { selectionMode: {ListSelectionModel.MULTIPLE_INTERVAL_SELECTION}; - /*selectionBackground: {null};*/ selectionForeground: {Color.BLACK}; - sortable: false; + sortable: true; } #filterTablePane { 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-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -40,6 +40,7 @@ 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.service.WeightUnit; import fr.ifremer.tutti.service.catches.ValidateCruiseOperationsService; @@ -81,6 +82,7 @@ import org.jdesktop.swingx.decorator.HighlightPredicate; import org.jdesktop.swingx.decorator.Highlighter; import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import org.jdesktop.swingx.table.TableColumnExt; import org.jdesktop.swingx.table.TableColumnModelExt; import org.nuiton.decorator.Decorator; import org.nuiton.validator.NuitonValidatorResult; @@ -89,6 +91,8 @@ import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.RowFilter; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumnModel; import java.awt.Color; @@ -108,7 +112,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.1 */ -public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<SpeciesBatchRowModel, SpeciesBatchUIModel, SpeciesBatchUI> { +public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<SpeciesBatchRowModel, SpeciesBatchUIModel, SpeciesBatchTableModel, SpeciesBatchUI> { /** Logger. */ private static final Log log = @@ -718,10 +722,15 @@ { // Species column - addColumnToModel(columnModel, - null, - newTableCellRender(Species.class, DecoratorService.FROM_PROTOCOL), - SpeciesBatchTableModel.SPECIES); + TableColumnExt speciesColumn = addColumnToModel( + columnModel, + null, + null, + SpeciesBatchTableModel.SPECIES); +// speciesColumn.setSortable(true); + DecoratorService.SpeciesFromProtocolDecorator speciesDecorator = new DecoratorService.SpeciesFromProtocolDecorator(); + speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); + speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); } // Sample category columns @@ -813,6 +822,71 @@ } @Override + protected void initBatchTable(final JXTable table, + TableColumnModelExt columnModel, + SpeciesBatchTableModel tableModel) { + super.initBatchTable(table, + columnModel, + tableModel); + + // by default do not authorize to change column orders + table.getTableHeader().setReorderingAllowed(false); + + // get the species column + final TableColumnExt speciesColumn = + (TableColumnExt) table.getColumns().get(0); + + // when model change, then rebuild the species comparator + set model as modified + + tableModel.addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + + SpeciesBatchTableModel tableModel = + (SpeciesBatchTableModel) e.getSource(); + int type = e.getType(); + if (type == TableModelEvent.DELETE || + type == TableModelEvent.INSERT || + e.getLastRow() == Integer.MAX_VALUE) { + + // get column comparator + TuttiDecorator.TuttiDecoratorComparator<Species> comparator = + (TuttiDecorator.TuttiDecoratorComparator<Species>) + speciesColumn.getComparator(); + + // get column comparator + TuttiDecorator<Species> decorator = + TuttiUIUtil.getSpeciesColumnDecorator(speciesColumn); + + 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.getSpeciesList()); + + if (comparatorNull) { + + // affect it to colum + speciesColumn.setComparator(comparator); + } + } + } + }); + + // create popup to change species decorator + TuttiUIUtil.<SpeciesBatchRowModel, SpeciesBatchTableModel>installSpeciesColumnComparatorPopup( + table, + speciesColumn, + _("tutti.species.surveyCode.tip"), + _("tutti.species.name.tip") + ); + } + + @Override protected JComponent getComponentToFocus() { return getUI().getTable(); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddBenthosProtocolAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddBenthosProtocolAction.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddBenthosProtocolAction.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -77,6 +77,10 @@ EditProtocolSpeciesRowModel protocol = tableModel.createNewRow(); protocol.setSpecies(species); tableModel.addNewRow(protocol); + + int rowIndex = tableModel.getRowIndex(protocol); + int selectedRowIndex = handler.getBenthosTable().convertRowIndexToView(rowIndex); + handler.getBenthosTable().getSelectionModel().setSelectionInterval(selectedRowIndex, selectedRowIndex); } @Override Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/AddSpeciesProtocolAction.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -75,6 +75,9 @@ EditProtocolSpeciesRowModel protocol = tableModel.createNewRow(); protocol.setSpecies(species); tableModel.addNewRow(protocol); + int rowIndex = tableModel.getRowIndex(protocol); + int selectedRowIndex = handler.getSpeciesTable().convertRowIndexToView(rowIndex); + handler.getSpeciesTable().getSelectionModel().setSelectionInterval(selectedRowIndex, selectedRowIndex); } @Override Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolSpeciesTableModel.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -26,6 +26,7 @@ import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import org.jdesktop.swingx.table.TableColumnModelExt; @@ -113,4 +114,19 @@ fireTableCellUpdated(rowIndex, columnIndex); } + /** + * Return the list of used species in the table (used to fill the + * comparator cache for species sort) + * + * @return the list of used species in the table. + * @since 2.8 + */ + public List<Species> getSpeciesList() { + List<Species> result = Lists.newArrayList(); + for (EditProtocolSpeciesRowModel row : rows) { + result.add(row.getSpecies()); + } + return result; + } + } 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 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -36,6 +36,7 @@ import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiDecorator; import fr.ifremer.tutti.ui.swing.content.home.CloneProtocolAction; @@ -44,6 +45,7 @@ import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.util.CloseableUI; import fr.ifremer.tutti.ui.swing.util.TuttiUI; +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; @@ -72,6 +74,7 @@ import javax.swing.event.ListSelectionListener; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; +import javax.swing.table.JTableHeader; import javax.swing.table.TableColumnModel; import java.awt.Dimension; import java.beans.PropertyChangeEvent; @@ -94,6 +97,8 @@ private static final Log log = LogFactory.getLog(EditProtocolUIHandler.class); +// public static final String SPECIES_DECORATOR_INDEX = "decoratorIndex"; + public static String getTitle(boolean exist) { String result; @@ -307,8 +312,10 @@ newTableCellRender(Species.class), EditProtocolSpeciesTableModel.SPECIES_ID); speciesColumn.setSortable(true); + DecoratorService.SpeciesDecorator speciesDecorator = new DecoratorService.SpeciesDecorator(); + speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); + speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); - TableColumnExt speciesSurveyCodeColumn = addColumnToModel(columnModel, null, null, @@ -339,25 +346,17 @@ addBooleanColumnToModel(columnModel, EditProtocolSpeciesTableModel.CALCIFY_SAMPLE_ENABLED, table); - EditProtocolSpeciesTableModel tableModel = - new EditProtocolSpeciesTableModel(sampleCategoryModel, columnModel); - table.setModel(tableModel); - table.setColumnModel(columnModel); - - initTable(table); - - table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - ListSelectionModel source = (ListSelectionModel) e.getSource(); - getModel().setRemoveSpeciesEnabled(!source.isSelectionEmpty()); - } - }); - - tableModel.setRows(speciesRows); - getModel().setRemoveSpeciesEnabled(false); - - initSpeciesComparator(); + initTable(table, + columnModel, + speciesColumn, + speciesRows, + new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + ListSelectionModel source = (ListSelectionModel) e.getSource(); + getModel().setRemoveSpeciesEnabled(!source.isSelectionEmpty()); + } + }); } { @@ -372,8 +371,9 @@ newTableCellRender(Species.class), EditProtocolSpeciesTableModel.SPECIES_ID); speciesColumn.setSortable(true); - TuttiDecorator<Species> decorator = (TuttiDecorator<Species>) getDecorator(Species.class, null); - speciesColumn.setComparator(decorator.getCurrentComparator()); + DecoratorService.SpeciesDecorator speciesDecorator = new DecoratorService.SpeciesDecorator(); + speciesColumn.putClientProperty(TuttiUIUtil.SPECIES_DECORATOR, speciesDecorator); + speciesColumn.setCellRenderer(newTableCellRender(speciesDecorator)); TableColumnExt speciesSurveyCodeColumn = addColumnToModel(columnModel, null, @@ -405,26 +405,16 @@ addBooleanColumnToModel(columnModel, EditProtocolSpeciesTableModel.CALCIFY_SAMPLE_ENABLED, table); - EditProtocolSpeciesTableModel tableModel = - new EditProtocolSpeciesTableModel(sampleCategoryModel, - columnModel); - table.setModel(tableModel); - table.setColumnModel(columnModel); - - initTable(table); - - table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - ListSelectionModel source = (ListSelectionModel) e.getSource(); - getModel().setRemoveBenthosEnabled(!source.isSelectionEmpty()); - } - }); - - tableModel.setRows(benthosRows); - getModel().setRemoveBenthosEnabled(false); - - initBenthosComparator(); + initTable(table, + columnModel, + speciesColumn, speciesRows, + new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + ListSelectionModel source = (ListSelectionModel) e.getSource(); + getModel().setRemoveBenthosEnabled(!source.isSelectionEmpty()); + } + }); } allDoubleLists = Lists.newArrayList( @@ -493,39 +483,6 @@ dialog = new SelectSpeciesUI(ui); } - protected void initSpeciesComparator() { - - JXTable table = getSpeciesTable(); - - TuttiDecorator<Species> decorator = (TuttiDecorator<Species>) getDecorator(Species.class, null); - TuttiDecorator.TuttiDecoratorComparator currentComparator = (TuttiDecorator.TuttiDecoratorComparator) decorator.getCurrentComparator(); - TableColumnExt tableColumn = (TableColumnExt) table.getColumns().get(0); - List<Species> species = Lists.newArrayList(); - List<EditProtocolSpeciesRowModel> rows = getModel().getSpeciesRow(); - for (EditProtocolSpeciesRowModel row : rows) { - species.add(row.getSpecies()); - } - currentComparator.init(decorator, species); - - tableColumn.setComparator(currentComparator); - } - - protected void initBenthosComparator() { - - JXTable table = getBenthosTable(); - - TuttiDecorator<Species> decorator = (TuttiDecorator<Species>) getDecorator(Species.class, null); - TuttiDecorator.TuttiDecoratorComparator currentComparator = (TuttiDecorator.TuttiDecoratorComparator) decorator.getCurrentComparator(); - TableColumnExt tableColumn = (TableColumnExt) table.getColumns().get(0); - List<Species> species = Lists.newArrayList(); - List<EditProtocolSpeciesRowModel> rows = getModel().getBenthosRow(); - for (EditProtocolSpeciesRowModel row : rows) { - species.add(row.getSpecies()); - } - currentComparator.init(decorator, species); - - tableColumn.setComparator(currentComparator); - } @Override protected JComponent getComponentToFocus() { return getUI().getNameField(); @@ -726,22 +683,84 @@ EditProtocolSpeciesTableModel.LENGTH_STEP_PMFM_ID); } - protected void initTable(JXTable table) { + protected void initTable(final JXTable table, + DefaultTableColumnModelExt columnModel, + TableColumnExt speciesColumn, + List<EditProtocolSpeciesRowModel> rows, + ListSelectionListener selectionListener) { + final EditProtocolSpeciesTableModel tableModel = + new EditProtocolSpeciesTableModel(sampleCategoryModel, columnModel); + table.setModel(tableModel); + table.setColumnModel(columnModel); + + JTableHeader tableHeader = table.getTableHeader(); + // by default do not authorize to change column orders - table.getTableHeader().setReorderingAllowed(false); + tableHeader.setReorderingAllowed(false); addHighlighters(table); // always scroll to selected row SwingUtil.scrollToTableSelection(table); - table.getModel().addTableModelListener(new TableModelListener() { + // add selection listener + table.getSelectionModel().addListSelectionListener(selectionListener); + + // when model change, then rebuild the species comparator + set model as modified + tableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { getModel().setModify(true); + + int type = e.getType(); + if (type == TableModelEvent.DELETE || + type == TableModelEvent.INSERT || + e.getLastRow() == Integer.MAX_VALUE) { + + // get species column + TableColumnExt tableColumn = + (TableColumnExt) table.getColumns().get(0); + + // get column comparator + TuttiDecorator.TuttiDecoratorComparator<Species> comparator = + (TuttiDecorator.TuttiDecoratorComparator<Species>) + tableColumn.getComparator(); + + // get column comparator + TuttiDecorator<Species> decorator = + TuttiUIUtil.getSpeciesColumnDecorator(tableColumn); + + 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.getSpeciesList()); + + if (comparatorNull) { + + // affect it to colum + tableColumn.setComparator(comparator); + } + } } }); + + // create popup to change species decorator + + TuttiUIUtil.<EditProtocolSpeciesRowModel, EditProtocolSpeciesTableModel>installSpeciesColumnComparatorPopup( + table, + speciesColumn, + _("tutti.species.refTaxCode.tip"), + _("tutti.species.name.tip") + ); + + // at the very end, set rows to model + tableModel.setRows(rows); } protected static class UpdateSelectedList implements PropertyChangeListener { @@ -813,4 +832,85 @@ return result; } } + +// public static class SpeciesDecoratorListener 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(SPECIES_DECORATOR_INDEX); +// +// if (log.isInfoEnabled()) { +// log.info("Selected decorator context index: " + index); +// } +// +// decorator.setContextIndex(index); +// +// column.setComparator(decorator.getCurrentComparator()); +// +// +// EditProtocolSpeciesTableModel tableModel = +// (EditProtocolSpeciesTableModel) table.getModel(); +// +// // keep selected rows +// int[] rowIndexes = table.getSelectedRows(); +// List<EditProtocolSpeciesRowModel> rowsToReSelect = Lists.newArrayList(); +// for (int viewRowIndex : rowIndexes) { +// int modelRowIndex = table.convertRowIndexToModel(viewRowIndex); +// EditProtocolSpeciesRowModel row = tableModel.getEntry(modelRowIndex); +// rowsToReSelect.add(row); +// } +// +// // fire model (will reload the comparator) +// tableModel.fireTableDataChanged(); +// +// // reselect rows +// for (EditProtocolSpeciesRowModel row : rowsToReSelect) { +// int modelRowIndex = tableModel.getRowIndex(row); +// int viewRowIndex = table.convertRowIndexToView(modelRowIndex); +// table.addRowSelectionInterval(viewRowIndex, viewRowIndex); +// } +// } +// } +// +// private 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/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveBenthosProtocolAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveBenthosProtocolAction.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveBenthosProtocolAction.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -24,6 +24,7 @@ * #L% */ +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -52,12 +53,26 @@ JTable table = handler.getBenthosTable(); - EditProtocolSpeciesTableModel tableModel = handler.getBenthosTableModel(); + // need to have a selection + Preconditions.checkState(!table.getSelectionModel().isSelectionEmpty()); - int[] rowIndex = table.getSelectedRows(); + // build the list of model row indexes from selected view row indexes + List<Integer> modelIndexes = Lists.newArrayList(); - for (int i = rowIndex.length - 1; i > -1; i--) { - int index = rowIndex[i]; + for (int index : table.getSelectedRows()) { + int modelRowIndex = table.convertRowIndexToModel(index); + modelIndexes.add(modelRowIndex); + } + + // sort it and reverse it (must delete first max row index) + Collections.sort(modelIndexes); + Collections.reverse(modelIndexes); + + EditProtocolSpeciesTableModel tableModel = + (EditProtocolSpeciesTableModel) table.getModel(); + + for (Integer index : modelIndexes) { + removeRow(tableModel, index); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -24,6 +24,7 @@ * #L% */ +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -52,12 +53,26 @@ JTable table = handler.getSpeciesTable(); - EditProtocolSpeciesTableModel tableModel = handler.getSpeciesTableModel(); + // need to have a selection + Preconditions.checkState(!table.getSelectionModel().isSelectionEmpty()); - int[] rowIndex = table.getSelectedRows(); + // build the list of model row indexes from selected view row indexes + List<Integer> modelIndexes = Lists.newArrayList(); - for (int i = rowIndex.length - 1; i > -1; i--) { - int index = rowIndex[i]; + for (int index : table.getSelectedRows()) { + int modelRowIndex = table.convertRowIndexToModel(index); + modelIndexes.add(modelRowIndex); + } + + // sort it and reverse it (must delete first max row index) + Collections.sort(modelIndexes); + Collections.reverse(modelIndexes); + + EditProtocolSpeciesTableModel tableModel = + (EditProtocolSpeciesTableModel) table.getModel(); + + for (Integer index : modelIndexes) { + removeRow(tableModel, index); } 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 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java 2013-10-09 16:27:15 UTC (rev 1291) @@ -24,19 +24,39 @@ * #L% */ +import com.google.common.base.Joiner; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import fr.ifremer.tutti.TuttiBusinessException; import fr.ifremer.tutti.TuttiTechnicalException; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.TuttiDecorator; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import org.apache.commons.beanutils.PropertyUtils; 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.decorator.HighlightPredicate; import org.jdesktop.swingx.decorator.Highlighter; +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.Color; import java.awt.Desktop; +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.URI; import java.net.URISyntaxException; @@ -44,6 +64,7 @@ import java.net.URLConnection; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; +import java.util.List; import static org.nuiton.i18n.I18n._; @@ -55,6 +76,10 @@ */ public final class TuttiUIUtil { + 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); @@ -280,4 +305,146 @@ 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 AbstractTuttiTableModel<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 AbstractTuttiTableModel<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 + int[] rowIndexes = table.getSelectedRows(); + List<R> rowsToReSelect = Lists.newArrayList(); + for (int viewRowIndex : rowIndexes) { + int modelRowIndex = table.convertRowIndexToModel(viewRowIndex); + R row = tableModel.getEntry(modelRowIndex); + rowsToReSelect.add(row); + } + + // fire model (will reload the comparator) + tableModel.fireTableDataChanged(); + + // reselect rows + for (R row : rowsToReSelect) { + int modelRowIndex = tableModel.getRowIndex(row); + int viewRowIndex = table.convertRowIndexToView(modelRowIndex); + table.addRowSelectionInterval(viewRowIndex, viewRowIndex); + } + } + + 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 2013-10-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-10-09 16:27:15 UTC (rev 1291) @@ -86,6 +86,8 @@ tutti.common.file.tuttiMarineLitter= tutti.common.file.tuttiSpecies= tutti.common.file.zip= +tutti.common.name= +tutti.common.refTaxCode= tutti.common.validate= tutti.common.validate.mnemonic= tutti.config.action.reload.actions= @@ -1357,7 +1359,10 @@ tutti.option.edit= tutti.option.import= tutti.property.get.error= +tutti.property.name= +tutti.property.refTaxCode= tutti.property.set.error= +tutti.property.surveycode= tutti.reimport.step.backupDb= tutti.reimport.step.closeDb= tutti.reimport.step.reloadApplication= @@ -1429,6 +1434,9 @@ tutti.sendCruiseReport.mail.body= tutti.sendCruiseReport.mail.subject= tutti.sendCruiseReport.title.choose.exportFile= +tutti.species.name.tip= +tutti.species.refTaxCode.tip= +tutti.species.surveyCode.tip= tutti.splitBenthosBatch.action.cancel= tutti.splitBenthosBatch.action.cancel.mnemonic= tutti.splitBenthosBatch.action.cancel.tip= @@ -1462,6 +1470,7 @@ tutti.splitSpeciesBatch.table.header.weight= tutti.splitSpeciesBatch.title= tutti.timeeditor.H= +tutti.ui.change.species.decorator= tutti.update.db= tutti.update.help= tutti.update.i18n= 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-08 16:24:46 UTC (rev 1290) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-10-09 16:27:15 UTC (rev 1291) @@ -1357,7 +1357,10 @@ tutti.option.edit=Éditer tutti.option.import=Importer tutti.property.get.error=Propriété %1s non trouvée sur l'objet de type %2s +tutti.property.name= +tutti.property.refTaxCode= tutti.property.set.error=Propriété %1s non trouvée sur l'objet de type %2s +tutti.property.surveycode= 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... @@ -1429,6 +1432,9 @@ tutti.sendCruiseReport.mail.body=Bonjour,\n\nVeuillez trouver ci-joint le rapport des captures de la campagne %1s.\n*Pensez à joindre le fichier %2s*\n\nCordialement,\n\n*Votre nom* tutti.sendCruiseReport.mail.subject=Captures de la campagne %s tutti.sendCruiseReport.title.choose.exportFile=Envoyer les captures de la campagne +tutti.species.name.tip=Nom scientifique +tutti.species.refTaxCode.tip=Code Rubin +tutti.species.surveyCode.tip=Code campagne ou code rubin tutti.splitBenthosBatch.action.cancel=Annuler tutti.splitBenthosBatch.action.cancel.mnemonic=A tutti.splitBenthosBatch.action.cancel.tip=Annuler le sous-échantillonnage @@ -1462,6 +1468,7 @@ tutti.splitSpeciesBatch.table.header.weight=Poids tutti.splitSpeciesBatch.title=Catégorisation du lot tutti.timeeditor.H=H +tutti.ui.change.species.decorator=Changer la décoration tutti.update.db=Base de données tutti.update.help=Aide en ligne tutti.update.i18n=Traductions
participants (1)
-
tchemit@users.forge.codelutin.com