- Timestamp:
- 2019-03-09T14:58:23+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
r14856 r14857 8 8 import java.util.ArrayList; 9 9 import java.util.Collection; 10 import java.util.Collections;11 10 import java.util.Enumeration; 12 11 import java.util.HashSet; … … 72 71 protected DefaultTreeModel valTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); 73 72 74 /** The list of errors shown in the tree 75 private transient List<TestError> errors = new ArrayList<>();73 /** The list of errors shown in the tree, normally identical to field validationErrors in current edit layer*/ 74 private transient List<TestError> errors; 76 75 77 76 /** … … 91 90 */ 92 91 public ValidatorTreePanel(List<TestError> errors) { 92 setErrorList(errors); 93 93 ToolTipManager.sharedInstance().registerComponent(this); 94 94 this.setModel(valTreeModel); … … 99 99 this.setCellRenderer(new ValidatorTreeRenderer()); 100 100 this.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); 101 setErrorList(errors);102 101 for (KeyListener keyListener : getKeyListeners()) { 103 102 // Fix #3596 - Remove default keyListener to avoid conflicts with JOSM commands … … 159 158 return; 160 159 } 161 // Sort validation errors - #8517162 sortErrors(errors);163 160 164 161 // Remember first selected tree row … … 264 261 } 265 262 263 // add the matching errors to the current node 266 264 errors.stream().map(DefaultMutableTreeNode::new).forEach(messageNode::add); 267 265 }); … … 283 281 284 282 /** 285 * Sort list or errors in place. 286 * @param errors error list to be sorted 287 */ 288 static void sortErrors(List<TestError> errors) { 283 * Sort list of errors in place (#8517). 284 */ 285 void sortErrors() { 286 if (errors.isEmpty()) 287 return; 289 288 // Calculate the string to sort only once for each element 290 // Avoids to call TestError.compare() which costly289 // Avoids to call TestError.compare() which is costly 291 290 List<Pair<String, TestError>> toSort = new ArrayList<>(); 292 291 for (int i = 0; i < errors.size(); i++) { … … 325 324 */ 326 325 public final void setErrorList(List<TestError> errors) { 327 this.errors = errors; 326 this.errors = errors != null ? errors : new ArrayList<>(); 327 sortErrors(); 328 328 if (isVisible()) { 329 329 buildTree(); … … 336 336 */ 337 337 public void setErrors(List<TestError> newerrors) { 338 if (errors == null) 339 return; 340 clearErrors(); 338 errors.clear(); 341 339 for (TestError error : newerrors) { 342 340 if (!error.isIgnored()) { … … 344 342 } 345 343 } 344 sortErrors(); 346 345 if (isVisible()) { 347 346 buildTree(); … … 354 353 */ 355 354 public List<TestError> getErrors() { 356 return errors != null ? errors : Collections.<TestError>emptyList();355 return errors; 357 356 } 358 357 … … 436 435 } 437 436 438 private void clearErrors() {439 if (errors != null) {440 errors.clear();441 }442 }443 444 437 @Override 445 438 public void destroy() { 446 439 DatasetEventManager.getInstance().removeDatasetListener(this); 447 440 ToolTipManager.sharedInstance().unregisterComponent(this); 448 clearErrors();441 errors.clear(); 449 442 } 450 443 … … 546 539 */ 547 540 private boolean filterRemovedPrimitives() { 548 return errors != null && errors.removeIf(541 return errors.removeIf( 549 542 error -> error.getPrimitives().stream().anyMatch(p -> p.isDeleted() || p.getDataSet() == null)); 550 543 }
Note:
See TracChangeset
for help on using the changeset viewer.