Ticket #17268: clear_ignored_errors_v14.patch
| File clear_ignored_errors_v14.patch, 10.6 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/data/preferences/sources/ValidatorPrefHelper.java
10 10 import java.util.Map; 11 11 12 12 import org.openstreetmap.josm.data.preferences.BooleanProperty; 13 import org.openstreetmap.josm.data.preferences.ListProperty; 13 14 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker; 14 15 15 16 /** … … 44 45 /** The preferences for ignored severity other */ 45 46 public static final BooleanProperty PREF_OTHER = new BooleanProperty(PREFIX + ".other", false); 46 47 48 /** The preferences key for the ignorelist */ 49 public static final ListProperty PREF_IGNORELIST = new ListProperty(PREFIX + ".ignorelist", new ArrayList<String>()); 50 51 /** The preferences key for the ignorelist backup */ 52 public static final ListProperty PREF_IGNORELIST_BACKUP = new ListProperty(PREFIX + ".ignorelist.bak", new ArrayList<String>()); 53 54 /** The preferences key for whether or not the ignorelist backup should be cleared on start */ 55 public static final BooleanProperty PREF_IGNORELIST_KEEP_BACKUP = new BooleanProperty(PREFIX + ".ignorelist.bak.keep", false); 47 56 /** 48 57 * The preferences key for enabling the permanent filtering 49 58 * of the displayed errors in the tree regarding the current selection -
src/org/openstreetmap/josm/data/validation/OsmValidator.java
7 7 import java.io.File; 8 8 import java.io.FileNotFoundException; 9 9 import java.io.IOException; 10 import java.io.PrintWriter;11 10 import java.nio.charset.StandardCharsets; 12 11 import java.nio.file.Files; 13 12 import java.nio.file.Path; … … 89 88 private static double griddetail; 90 89 91 90 private static final Collection<String> ignoredErrors = new TreeSet<>(); 91 /** 92 * The preference value for the validator's ignorederrors list 93 */ 94 public static final String prefIgnoredErrors = "validator.ignorederrors"; 92 95 93 96 /** 94 97 * All registered tests … … 204 207 private static void loadIgnoredErrors() { 205 208 ignoredErrors.clear(); 206 209 if (ValidatorPrefHelper.PREF_USE_IGNORE.get()) { 210 ignoredErrors.addAll(ValidatorPrefHelper.PREF_IGNORELIST.get()); 207 211 Path path = Paths.get(getValidatorDir()).resolve("ignorederrors"); 208 212 try { 209 213 if (path.toFile().exists()) { 210 214 try { 211 215 ignoredErrors.addAll(Files.readAllLines(path, StandardCharsets.UTF_8)); 216 saveIgnoredErrors(); 217 Files.deleteIfExists(path); 212 218 } catch (FileNotFoundException e) { 213 219 Logging.debug(Logging.getErrorMessage(e)); 214 220 } catch (IOException e) { … … 241 247 } 242 248 243 249 /** 250 * Get the list of all ignored errors 251 * @return The <code>Collection<String></code> of errors that are ignored 252 */ 253 public static Collection<String> getIgnoredErrors() { 254 return ignoredErrors; 255 } 256 257 /** 258 * Reset the error list by deleting ignorederrors 259 */ 260 public static void resetErrorList() { 261 saveIgnoredErrors(); 262 backupErrorList(); 263 ValidatorPrefHelper.PREF_IGNORELIST.put(null); 264 OsmValidator.initialize(); 265 } 266 267 /** 268 * Restore the error list by copying ignorederrors.bak to ignorederrors 269 */ 270 public static void restoreErrorList() { 271 saveIgnoredErrors(); 272 List<String> tlist = ValidatorPrefHelper.PREF_IGNORELIST_BACKUP.get(); 273 backupErrorList(); 274 ValidatorPrefHelper.PREF_IGNORELIST.put(tlist); 275 OsmValidator.initialize(); 276 } 277 278 private static void backupErrorList() { 279 List<String> tlist = ValidatorPrefHelper.PREF_IGNORELIST.get(); 280 if (tlist.isEmpty()) tlist = null; 281 ValidatorPrefHelper.PREF_IGNORELIST_BACKUP.put(tlist); 282 } 283 284 /** 244 285 * Saves the names of the ignored errors to a file 245 286 */ 246 287 public static void saveIgnoredErrors() { 247 try (PrintWriter out = new PrintWriter(new File(getValidatorDir(), "ignorederrors"), StandardCharsets.UTF_8.name())) { 248 for (String e : ignoredErrors) { 249 out.println(e); 250 } 251 } catch (IOException e) { 252 Logging.error(e); 253 } 288 List<String> list = new ArrayList<>(ignoredErrors); 289 Collections.sort(list); 290 ValidatorPrefHelper.PREF_IGNORELIST.put(list); 254 291 } 255 292 256 293 /** -
src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
46 46 import org.openstreetmap.josm.data.validation.OsmValidator; 47 47 import org.openstreetmap.josm.data.validation.TestError; 48 48 import org.openstreetmap.josm.data.validation.ValidatorVisitor; 49 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 49 50 import org.openstreetmap.josm.gui.MainApplication; 51 import org.openstreetmap.josm.gui.MapFrame; 50 52 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 51 53 import org.openstreetmap.josm.gui.PopupMenuHandler; 52 54 import org.openstreetmap.josm.gui.SideButton; … … 85 87 private final SideButton fixButton; 86 88 /** The ignore button */ 87 89 private final SideButton ignoreButton; 90 /** The reset ignorelist button */ 91 private final SideButton resetignorelistButton; 88 92 /** The select button */ 89 93 private final SideButton selectButton; 90 94 /** The lookup button */ … … 174 178 }); 175 179 ignoreButton.setEnabled(false); 176 180 buttons.add(ignoreButton); 181 182 final String clearHide; 183 if (!ValidatorPrefHelper.PREF_IGNORELIST_KEEP_BACKUP.get()) { 184 // Clear the backup ignore list 185 ValidatorPrefHelper.PREF_IGNORELIST_BACKUP.put(null); 186 clearHide = "Clear"; 187 } else { 188 clearHide = "Hide"; 189 } 190 resetignorelistButton = new SideButton(new AbstractAction() { 191 int reset; 192 { 193 toggle(); 194 } 195 196 public void toggle() { 197 this.setEnabled(true); 198 if (!OsmValidator.getIgnoredErrors().isEmpty()) { 199 putValue(NAME, tr(clearHide + " Ignore")); 200 putValue(SHORT_DESCRIPTION, tr(clearHide + " ignore list")); 201 new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true); 202 reset = 1; 203 } else { 204 List<String> ignoredErrors = ValidatorPrefHelper.PREF_IGNORELIST_BACKUP.get(); 205 if (!ignoredErrors.isEmpty()) { 206 putValue(NAME, tr("Restore Ignore")); 207 putValue(SHORT_DESCRIPTION, tr("Restore ignore list")); 208 new ImageProvider("copy").getResource().attachImageIcon(this, true); 209 reset = 2; 210 } else { 211 putValue(NAME, tr("Ignore list modification")); 212 putValue(SHORT_DESCRIPTION, tr("Hide/Clear/Restore the ignore list, depending upon various conditions")); 213 new ImageProvider("dialogs", "validator").getResource().attachImageIcon(this, true); 214 this.setEnabled(false); 215 } 216 } 217 } 218 219 @Override 220 public void actionPerformed(ActionEvent e) { 221 int doToggle = JOptionPane.NO_OPTION; 222 if (e != null) { 223 if (reset == 1 || reset == 2) doToggle = rerunValidatorPrompt(); 224 if (reset == 1 && (doToggle == JOptionPane.YES_OPTION || doToggle == JOptionPane.NO_OPTION)) { 225 OsmValidator.resetErrorList(); 226 } else if (reset == 2 && (doToggle == JOptionPane.YES_OPTION || doToggle == JOptionPane.NO_OPTION)) { 227 OsmValidator.restoreErrorList(); 228 } 229 } 230 if (doToggle == JOptionPane.YES_OPTION || doToggle == JOptionPane.NO_OPTION) toggle(); 231 } 232 }); 233 buttons.add(resetignorelistButton); 177 234 } else { 178 235 ignoreButton = null; 236 resetignorelistButton = null; 179 237 } 238 180 239 createLayout(tree, true, buttons); 181 240 } 182 241 … … 280 339 if (changed.get()) { 281 340 tree.resetErrors(); 282 341 OsmValidator.saveIgnoredErrors(); 342 if (resetignorelistButton != null) { 343 resetignorelistButton.getAction().actionPerformed(null); 344 } 283 345 invalidateValidatorLayers(); 284 346 } 285 347 } 286 348 287 349 /** 350 * Prompt to rerun the validator when the ignore list changes 351 * @return {@code JOptionPane.YES_OPTION}, {@code JOptionPane.NO_OPTION}, 352 * or {@code JOptionPane.CANCEL_OPTION} 353 */ 354 public int rerunValidatorPrompt() { 355 MapFrame map = MainApplication.getMap(); 356 List<TestError> errors = map.validatorDialog.tree.getErrors(); 357 if (!validateAction.isEnabled() || errors == null || errors.isEmpty()) return JOptionPane.NO_OPTION; 358 final int answer = ConditionalOptionPaneUtil.showOptionDialog( 359 "rerun_validation_when_ignorelist_changed", 360 MainApplication.getMainFrame(), 361 "<hmtl><h3>" + tr("Should the validation be rerun?") + "</h3></html>", 362 tr("Ignored error filter changed"), 363 JOptionPane.YES_NO_CANCEL_OPTION, 364 JOptionPane.QUESTION_MESSAGE, 365 null, 366 null); 367 if (answer == JOptionPane.YES_OPTION) { 368 validateAction.doValidate(true); 369 } 370 return answer; 371 } 372 373 /** 288 374 * Sets the selection of the map to the current selected items. 289 375 */ 290 @SuppressWarnings("unchecked")291 376 private void setSelectedItems() { 292 377 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 293 378 if (tree == null || ds == null)
