| | 364 | // Create validation info multimap |
| | 365 | Collection<TestError> errors = MainApplication.getMap().validatorDialog.tree.getErrors(); |
| | 366 | MultiMap<Long, String> valInfoMultiMap = new MultiMap<>(); |
| | 367 | if (!errors.isEmpty()) { |
| | 368 | for (TestError error : errors) { |
| | 369 | for (OsmPrimitive prim : error.getPrimitives()) { |
| | 370 | String valInfo = error.getSeverity() + ": (#" + error.getCode() + ") " |
| | 371 | + error.getMessage(); |
| | 372 | if (error.getDescription() != null) { |
| | 373 | valInfo += " | " + error.getDescription(); |
| | 374 | } |
| | 375 | valInfoMultiMap.put(prim.getUniqueId(), valInfo); |
| | 376 | } |
| | 377 | } |
| | 378 | } |
| | 379 | |
| | 401 | |
| | 402 | // Collect validation information |
| | 403 | Collection<String> valInfoCollection = null; |
| | 404 | if (!valInfoMultiMap.isEmpty()) { |
| | 405 | for (Long key : valInfoMultiMap.keySet()) { |
| | 406 | if (key.equals(osm.getUniqueId())) { |
| | 407 | valInfoCollection = valInfoMultiMap.getValues(key); |
| | 408 | } |
| | 409 | } |
| | 410 | } |
| | 411 | List<String> valInfoList = new ArrayList<>(); |
| | 412 | if (valInfoCollection != null) { |
| | 413 | List<String> valErrors = new ArrayList<>(); |
| | 414 | List<String> valWarnings = new ArrayList<>(); |
| | 415 | List<String> valOther = new ArrayList<>(); |
| | 416 | for (String valInfo : valInfoCollection) { |
| | 417 | if (valInfo.startsWith("Errors")) { |
| | 418 | valInfo = valInfo.replaceFirst("Errors", "Error"); |
| | 419 | valErrors.add(valInfo); |
| | 420 | } |
| | 421 | if (valInfo.startsWith("Warnings")) { |
| | 422 | valInfo = valInfo.replaceFirst("Warnings", "Warning"); |
| | 423 | valWarnings.add(valInfo); |
| | 424 | } |
| | 425 | if (valInfo.startsWith("Other")) { |
| | 426 | valOther.add(valInfo); |
| | 427 | } |
| | 428 | } |
| | 429 | if (!valErrors.isEmpty()) { |
| | 430 | List<String> valErrorsSorted = valErrors.stream() |
| | 431 | .sorted(Comparator.comparing((String e) -> e.split(" ",0)[2].toUpperCase())) |
| | 432 | .collect(Collectors.toCollection(ArrayList::new)); |
| | 433 | valInfoList.addAll(valErrorsSorted); |
| | 434 | } |
| | 435 | |
| | 436 | if (!valWarnings.isEmpty()) { |
| | 437 | List<String> valWarningsSorted = valWarnings.stream() |
| | 438 | .sorted(Comparator.comparing((String e) -> e.split(" ",0)[2].toUpperCase())) |
| | 439 | .collect(Collectors.toCollection(ArrayList::new)); |
| | 440 | valInfoList.addAll(valWarningsSorted); |
| | 441 | } |
| | 442 | |
| | 443 | if (!valOther.isEmpty()) { |
| | 444 | List<String> valOtherSorted = valOther.stream() |
| | 445 | .sorted(Comparator.comparing((String e) -> e.split(" ",0)[2].toUpperCase())) |
| | 446 | .collect(Collectors.toCollection(ArrayList::new)); |
| | 447 | valInfoList.addAll(valOtherSorted); |
| | 448 | } |
| | 449 | } |
| | 450 | |
| | 792 | * Builds labels with all necessary listeners for the info popup for the |
| | 793 | * given OsmPrimitive and corresponding validation information. |
| | 794 | * @author Milla Zagorski |
| | 795 | * @param osm The primitive to create the label for |
| | 796 | * @param valInfoList The list of validation results information |
| | 797 | * @return labels for validation info popup |
| | 798 | */ |
| | 799 | private JLabel popupBuildValidationLabels(OsmPrimitive osm, List<String> valInfoList) { |
| | 800 | final StringBuilder valText = new StringBuilder(32); |
| | 801 | |
| | 802 | if (valInfoList != null) { |
| | 803 | valText.append("Validation information:"); |
| | 804 | for (String info : valInfoList) { |
| | 805 | valText.append("<br> ").append(info); |
| | 806 | } |
| | 807 | |
| | 808 | JLabel l = new JLabel("<html>" + valText.toString() + "</html>", |
| | 809 | ImageProvider.get("layer", "validator_small"), JLabel.HORIZONTAL); |
| | 810 | l.setOpaque(true); |
| | 811 | popupSetLabelColors(l, osm); |
| | 812 | l.setFont(l.getFont().deriveFont(Font.PLAIN)); |
| | 813 | l.setVerticalTextPosition(JLabel.TOP); |
| | 814 | l.setHorizontalAlignment(JLabel.LEFT); |
| | 815 | l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
| | 816 | return l; |
| | 817 | } else { |
| | 818 | return null; |
| | 819 | } |
| | 820 | } |
| | 821 | |
| | 822 | /** |