Ticket #17268: clear_ignored_errors_v9.patch
File clear_ignored_errors_v9.patch, 8.3 KB (added by , 5 years ago) |
---|
-
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(Config.getPref().getList(prefIgnoredErrors)); 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 Config.getPref().putList(prefIgnoredErrors, 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 = Config.getPref().getList(prefIgnoredErrors + ".bak"); 273 backupErrorList(); 274 Config.getPref().putList(prefIgnoredErrors, tlist); 275 OsmValidator.initialize(); 276 } 277 278 private static void backupErrorList() { 279 List<String> tlist = Config.getPref().getList(prefIgnoredErrors); 280 if (tlist.isEmpty()) tlist = null; 281 Config.getPref().putList(prefIgnoredErrors + ".bak", 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 Config.getPref().putList(prefIgnoredErrors, 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; 50 51 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 51 52 import org.openstreetmap.josm.gui.PopupMenuHandler; … … 85 86 private final SideButton fixButton; 86 87 /** The ignore button */ 87 88 private final SideButton ignoreButton; 89 /** The reset ignorelist button */ 90 private final SideButton resetignorelistButton; 88 91 /** The select button */ 89 92 private final SideButton selectButton; 90 93 /** The lookup button */ … … 174 177 }); 175 178 ignoreButton.setEnabled(false); 176 179 buttons.add(ignoreButton); 180 resetignorelistButton = new SideButton(new AbstractAction() { 181 /* Java integers initialize to "0" by default */ 182 int reset; 183 { 184 toggle(); 185 } 186 187 public void toggle() { 188 this.setEnabled(true); 189 if (!OsmValidator.getIgnoredErrors().isEmpty()) { 190 putValue(NAME, tr("Clear Ignore")); 191 putValue(SHORT_DESCRIPTION, tr("Clear ignore list")); 192 new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true); 193 reset = 1; 194 } else { 195 List<String> ignoredErrors = Config.getPref().getList(OsmValidator.prefIgnoredErrors + ".bak"); 196 if (!ignoredErrors.isEmpty()) { 197 putValue(NAME, tr("Restore Ignore")); 198 putValue(SHORT_DESCRIPTION, tr("Restore ignore list")); 199 new ImageProvider("copy").getResource().attachImageIcon(this, true); 200 reset = 2; 201 } else if (!OsmValidator.getIgnoredErrors().isEmpty()) { 202 putValue(NAME, tr("Save Ignore")); 203 putValue(SHORT_DESCRIPTION, tr("Save ignore list")); 204 new ImageProvider("save").getResource().attachImageIcon(this, true); 205 reset = 3; 206 } else { 207 putValue(NAME, tr("Ignore list modification")); 208 putValue(SHORT_DESCRIPTION, tr("Clear/Restore/Save the ignore list, depending upon various conditions")); 209 new ImageProvider("dialogs", "validator").getResource().attachImageIcon(this, true); 210 //this.setEnabled(false); // TODO enable when I figure out how to call from ignore 211 } 212 } 213 } 214 215 @Override 216 public void actionPerformed(ActionEvent e) { 217 if (reset == 1) { 218 OsmValidator.resetErrorList(); 219 } else if (reset == 2) { 220 OsmValidator.restoreErrorList(); 221 } else if (reset == 3 && !OsmValidator.getIgnoredErrors().isEmpty()) { 222 OsmValidator.saveIgnoredErrors(); 223 } else if (reset == 0) { 224 // Do nothing 225 } 226 if (reset == 1 || reset == 2) rerunValidatorPrompt(); 227 toggle(); 228 } 229 }); 230 buttons.add(resetignorelistButton); 177 231 } else { 178 232 ignoreButton = null; 233 resetignorelistButton = null; 179 234 } 235 180 236 createLayout(tree, true, buttons); 181 237 } 182 238 … … 285 341 } 286 342 287 343 /** 344 * Prompt to rerun the validator when the ignore list changes 345 */ 346 public void rerunValidatorPrompt() { 347 if (!validateAction.isEnabled()) return; 348 final int answer = ConditionalOptionPaneUtil.showOptionDialog( 349 "rerun_validation_when_ignorelist_changed", 350 MainApplication.getMainFrame(), 351 "<hmtl><h3>" + tr("Should the validation be rerun?") + "</h3></html>", 352 tr("Ignored error filter changed"), 353 JOptionPane.YES_NO_CANCEL_OPTION, 354 JOptionPane.QUESTION_MESSAGE, 355 null, 356 null); 357 if (answer == JOptionPane.YES_OPTION) { 358 validateAction.doValidate(true); 359 } 360 } 361 362 /** 288 363 * Sets the selection of the map to the current selected items. 289 364 */ 290 365 @SuppressWarnings("unchecked")