r1302 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol
Author: tchemit Date: 2013-10-15 08:27:40 +0200 (Tue, 15 Oct 2013) New Revision: 1302 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1302 Log: refs #3328: [ERGO] Tri du tableau des esp?\195?\168ces 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/RemoveBenthosProtocolAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java 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-14 18:41:57 UTC (rev 1301) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-10-15 06:27:40 UTC (rev 1302) @@ -407,7 +407,8 @@ initTable(table, columnModel, - speciesColumn, speciesRows, + speciesColumn, + benthosRows, new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { 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-14 18:41:57 UTC (rev 1301) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveBenthosProtocolAction.java 2013-10-15 06:27:40 UTC (rev 1302) @@ -55,6 +55,14 @@ */ protected Set<Species> removedSpecies; + /** + * Set of removed rows. + * + * @since 2.8 + */ + protected Set<EditProtocolSpeciesRowModel> removedRows; + + public RemoveBenthosProtocolAction(EditProtocolUIHandler handler) { super(handler, false); } @@ -67,21 +75,11 @@ // need to have a selection Preconditions.checkState(!table.getSelectionModel().isSelectionEmpty()); -// // build the list of model row indexes from selected view row indexes -// List<Integer> modelIndexes = Lists.newArrayList(); -// -// for (int index : SwingUtil.getSelectedModelRows(table)) { -// modelIndexes.add(index); -// } -// -// // sort it and reverse it (must delete first max row index) -// Collections.sort(modelIndexes); -// Collections.reverse(modelIndexes); - EditProtocolSpeciesTableModel tableModel = (EditProtocolSpeciesTableModel) table.getModel(); removedSpecies = Sets.newHashSet(); + removedRows = Sets.newHashSet(); EditProtocolUIModel model = getModel(); @@ -101,42 +99,16 @@ allSynonyms.remove(species); model.getAllSynonyms().addAll(allSynonyms); - // remove the row from the model - model.getBenthosRow().remove(selectedRow); + // mark row to be removed at the very last moment + removedRows.add(selectedRow); } // reorder the list by name, otherwise, // all the species without a reftax code will be at the end Collections.sort(model.getAllSynonyms(), TuttiEntities.SPECIES_BY_NAME_COMPARATOR); - -// table.clearSelection(); } -// protected void removeRow(EditProtocolSpeciesTableModel tableModel, int rowIndex) { -// -// EditProtocolSpeciesRowModel selectedRow = tableModel.getEntry(rowIndex); -// -// // re-add all synonym of this taxon to the species / benthos combobox -// Species species = selectedRow.getSpecies(); -// getUI().getBenthosComboBox().addItem(species); -// getUI().getSpeciesComboBox().addItem(species); -// -// EditProtocolUIModel model = getModel(); -// Integer taxonId = species.getReferenceTaxonId(); -// List<Species> allSynonyms = Lists.newArrayList( -// model.getAllSynonyms(String.valueOf(taxonId))); -// allSynonyms.remove(species); -// model.getAllSynonyms().addAll(allSynonyms); -// -// // remove the row from the model -// tableModel.removeRow(rowIndex); -// -// String speciesStr = decorate(selectedRow.getSpecies()); -// sendMessage(_("tutti.flash.info.benthos.remove.from.protocol", -// speciesStr)); -// } - @Override public void postSuccessAction() { super.postSuccessAction(); @@ -145,6 +117,9 @@ getUI().getBenthosComboBox().addItems(removedSpecies); getUI().getSpeciesComboBox().addItems(removedSpecies); + // remove all rows from model + getModel().getBenthosRow().removeAll(removedRows); + // fire table data changed handler.getBenthosTableModel().fireTableDataChanged(); 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-14 18:41:57 UTC (rev 1301) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/RemoveSpeciesProtocolAction.java 2013-10-15 06:27:40 UTC (rev 1302) @@ -54,6 +54,13 @@ */ protected Set<Species> removedSpecies; + /** + * Set of removed rows. + * + * @since 2.8 + */ + protected Set<EditProtocolSpeciesRowModel> removedRows; + public RemoveSpeciesProtocolAction(EditProtocolUIHandler handler) { super(handler, false); } @@ -66,28 +73,16 @@ // need to have a selection Preconditions.checkState(!table.getSelectionModel().isSelectionEmpty()); -// // build the list of model row indexes from selected view row indexes -// List<Integer> modelIndexes = Lists.newArrayList(); -// -// for (int index : SwingUtil.getSelectedModelRows(table)) { -// modelIndexes.add(index); -// } -// -// // sort it and reverse it (must delete first max row index) -// Collections.sort(modelIndexes); -// Collections.reverse(modelIndexes); - EditProtocolSpeciesTableModel tableModel = (EditProtocolSpeciesTableModel) table.getModel(); EditProtocolUIModel model = getModel(); removedSpecies = Sets.newHashSet(); + removedRows = Sets.newHashSet(); for (Integer rowIndex : SwingUtil.getSelectedModelRows(table)) { -// removeRow(tableModel, index); - // get row to remove EditProtocolSpeciesRowModel selectedRow = tableModel.getEntry(rowIndex); @@ -102,41 +97,15 @@ allSynonyms.remove(species); model.getAllSynonyms().addAll(allSynonyms); - // remove the row from the model - model.getSpeciesRow().remove(selectedRow); + // mark row to be removed at the very last moment + removedRows.add(selectedRow); } // reorder the list by name, otherwise, // all the species without a reftax code will be at the end Collections.sort(model.getAllSynonyms(), TuttiEntities.SPECIES_BY_NAME_COMPARATOR); - -// table.clearSelection(); } - protected void removeRow(EditProtocolSpeciesTableModel tableModel, int rowIndex) { - - EditProtocolSpeciesRowModel selectedRow = tableModel.getEntry(rowIndex); - - // re-add all synonym of this taxon to the species / benthos combobox - Species species = selectedRow.getSpecies(); - getUI().getBenthosComboBox().addItem(species); - getUI().getSpeciesComboBox().addItem(species); - - EditProtocolUIModel model = getModel(); - Integer taxonId = species.getReferenceTaxonId(); - List<Species> allSynonyms = Lists.newArrayList( - model.getAllSynonyms(String.valueOf(taxonId))); - allSynonyms.remove(species); - model.getAllSynonyms().addAll(allSynonyms); - - // remove the row from the model - tableModel.removeRow(rowIndex); - - String speciesStr = decorate(selectedRow.getSpecies()); - sendMessage(_("tutti.flash.info.species.remove.from.protocol", - speciesStr)); - } - @Override public void postSuccessAction() { super.postSuccessAction(); @@ -145,6 +114,9 @@ getUI().getBenthosComboBox().addItems(removedSpecies); getUI().getSpeciesComboBox().addItems(removedSpecies); + // remove all rows from model + getModel().getBenthosRow().removeAll(removedRows); + // fire table data changed handler.getBenthosTableModel().fireTableDataChanged();
participants (1)
-
tchemit@users.forge.codelutin.com