Author: chatellier Date: 2010-11-17 15:03:14 +0000 (Wed, 17 Nov 2010) New Revision: 222 Log: Validation de toutes les categories en meme tps. Presentation des erreurs par categories. Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/control/ValidationError.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java trunk/coser-business/src/main/resources/fr/ifremer/coser/data/Catch-error-validation.xml trunk/coser-business/src/main/resources/fr/ifremer/coser/data/Haul-fatal-validation.xml trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties trunk/coser-business/src/test/java/fr/ifremer/coser/services/ValidationServiceTest.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationGroup.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/control/ValidationError.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/control/ValidationError.java 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/control/ValidationError.java 2010-11-17 15:03:14 UTC (rev 222) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2010 Codelutin, Chatellier Eric + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -27,6 +27,7 @@ import java.io.Serializable; +import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.CoserConstants.ValidationLevel; /** @@ -45,6 +46,9 @@ /** serialVersionUID. */ private static final long serialVersionUID = -1806823191454701123L; + /** Category de l'erreur. */ + protected Category category; + /** Niveau de l'erreur (fatal, error, warning, info). */ protected ValidationLevel level; @@ -66,6 +70,26 @@ } /** + * Category de l'erreur. + * + * Peut etre null si l'erreur n'est pas associées à une category en particulier. + * + * @return category de l'erreur + */ + public Category getCategory() { + return category; + } + + /** + * Category de l'erreur. + * + * @param category category de l'erreur + */ + public void setCategory(Category category) { + this.category = category; + } + + /** * Niveau de l'erreur (fatal, error, warning, info). * * @return level Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java 2010-11-17 15:03:14 UTC (rev 222) @@ -120,9 +120,10 @@ * Valide un seul bean, retourne la liste des erreurs trouvées. * * @param bean bean to validate + * @param category result errors category * @return */ - protected List<ValidationError> validate(AbstractDataEntity bean) { + protected List<ValidationError> validate(AbstractDataEntity bean, Category category) { List<ValidationError> result = new ArrayList<ValidationError>();; try { // obligatoire pour les appel dans les thread et swing EDT @@ -138,6 +139,7 @@ for (List<String> errors : fieldErrors.values()) { ValidationError error = new ValidationError(); + error.setCategory(category); String messages = StringUtils.join(errors, ", "); error.setMessage(messages); error.setLevel(validationLevel); @@ -151,6 +153,7 @@ Collection<String> actionMessages = validationContext.getActionErrors(); if (CollectionUtils.isNotEmpty(actionMessages)) { ValidationError error = new ValidationError(); + error.setCategory(category); String messages = StringUtils.join(actionMessages, ", "); error.setMessage(messages); error.setLevel(validationLevel); @@ -182,6 +185,52 @@ } /** + * Valide toutes les données du projet. + * + * @param control control a valider + * @param progress progress monitor + * @return les erreurs de validation + */ + public List<ValidationError> validateData(Control control, ProgressMonitor progress) { + + // compte le nombre de category a valider + int categoryCount = 0; + for (Category category : Category.values()) { + if (category.isDataCategory()) { + categoryCount++; + } + } + + // valide chaque category + int categoryIndex = 0; + List<ValidationError> validationErrors = new ArrayList<ValidationError>(); + for (Category category : Category.values()) { + if (category.isDataCategory()) { + // validation de la category seule (generique) + List<ValidationError> categoryErrors = validateCategoryXWork(control, category, progress); + if (categoryErrors != null) { + validationErrors.addAll(categoryErrors); + } + // validation specifique de la category + List<ValidationError> specificErrors = validateCategorySpecific(control, category, progress); + if (specificErrors != null) { + categoryErrors.addAll(specificErrors); + } + } + } + + // cas particulier, s'il n'y a aucune erreur, on ajout une erreur de + // type info pour dire qu'il n'y a pas d'erreur + if (validationErrors.isEmpty()) { + ValidationError noErrorError = new ValidationError(); + noErrorError.setLevel(ValidationLevel.INFO); + noErrorError.setMessage(_("coser.business.control.noerrorfound")); + validationErrors.add(noErrorError); + } + return validationErrors; + } + + /** * Valide une category entière d'un project. * * @param control control a valider @@ -190,6 +239,7 @@ * @return les erreurs de validation */ public List<ValidationError> validateCategory(Control control, Category category, ProgressMonitor progress) { + // validation de la category seule (generique) List<ValidationError> errors = validateCategoryXWork(control, category, progress); // validation specifique de la category @@ -198,14 +248,6 @@ errors.addAll(specificErrors); } - // cas particulier, s'il n'y a aucune erreur, on ajout une erreur de - // type info pour dire qu'il n'y a pas d'erreur - if (errors.isEmpty()) { - ValidationError noErrorError = new ValidationError(); - noErrorError.setLevel(ValidationLevel.INFO); - noErrorError.setMessage(_("coser.business.control.noerrorfound")); - errors.add(noErrorError); - } return errors; } @@ -245,7 +287,7 @@ // update progress int total = dataToCheck.size() - 1; if (progress != null) { - progress.setText(_("coser.business.control.step.xworks", 0)); + progress.setText(_("coser.business.control.step.xworks", _(category.getTranslationKey()), 0)); progress.setTotal(total); } @@ -270,19 +312,19 @@ switch (category) { case CATCH: beanCatch.setData(line); - errors = validate(beanCatch); + errors = validate(beanCatch, category); break; case HAUL: beanHaul.setData(line); - errors = validate(beanHaul); + errors = validate(beanHaul, category); break; case LENGTH: beanLength.setData(line); - errors = validate(beanLength); + errors = validate(beanLength, category); break; case STRATA: beanStrata.setData(line); - errors = validate(beanStrata); + errors = validate(beanStrata, category); break; } if (errors != null) { @@ -293,6 +335,7 @@ String uniqueDataKey = getSignificantData(category, line); if (uniqueDataKeys.contains(uniqueDataKey)) { ValidationError error = new ValidationError(); + error.setCategory(category); error.setLevel(ValidationLevel.ERROR); error.setLineNumber(line[AbstractDataEntity.INDEX_LINE]); error.setMessage(_("coser.business.control.error.duplicatedLine")); @@ -477,6 +520,7 @@ String lineNumber = firstLineForKey.get(key); ValidationError error = new ValidationError(); + error.setCategory(Category.CATCH); error.setLevel(ValidationLevel.WARNING); error.setLineNumber(lineNumber); error.setMessage(_("coser.business.control.error.minObservationCount")); @@ -569,6 +613,7 @@ String lineNumber = firstLineForKey.get(key); ValidationError error = new ValidationError(); + error.setCategory(Category.LENGTH); error.setLevel(ValidationLevel.WARNING); error.setLineNumber(lineNumber); error.setMessage(_("coser.business.control.error.minObservationCount", key, value)); Modified: trunk/coser-business/src/main/resources/fr/ifremer/coser/data/Catch-error-validation.xml =================================================================== --- trunk/coser-business/src/main/resources/fr/ifremer/coser/data/Catch-error-validation.xml 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-business/src/main/resources/fr/ifremer/coser/data/Catch-error-validation.xml 2010-11-17 15:03:14 UTC (rev 222) @@ -64,6 +64,6 @@ </field> <validator type="coserExpression"> <param name="expression"><![CDATA[ (weight > 0 && number > 0) || weight == 0]]></param> - <message><![CDATA[coser.business.control.error.noCatchNumberWithWeight]]></message> + <message>coser.business.control.error.noCatchNumberWithWeight</message> </validator> </validators> \ No newline at end of file Modified: trunk/coser-business/src/main/resources/fr/ifremer/coser/data/Haul-fatal-validation.xml =================================================================== --- trunk/coser-business/src/main/resources/fr/ifremer/coser/data/Haul-fatal-validation.xml 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-business/src/main/resources/fr/ifremer/coser/data/Haul-fatal-validation.xml 2010-11-17 15:03:14 UTC (rev 222) @@ -29,19 +29,19 @@ <field name="sweptSurface"> <field-validator type="regex"> <param name="expression">\-?[0-9]+\.[0-9]{3,}</param> - <message>lat must contains at least 5 decimal</message> + <message>lat must contains at least 3 decimal</message> </field-validator> </field> <field name="lat"> <field-validator type="regex"> <param name="expression">\-?[0-9]+\.[0-9]{3,}</param> - <message>lat must contains at least 5 decimal</message> + <message>lat must contains at least 3 decimal</message> </field-validator> </field> <field name="long"> <field-validator type="regex"> <param name="expression">\-?[0-9]+\.[0-9]{3,}</param> - <message>long must contains at least 5 decimal</message> + <message>long must contains at least 3 decimal</message> </field-validator> </field> </validators> \ No newline at end of file Modified: trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties 2010-11-17 15:03:14 UTC (rev 222) @@ -37,6 +37,7 @@ coser.business.control.error.duplicatedLine= coser.business.control.error.minObservationCount= coser.business.control.error.minObservationCountDetail= +coser.business.control.error.noCatchNumberWithWeight= coser.business.control.noerrorfound=No error found coser.business.control.step.observation= coser.business.control.step.xworks= @@ -50,10 +51,10 @@ coser.config.reference.typeEspeces.description= coser.config.validator.directory.description= lat\ attribute\ is\ not\ a\ valid\ double= -lat\ must\ contains\ at\ least\ 5\ decimal= +lat\ must\ contains\ at\ least\ 3\ decimal= length\ attribute\ is\ not\ a\ valid\ double= long\ attribute\ is\ not\ a\ valid\ double= -long\ must\ contains\ at\ least\ 5\ decimal= +long\ must\ contains\ at\ least\ 3\ decimal= number\ attribute\ is\ not\ a\ valid\ double= sweptSurface\ attribute\ is\ not\ a\ valid\ double= year\ is\ not\ valid= Modified: trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties 2010-11-17 15:03:14 UTC (rev 222) @@ -37,6 +37,7 @@ coser.business.control.error.duplicatedLine=Ligne en doublon coser.business.control.error.minObservationCount=Nombre minimal d'observation non atteint coser.business.control.error.minObservationCountDetail=Nombre minimal d'observation non atteint (%s) \: %.2f +coser.business.control.error.noCatchNumberWithWeight=Poids sp\u00E9cifi\u00E9 sans captures coser.business.control.noerrorfound=Aucune erreur d\u00E9tect\u00E9e coser.business.control.step.observation=V\u00E9rification du nombre d'observation (%d%%) coser.business.control.step.xworks=Validation par lignes (%d%%) @@ -50,10 +51,10 @@ coser.config.reference.typeEspeces.description=Emplacement du fichier de code type des esp\u00E8ces coser.config.validator.directory.description=Emplacement des fichiers de validations lat\ attribute\ is\ not\ a\ valid\ double= -lat\ must\ contains\ at\ least\ 5\ decimal= +lat\ must\ contains\ at\ least\ 3\ decimal= length\ attribute\ is\ not\ a\ valid\ double= long\ attribute\ is\ not\ a\ valid\ double= -long\ must\ contains\ at\ least\ 5\ decimal= +long\ must\ contains\ at\ least\ 3\ decimal= number\ attribute\ is\ not\ a\ valid\ double= sweptSurface\ attribute\ is\ not\ a\ valid\ double= year\ is\ not\ valid= Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ValidationServiceTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/ValidationServiceTest.java 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ValidationServiceTest.java 2010-11-17 15:03:14 UTC (rev 222) @@ -64,12 +64,12 @@ Catch myCatch = new Catch(); myCatch.setData(new String[]{"1", "","","","","",""}); - List<ValidationError> errors = validationService.validate(myCatch); + List<ValidationError> errors = validationService.validate(myCatch, Category.CATCH); Assert.assertNotNull(errors); Assert.assertEquals(3, errors.size()); myCatch.setData(new String[]{"1", "Toto","","","","999",""}); - errors = validationService.validate(myCatch); + errors = validationService.validate(myCatch, Category.CATCH); Assert.assertNotNull(errors); Assert.assertEquals(2, errors.size()); } @@ -81,7 +81,7 @@ public void testDoubleValidation() { Catch myCatch = new Catch(); myCatch.setData(new String[]{"1", "Test survey","1999","Test trait","Test sp","NA","12"}); - List<ValidationError> errors = validationService.validate(myCatch); + List<ValidationError> errors = validationService.validate(myCatch, Category.CATCH); log.warn(errors); Assert.assertTrue(errors.isEmpty()); } @@ -93,11 +93,11 @@ public void test5DecimalValidation() { Haul haulBean = new Haul(); haulBean.setData(new String[]{"1", "COSER_TEST","2010","TRAIT3","10","STR3","0.06","43.89","1.73","115.00"}); - List<ValidationError> errors = validationService.validate(haulBean); + List<ValidationError> errors = validationService.validate(haulBean, Category.HAUL); Assert.assertEquals(3, errors.size()); haulBean.setData(new String[]{"1","COSER_TEST","2010","TRAIT3","10","STR3","0.06000","43.89000","1.73234","115.00"}); - errors = validationService.validate(haulBean); + errors = validationService.validate(haulBean, Category.HAUL); Assert.assertTrue(errors.isEmpty()); } Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-11-17 15:03:14 UTC (rev 222) @@ -309,7 +309,7 @@ public void checkData(final ControlView view) { final ValidationService validationService = view.getContextValue(ValidationService.class); final Project project = view.getContextValue(Project.class); - final Category category = (Category)view.getCategoryComboBox().getSelectedItem(); + //final Category category = (Category)view.getCategoryComboBox().getSelectedItem(); final ControlProgressBar progressBar = view.getCheckProgressBar(); SwingWorker<List<ValidationError>, Void> task = new SwingWorker<List<ValidationError>, Void>() { @@ -319,7 +319,7 @@ @Override public List<ValidationError> doInBackground() { - List<ValidationError> validationErrors = validationService.validateCategory(project.getControl(), category, progressBar); + List<ValidationError> validationErrors = validationService.validateData(project.getControl(), progressBar); return validationErrors; } @@ -430,8 +430,13 @@ // 2 = validation group (middle level) // 3 = validation error (last level) - if (pathWay.length == 3) { - ValidationError error = (ValidationError)pathWay[2]; + if (pathWay.length == 4 && pathWay[1] instanceof Category) { + Category category = (Category)pathWay[1]; + + // swap category + view.getCategoryComboBoxModel().setSelectedItem(category); + + ValidationError error = (ValidationError)pathWay[3]; String errorLineNumber = error.getLineNumber(); // peut être null, si l'erreur ne porte pas sur un bean en particulier if (errorLineNumber != null) { @@ -465,30 +470,37 @@ Object[] pathWay = selectedError.getPath(); // 2 = validation group (middle level) - if (pathWay.length == 2) { - final GlobalValidationGroup validationGroup = (GlobalValidationGroup)pathWay[1]; - JPopupMenu popupMenu = new JPopupMenu(_("coser.ui.control.globalErrorMenuLabel")); - JMenuItem replaceMenu = new JMenuItem(_("coser.ui.control.globalErrorMenuSelectAll")); - replaceMenu.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectAllErrorGroupLines(controlView, validationGroup); - } - }); - popupMenu.add(replaceMenu); - popupMenu.show(controlView.getValidationGlobalErrorsTable(), event.getX(), event.getY()); + if (pathWay.length == 3) { + if (pathWay[1] instanceof Category) { + final Category category = (Category)pathWay[1]; + final GlobalValidationGroup validationGroup = (GlobalValidationGroup)pathWay[2]; + JPopupMenu popupMenu = new JPopupMenu(_("coser.ui.control.globalErrorMenuLabel")); + JMenuItem replaceMenu = new JMenuItem(_("coser.ui.control.globalErrorMenuSelectAll")); + replaceMenu.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + selectAllErrorGroupLines(controlView, category, validationGroup); + } + }); + popupMenu.add(replaceMenu); + popupMenu.show(controlView.getValidationGlobalErrorsTable(), event.getX(), event.getY()); + } } } } } /** - * Selectionne toutes les lignes associés au erreur d'un group d'erreur. + * Selectionne toutes les lignes associés au erreur d'un groupe d'erreur. * * @param controlView controlView * @param validationGroup validationGroup */ - protected void selectAllErrorGroupLines(ControlView controlView, GlobalValidationGroup validationGroup) { + protected void selectAllErrorGroupLines(ControlView controlView, Category category, GlobalValidationGroup validationGroup) { + // swap category + controlView.getCategoryComboBoxModel().setSelectedItem(category); + + // select all lines GlobalValidationModel model = controlView.getGlobalValidationModel(); controlView.getControlDataTableSelectionModel().clearSelection(); int childCount = model.getChildCount(validationGroup); Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java 2010-11-17 15:03:14 UTC (rev 222) @@ -33,6 +33,7 @@ import javax.swing.tree.DefaultTreeCellRenderer; import jaxx.runtime.validator.swing.SwingValidatorUtil; +import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.CoserConstants.ValidationLevel; import fr.ifremer.coser.control.ValidationError; @@ -73,7 +74,13 @@ ImageIcon icon = null; String text = null; - if (value instanceof GlobalValidationGroup) { + if (value instanceof String) { + text = _((String)value); + } + else if (value instanceof Category) { + text = _(((Category)value).getTranslationKey()); + } + else if (value instanceof GlobalValidationGroup) { GlobalValidationGroup validationErrorGroup = (GlobalValidationGroup)value; ValidationLevel level = validationErrorGroup.getValidationLevel(); switch (level) { Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationGroup.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationGroup.java 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationGroup.java 2010-11-17 15:03:14 UTC (rev 222) @@ -23,6 +23,7 @@ package fr.ifremer.coser.ui.control; +import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.CoserConstants.ValidationLevel; /** @@ -36,36 +37,36 @@ */ public class GlobalValidationGroup implements Comparable<GlobalValidationGroup> { - protected ValidationLevel validationLevel; + protected final Category category; + + protected final ValidationLevel validationLevel; - protected String message; + protected final String message; /** + * @param category * @param validationLevel * @param message */ - public GlobalValidationGroup(ValidationLevel validationLevel, String message) { + public GlobalValidationGroup(Category category, ValidationLevel validationLevel, String message) { super(); + this.category = category; this.validationLevel = validationLevel; this.message = message; } + public Category getCategory() { + return category; + } + public ValidationLevel getValidationLevel() { return validationLevel; } - public void setValidationLevel(ValidationLevel validationLevel) { - this.validationLevel = validationLevel; - } - public String getMessage() { return message; } - public void setMessage(String message) { - this.message = message; - } - /* * @see java.lang.Comparable#compareTo(java.lang.Object) */ @@ -82,6 +83,7 @@ public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((category == null) ? 0 : category.hashCode()); result = prime * result + ((message == null) ? 0 : message.hashCode()); result = prime * result + ((validationLevel == null) ? 0 : validationLevel.hashCode()); return result; @@ -109,6 +111,9 @@ if (validationLevel != other.validationLevel) { return false; } + if (category != other.category) { + return false; + } return true; } } Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java 2010-11-17 15:03:14 UTC (rev 222) @@ -24,17 +24,20 @@ package fr.ifremer.coser.ui.control; import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.n_; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; -import java.util.SortedMap; -import java.util.TreeMap; import org.jdesktop.swingx.treetable.AbstractTreeTableModel; +import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.CoserConstants.ValidationLevel; import fr.ifremer.coser.control.ValidationError; @@ -52,8 +55,9 @@ /** serialVersionUID. */ private static final long serialVersionUID = -32286733264427664L; - protected List<GlobalValidationGroup> validationErrorsGroups; - protected SortedMap<GlobalValidationGroup, List<ValidationError>> validationErrorsChilds; + protected List<Object> validationErrorCategory; + protected Map<Object, List<GlobalValidationGroup>> validationCategoryChild; + protected Map<GlobalValidationGroup, List<ValidationError>> validationErrorsChilds; protected Set<Object> checkedValidationErrors; public GlobalValidationModel() { @@ -72,23 +76,53 @@ */ protected void getValidationErrorAsMaps(List<ValidationError> validationErrors) { - validationErrorsChilds = new TreeMap<GlobalValidationGroup, List<ValidationError>>(); - + validationCategoryChild = new HashMap<Object, List<GlobalValidationGroup>>(); + validationErrorsChilds = new HashMap<GlobalValidationGroup, List<ValidationError>>(); + for (ValidationError validationError : validationErrors) { - GlobalValidationGroup group = new GlobalValidationGroup(validationError.getLevel(), validationError.getMessage()); + + Object category = validationError.getCategory() == null ? + n_("coser.ui.control.error.allCategories") : validationError.getCategory(); + List<GlobalValidationGroup> errorGroup = validationCategoryChild.get(category); + if (errorGroup == null) { + errorGroup = new ArrayList<GlobalValidationGroup>(); + validationCategoryChild.put(category, errorGroup); + } + GlobalValidationGroup group = new GlobalValidationGroup(validationError.getCategory(), validationError.getLevel(), validationError.getMessage()); + List<ValidationError> childErrors = validationErrorsChilds.get(group); if (childErrors == null) { childErrors = new ArrayList<ValidationError>(); + validationErrorsChilds.put(group, childErrors); + errorGroup.add(group); } childErrors.add(validationError); - validationErrorsChilds.put(group, childErrors); } - validationErrorsGroups = new ArrayList<GlobalValidationGroup>(validationErrorsChilds.keySet()); - Collections.sort(validationErrorsGroups); + validationErrorCategory = new ArrayList<Object>(validationCategoryChild.keySet()); + Collections.sort(validationErrorCategory, new Comparator<Object>() { + @Override + public int compare(Object o1, Object o2) { + int result = -1; + if (o1 instanceof String) { + if (o2 instanceof String) { + result = ((String)o1).compareTo((String)o2); + } + } + else if (o1 instanceof Category) { + if (o2 instanceof Category) { + result = ((Category)o1).compareTo((Category)o2); + } + } + return result; + } + }); + for (List<GlobalValidationGroup> groups : validationCategoryChild.values()) { + Collections.sort(groups); + } checkedValidationErrors = new HashSet<Object>(); } @@ -161,8 +195,11 @@ Object result = null; if (parent == getRoot()) { - result = validationErrorsGroups.get(index); + result = validationErrorCategory.get(index); } + else if (parent instanceof String || parent instanceof Category) { + result = validationCategoryChild.get(parent).get(index); + } else if (parent instanceof GlobalValidationGroup) { List<ValidationError> childError = validationErrorsChilds.get(parent); result = childError.get(index); @@ -179,10 +216,13 @@ int result = 0; if (parent == getRoot()) { - if (validationErrorsGroups != null) { - result = validationErrorsGroups.size(); + if (validationErrorCategory != null) { + result = validationErrorCategory.size(); } } + else if (parent instanceof String || parent instanceof Category) { + result = validationCategoryChild.get(parent).size(); + } else if (parent instanceof GlobalValidationGroup) { List<ValidationError> childError = validationErrorsChilds.get(parent); result = childError.size(); @@ -199,8 +239,11 @@ int result = -1; if (parent == getRoot()) { - result = validationErrorsGroups.indexOf(child); + result = validationErrorCategory.indexOf(child); } + else if (parent instanceof String || parent instanceof Category) { + result = validationCategoryChild.get(parent).indexOf(child); + } else if (parent instanceof GlobalValidationGroup) { List<ValidationError> childError = validationErrorsChilds.get(parent); result = childError.indexOf(child); @@ -230,7 +273,7 @@ } // recursive check of sub errors - if (node instanceof GlobalValidationGroup) { + if (node instanceof String || node instanceof GlobalValidationGroup) { int childCount = getChildCount(node); for (int i = 0 ; i < childCount; ++i) { Object child = getChild(node, i); Modified: trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties =================================================================== --- trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties 2010-11-17 15:03:14 UTC (rev 222) @@ -29,6 +29,7 @@ coser.ui.control.dataMenuReplace=Replace in %s for selection coser.ui.control.dataMenuReplaceAll=Replace in %s in all data coser.ui.control.deleteLine=Delete line +coser.ui.control.error.allCategories= coser.ui.control.global.done=\u2026 coser.ui.control.global.message=Message coser.ui.control.globalErrorMenuLabel=Error menu Modified: trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties =================================================================== --- trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties 2010-11-17 15:00:58 UTC (rev 221) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties 2010-11-17 15:03:14 UTC (rev 222) @@ -29,6 +29,7 @@ coser.ui.control.dataMenuReplace=Remplacer dans %s pour la s\u00E9lection coser.ui.control.dataMenuReplaceAll=Remplacer dans %s pour toutes les lignes coser.ui.control.deleteLine=Supprimer la ligne +coser.ui.control.error.allCategories=Toutes les cat\u00E9gories coser.ui.control.global.done=\u2026 coser.ui.control.global.message=Message coser.ui.control.globalErrorMenuLabel=Menu des erreurs