r427 - in trunk/tutti-ui-swing/src/main: java/fr/ifremer/tutti/ui/swing java/fr/ifremer/tutti/ui/swing/content/operation/catches java/fr/ifremer/tutti/ui/swing/content/operation/catches/species java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split java/fr/ifremer/tutti/ui/swing/util java/fr/ifremer/tutti/ui/swing/util/editor resources/fr/ifremer/tutti/ui/swing/content/operation resources/i18n
Author: kmorin Date: 2013-02-15 19:24:13 +0100 (Fri, 15 Feb 2013) New Revision: 427 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/427 Log: refs #2003 [CAPTURE] ?\195?\137l?\195?\169vation des poids remains error cases to treat Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiApplicationUpdaterCallBack.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUI.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.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/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/operation/catches/species/frequency/FrequencyCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.java trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-edit-warning-validation.xml trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-validate-warning-validation.xml trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2013-02-15 18:24:13 UTC (rev 427) @@ -34,6 +34,7 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.UIMessageNotifier; import fr.ifremer.tutti.ui.swing.util.editor.SimpleTimeEditor; +import java.awt.Color; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.editor.NumberEditor; @@ -67,6 +68,7 @@ import javax.swing.text.JTextComponent; import java.awt.Component; import java.awt.Dimension; +import java.awt.Font; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; @@ -80,6 +82,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.swing.JTextField; +import javax.swing.UIManager; +import org.apache.commons.lang3.ArrayUtils; import static org.nuiton.i18n.I18n._; @@ -288,10 +293,13 @@ Object component = entry.getValue(); if (component instanceof NumberEditor) { initNumberEditor((NumberEditor) component); + } else if (component instanceof JXDatePicker) { initDatePicker((JXDatePicker) component); + } else if (component instanceof SimpleTimeEditor) { initTimeEditor((SimpleTimeEditor) component); + } else if (component instanceof JLabel) { JLabel jLabel = (JLabel) component; Boolean strongStyle = (Boolean) jLabel.getClientProperty("strongStyle"); @@ -307,6 +315,18 @@ } jLabel.setText("<html>" + text + "</html>"); } + + } else if (component instanceof JTextField) { + JTextField jTextField = (JTextField) component; + Boolean computed = (Boolean) jTextField.getClientProperty("computed"); + if (computed != null && computed) { + Font font = jTextField.getFont().deriveFont(Font.ITALIC); + jTextField.setFont(font); + jTextField.setEditable(!computed); + jTextField.setEnabled(!computed); + jTextField.setDisabledTextColor(Color.BLUE); + } + } else if (component instanceof AbstractButton) { AbstractButton abstractButton = (AbstractButton) component; Class<? extends AbstractTuttiAction> actionName = (Class<? extends AbstractTuttiAction>) abstractButton.getClientProperty("tuttiAction"); @@ -551,9 +571,7 @@ protected void listModelIsModify(AbstractTuttiBeanUIModel model) { model.addPropertyChangeListener(new PropertyChangeListener() { - final Set<String> excludeProperties = Sets.newHashSet( - AbstractTuttiBeanUIModel.PROPERTY_MODIFY, - AbstractTuttiBeanUIModel.PROPERTY_VALID); + final Set<String> excludeProperties = getPropertiesToIgnore(); @Override public void propertyChange(PropertyChangeEvent evt) { @@ -563,6 +581,12 @@ } }); } + + protected Set<String> getPropertiesToIgnore() { + return Sets.newHashSet( + AbstractTuttiBeanUIModel.PROPERTY_MODIFY, + AbstractTuttiBeanUIModel.PROPERTY_VALID); + } public <B> void selectFirstInCombo(BeanComboBox<B> combo) { List<B> data = combo.getData(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiApplicationUpdaterCallBack.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiApplicationUpdaterCallBack.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiApplicationUpdaterCallBack.java 2013-02-15 18:24:13 UTC (rev 427) @@ -104,7 +104,6 @@ return result; } - @Override public void startUpdate(ApplicationUpdater.ApplicationInfo info) { if (UpdateType.DB.name().toLowerCase().equals(info.name)) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUI.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUI.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUI.java 2013-02-15 18:24:13 UTC (rev 427) @@ -24,6 +24,8 @@ * #L% */ +import java.awt.Font; +import javax.swing.UIManager; import jaxx.runtime.JAXXObject; /** @@ -100,7 +102,7 @@ * * @since 0.1 */ - public static final String DECIMAL1_PATTERN = "\\d{0,6}|\\d{1,6}.\\d{0,1}"; + public static final String DECIMAL1_PATTERN = "\\d{0,6}|\\d{1,6}\\.\\d{0,1}"; /** * Pattern to use for decimal numeric values with 2 decimal digits in @@ -108,7 +110,7 @@ * * @since 0.1 */ - public static final String DECIMAL2_PATTERN = "\\d{0,6}|\\d{1,6}.\\d{0,2}"; + public static final String DECIMAL2_PATTERN = "\\d{0,6}|\\d{1,6}\\.\\d{0,2}"; /** * Pattern to use for decimal numeric values with 3 decimal digits in @@ -116,17 +118,9 @@ * * @since 0.1 */ - public static final String DECIMAL3_PATTERN = "\\d{0,6}|\\d{1,6}.\\d{0,3}"; + public static final String DECIMAL3_PATTERN = "\\d{0,6}|\\d{1,6}\\.\\d{0,3}"; /** - * Pattern to use for decimal numeric values with 3 decimal digits in - * editors. - * - * @since 0.1 - */ - public static final String DECIMALFORCE3_PATTERN = "\\d{0,6}|\\d{1,6}.\\d{3}"; - - /** * Pattern to use for decimal numeric values with 2 digits + 3 decimal digits in * editors. * @@ -134,4 +128,7 @@ */ public static final String DECIMAL2_3_PATTERN = "\\d{0,2}|\\d{1,2}\\.\\d{0,3}"; + public static final Font TEXTFIELD_NORMAL_FONT = UIManager.getDefaults().getFont("TextField.font"); + + public static final Font TEXTFIELD_COMPUTED_FONT = UIManager.getDefaults().getFont("TextField.font").deriveFont(Font.ITALIC); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-02-15 18:24:13 UTC (rev 427) @@ -25,6 +25,7 @@ * #L% */ +import com.google.common.collect.Maps; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SampleCategory; @@ -33,8 +34,13 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel; import java.awt.event.ActionEvent; import java.util.List; +import java.util.Map; import javax.swing.JOptionPane; +import javax.swing.JTextField; +import jaxx.runtime.JAXXUtil; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import static org.nuiton.i18n.I18n._; @@ -46,6 +52,12 @@ public class ComputeWeightsAction extends AbstractTuttiAction<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> { private static final long serialVersionUID = 1L; + + private static final Log log = LogFactory.getLog(ComputeWeightsAction.class); + + protected enum Weights { + UNSORTED, SAMPLE_SORTED, SORTED, TOTAL + } public ComputeWeightsAction(EditCatchesUIHandler handler) { super(handler, @@ -58,27 +70,61 @@ @Override protected void doAction(ActionEvent event) throws Exception { - computeSpeciesBatches(); + Map<Weights, Float> speciesWeights = computeSpeciesBatches(); + + EditCatchesUI ui = getUI(); + setComputedValue(ui.getCatchTotalUnsortedWeightField(), + speciesWeights.get(Weights.UNSORTED)); + setComputedValue(ui.getCatchTotalSortedWeightField(), + speciesWeights.get(Weights.SORTED)); + + EditCatchesUIModel model = getModel(); + Float totalWeight = model.getCatchTotalWeight(); + Float rejectedWeight = model.getCatchTotalRejectedWeight(); + + if (rejectedWeight == null && totalWeight != null) { + model.setCatchTotalRejectedComputedWeight(totalWeight + - speciesWeights.get(Weights.UNSORTED) + - speciesWeights.get(Weights.SORTED)); + + } else if (totalWeight == null) { + if (rejectedWeight == null) { + rejectedWeight = 0f; + } + model.setCatchTotalComputedWeight(speciesWeights.get(Weights.UNSORTED) + + speciesWeights.get(Weights.SORTED)+ rejectedWeight); + + } else if (rejectedWeight != null + && !totalWeight.equals(speciesWeights.get(Weights.UNSORTED) + + speciesWeights.get(Weights.SORTED)+ rejectedWeight)) { + // TODO handle error + } + } //------------------------------------------------------------------------// //-- Internal methods --// //------------------------------------------------------------------------// - protected void computeSpeciesBatches() { + protected Map<Weights, Float> computeSpeciesBatches() { + Map<Weights, Float> result = Maps.newEnumMap(Weights.class); + PersistenceService persistenceService = getService(PersistenceService.class); + EditCatchesUIModel model = getModel(); Float totalSortedWeight = 0f; Float totalUnsortedWeight = 0f; - SpeciesBatchUI ui = getUI().getSpeciesTabContent(); + SpeciesBatchUI speciesUI = getUI().getSpeciesTabContent(); + EditCatchesUI ui = getUI(); + List<SpeciesBatchRowModel> roots = getUI().getSpeciesTabContent().getModel().getRows(); for (SpeciesBatchRowModel row : roots) { if (row.isBatchRoot()) { Float weight = computeSpeciesBatch(row); if (weight == null) { JOptionPane.showMessageDialog( - ui, + speciesUI, _("tutti.dialog.catches.species.computeWeight.error.message"), _("tutti.dialog.catches.species.computeWeight.error.title"), JOptionPane.ERROR_MESSAGE); @@ -93,43 +139,57 @@ } } } - Number inertWeight = ui.getSpeciesTotalInertWeightField().getModel(); + Number inertWeight = speciesUI.getSpeciesTotalInertWeightField().getModel(); if (inertWeight != null) { totalSortedWeight += inertWeight.floatValue(); } - Number livingNotItemizedWeight = ui.getSpeciesTotalLivingNotItemizedWeightField().getModel(); + Number livingNotItemizedWeight = speciesUI.getSpeciesTotalLivingNotItemizedWeightField().getModel(); if (livingNotItemizedWeight != null) { totalSortedWeight += livingNotItemizedWeight.floatValue(); } - ui.getSpeciesTotalSampleSortedWeightField() - .setText(totalSortedWeight != null ? totalSortedWeight.toString() : ""); + setComputedValue(speciesUI.getSpeciesTotalSampleSortedWeightField(), + totalSortedWeight); + setComputedValue(ui.getSpeciesTotalSampleSortedWeightField(), + totalSortedWeight); + result.put(Weights.SAMPLE_SORTED, totalSortedWeight); - if (ui.getSpeciesTotalSortedWeightField().getModel() == null) { - ui.getSpeciesTotalSortedWeightField().setModel(totalSortedWeight); + Float speciesTotalSortedWeight = model.getSpeciesTotalSortedWeight(); + if (speciesTotalSortedWeight == null) { + speciesTotalSortedWeight = totalSortedWeight; + model.setSpeciesTotalSortedComputedWeight(totalSortedWeight); + + } else if (speciesTotalSortedWeight < totalSortedWeight) { + // TODO handle error + } else if (speciesTotalSortedWeight < 1.05 * totalSortedWeight) { + // TODO Si le "Poids total VRAC" est saisi est que sa valeur + // est supérieure de moins de x% (x en configuration) + // du "Poids total Vrac trié", demander confirmation que + // le "Poids total VRAC" est bien une valeur observée + // sinon la remplacer par le "Poids total Vrac trié" } + result.put(Weights.SORTED, speciesTotalSortedWeight); - ui.getSpeciesTotalUnsortedWeightField() - .setText(totalUnsortedWeight != null ? totalUnsortedWeight.toString() : ""); + setComputedValue(speciesUI.getSpeciesTotalUnsortedWeightField(), + totalUnsortedWeight); + setComputedValue(ui.getSpeciesTotalUnsortedWeightField(), + totalUnsortedWeight); + result.put(Weights.UNSORTED, totalUnsortedWeight); + + Float totalWeight = totalUnsortedWeight + speciesTotalSortedWeight; + setComputedValue(speciesUI.getSpeciesTotalWeightField(), + totalWeight); + setComputedValue(ui.getSpeciesTotalWeightField(), + totalWeight); + result.put(Weights.TOTAL, speciesTotalSortedWeight); + + speciesUI.getTable().repaint(); + + return result; } protected Float computeSpeciesBatch(SpeciesBatchRowModel row) { - SampleCategory finestCategory; - if (row.getAgeCategory().isValid()) { - finestCategory = row.getAgeCategory(); - - } else if (row.getMaturityCategory().isValid()) { - finestCategory = row.getMaturityCategory(); - - } else if (row.getSexCategory().isValid()) { - finestCategory = row.getSexCategory(); - - } else if (row.getSizeCategory().isValid()) { - finestCategory = row.getSizeCategory(); - - } else { - finestCategory = row.getSortedUnsortedCategory(); - } + SampleCategory finestCategory = row.getFinestCategory(); Float result = null; Float categoryWeight = finestCategory.getCategoryWeight(); @@ -152,15 +212,27 @@ if (sum != null) { if (categoryWeight == null) { finestCategory.setComputedWeight(sum); - } else if (categoryWeight != sum) { + for (SpeciesBatchRowModel child : children) { + child.getFinestCategory().setSubSample(false); + } + + } else if (categoryWeight < sum) { // handle error + + } else { + boolean subSample = categoryWeight > sum; + for (SpeciesBatchRowModel child : children) { + child.getFinestCategory().setSubSample(subSample); + } } result = sum; } } else {// the row is a leaf + row.setComputedWeight(null); + List<SpeciesFrequencyRowModel> frequency = row.getFrequency(); - + if (CollectionUtils.isNotEmpty(frequency)) { // if there are frequencies, then compute their weight Float frequencyWeight = 0f; @@ -178,7 +250,7 @@ frequencyWeight += w; } } - + if (categoryWeight == null && rowWeight != null) { //TODO handle error @@ -188,18 +260,22 @@ finestCategory.setComputedWeight(frequencyWeight); result = frequencyWeight; - } else if (frequencyWeight != null && frequencyWeight != categoryWeight) { + } else if (frequencyWeight != null + && !frequencyWeight.equals(categoryWeight)) { + // if the weight of the frequencies is different from the category // weight, then set the weight of the sample - if (rowWeight == null) { + if (categoryWeight != null && frequencyWeight > categoryWeight) { + //TODO handle error + + } else if (rowWeight == null) { row.setComputedWeight(frequencyWeight); - } else if (rowWeight != frequencyWeight) { + } else if (!rowWeight.equals(frequencyWeight)) { //TODO handle error } result = categoryWeight; - } else { result = categoryWeight; } @@ -211,4 +287,14 @@ return result; } + + protected void setComputedValue(JTextField textField, Float value) { + String textValue; + if (value != null) { + textValue = String.format("%.3f", value); + } else { + textValue = JAXXUtil.getStringValue(value); + } + textField.setText(textValue); + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-02-15 18:24:13 UTC (rev 427) @@ -27,8 +27,19 @@ showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; bean: {model}; showReset: true; + useFloat: true; + numberPattern: {DECIMAL3_PATTERN}; } +TuttiComputedOrNotDataEditor { + autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; + showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; + showReset: true; + useFloat: true; + numberPattern: {DECIMAL3_PATTERN}; + decimalNumber: 3; +} + #catchTable { border: {BorderFactory.createTitledBorder(_("tutti.legend.catch.total"))}; } @@ -40,16 +51,19 @@ } #catchTotalWeightField { - property: catchTotalWeight; + bean: {model.getCatchTotalComputedOrNotWeight()}; model: {model.getCatchTotalWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; } #catchTotalSortedWeightLabel { text: "tutti.label.catches.catchTotalSortedWeight"; + labelFor: {catchTotalSortedWeightField}; } +#catchTotalSortedWeightField { + _computed: true; +} + #catchTotalSortedTremisWeightLabel { text: "tutti.label.catches.catchTotalSortedTremisWeight"; labelFor: {catchTotalSortedTremisWeightField}; @@ -58,8 +72,6 @@ #catchTotalSortedTremisWeightField { property: catchTotalSortedTremisWeight; model: {model.getCatchTotalSortedTremisWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; } #catchTotalSortedCarousselWeightLabel { @@ -70,8 +82,6 @@ #catchTotalSortedCarousselWeightField { property: catchTotalSortedCarousselWeight; model: {model.getCatchTotalSortedCarousselWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; } #catchTotalRejectedWeightLabel { @@ -80,10 +90,8 @@ } #catchTotalRejectedWeightField { - property: catchTotalRejectedWeight; + bean: {model.getCatchTotalRejectedComputedOrNotWeight()}; model: {model.getCatchTotalRejectedWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; } #catchTotalUnsortedWeightLabel { @@ -92,9 +100,7 @@ } #catchTotalUnsortedWeightField { - editable: false; - enabled: false; - text: {getStringValue(model.getCatchTotalUnsortedWeight())}; + _computed: true; } #catchThalassaLabel { @@ -117,10 +123,7 @@ } #speciesTotalWeightField { - property: speciesTotalWeight; - model: {model.getSpeciesTotalWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; + _computed: true; } #speciesTotalSortedWeightLabel { @@ -129,10 +132,12 @@ } #speciesTotalSortedWeightField { - property: speciesTotalSortedWeight; - model: {model.getSpeciesTotalSortedWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; + text: {getStringValue(model.getSpeciesTotalSortedWeight() != null ? + String.format("%.3f", model.getSpeciesTotalSortedWeight()) : + model.getSpeciesTotalSortedComputedWeight() != null ? + String.format("%.3f", model.getSpeciesTotalSortedComputedWeight()) : + null)}; + _computed: true; } #speciesTotalSampleSortedWeightLabel { @@ -142,10 +147,7 @@ } #speciesTotalSampleSortedWeightField { - property: speciesTotalSampleSortedWeight; - model: {model.getSpeciesTotalSampleSortedWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; + _computed: true; } #speciesTotalUnsortedWeightLabel { @@ -154,9 +156,7 @@ } #speciesTotalUnsortedWeightField { - text: {getStringValue(model.getSpeciesTotalUnsortedWeight())}; - editable: false; - enabled: false; + _computed: true; } #benthosTable { @@ -170,10 +170,7 @@ } #benthosTotalWeightField { - property: benthosTotalWeight; - model: {model.getBenthosTotalWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; + _computed: true; } #benthosTotalSortedWeightLabel { @@ -182,10 +179,7 @@ } #benthosTotalSortedWeightField { - property: benthosTotalSortedWeight; - model: {model.getBenthosTotalSortedWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; + _computed: true; } #benthosTotalSampleSortedWeightLabel { @@ -195,10 +189,7 @@ } #benthosTotalSampleSortedWeightField { - property: benthosTotalSampleSortedWeight; - model: {model.getBenthosTotalSampleSortedWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; + _computed: true; } #benthosTotalUnsortedWeightLabel { @@ -207,9 +198,7 @@ } #benthosTotalUnsortedWeightField { - text: {getStringValue(model.getBenthosTotalUnsortedWeight())}; - editable: false; - enabled: false; + _computed: true; } #macroWasteTable { @@ -223,10 +212,7 @@ } #macroWasteTotalWeightField { - property: macroWasteTotalWeight; - model: {model.getMacroWasteTotalWeight()}; - useFloat: false; - numberPattern: {INT_6_DIGITS_PATTERN}; + _computed: true; } #importPupitriButton { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-02-15 18:24:13 UTC (rev 427) @@ -36,6 +36,8 @@ fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchUI fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI + fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataEditor + org.jdesktop.swingx.JXTitledPanel jaxx.runtime.swing.CardLayout2Ext @@ -71,19 +73,15 @@ <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> <field name='catchTotalWeight' component='catchTotalWeightField'/> - <field name='catchTotalSortedTremisWeight' +<!-- <field name='catchTotalSortedTremisWeight' component='catchTotalSortedTremisWeightField'/> <field name='catchTotalSortedCarousselWeight' - component='catchTotalSortedCarousselWeightField'/> + component='catchTotalSortedCarousselWeightField'/>--> <field name='catchTotalRejectedWeight' component='catchTotalRejectedWeightField'/> <field name='speciesTotalSortedWeight' component='speciesTotalSortedWeightField'/> - <field name='speciesTotalSampleSortedWeight' - component='speciesTotalSampleSortedWeightField'/> - <field name='speciesTotalUnsortedWeight' - component='speciesTotalUnsortedWeightField'/> <field name='benthosTotalSortedWeight' component='benthosTotalSortedWeightField'/> @@ -115,17 +113,20 @@ <cell anchor='west'> <JLabel id='catchTotalWeightLabel'/> </cell> - <cell columns='4'> - <NumberEditor id='catchTotalWeightField' + <cell columns='4' weightx='1.0'> + <TuttiComputedOrNotDataEditor id='catchTotalWeightField' constructorParams='this'/> </cell> </row> - <!-- Poids total trié balance tremis / caroussel--> + <!-- Poids total trié balance tremie / caroussel--> <row> <cell anchor='west'> <JLabel id='catchTotalSortedWeightLabel'/> </cell> - <cell anchor='west'> + <cell columns='4' weightx='1.0'> + <JTextField id='catchTotalSortedWeightField'/> + </cell> +<!-- <cell anchor='west'> <JLabel id='catchTotalSortedCarousselWeightLabel'/> </cell> <cell weightx='1.0'> @@ -138,14 +139,14 @@ <cell weightx='1.0'> <NumberEditor id='catchTotalSortedTremisWeightField' constructorParams='this'/> - </cell> + </cell>--> </row> <!--Poids total hors vrac--> <row> <cell> <JLabel id='catchTotalUnsortedWeightLabel'/> </cell> - <cell columns='4'> + <cell columns='4' weightx='1.0'> <JTextField id='catchTotalUnsortedWeightField'/> </cell> </row> @@ -154,8 +155,8 @@ <cell> <JLabel id='catchTotalRejectedWeightLabel'/> </cell> - <cell columns='4'> - <NumberEditor id='catchTotalRejectedWeightField' + <cell columns='4' weightx='1.0'> + <TuttiComputedOrNotDataEditor id='catchTotalRejectedWeightField' constructorParams='this'/> </cell> </row> @@ -177,8 +178,7 @@ <JLabel id='speciesTotalWeightLabel'/> </cell> <cell weightx='1.0'> - <NumberEditor id='speciesTotalWeightField' - constructorParams='this'/> + <JTextField id='speciesTotalWeightField'/> </cell> </row> <!-- Poids total vrac --> @@ -187,8 +187,7 @@ <JLabel id='speciesTotalSortedWeightLabel'/> </cell> <cell weightx='1.0'> - <NumberEditor id='speciesTotalSortedWeightField' - constructorParams='this'/> + <JTextField id='speciesTotalSortedWeightField'/> </cell> </row> @@ -198,8 +197,7 @@ <JLabel id='speciesTotalSampleSortedWeightLabel'/> </cell> <cell> - <NumberEditor id='speciesTotalSampleSortedWeightField' - constructorParams='this'/> + <JTextField id='speciesTotalSampleSortedWeightField'/> </cell> </row> <!-- Poids total hors vrac --> @@ -223,8 +221,7 @@ <JLabel id='benthosTotalWeightLabel'/> </cell> <cell weightx='1.0'> - <NumberEditor id='benthosTotalWeightField' - constructorParams='this'/> + <JTextField id='benthosTotalWeightField'/> </cell> </row> <!-- Poids total vrac --> @@ -233,8 +230,7 @@ <JLabel id='benthosTotalSortedWeightLabel'/> </cell> <cell weightx='1.0'> - <NumberEditor id='benthosTotalSortedWeightField' - constructorParams='this'/> + <JTextField id='benthosTotalSortedWeightField'/> </cell> </row> @@ -244,8 +240,7 @@ <JLabel id='benthosTotalSampleSortedWeightLabel'/> </cell> <cell> - <NumberEditor id='benthosTotalSampleSortedWeightField' - constructorParams='this'/> + <JTextField id='benthosTotalSampleSortedWeightField'/> </cell> </row> <!-- Poids total hors vrac --> @@ -270,8 +265,7 @@ <JLabel id='macroWasteTotalWeightLabel'/> </cell> <cell weightx='1.0'> - <NumberEditor id='macroWasteTotalWeightField' - constructorParams='this'/> + <JTextField id='macroWasteTotalWeightField'/> </cell> </row> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-02-15 18:24:13 UTC (rev 427) @@ -24,6 +24,7 @@ * #L% */ +import com.google.common.collect.Sets; import fr.ifremer.tutti.ui.swing.TuttiUI; import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI; import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUIHandler; @@ -40,6 +41,7 @@ import javax.swing.JPanel; import javax.swing.JTabbedPane; import java.awt.event.ActionEvent; +import java.util.Set; import static org.nuiton.i18n.I18n._; import static org.nuiton.i18n.I18n.n_; @@ -82,17 +84,8 @@ public EditCatchesUIHandler(FishingOperationsUI parentUi, EditCatchesUI ui) { super(parentUi.getHandler().getContext(), ui); this.parentUi = parentUi; -// this.persistenceService = context.getService(PersistenceService.class); this.catchBatchMonitor = new TuttiBeanMonitor<EditCatchesUIModel>( - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_WEIGHT, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_WEIGHT, - EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_PLANKTON_TOTAL_WEIGHT, - EditCatchesUIModel.PROPERTY_PLANKTON_TOTAL_SAMPLE_WEIGHT, - EditCatchesUIModel.PROPERTY_MACRO_WASTE_TOTAL_WEIGHT); + EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT); } //------------------------------------------------------------------------// @@ -141,6 +134,16 @@ return ui.getValidator(); } + @Override + protected Set<String> getPropertiesToIgnore() { + Set<String> result = super.getPropertiesToIgnore(); + result.addAll(Sets.newHashSet( + EditCatchesUIModel.PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, + EditCatchesUIModel.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT + )); + return result; + } @Override protected JTabbedPane getTabPanel() { @@ -234,109 +237,6 @@ return getParentUi().getHandler(); } - // public void selectFishingOperation(FishingOperation bean, -// String fishingOperationText) { -// -// boolean empty = bean == null; -// Preconditions.checkState(!empty, "can not edit a null fishing operation."); -// boolean newOperation = TuttiEntities.isNew(bean); -// boolean wasModified = fishingOperationMonitor.wasModified(); -// -// // 1) Save any modification of the current fishingOperation -// -// if (wasModified) { -// save(); -// } -// -// ui.getSpeciesTabContent().getHandler().clearTableSelection(); -//// ui.getBenthosTabContent().getHandler().clearTableSelection(); -//// ui.getPlanktonTabContent().getHandler().clearTableSelection(); -//// ui.getMacroWasteTabContent().getHandler().clearTableSelection(); -//// ui.getAccidentalTabContent().getHandler().clearTableSelection(); -// -// // 2) Use new selected fishingOperation -// -// EditCatchesUIModel catchesUIModel = getModel(); -// -// boolean otherOperation = -// ObjectUtils.notEqual(bean, catchesUIModel.getFishingOperation()); -// -// if (empty || newOperation || otherOperation || wasModified) { -// -// CatchBatch batch; -// -// if (empty || newOperation) { -// -// // create a new CatchBatch -// if (log.isInfoEnabled()) { -// log.info("Create a new CatchBatch"); -// } -// batch = new CatchBatch(); -// batch.setFishingOperation(bean); -// -// } else { -// -// String operationId = bean.getId(); -// -// if (log.isInfoEnabled()) { -// log.info("Load existing CatchBatch from operation id: " + -// operationId); -// } -// -// batch = persistenceService.getCatchBatchFromFishingOperation( -// operationId); -// -//// model.setCatchBatch(batch); -//// model.setFishingOperation(bean); -// } -// -// catchesUIModel.setCatchBatch(batch); -// catchesUIModel.setFishingOperation(bean); -// -// catchesUIModel.fromBean(batch); -// -// catchesUIModel.setModify(false); -// fishingOperationMonitor.clearModified(); -// -// // 3) Propagate title to others tabs -// ui.getCatchesCaracteristicsTabPane().setTitle(fishingOperationText); -// ui.getSpeciesTabFishingOperationReminderLabel().setTitle(fishingOperationText); -//// ui.getBenthosTabFishingOperationReminderLabel().setTitle(fishingOperationText); -//// ui.getPlanktonTabFishingOperationReminderLabel().setTitle(fishingOperationText); -//// ui.getMacroWasteTabFishingOperationReminderLabel().setTitle(fishingOperationText); -//// ui.getAccidentalTabFishingOperationReminderLabel().setTitle(fishingOperationText); -// -// // 4) Propagate new selected fishingoperation to others tabs -// -// ui.getSpeciesTabContent().getHandler().selectFishingOperation(bean); -//// ui.getBenthosTabContent().getHandler().selectFishingOperation(bean); -//// ui.getPlanktonTabContent().getHandler().selectFishingOperation(bean); -//// ui.getMacroWasteTabContent().getHandler().selectFishingOperation(bean); -//// ui.getAccidentalTabContent().getHandler().selectFishingOperation(bean); -// -// ui.getTabPane().repaint(); -// } -// } - -// public void save() { -// -// // previous fishingOperation was modified, let's save it -// EditCatchesUIModel beanToSave = catchBatchMonitor.getBean(); -// -// CatchBatch catchBatch = beanToSave.toBean(); -// -// if (log.isInfoEnabled()) { -// log.info("FishingOperation " + catchBatch.getId() + -// " was modified, will save it."); -// } -// -// showInformationMessage( -// "[ Captures - Caractéristiques générales ] " + -// "Sauvegarde des modifications du résumé de la capture."); -// -// persistenceService.saveCatchBatch(catchBatch); -// } - protected void registerValidators() { registerValidators(getValidator(), ui.getSpeciesTabContent().getHandler().getValidator()); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-02-15 18:24:13 UTC (rev 427) @@ -27,6 +27,7 @@ import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -41,23 +42,21 @@ private static final long serialVersionUID = 1L; public static final String PROPERTY_CATCH_TOTAL_WEIGHT = "catchTotalWeight"; + + public static final String PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT = "catchTotalComputedWeight"; public static final String PROPERTY_CATCH_TOTAL_SORTED_TREMIS_WEIGHT = "catchTotalSortedTremisWeight"; public static final String PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT = "catchTotalSortedCarousselWeight"; public static final String PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT = "catchTotalRejectedWeight"; + + public static final String PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT = "catchTotalRejectedComputedWeight"; - public static final String PROPERTY_CATCH_TOTAL_UNSORTED_WEIGHT = "catchTotalUnsortedWeight"; - - public static final String PROPERTY_SPECIES_TOTAL_WEIGHT = "speciesTotalWeight"; - public static final String PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT = "speciesTotalSortedWeight"; + + public static final String PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT = "speciesTotalSortedComputedWeight"; - public static final String PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT = "speciesTotalSampleSortedWeight"; - - public static final String PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT = "speciesTotalUnsortedWeight"; - public static final String PROPERTY_SPECIES_TOTAL_INERT_WEIGHT = "speciesTotalInertWeight"; public static final String PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT = "speciesTotalLivingNotItemizedWeight"; @@ -119,18 +118,12 @@ protected static final Binder<EditCatchesUIModel, CatchBatch> toBeanBinder = BinderFactory.newBinder(EditCatchesUIModel.class, CatchBatch.class); - protected Float speciesTotalWeight; + protected TuttiComputedOrNotData<Float> speciesTotalSortedComputedOrNotWeight = new TuttiComputedOrNotData<Float>(); - protected Float speciesTotalSortedWeight; + protected Float speciesTotalInertWeight = 0f; - protected Float speciesTotalSampleSortedWeight; + protected Float speciesTotalLivingNotItemizedWeight = 0f; - protected Float speciesTotalUnsortedWeight; - - protected Float speciesTotalInertWeight; - - protected Float speciesTotalLivingNotItemizedWeight; - protected Float benthosTotalWeight; protected Float benthosTotalSortedWeight; @@ -145,16 +138,16 @@ protected Float macroWasteTotalWeight; - protected Float catchTotalWeight; + protected TuttiComputedOrNotData<Float> catchTotalComputedOrNotWeight + = new TuttiComputedOrNotData<Float>(); protected Float catchTotalSortedTremisWeight; protected Float catchTotalSortedCarousselWeight; - protected Float catchTotalRejectedWeight; + protected TuttiComputedOrNotData<Float> catchTotalRejectedComputedOrNotWeight + = new TuttiComputedOrNotData<Float>(); - protected Float catchTotalUnsortedWeight; - protected FishingOperation fishingOperation; protected CatchBatch catchBatch; @@ -173,7 +166,7 @@ } public void setCatchBatch(CatchBatch catchBatch) { - Object oldValue = getCatchTotalWeight(); + Object oldValue = getCatchBatch(); this.catchBatch = catchBatch; firePropertyChange(PROPERTY_CATCH_BATCH, oldValue, catchBatch); } @@ -188,16 +181,30 @@ firePropertyChange(PROPERTY_FISHING_OPERATION, oldValue, fishingOperation); } + public TuttiComputedOrNotData<Float> getCatchTotalComputedOrNotWeight() { + return catchTotalComputedOrNotWeight; + } + public Float getCatchTotalWeight() { - return catchTotalWeight; + return catchTotalComputedOrNotWeight.getData(); } public void setCatchTotalWeight(Float catchTotalWeight) { Object oldValue = getCatchTotalWeight(); - this.catchTotalWeight = catchTotalWeight; + this.catchTotalComputedOrNotWeight.setData(catchTotalWeight); firePropertyChange(PROPERTY_CATCH_TOTAL_WEIGHT, oldValue, catchTotalWeight); } + + public Float getCatchTotalComputedWeight() { + return catchTotalComputedOrNotWeight.getComputedData(); + } + public void setCatchTotalComputedWeight(Float catchTotalComputedWeight) { + Object oldValue = getCatchTotalComputedWeight(); + this.catchTotalComputedOrNotWeight.setComputedData(catchTotalComputedWeight); + firePropertyChange(PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, oldValue, catchTotalComputedWeight); + } + public Float getCatchTotalSortedTremisWeight() { return catchTotalSortedTremisWeight; } @@ -218,66 +225,54 @@ firePropertyChange(PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT, oldValue, catchTotalSortedCarousselWeight); } + public TuttiComputedOrNotData<Float> getCatchTotalRejectedComputedOrNotWeight() { + return catchTotalRejectedComputedOrNotWeight; + } + public Float getCatchTotalRejectedWeight() { - return catchTotalRejectedWeight; + return catchTotalRejectedComputedOrNotWeight.getData(); } public void setCatchTotalRejectedWeight(Float catchTotalRejectedWeight) { Object oldValue = getCatchTotalRejectedWeight(); - this.catchTotalRejectedWeight = catchTotalRejectedWeight; + this.catchTotalRejectedComputedOrNotWeight.setData(catchTotalRejectedWeight); firePropertyChange(PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, oldValue, catchTotalRejectedWeight); } - public Float getCatchTotalUnsortedWeight() { - return catchTotalUnsortedWeight; + public Float getCatchTotalRejectedComputedWeight() { + return catchTotalRejectedComputedOrNotWeight.getComputedData(); } - public void setCatchTotalUnsortedWeight(Float catchTotalUnsortedWeight) { - Object oldValue = getCatchTotalUnsortedWeight(); - this.catchTotalUnsortedWeight = catchTotalUnsortedWeight; - firePropertyChange(PROPERTY_CATCH_TOTAL_UNSORTED_WEIGHT, oldValue, catchTotalUnsortedWeight); + public void setCatchTotalRejectedComputedWeight(Float catchTotalRejectedComputedWeight) { + Object oldValue = getCatchTotalRejectedComputedWeight(); + this.catchTotalRejectedComputedOrNotWeight.setComputedData(catchTotalRejectedComputedWeight); + firePropertyChange(PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, oldValue, catchTotalRejectedComputedWeight); } - - public Float getSpeciesTotalWeight() { - return speciesTotalWeight; + + public TuttiComputedOrNotData<Float> getSpeciesTotalSortedComputedOrNotWeight() { + return speciesTotalSortedComputedOrNotWeight; } - - public void setSpeciesTotalWeight(Float speciesTotalWeight) { - Object oldValue = getSpeciesTotalWeight(); - this.speciesTotalWeight = speciesTotalWeight; - firePropertyChange(PROPERTY_SPECIES_TOTAL_WEIGHT, oldValue, speciesTotalWeight); - } - + public Float getSpeciesTotalSortedWeight() { - return speciesTotalSortedWeight; + return speciesTotalSortedComputedOrNotWeight.getData(); } public void setSpeciesTotalSortedWeight(Float speciesTotalSortedWeight) { Object oldValue = getSpeciesTotalSortedWeight(); - this.speciesTotalSortedWeight = speciesTotalSortedWeight; + this.speciesTotalSortedComputedOrNotWeight.setData(speciesTotalSortedWeight); firePropertyChange(PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, oldValue, speciesTotalSortedWeight); } - - public Float getSpeciesTotalSampleSortedWeight() { - return speciesTotalSampleSortedWeight; + + public Float getSpeciesTotalSortedComputedWeight() { + return speciesTotalSortedComputedOrNotWeight.getComputedData(); } - public void setSpeciesTotalSampleSortedWeight(Float speciesTotalSampleSortedWeight) { - Object oldValue = getSpeciesTotalSampleSortedWeight(); - this.speciesTotalSampleSortedWeight = speciesTotalSampleSortedWeight; - firePropertyChange(PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT, oldValue, speciesTotalSampleSortedWeight); + public void setSpeciesTotalSortedComputedWeight(Float speciesTotalSortedComputedWeight) { + Object oldValue = getSpeciesTotalSortedComputedWeight(); + this.speciesTotalSortedComputedOrNotWeight.setComputedData(speciesTotalSortedComputedWeight); + firePropertyChange(PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, oldValue, speciesTotalSortedComputedWeight); } - public Float getSpeciesTotalUnsortedWeight() { - return speciesTotalUnsortedWeight; - } - - public void setSpeciesTotalUnsortedWeight(Float speciesTotalUnsortedWeight) { - Object oldValue = getSpeciesTotalUnsortedWeight(); - this.speciesTotalUnsortedWeight = speciesTotalUnsortedWeight; - firePropertyChange(PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT, oldValue, speciesTotalUnsortedWeight); - } - public Float getSpeciesTotalInertWeight() { return speciesTotalInertWeight; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java 2013-02-15 18:24:13 UTC (rev 427) @@ -65,6 +65,22 @@ * @since 1.0 */ protected Float computedWeight; + + /** + * Is this sample a subsample ? + * Available only if the category is the finest category of the row + * + * @since 1.0 + */ + protected boolean subSample; + + /** + * Has the row only one frequency ? + * Available only if the category is the finest category of the row + * + * @since 1.0 + */ + protected boolean onlyOneFrequency; public static <C extends Serializable> SampleCategory<C> newSample(SampleCategoryType categoryType) { SampleCategory<C> result = new SampleCategory<C>(); @@ -107,6 +123,22 @@ this.computedWeight = computedWeight; } + public boolean isSubSample() { + return subSample; + } + + public void setSubSample(boolean subSample) { + this.subSample = subSample; + } + + public boolean hasOnlyOneFrequency() { + return onlyOneFrequency; + } + + public void setOnlyOneFrequency(boolean onlyOneFrequency) { + this.onlyOneFrequency = onlyOneFrequency; + } + public boolean isValid() { return categoryValue != null; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java 2013-02-15 18:24:13 UTC (rev 427) @@ -38,6 +38,7 @@ import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Component; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; @@ -208,6 +209,7 @@ boolean hasFocus, int row, int column) { + SampleCategory<C> sampleCategory = (SampleCategory<C>) value; String text = null; @@ -219,12 +221,25 @@ Float number = sampleCategory.getCategoryWeight(); Float computedNumber = sampleCategory.getComputedWeight(); - text = "<html>" + categoryDecorator.toString(categoryValue) + " / "; + text = "<html>" + categoryDecorator.toString(categoryValue) + " /"; + + if (sampleCategory.isSubSample()) { + text += "/"; + } + text += " "; if (number != null) { - text += number; + text += String.format("%.3f", number); + } else if (computedNumber != null) { - text += "<em style='color: blue'>" + computedNumber + "</em>"; + if (sampleCategory.hasOnlyOneFrequency()) { + text += String.format("%.3f", computedNumber); + + } else { + String blue = Integer.toHexString(Color.BLUE.getRGB()).substring(2); + text += "<em style='color: #" + blue + "'>" + + String.format("%.3f", computedNumber) + "</em>"; + } } else { text += "-"; } 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-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-02-15 18:24:13 UTC (rev 427) @@ -34,12 +34,15 @@ import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel; import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import org.apache.commons.collections.CollectionUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; import java.util.Collections; import java.util.List; +import org.apache.commons.logging.LogFactory; /** * Represents a species batch (i.e a row in the batch table). @@ -239,6 +242,40 @@ sexCategory = SampleCategory.newSample(SampleCategoryType.sex); maturityCategory = SampleCategory.newSample(SampleCategoryType.maturity); ageCategory = SampleCategory.newSample(SampleCategoryType.age); + + computedOrNotWeight.addPropertyChangeListener( + TuttiComputedOrNotData.PROPERTY_DATA, + new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_WEIGHT, evt.getOldValue(), evt.getNewValue()); + } + }); + computedOrNotWeight.addPropertyChangeListener( + TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, + new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_COMPUTED_WEIGHT, evt.getOldValue(), evt.getNewValue()); + } + }); + + computedOrNotNumber.addPropertyChangeListener( + TuttiComputedOrNotData.PROPERTY_DATA, + new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_NUMBER, evt.getOldValue(), evt.getNewValue()); + } + }); + computedOrNotNumber.addPropertyChangeListener( + TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, + new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_COMPUTED_NUMBER, evt.getOldValue(), evt.getNewValue()); + } + }); } public SpeciesBatchRowModel(SpeciesBatch aBatch, @@ -287,6 +324,26 @@ return sampleCategory; } + public SampleCategory getFinestCategory() { + SampleCategory finestCategory; + if (ageCategory.isValid()) { + finestCategory = ageCategory; + + } else if (maturityCategory.isValid()) { + finestCategory = maturityCategory; + + } else if (sexCategory.isValid()) { + finestCategory = sexCategory; + + } else if (sizeCategory.isValid()) { + finestCategory = sizeCategory; + + } else { + finestCategory = sortedUnsortedCategory; + } + return finestCategory; + } + //------------------------------------------------------------------------// //-- Species category --// //------------------------------------------------------------------------// @@ -515,9 +572,7 @@ } public void setWeight(Float weight) { - Object oldValue = getWeight(); this.computedOrNotWeight.setData(weight); - firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); } public Integer getNumber() { @@ -525,9 +580,7 @@ } public void setNumber(Integer number) { - Object oldValue = getNumber(); computedOrNotNumber.setData(number); - firePropertyChange(PROPERTY_NUMBER, oldValue, number); } public String getComment() { @@ -565,10 +618,7 @@ } public void setComputedNumber(Integer computedNumber) { - Object oldValue = getComputedNumber(); computedOrNotNumber.setComputedData(computedNumber); - firePropertyChange(PROPERTY_COMPUTED_NUMBER, oldValue, - computedNumber); } public Float getComputedWeight() { @@ -576,10 +626,7 @@ } public void setComputedWeight(Float computedWeight) { - Object oldValue = getComputedWeight(); computedOrNotWeight.setComputedData(computedWeight); - firePropertyChange(PROPERTY_COMPUTED_WEIGHT, oldValue, - computedWeight); } public TuttiComputedOrNotData<Integer> getComputedOrNotNumber() { 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-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2013-02-15 18:24:13 UTC (rev 427) @@ -27,18 +27,26 @@ showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; bean: {model}; showReset: true; + useFloat: true; + numberPattern: {DECIMAL3_PATTERN}; } +TuttiComputedOrNotDataEditor { + autoPopup: {handler.getConfig().isAutoPopupNumberEditor()}; + showPopupButton: {handler.getConfig().isShowNumberEditorButton()}; + showReset: true; + useFloat: true; + numberPattern: {DECIMAL3_PATTERN}; + decimalNumber: 3; +} + #speciesTotalWeightLabel { text: "tutti.label.catches.speciesTotalWeight"; labelFor: {speciesTotalWeightField}; } #speciesTotalWeightField { - property: speciesTotalWeight; - model: {model.getSpeciesTotalWeight()}; - numberPattern: {DECIMALFORCE3_PATTERN}; - useFloat: true; + _computed: true; } #speciesTotalSortedWeightLabel { @@ -47,10 +55,8 @@ } #speciesTotalSortedWeightField { - property: speciesTotalSortedWeight; + bean: {model.getSpeciesTotalSortedComputedOrNotWeight()}; model: {model.getSpeciesTotalSortedWeight()}; - numberPattern: {DECIMALFORCE3_PATTERN}; - useFloat: true; } #speciesTotalSampleSortedWeightLabel { @@ -59,9 +65,7 @@ } #speciesTotalSampleSortedWeightField { - text: {getStringValue(model.getSpeciesTotalUnsortedWeight())}; - editable: false; - enabled: false; + _computed: true; } #speciesTotalUnsortedWeightLabel { @@ -70,9 +74,7 @@ } #speciesTotalUnsortedWeightField { - text: {getStringValue(model.getSpeciesTotalUnsortedWeight())}; - editable: false; - enabled: false; + _computed: true; } #speciesTotalInertWeightLabel { @@ -83,8 +85,7 @@ #speciesTotalInertWeightField { property: speciesTotalInertWeight; model: {model.getSpeciesTotalInertWeight()}; - numberPattern: {DECIMALFORCE3_PATTERN}; - useFloat: true; + showReset: false; } #speciesTotalLivingNotItemizedWeightLabel { @@ -95,8 +96,7 @@ #speciesTotalLivingNotItemizedWeightField { property: speciesTotalLivingNotItemizedWeight; model: {model.getSpeciesTotalLivingNotItemizedWeight()}; - numberPattern: {DECIMALFORCE3_PATTERN}; - useFloat: true; + showReset: false; } #tablePopup { 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 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2013-02-15 18:24:13 UTC (rev 427) @@ -29,6 +29,7 @@ fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI + fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataEditor org.jdesktop.swingx.JXTable @@ -67,13 +68,8 @@ <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> - <field name='speciesTotalWeight' component='speciesTotalWeightField'/> <field name='speciesTotalSortedWeight' component='speciesTotalSortedWeightField'/> - <field name='speciesTotalSampleSortedWeight' - component='speciesTotalSampleSortedWeightField'/> - <field name='speciesTotalUnsortedWeight' - component='speciesTotalUnsortedWeightField'/> </BeanValidator> <LongTextEditorUI id='longTextEditor'/> @@ -96,13 +92,13 @@ <JLabel id='speciesTotalWeightLabel'/> </cell> <cell weightx='1.0'> - <NumberEditor id='speciesTotalWeightField' constructorParams='this'/> + <JTextField id='speciesTotalWeightField'/> </cell> <cell anchor='west'> <JLabel id='speciesTotalSortedWeightLabel'/> </cell> <cell weightx='1.0'> - <NumberEditor id='speciesTotalSortedWeightField' + <TuttiComputedOrNotDataEditor id='speciesTotalSortedWeightField' constructorParams='this'/> </cell> </row> 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-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-02-15 18:24:13 UTC (rev 427) @@ -58,7 +58,7 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; -import fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataEditor; +import fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataTableCell; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; @@ -132,7 +132,6 @@ public SpeciesBatchUIHandler(TuttiUI<?, ?> parentUi, SpeciesBatchUI ui) { super(parentUi, ui, - SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM, SpeciesBatchRowModel.PROPERTY_SPECIES, SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY_WEIGHT, @@ -148,7 +147,8 @@ SpeciesBatchRowModel.PROPERTY_NUMBER, SpeciesBatchRowModel.PROPERTY_COMMENT, SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, - SpeciesBatchRowModel.PROPERTY_FREQUENCY); + SpeciesBatchRowModel.PROPERTY_FREQUENCY, + SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM); tableFilters = new EnumMap<TableViewMode, RowFilter<SpeciesBatchTableModel, Integer>>(TableViewMode.class); tableFilters.put(TableViewMode.ALL, new RowFilter<SpeciesBatchTableModel, Integer>() { @@ -277,14 +277,13 @@ Object oldValue, Object newValue) { - if (SAMPLING_PROPERTIES.contains(propertyName) || - SpeciesBatchRowModel.PROPERTY_WEIGHT.equals(propertyName)) { + if (SAMPLING_PROPERTIES.contains(propertyName)) { // species has changed, recompute valid property recomputeRowValidState(row); // recompute the totalUnsorted weight - recomputeTotalUnsortedWeight(); +// recomputeTotalUnsortedWeight(); } // when row valid state has changed, recompute action enabled states @@ -294,11 +293,12 @@ @Override protected void saveSelectedRowIfRequired(TuttiBeanMonitor<SpeciesBatchRowModel> rowMonitor, SpeciesBatchRowModel row) { - +log.debug("saveSelectedRowIfRequired"); if (row.isValid()) { // there is a valid bean attached to the monitor - +log.debug("isValid"); if (rowMonitor.wasModified()) { +log.debug("wasModified"); // monitored bean was modified, save it if (log.isInfoEnabled()) { @@ -315,6 +315,7 @@ rowMonitor.clearModified(); } } else { +log.debug("wasNotModified"); //FIXME See how to delete rows ? Or moreover how to save tehem... if (log.isWarnEnabled()) { @@ -592,15 +593,11 @@ { // Weight column - TuttiComputedOrNotDataEditor<Float> editor = - new TuttiComputedOrNotDataEditor(Float.class, false); - editor.getNumberEditor().setSelectAllTextOnError(true); - editor.getNumberEditor().getTextField().setBorder(new LineBorder(Color.GRAY, 2)); - editor.getNumberEditor().setNumberPattern(TuttiUI.DECIMALFORCE3_PATTERN); - addColumnToModel(columnModel, - editor, - null, + TuttiComputedOrNotDataTableCell.newEditor( + Float.class, false, true, 3), + TuttiComputedOrNotDataTableCell.newRender( + defaultRenderer, true, 3), SpeciesBatchTableModel.WEIGHT); } @@ -852,6 +849,7 @@ } } row.setComputedNumber(totalNumber); + row.getFinestCategory().setOnlyOneFrequency(frequency.size() == 1); } } @@ -957,7 +955,8 @@ log.info("New total vrac / hors vrac: " + totalVrac + " / " + totalHorsVrac); } - getModel().setSpeciesTotalUnsortedWeight(totalHorsVrac); + ui.getSpeciesTotalUnsortedWeightField() + .setText(JAXXUtil.getStringValue(totalHorsVrac)); //TODO Should we also set the total vrac weight ? // getModel().setTotalVracWeight(totalVrac); } 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 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-02-15 18:24:13 UTC (rev 427) @@ -30,6 +30,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; import java.util.List; @@ -132,22 +133,15 @@ public SpeciesBatchUIModel(EditCatchesUIModel catchesUIModel) { super(catchesUIModel, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_WEIGHT, EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT, - EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT, EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT); } - public Float getSpeciesTotalWeight() { - return catchesUIModel.getSpeciesTotalWeight(); + public TuttiComputedOrNotData<Float> getSpeciesTotalSortedComputedOrNotWeight() { + return catchesUIModel.getSpeciesTotalSortedComputedOrNotWeight(); } - public void setSpeciesTotalWeight(Float speciesTotalWeight) { - catchesUIModel.setSpeciesTotalWeight(speciesTotalWeight); - } - public Float getSpeciesTotalSortedWeight() { return catchesUIModel.getSpeciesTotalSortedWeight(); } @@ -155,23 +149,15 @@ public void setSpeciesTotalSortedWeight(Float speciesTotalSortedWeight) { catchesUIModel.setSpeciesTotalSortedWeight(speciesTotalSortedWeight); } - - public Float getSpeciesTotalSampleSortedWeight() { - return catchesUIModel.getSpeciesTotalSampleSortedWeight(); + + public Float getSpeciesTotalSortedComputedWeight() { + return catchesUIModel.getSpeciesTotalSortedComputedWeight(); } - public void setSpeciesTotalSampleSortedWeight(Float speciesSampleSortedWeight) { - catchesUIModel.setSpeciesTotalSampleSortedWeight(speciesSampleSortedWeight); + public void setSpeciesTotalSortedComputedWeight(Float speciesTotalSortedComputedWeight) { + catchesUIModel.setSpeciesTotalSortedComputedWeight(speciesTotalSortedComputedWeight); } - public Float getSpeciesTotalUnsortedWeight() { - return catchesUIModel.getSpeciesTotalUnsortedWeight(); - } - - public void setSpeciesTotalUnsortedWeight(Float speciesTotalUnsortedWeight) { - catchesUIModel.setSpeciesTotalUnsortedWeight(speciesTotalUnsortedWeight); - } - public Float getSpeciesTotalInertWeight() { return catchesUIModel.getSpeciesTotalInertWeight(); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-02-15 18:24:13 UTC (rev 427) @@ -26,6 +26,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; +import fr.ifremer.tutti.ui.swing.TuttiUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; @@ -46,6 +47,7 @@ import javax.swing.table.TableCellRenderer; import java.awt.Color; import java.awt.Component; +import java.awt.Font; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -72,7 +74,26 @@ setHorizontalAlignment(CENTER); setIcon(SwingUtil.createActionIcon("show-frequency")); } + + public void setComputedOrNotText(TuttiComputedOrNotData<Integer> data) { + String text; + if (data != null && data.getData() != null) { + text = String.valueOf(data.getData()); + + } else if (data != null + && data.getComputedData() != null + && data.getComputedData() != 0) { + + String blue = Integer.toHexString(Color.BLUE.getRGB()).substring(2); + text = "<html><em style='color: #" + blue + "'>" + data.getComputedData() + "</em></html>"; + + } else { + text = " - "; + } + setText(text); + } + public static TableCellRenderer newRender() { return new FrequencyCellRenderer(); } @@ -171,11 +192,7 @@ } // push back to batch - Integer number = null; - if (frequency.size() == 1) { - number = frequency.get(0).getNumber(); - } - editRow.setNumber(number); + editRow.setNumber(null); } @@ -207,14 +224,9 @@ this.table = table; columnIdentifier = tableModel.getPropertyName(column); } - String text; - if (value == null) { - text = " - "; - } else { - text = String.valueOf(value); - } - component.setText(text); - + TuttiComputedOrNotData<Integer> data = (TuttiComputedOrNotData<Integer>) value; + component.setComputedOrNotText(data); + rowIndex = row; columnIndex = column; @@ -275,21 +287,13 @@ int row, int column) { + TuttiComputedOrNotData<Integer> data = (TuttiComputedOrNotData<Integer>) value; FrequencyCellComponent result = (FrequencyCellComponent) component.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - if (table != null) { - String text; - if (value == null) { - text = " - "; - } else { - text = String.valueOf(value); - } - boolean editable = table.isCellEditable(row, column); - result.setEnabled(editable); - result.setText(text); - } - + boolean editable = table.isCellEditable(row, column); + result.setEnabled(editable); + result.setComputedOrNotText(data); return result; } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-02-15 18:24:13 UTC (rev 427) @@ -27,6 +27,7 @@ import com.ezware.oxbow.swingbits.util.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; @@ -59,6 +60,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; /** * @author tchemit <chemit@codelutin.com> @@ -77,6 +79,8 @@ private Map<Integer, SpeciesProtocol> speciesProtocol; private Map<String, Caracteristic> lengthStepCaracteristics; + + protected Set<SpeciesFrequencyRowModel> withWeightRows = Sets.newHashSet(); public SpeciesFrequencyUIHandler(TuttiUIContext context, SpeciesFrequencyUI ui) { @@ -104,7 +108,8 @@ protected boolean isRowValid(SpeciesFrequencyRowModel row) { return row.getLengthStepCaracteristic() != null && row.getLengthStep() != null && - row.getNumber() != null; + row.getNumber() != null && row.getNumber() > 0 && + (withWeightRows.isEmpty() || row.getWeight() != null && row.getWeight() > 0); } @Override @@ -114,7 +119,28 @@ Object oldValue, Object newValue) { - recomputeRowValidState(row); + boolean recomputeAllRows; + + if (row.getWeight() != null) { + // check if no row had a weight, then if one of them now has a weight, + // the other ones must have one too to be valid + recomputeAllRows = withWeightRows.isEmpty(); + withWeightRows.add(row); + + } else { + withWeightRows.remove(row); + // check if no row has a weight, then if none of them now has a weight, + // the other ones do not need to have a weight to be valid + recomputeAllRows = withWeightRows.isEmpty(); + } + if (recomputeAllRows) { + List<SpeciesFrequencyRowModel> rows = getModel().getRows(); + for (SpeciesFrequencyRowModel r : rows) { + recomputeRowValidState(r); + } + } else { + recomputeRowValidState(row); + } } @Override @@ -237,7 +263,7 @@ addFloatColumnToModel(columnModel, SpeciesFrequencyTableModel.WEIGHT, - TuttiUI.DECIMALFORCE3_PATTERN); + TuttiUI.DECIMAL3_PATTERN); } // create table model @@ -367,9 +393,10 @@ } public void editBatch(SpeciesBatchRowModel speciesBatch, FrequencyCellEditor editor) { - + withWeightRows.clear(); + frequencyEditor = editor; - + Caracteristic lengthStepCaracteristic = null; Float lengthStep = 1f; @@ -382,7 +409,7 @@ // try to load existing frequency - if (frequency != null) { + if (!CollectionUtils.isEmpty(frequency)) { SpeciesFrequencyTableModel tableModel = getTableModel(); @@ -394,22 +421,23 @@ newRow.setNumber(rowModel.getNumber()); newRow.setWeight(rowModel.getWeight()); editFrequency.add(newRow); + + if (newRow.getWeight() != null) { + withWeightRows.add(newRow); + } } - if (CollectionUtils.isNotEmpty(frequency)) { + // use first frequency row length step caracteristics - // use first frequency row length step caracteristics + SpeciesFrequencyRowModel rowModel = frequency.get(0); + lengthStepCaracteristic = rowModel.getLengthStepCaracteristic(); + lengthStep = rowModel.getLengthStep(); - SpeciesFrequencyRowModel rowModel = frequency.get(0); - lengthStepCaracteristic = rowModel.getLengthStepCaracteristic(); - lengthStep = rowModel.getLengthStep(); - - if (log.isInfoEnabled()) { - log.info("Use existing lengthStep " + - "caracteristic / step " + - decorate(lengthStepCaracteristic) + " / " + - lengthStep); - } + if (log.isInfoEnabled()) { + log.info("Use existing lengthStep " + + "caracteristic / step " + + decorate(lengthStepCaracteristic) + " / " + + lengthStep); } } @@ -454,7 +482,6 @@ mode = SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE_COUNTING; } } - if (speciesBatch.getNumber() != null && editFrequency.isEmpty()) { mode = SpeciesFrequencyUIModel.ConfigurationMode.SIMPLE_COUNTING; model.setSimpleCount(speciesBatch.getNumber()); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUI.css 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/CreateSpeciesBatchUI.css 2013-02-15 18:24:13 UTC (rev 427) @@ -75,7 +75,7 @@ property: batchWeight; model: {model.getBatchWeight()}; useFloat: true; - numberPattern: {DECIMALFORCE3_PATTERN}; + numberPattern: {DECIMAL3_PATTERN}; bean: {model}; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-02-15 18:24:13 UTC (rev 427) @@ -382,7 +382,7 @@ addFloatColumnToModel(columnModel, SplitSpeciesBatchTableModel.WEIGHT, - TuttiUI.DECIMALFORCE3_PATTERN); + TuttiUI.DECIMAL3_PATTERN); } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-02-15 18:24:13 UTC (rev 427) @@ -1,6 +1,8 @@ package fr.ifremer.tutti.ui.swing.util; +import org.jdesktop.beans.AbstractBean; + /* * #%L * Tutti :: UI @@ -29,8 +31,12 @@ * * @author kmorin <kmorin@codelutin.com> */ -public class TuttiComputedOrNotData<N extends Number> { +public class TuttiComputedOrNotData<N extends Number> extends AbstractBean { + public static final String PROPERTY_DATA = "data"; + + public static final String PROPERTY_COMPUTED_DATA = "computedData"; + protected N data; protected N computedData; @@ -50,7 +56,9 @@ } public void setData(N data) { + Object oldValue = getData(); this.data = data; + firePropertyChange(PROPERTY_DATA, oldValue, data); } public N getComputedData() { @@ -58,16 +66,18 @@ } public void setComputedData(N computedData) { + Object oldValue = getComputedData(); this.computedData = computedData; + firePropertyChange(PROPERTY_COMPUTED_DATA, oldValue, computedData); } - + @Override public String toString() { String result = null; if (data != null) { result = data.toString(); } else if (computedData != null) { - result = "<html><em style='color: blue'>" + computedData.toString() + "</em></html>"; + result = computedData.toString(); } return result; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.java 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.java 2013-02-15 18:24:13 UTC (rev 427) @@ -1,141 +1,10 @@ package fr.ifremer.tutti.ui.swing.util.editor; -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; -import java.awt.Component; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import javax.swing.AbstractCellEditor; -import javax.swing.JTable; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.event.AncestorEvent; -import javax.swing.event.AncestorListener; -import javax.swing.table.TableCellEditor; -import jaxx.runtime.swing.editor.NumberEditor; - /** - * Editor for TuttiComputedOrNotData - * + * * @author kmorin <kmorin@codelutin.com> - * @since 1.0 */ -public class TuttiComputedOrNotDataEditor<E extends Number> extends AbstractCellEditor - implements TableCellEditor, FocusListener, AncestorListener { +public class TuttiComputedOrNotDataEditor { - private static final long serialVersionUID = 1L; - - protected final NumberEditor numberEditor; - - protected TuttiComputedOrNotData<E> data; - - /** constructor */ - public TuttiComputedOrNotDataEditor(Class<E> type, boolean useSign) { - numberEditor = new NumberEditor(); - numberEditor.getTextField().setHorizontalAlignment(SwingConstants.RIGHT); - numberEditor.getTextField().setBorder(null); - numberEditor.getTextField().addFocusListener(this); - numberEditor.getTextField().addAncestorListener(this); - - numberEditor.setModelType(type); - - numberEditor.setUseSign(useSign); - numberEditor.init(); - } - - @Override - public Component getTableCellEditorComponent(JTable table, Object value, - boolean isSelected, int row, int column) { - - data = (TuttiComputedOrNotData<E>) value; - numberEditor.setModel(data.getData()); - - // Check nullity and set the text that will be selected with the current value - if (data.getData() != null) { - numberEditor.setModelText(String.valueOf(data.getData())); - } - return numberEditor; - } - - public NumberEditor getNumberEditor() { - return numberEditor; - } - - @Override - public TuttiComputedOrNotData<E> getCellEditorValue() { - return data; - } - - @Override - public void focusGained(FocusEvent e) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - numberEditor.getTextField().requestFocus(); - numberEditor.getTextField().selectAll(); - } - }); - } - - @Override - public void focusLost(FocusEvent e) { - } - - @Override - public void ancestorAdded(AncestorEvent event) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - numberEditor.getTextField().requestFocus(); - numberEditor.getTextField().selectAll(); - } - }); - } - - @Override - public void ancestorRemoved(AncestorEvent event) { - } - - @Override - public void ancestorMoved(AncestorEvent event) { - } - - @Override - public boolean stopCellEditing() { - boolean result = super.stopCellEditing(); - // Reset previous data to avoid keeping it on other cell edition - if (result) { - data.setData((E) numberEditor.getModel()); - - numberEditor.setModel(null); - // Use empty string, otherwise there is a NPE in NumberEditorHandler - numberEditor.setModelText(""); - - data = null; - } - return result; - } - } Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.jaxx 2013-02-15 18:24:13 UTC (rev 427) @@ -0,0 +1,23 @@ +<jaxx.runtime.swing.editor.NumberEditor> + + <import> + fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData + </import> + + <String id='property' javaBean='TuttiComputedOrNotData.PROPERTY_DATA'/> + + <TuttiComputedOrNotData id='bean' genericType='?' javaBean='null'/> + + <!-- ui handler --> + <TuttiComputedOrNotDataEditorHandler id='handler' constructorParams='this'/> + + <Integer id='decimalNumber' javaBean='null'/> + + <script><![CDATA[ + public void setProperty(String property) { + // cannot change the property + } +]]> + </script> + +</jaxx.runtime.swing.editor.NumberEditor> \ No newline at end of file Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java (from rev 411, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java 2013-02-15 18:24:13 UTC (rev 427) @@ -0,0 +1,113 @@ + +package fr.ifremer.tutti.ui.swing.util.editor; + +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; +import java.awt.Color; +import java.awt.Font; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.regex.Matcher; +import javax.swing.JTextField; +import javax.swing.UIManager; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.swing.editor.NumberEditorHandler; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author kmorin <kmorin@codelutin.com> + * @since 1.0 + */ +public class TuttiComputedOrNotDataEditorHandler extends NumberEditorHandler { + + private static final Log log = LogFactory.getLog(TuttiComputedOrNotDataEditorHandler.class); + + protected Integer decimalNumber; + + public TuttiComputedOrNotDataEditorHandler(TuttiComputedOrNotDataEditor ui) { + super(ui); + } + + @Override + public void init() { + final PropertyChangeListener l = new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + setComputedTextIfNullModel(); + } + }; + + TuttiComputedOrNotData bean = (TuttiComputedOrNotData) editor.getBean(); + if (bean != null) { + bean.addPropertyChangeListener(TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, l); + } + editor.addPropertyChangeListener(TuttiComputedOrNotDataEditor.PROPERTY_BEAN, new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + + TuttiComputedOrNotData bean = (TuttiComputedOrNotData) evt.getOldValue(); + if (bean != null) { + bean.removePropertyChangeListener(TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, l); + } + + bean = (TuttiComputedOrNotData) evt.getNewValue(); + if (bean != null) { + bean.addPropertyChangeListener(TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, l); + } + } + }); + + editor.getTextField().addFocusListener(new FocusListener() { + + public void focusGained(FocusEvent e) { + JTextField tf = editor.getTextField(); + tf.setFont(TuttiUI.TEXTFIELD_NORMAL_FONT); + tf.setForeground(Color.BLACK); + if (editor.getModel() == null) { + tf.setText(""); + } + } + + public void focusLost(FocusEvent e) { + setComputedTextIfNullModel(); + } + }); + + editor.addPropertyChangeListener(TuttiComputedOrNotDataEditor.PROPERTY_DECIMAL_NUMBER, + new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + decimalNumber = (Integer) evt.getNewValue(); + } + }); + decimalNumber = ((TuttiComputedOrNotDataEditor) editor).getDecimalNumber(); + + super.init(); + + } + + protected void setComputedTextIfNullModel() { + TuttiComputedOrNotData bean = (TuttiComputedOrNotData) editor.getBean(); + if (bean != null && editor.getModel() == null) { + JTextField tf = editor.getTextField(); + tf.setFont(TuttiUI.TEXTFIELD_COMPUTED_FONT); + tf.setForeground(Color.BLUE); + + String modelText; + Number computedData = bean.getComputedData(); + if (editor.isUseFloat() + && decimalNumber != null && computedData != null) { + modelText = String.format("%." + decimalNumber + "f", computedData); + } else { + modelText = JAXXUtil.getStringValue(computedData); + } + tf.setText(modelText); + } + } + +} Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java (from rev 411, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java 2013-02-15 18:24:13 UTC (rev 427) @@ -0,0 +1,209 @@ +package fr.ifremer.tutti.ui.swing.util.editor; + +import fr.ifremer.tutti.ui.swing.TuttiUI; +import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import javax.swing.AbstractCellEditor; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.border.LineBorder; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import jaxx.runtime.JAXXUtil; + +/** + * Editor for TuttiComputedOrNotData + * + * @author kmorin <kmorin@codelutin.com> + * @since 1.0 + */ +public class TuttiComputedOrNotDataTableCell extends DefaultTableCellRenderer { + + public static TableCellRenderer newRender(TableCellRenderer renderer, + boolean useFloat, + Integer decimalNumber) { + + return new TuttiComputedOrNotDataTableCellRenderer(renderer, + useFloat, + decimalNumber); + } + + public static TableCellEditor newEditor(Class type, + boolean useSign, + boolean useFloat, + Integer decimalNumber) { + + return new TuttiComputedOrNotDataTableCellEditor(type, useSign, + useFloat, decimalNumber); + } + + public static class TuttiComputedOrNotDataTableCellEditor + extends AbstractCellEditor + implements TableCellEditor, FocusListener, AncestorListener { + + private static final long serialVersionUID = 1L; + protected final TuttiComputedOrNotDataEditor numberEditor; + protected TuttiComputedOrNotData data; + + /** + * constructor + */ + public TuttiComputedOrNotDataTableCellEditor(Class type, + boolean useSign, + boolean useFloat, + Integer decimalNumber) { + + numberEditor = new TuttiComputedOrNotDataEditor(); + numberEditor.getTextField().setHorizontalAlignment(SwingConstants.RIGHT); + numberEditor.getTextField().addFocusListener(this); + numberEditor.getTextField().addAncestorListener(this); + numberEditor.getTextField().setBorder(new LineBorder(Color.GRAY, 2)); + numberEditor.setSelectAllTextOnError(true); + numberEditor.setNumberPattern(TuttiUI.DECIMAL3_PATTERN); + + numberEditor.setModelType(type); + numberEditor.setUseSign(useSign); + numberEditor.setUseFloat(useFloat); + numberEditor.setDecimalNumber(decimalNumber); + numberEditor.init(); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, int row, int column) { + + data = (TuttiComputedOrNotData) value; + numberEditor.setModel(data.getData()); + + // Check nullity and set the text that will be selected with the current value + if (data.getData() != null) { + numberEditor.setModelText(String.valueOf(data.getData())); + } + return numberEditor; + } + + public TuttiComputedOrNotDataEditor getNumberEditor() { + return numberEditor; + } + + @Override + public TuttiComputedOrNotData getCellEditorValue() { + return data; + } + + @Override + public void focusGained(FocusEvent e) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + numberEditor.getTextField().requestFocus(); + numberEditor.getTextField().selectAll(); + } + }); + } + + @Override + public void focusLost(FocusEvent e) { + } + + @Override + public void ancestorAdded(AncestorEvent event) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + numberEditor.getTextField().requestFocus(); + numberEditor.getTextField().selectAll(); + } + }); + } + + @Override + public void ancestorRemoved(AncestorEvent event) { + } + + @Override + public void ancestorMoved(AncestorEvent event) { + } + + @Override + public boolean stopCellEditing() { + boolean result = super.stopCellEditing(); + // Reset previous data to avoid keeping it on other cell edition + if (result) { + data.setData(numberEditor.getModel()); + + numberEditor.setBean(null); + + data = null; + } + return result; + } + } + + public static class TuttiComputedOrNotDataTableCellRenderer<E> + implements TableCellRenderer { + + protected final TableCellRenderer delegate; + + protected Integer decimalNumber; + + protected boolean useFloat; + + public TuttiComputedOrNotDataTableCellRenderer( + TableCellRenderer delegate, + boolean useFloat, + Integer decimalNumber) { + + this.delegate = delegate; + this.useFloat = useFloat; + this.decimalNumber = decimalNumber; + } + + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + + TuttiComputedOrNotData data = (TuttiComputedOrNotData) value; + Number dataValue = data.getData(); + Font font; + Color foreground; + if (dataValue == null) { + dataValue = data.getComputedData(); + font = TuttiUI.TEXTFIELD_COMPUTED_FONT; + foreground = Color.BLUE; + + } else { + font = TuttiUI.TEXTFIELD_NORMAL_FONT; + foreground = Color.BLACK; + } + String text; + if (useFloat && decimalNumber != null && dataValue != null) { + text = JAXXUtil.getStringValue( + String.format("%." + decimalNumber + "f", dataValue)); + } else { + text = JAXXUtil.getStringValue(dataValue); + } + + Component component = delegate.getTableCellRendererComponent(table, + text, + isSelected, + hasFocus, + row, + column); + component.setFont(font); + component.setForeground(foreground); + + return component; + } + + } +} Modified: trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-edit-warning-validation.xml =================================================================== --- trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-edit-warning-validation.xml 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-edit-warning-validation.xml 2013-02-15 18:24:13 UTC (rev 427) @@ -42,9 +42,11 @@ <field-validator type="fieldexpression" short-circuit="true"> <param name="expression"> <![CDATA[ gearShootingStartDate == null || gearShootingEndDate == null - || org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) <= 45 ]]> + || (org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) <= 45 + && org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) >= 20 ) + ]]> </param> - <message>tutti.validator.error.fishingOperation.dates.tooLong</message> + <message>tutti.validator.error.fishingOperation.dates.wrongTime</message> </field-validator> </field> @@ -61,9 +63,11 @@ <field-validator type="fieldexpression" short-circuit="true"> <param name="expression"> <![CDATA[ gearShootingStartDate == null || gearShootingEndDate == null - || org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) <= 45 ]]> + || (org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) <= 45 + && org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) >= 20 ) + ]]> </param> - <message>tutti.validator.error.fishingOperation.dates.tooLong</message> + <message>tutti.validator.error.fishingOperation.dates.wrongTime</message> </field-validator> </field> Modified: trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-validate-warning-validation.xml =================================================================== --- trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-validate-warning-validation.xml 2013-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/resources/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel-validate-warning-validation.xml 2013-02-15 18:24:13 UTC (rev 427) @@ -35,9 +35,11 @@ <field-validator type="fieldexpression" short-circuit="true"> <param name="expression"> <![CDATA[ gearShootingStartDate == null || gearShootingEndDate == null - || org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) <= 45 ]]> + || org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) <= 45 + && org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) >= 20 ) + ]]> </param> - <message>tutti.validator.error.fishingOperation.dates.tooLong</message> + <message>tutti.validator.error.fishingOperation.dates.wrongTime</message> </field-validator> </field> @@ -47,9 +49,11 @@ <field-validator type="fieldexpression" short-circuit="true"> <param name="expression"> <![CDATA[ gearShootingStartDate == null || gearShootingEndDate == null - || org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) <= 45 ]]> + || org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) <= 45 + && org.nuiton.util.DateUtil.getDifferenceInMinutes(gearShootingStartDate, gearShootingEndDate) >= 20 ) + ]]> </param> - <message>tutti.validator.error.fishingOperation.dates.tooLong</message> + <message>tutti.validator.error.fishingOperation.dates.wrongTime</message> </field-validator> </field> 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-02-15 17:55:53 UTC (rev 426) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-02-15 18:24:13 UTC (rev 427) @@ -195,7 +195,7 @@ tutti.label.catches.catchThalassa=(*) uniquement sur Thalassa tutti.label.catches.catchTotalRejectedWeight=Poids total NON TRIÉ (kg) tutti.label.catches.catchTotalSortedCarousselWeight=Caroussel Observé (*) -tutti.label.catches.catchTotalSortedTremisWeight=Tremis (*) +tutti.label.catches.catchTotalSortedTremisWeight=Tremie (*) tutti.label.catches.catchTotalSortedWeight=Poids total VRAC (kg) tutti.label.catches.catchTotalUnsortedWeight=Poids total HORS VRAC (kg) tutti.label.catches.catchTotalWeight=Poids TOTAL (kg) @@ -497,7 +497,7 @@ tutti.validator.error.fishingOperation.dates.endBeforeStart=La date de fin doit être après la date de début tutti.validator.error.fishingOperation.dates.endOutOfCruiseDates=La date de fin est en dehors des dates de la campagne tutti.validator.error.fishingOperation.dates.startOutOfCruiseDates=La date de début est en dehors des dates de la campagne -tutti.validator.error.fishingOperation.dates.tooLong=La durée du trait dépasse 45 minutes, merci de vérifier les dates/heures du trait +tutti.validator.error.fishingOperation.dates.wrongTime=La durée du trait dépasse 45 minutes ou est inférieure à 20 minutes, merci de vérifier les dates/heures du trait tutti.validator.error.fishingOperation.existingKey=La clé code station/numéro de trait/date de début existe déjà tutti.validator.error.fishingOperation.fishingOperationNumber.required=Le numéro de trait est obligatoire tutti.validator.error.fishingOperation.fishingOperationValid.required=La validité du traît est obligatoire
participants (1)
-
kmorin@users.forge.codelutin.com