- Timestamp:
- 2018-06-17T14:14:33+02:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r13925 r13940 16 16 import java.util.List; 17 17 import java.util.Set; 18 import java.util.concurrent.atomic.AtomicBoolean; 18 19 19 20 import javax.swing.AbstractAction; … … 207 208 * Fix selected errors 208 209 */ 209 @SuppressWarnings("unchecked")210 210 private void fixErrors() { 211 211 TreePath[] selectionPaths = tree.getSelectionPaths(); … … 218 218 for (TreePath path : selectionPaths) { 219 219 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 220 if (node == null) { 221 continue; 222 } 223 224 Enumeration<TreeNode> children = node.breadthFirstEnumeration(); 225 while (children.hasMoreElements()) { 226 DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); 227 if (processedNodes.contains(childNode)) { 228 continue; 229 } 230 231 processedNodes.add(childNode); 232 Object nodeInfo = childNode.getUserObject(); 233 if (nodeInfo instanceof TestError) { 234 errorsToFix.add((TestError) nodeInfo); 235 } 220 if (node != null) { 221 ValidatorTreePanel.visitTestErrors(node, errorsToFix::add, processedNodes); 236 222 } 237 223 } 238 224 239 225 // run fix task asynchronously 240 // 241 FixTask fixTask = new FixTask(errorsToFix); 242 MainApplication.worker.submit(fixTask); 226 MainApplication.worker.submit(new FixTask(errorsToFix)); 243 227 } 244 228 … … 246 230 * Set selected errors to ignore state 247 231 */ 248 @SuppressWarnings("unchecked")249 232 private void ignoreErrors() { 250 233 int asked = JOptionPane.DEFAULT_OPTION; 251 boolean changed = false;234 AtomicBoolean changed = new AtomicBoolean(); 252 235 TreePath[] selectionPaths = tree.getSelectionPaths(); 253 236 if (selectionPaths == null) … … 272 255 } 273 256 if (asked == JOptionPane.YES_NO_OPTION) { 274 Enumeration<TreeNode> children = node.breadthFirstEnumeration(); 275 while (children.hasMoreElements()) { 276 DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); 277 if (processedNodes.contains(childNode)) { 278 continue; 279 } 280 281 processedNodes.add(childNode); 282 Object nodeInfo = childNode.getUserObject(); 283 if (nodeInfo instanceof TestError) { 284 TestError err = (TestError) nodeInfo; 285 err.setIgnored(true); 286 changed = true; 287 state.add(node.getDepth() == 1 ? err.getIgnoreSubGroup() : err.getIgnoreGroup()); 288 } 289 } 257 ValidatorTreePanel.visitTestErrors(node, err -> { 258 err.setIgnored(true); 259 changed.set(true); 260 state.add(node.getDepth() == 1 ? err.getIgnoreSubGroup() : err.getIgnoreGroup()); 261 }, processedNodes); 290 262 for (String s : state) { 291 263 OsmValidator.addIgnoredError(s); … … 297 269 } 298 270 299 Enumeration<TreeNode> children = node.breadthFirstEnumeration(); 300 while (children.hasMoreElements()) { 301 DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); 302 if (processedNodes.contains(childNode)) { 303 continue; 304 } 305 306 processedNodes.add(childNode); 307 Object nodeInfo = childNode.getUserObject(); 308 if (nodeInfo instanceof TestError) { 309 TestError error = (TestError) nodeInfo; 310 String state = error.getIgnoreState(); 311 if (state != null) { 312 OsmValidator.addIgnoredError(state); 313 } 314 changed = true; 315 error.setIgnored(true); 316 } 317 } 318 } 319 if (changed) { 271 ValidatorTreePanel.visitTestErrors(node, error -> { 272 String state = error.getIgnoreState(); 273 if (state != null) { 274 OsmValidator.addIgnoredError(state); 275 } 276 changed.set(true); 277 error.setIgnored(true); 278 }, processedNodes); 279 } 280 if (changed.get()) { 320 281 tree.resetErrors(); 321 282 OsmValidator.saveIgnoredErrors(); … … 329 290 @SuppressWarnings("unchecked") 330 291 private void setSelectedItems() { 331 if (tree == null) 292 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 293 if (tree == null || ds == null) 332 294 return; 333 334 Collection<OsmPrimitive> sel = new HashSet<>(40);335 295 336 296 TreePath[] selectedPaths = tree.getSelectionPaths(); … … 338 298 return; 339 299 300 Collection<OsmPrimitive> sel = new HashSet<>(40); 340 301 for (TreePath path : selectedPaths) { 341 302 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); … … 352 313 } 353 314 } 354 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 355 if (ds != null) { 356 ds.setSelected(sel); 357 } 315 ds.setSelected(sel); 358 316 } 359 317 … … 368 326 * @return whether the selected elements has any fix 369 327 */ 370 @SuppressWarnings("unchecked")371 328 private boolean setSelection(Collection<OsmPrimitive> sel, boolean addSelected) { 372 boolean hasFixes = false;329 AtomicBoolean hasFixes = new AtomicBoolean(); 373 330 374 331 DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); 375 332 if (lastSelectedNode != null && !lastSelectedNode.equals(node)) { 376 Enumeration<TreeNode> children = lastSelectedNode.breadthFirstEnumeration(); 377 while (children.hasMoreElements()) { 378 DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); 379 Object nodeInfo = childNode.getUserObject(); 380 if (nodeInfo instanceof TestError) { 381 TestError error = (TestError) nodeInfo; 382 error.setSelected(false); 383 } 384 } 333 ValidatorTreePanel.visitTestErrors(lastSelectedNode, error -> error.setSelected(false)); 385 334 } 386 335 387 336 lastSelectedNode = node; 388 if (node == null) 389 return hasFixes; 390 391 Enumeration<TreeNode> children = node.breadthFirstEnumeration(); 392 while (children.hasMoreElements()) { 393 DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); 394 Object nodeInfo = childNode.getUserObject(); 395 if (nodeInfo instanceof TestError) { 396 TestError error = (TestError) nodeInfo; 337 if (node != null) { 338 ValidatorTreePanel.visitTestErrors(node, error -> { 397 339 error.setSelected(true); 398 340 399 hasFixes = hasFixes || error.isFixable();341 hasFixes.set(hasFixes.get() || error.isFixable()); 400 342 if (addSelected) { 401 343 error.getPrimitives().stream() … … 403 345 .forEach(sel::add); 404 346 } 405 } 406 }407 selectButton.setEnabled(true);408 if (ignoreButton != null) {409 ignoreButton.setEnabled(true);410 } 411 412 return hasFixes ;347 }); 348 selectButton.setEnabled(true); 349 if (ignoreButton != null) { 350 ignoreButton.setEnabled(true); 351 } 352 } 353 354 return hasFixes.get(); 413 355 } 414 356 -
trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
r13434 r13940 14 14 import java.util.Map; 15 15 import java.util.Set; 16 import java.util.function.Consumer; 16 17 import java.util.function.Predicate; 17 18 … … 388 389 * Expands complete tree 389 390 */ 390 @SuppressWarnings("unchecked")391 391 public void expandAll() { 392 DefaultMutableTreeNode root = getRoot(); 393 394 int row = 0; 395 Enumeration<TreeNode> children = root.breadthFirstEnumeration(); 396 while (children.hasMoreElements()) { 397 children.nextElement(); 398 expandRow(row++); 399 } 392 visitTreeNodes(getRoot(), x -> expandPath(new TreePath(x.getPath()))); 400 393 } 401 394 … … 423 416 } 424 417 418 /** 419 * Visitor call for all tree nodes children of root, in breadth-first order. 420 * @param root Root node 421 * @param visitor Visitor 422 * @since 13940 423 */ 424 public static void visitTreeNodes(DefaultMutableTreeNode root, Consumer<DefaultMutableTreeNode> visitor) { 425 @SuppressWarnings("unchecked") 426 Enumeration<TreeNode> errorMessages = root.breadthFirstEnumeration(); 427 while (errorMessages.hasMoreElements()) { 428 visitor.accept(((DefaultMutableTreeNode) errorMessages.nextElement())); 429 } 430 } 431 432 /** 433 * Visitor call for all {@link TestError} nodes children of root, in breadth-first order. 434 * @param root Root node 435 * @param visitor Visitor 436 * @since 13940 437 */ 438 public static void visitTestErrors(DefaultMutableTreeNode root, Consumer<TestError> visitor) { 439 visitTestErrors(root, visitor, null); 440 } 441 442 /** 443 * Visitor call for all {@link TestError} nodes children of root, in breadth-first order. 444 * @param root Root node 445 * @param visitor Visitor 446 * @param processedNodes Set of already visited nodes (optional) 447 * @since 13940 448 */ 449 public static void visitTestErrors(DefaultMutableTreeNode root, Consumer<TestError> visitor, 450 Set<DefaultMutableTreeNode> processedNodes) { 451 visitTreeNodes(root, n -> { 452 if (processedNodes == null || !processedNodes.contains(n)) { 453 if (processedNodes != null) { 454 processedNodes.add(n); 455 } 456 Object o = n.getUserObject(); 457 if (o instanceof TestError) { 458 visitor.accept((TestError) o); 459 } 460 } 461 }); 462 } 463 425 464 @Override public void primitivesRemoved(PrimitivesRemovedEvent event) { 426 465 // Remove purged primitives (fix #8639) -
trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java
r12823 r13940 7 7 import java.io.File; 8 8 import java.util.Collections; 9 import java.util.Enumeration;10 9 import java.util.List; 11 10 … … 13 12 import javax.swing.Icon; 14 13 import javax.swing.tree.DefaultMutableTreeNode; 15 import javax.swing.tree.TreeNode;16 14 17 15 import org.openstreetmap.josm.actions.RenameLayerAction; … … 26 24 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 27 25 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 26 import org.openstreetmap.josm.gui.dialogs.validator.ValidatorTreePanel; 28 27 import org.openstreetmap.josm.gui.io.importexport.ValidatorErrorExporter; 29 28 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; … … 68 67 * Draw nodes last to overlap the ways they belong to. 69 68 */ 70 @SuppressWarnings("unchecked")71 69 @Override 72 70 public void paint(final Graphics2D g, final MapView mv, Bounds bounds) { … … 79 77 DefaultMutableTreeNode severity = (DefaultMutableTreeNode) root.getLastChild(); 80 78 while (severity != null) { 81 Enumeration<TreeNode> errorMessages = severity.breadthFirstEnumeration(); 82 while (errorMessages.hasMoreElements()) { 83 Object tn = ((DefaultMutableTreeNode) errorMessages.nextElement()).getUserObject(); 84 if (tn instanceof TestError) { 85 paintVisitor.visit((TestError) tn); 86 } 87 } 79 ValidatorTreePanel.visitTestErrors(severity, paintVisitor::visit); 88 80 89 81 // Severities in inverse order
Note:
See TracChangeset
for help on using the changeset viewer.