Changeset 17616 in josm for trunk/src/org
- Timestamp:
- 2021-03-21T13:56:15+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ValidateAction.java
r17188 r17616 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 import java.io.IOException;9 import java.util.ArrayList;10 8 import java.util.Collection; 11 import java.util.List;12 9 import java.util.Optional; 13 10 14 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;16 12 import org.openstreetmap.josm.data.validation.OsmValidator; 17 13 import org.openstreetmap.josm.data.validation.Test; 18 import org.openstreetmap.josm.data.validation. TestError;14 import org.openstreetmap.josm.data.validation.ValidationTask; 19 15 import org.openstreetmap.josm.data.validation.util.AggregatePrimitivesVisitor; 20 16 import org.openstreetmap.josm.gui.MainApplication; 21 17 import org.openstreetmap.josm.gui.MapFrame; 22 import org.openstreetmap.josm.gui.PleaseWaitRunnable;23 import org.openstreetmap.josm.gui.layer.ValidatorLayer;24 import org.openstreetmap.josm.gui.util.GuiHelper;25 import org.openstreetmap.josm.io.OsmTransferException;26 18 import org.openstreetmap.josm.tools.Shortcut; 27 import org.xml.sax.SAXException;28 19 29 20 /** … … 104 95 } 105 96 106 /**107 * Asynchronous task for running a collection of tests against a collection of primitives108 */109 static class ValidationTask extends PleaseWaitRunnable {110 private Collection<Test> tests;111 private final Collection<OsmPrimitive> validatedPrimitives;112 private final Collection<OsmPrimitive> formerValidatedPrimitives;113 private boolean canceled;114 private List<TestError> errors;115 116 /**117 * Constructs a new {@code ValidationTask}118 * @param tests the tests to run119 * @param validatedPrimitives the collection of primitives to validate.120 * @param formerValidatedPrimitives the last collection of primitives being validates. May be null.121 */122 ValidationTask(Collection<Test> tests, Collection<OsmPrimitive> validatedPrimitives,123 Collection<OsmPrimitive> formerValidatedPrimitives) {124 super(tr("Validating"), false /*don't ignore exceptions */);125 this.validatedPrimitives = validatedPrimitives;126 this.formerValidatedPrimitives = formerValidatedPrimitives;127 this.tests = tests;128 }129 130 @Override131 protected void cancel() {132 this.canceled = true;133 }134 135 @Override136 protected void finish() {137 if (canceled) return;138 139 // update GUI on Swing EDT140 //141 GuiHelper.runInEDT(() -> {142 MapFrame map = MainApplication.getMap();143 map.validatorDialog.unfurlDialog();144 map.validatorDialog.tree.setErrors(errors);145 //FIXME: nicer way to find / invalidate the corresponding error layer146 MainApplication.getLayerManager().getLayersOfType(ValidatorLayer.class).forEach(ValidatorLayer::invalidate);147 if (!errors.isEmpty()) {148 OsmValidator.initializeErrorLayer();149 }150 });151 }152 153 @Override154 protected void realRun() throws SAXException, IOException,155 OsmTransferException {156 if (tests == null || tests.isEmpty())157 return;158 errors = new ArrayList<>();159 getProgressMonitor().setTicksCount(tests.size() * validatedPrimitives.size());160 int testCounter = 0;161 for (Test test : tests) {162 if (canceled)163 return;164 testCounter++;165 getProgressMonitor().setCustomText(tr("Test {0}/{1}: Starting {2}", testCounter, tests.size(), test.getName()));166 test.setBeforeUpload(false);167 test.setPartialSelection(formerValidatedPrimitives != null);168 test.startTest(getProgressMonitor().createSubTaskMonitor(validatedPrimitives.size(), false));169 test.visit(validatedPrimitives);170 test.endTest();171 errors.addAll(test.getErrors());172 test.clear();173 }174 tests = null;175 if (Boolean.TRUE.equals(ValidatorPrefHelper.PREF_USE_IGNORE.get())) {176 getProgressMonitor().setCustomText("");177 getProgressMonitor().subTask(tr("Updating ignored errors ..."));178 for (TestError error : errors) {179 if (canceled) return;180 error.updateIgnored();181 }182 }183 }184 }185 97 }
Note:
See TracChangeset
for help on using the changeset viewer.