Changeset 13940 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
- Timestamp:
- 2018-06-17T14:14:33+02:00 (6 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.