Author: tchemit Date: 2013-10-01 14:24:29 +0200 (Tue, 01 Oct 2013) New Revision: 1260 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1260 Log: fixes #3405: [ESPECES] Cat?\195?\169gorisation des lots : on ne peut plus ajouter une cat?\195?\169gorie une fois la cat?\195?\169gorisation effectu?\195?\169e Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-10-01 10:31:41 UTC (rev 1259) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-10-01 12:24:29 UTC (rev 1260) @@ -601,17 +601,17 @@ @Override public BenthosBatch getChildBatchs(int index) { - return null; + return childBatch.get(index); } @Override public boolean isChildBatchsEmpty() { - return false; + return childBatch.isEmpty(); } @Override public int sizeChildBatchs() { - return 0; + return childBatch.size(); } @Override 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-01 10:31:41 UTC (rev 1259) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-10-01 12:24:29 UTC (rev 1260) @@ -24,12 +24,13 @@ * #L% */ +import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryColumnIdentifier; -import fr.ifremer.tutti.service.WeightUnit; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import org.apache.commons.logging.Log; @@ -247,6 +248,49 @@ } /** + * Return the index of the next row that can be inserted as a child of the + * given row. + * + * @param row the parent row + * @return the index of the next row that can be inserted as a child of the + * given row + * @since 2.7 + */ + public final int getNextChildRowIndex(BenthosBatchRowModel row) { + + // get row index of the given row + int parentRowIndex = getRowIndex(row); + + // must find it + Preconditions.checkState(parentRowIndex != -1); + + int result = parentRowIndex; + + if (!row.isChildBatchsEmpty()) { + + // take his last child + BenthosBatchRowModel lastChild = + row.getChildBatch().get(row.sizeChildBatchs() - 1); + + // get the shell of this child (including himself) + Set<BenthosBatchRowModel> childs = Sets.newHashSet(); + childs.add(lastChild); + lastChild.collectShell(childs); + + // get row with max index + for (BenthosBatchRowModel child : childs) { + int childRowIndex = getRowIndex(child); + result = Math.max(childRowIndex, result); + } + } + + // result is the nex row + result++; + + return result; + } + + /** * Return the sample category id of a column or {@code null} if not on a * sample category column. * 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-01 10:31:41 UTC (rev 1259) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-10-01 12:24:29 UTC (rev 1260) @@ -1162,7 +1162,7 @@ BenthosBatchTableModel tableModel = getTableModel(); // get insert row index - int insertRow = tableModel.getRowIndex(parentBatch) + parentBatch.getChildBatch().size(); + int insertRow = tableModel.getNextChildRowIndex(parentBatch); // Create rows in batch table model List<BenthosBatchRowModel> newBatches = Lists.newArrayList(); @@ -1182,7 +1182,7 @@ recomputeRowValidState(newBatch); newBatches.add(newBatch); - tableModel.addNewRow(++insertRow, newBatch); + tableModel.addNewRow(insertRow++, newBatch); } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-10-01 10:31:41 UTC (rev 1259) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-10-01 12:24:29 UTC (rev 1260) @@ -374,17 +374,17 @@ @Override public SpeciesBatch getChildBatchs(int index) { - return null; + return childBatch.get(index); } @Override public boolean isChildBatchsEmpty() { - return false; + return childBatch.isEmpty(); } @Override public int sizeChildBatchs() { - return 0; + return childBatch.size(); } @Override 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-01 10:31:41 UTC (rev 1259) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-10-01 12:24:29 UTC (rev 1260) @@ -24,12 +24,13 @@ * #L% */ +import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryColumnIdentifier; -import fr.ifremer.tutti.service.WeightUnit; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import org.apache.commons.logging.Log; @@ -246,6 +247,49 @@ } /** + * Return the index of the next row that can be inserted as a child of the + * given row. + * + * @param row the parent row + * @return the index of the next row that can be inserted as a child of the + * given row + * @since 2.7 + */ + public final int getNextChildRowIndex(SpeciesBatchRowModel row) { + + // get row index of the given row + int parentRowIndex = getRowIndex(row); + + // must find it + Preconditions.checkState(getRowIndex(row) != -1); + + int result = parentRowIndex; + + if (!row.isChildBatchsEmpty()) { + + // take his last child + SpeciesBatchRowModel lastChild = + row.getChildBatch().get(row.sizeChildBatchs() - 1); + + // get the shell of this child (including himself) + Set<SpeciesBatchRowModel> childs = Sets.newHashSet(); + childs.add(lastChild); + lastChild.collectShell(childs); + + // get row with max index + for (SpeciesBatchRowModel child : childs) { + int childRowIndex = getRowIndex(child); + result = Math.max(childRowIndex, result); + } + } + + // result is the nex row + result++; + + return result; + } + + /** * Return the sample category id of a column or {@code null} if not on a * sample category column. * 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-01 10:31:41 UTC (rev 1259) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-10-01 12:24:29 UTC (rev 1260) @@ -1165,7 +1165,7 @@ SpeciesBatchTableModel tableModel = getTableModel(); // get insert row index - int insertRow = tableModel.getRowIndex(parentBatch) + parentBatch.getChildBatch().size(); + int insertRow = tableModel.getNextChildRowIndex(parentBatch); // Create rows in batch table model List<SpeciesBatchRowModel> newBatches = Lists.newArrayList(); @@ -1185,7 +1185,7 @@ recomputeRowValidState(newBatch); newBatches.add(newBatch); - tableModel.addNewRow(++insertRow, newBatch); + tableModel.addNewRow(insertRow++, newBatch); } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-10-01 10:31:41 UTC (rev 1259) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-10-01 12:24:29 UTC (rev 1260) @@ -400,7 +400,7 @@ JXTable source = (JXTable) e.getSource(); int[] selectedRows = source.getSelectedRows(); -// int[] selectedColumns = source.getSelectedColumns(); + int[] selectedColumns = source.getSelectedColumns(); // get the row index at this point int rowIndex = source.rowAtPoint(p); @@ -435,12 +435,12 @@ source.setRowSelectionInterval(rowIndex, rowIndex); } -// // select column (could empty selection) -// if (columnIndex == -1) { -// source.clearSelection(); -// } else if (!ArrayUtils.contains(selectedColumns, columnIndex)) { -// source.setColumnSelectionInterval(columnIndex, columnIndex); -// } + // select column (could empty selection) + if (columnIndex == -1) { + source.clearSelection(); + } else if (!ArrayUtils.contains(selectedColumns, columnIndex)) { + source.setColumnSelectionInterval(columnIndex, columnIndex); + } if (rightClick) {