Author: kmorin Date: 2013-02-06 10:41:11 +0100 (Wed, 06 Feb 2013) New Revision: 347 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/347 Log: refs #1936 [CAPTURE] - Esp?\195?\168ce - pouvoir changer le nom d'une esp?\195?\168ce Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/RenameSpeciesBatchAction.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/RenameSpeciesBatchAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/RenameSpeciesBatchAction.java 2013-02-06 09:07:05 UTC (rev 346) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/RenameSpeciesBatchAction.java 2013-02-06 09:41:11 UTC (rev 347) @@ -34,6 +34,7 @@ import org.jdesktop.swingx.JXTable; import java.awt.event.ActionEvent; +import java.util.Collection; import java.util.List; import static org.nuiton.i18n.I18n._; @@ -69,11 +70,21 @@ boolean result = super.prepareAction(event); SpeciesBatchUIHandler handler = getHandler(); + + SpeciesBatchTableModel tableModel = handler.getTableModel(); + JXTable table = handler.getTable(); + SpeciesBatchRowModel row = tableModel.getEntry(table.getSelectedRow()); + SpeciesBatchUIModel model = handler.getModel(); List<Species> speciesList = Lists.newArrayList(model.getAllSpecies()); - speciesList.removeAll(Sets.newHashSet(model.getSpeciesUsed().values())); + speciesList.removeAll( + model.getSpeciesUsed().get( + row.getSortedUnsortedCategoryValue())); - selectedSpecies = getHandler().openAddSpeciesDialog(_("tutti.title.selectSpecies"), speciesList); + selectedSpecies = getHandler().openAddSpeciesDialog( + _("tutti.title.selectSpecies"), + speciesList + ); result &= selectedSpecies != null; return result; @@ -87,8 +98,27 @@ JXTable table = handler.getTable(); SpeciesBatchRowModel row = tableModel.getEntry(table.getSelectedRow()); - PersistenceService persistenceService = getContext().getService(PersistenceService.class); - persistenceService.changeSpeciesBatchSpecies(row.getId(), selectedSpecies); + // TODO 20130206 kmorin uncomment the following lines when the service is available +// PersistenceService persistenceService = getContext().getService(PersistenceService.class); +// persistenceService.changeSpeciesBatchSpecies(row.getId(), selectedSpecies); + + Collection<Species> speciesUSed = handler.getModel().getSpeciesUsed() + .get(row.getSortedUnsortedCategoryValue()); + speciesUSed.remove(row.getSpecies()); + changeChildrenSpecies(row, selectedSpecies); + speciesUSed.add(selectedSpecies); + + selectedSpecies = null; } + protected void changeChildrenSpecies(SpeciesBatchRowModel row, + Species species) { + row.setSpecies(species); + List<SpeciesBatchRowModel> children = row.getBatchChild(); + if (children != null) { + for (SpeciesBatchRowModel child : children) { + changeChildrenSpecies(child, species); + } + } + } }