| 187 | |
| 188 | resetignorelistButton = new SideButton(new AbstractAction() { |
| 189 | int reset = 0; |
| 190 | { |
| 191 | toggle(); |
| 192 | } |
| 193 | |
| 194 | public void toggle() { |
| 195 | this.setEnabled(true); |
| 196 | if (!OsmValidator.getIgnoredErrors().isEmpty()) { |
| 197 | putValue(NAME, tr("Clear Ignore")); |
| 198 | putValue(SHORT_DESCRIPTION, tr("Clear ignore list")); |
| 199 | new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true); |
| 200 | reset = 1; |
| 201 | } else { |
| 202 | File ignoredErrors = new File(OsmValidator.getValidatorDir()); |
| 203 | ignoredErrors = new File(ignoredErrors.getAbsolutePath() + File.separator + "ignorederrors.bak"); |
| 204 | if (ignoredErrors.isFile()) { |
| 205 | putValue(NAME, tr("Restore Ignore")); |
| 206 | putValue(SHORT_DESCRIPTION, tr("Restore ignore list")); |
| 207 | new ImageProvider("copy").getResource().attachImageIcon(this, true); |
| 208 | reset = 2; |
| 209 | } else if (!OsmValidator.getIgnoredErrors().isEmpty()) { |
| 210 | putValue(NAME, tr("Save Ignore")); |
| 211 | putValue(SHORT_DESCRIPTION, tr("Save ignore list")); |
| 212 | new ImageProvider("save").getResource().attachImageIcon(this, true); |
| 213 | reset = 3; |
| 214 | } else { |
| 215 | putValue(NAME, tr("Ignore list modification")); |
| 216 | putValue(SHORT_DESCRIPTION, tr("Clear/Restore/Save the ignore list, depending upon various conditions")); |
| 217 | new ImageProvider("dialogs", "validator").getResource().attachImageIcon(this, true); |
| 218 | //this.setEnabled(false); // TODO enable when I figure out how to call from ignore |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void actionPerformed(ActionEvent e) { |
| 225 | if (reset == 1) { |
| 226 | resetErrorList(); |
| 227 | } else if (reset == 2) { |
| 228 | restoreErrorList(); |
| 229 | } else if (reset == 3 && !OsmValidator.getIgnoredErrors().isEmpty()) { |
| 230 | OsmValidator.saveIgnoredErrors(); |
| 231 | } else if (reset == 0) { |
| 232 | // Do nothing |
| 233 | } |
| 234 | toggle(); |
| 235 | } |
| 236 | }); |
| 237 | buttons.add(resetignorelistButton); |
| 346 | * Prompt to rerun the validator when the ignore list changes |
| 347 | */ |
| 348 | public void rerunValidatorPrompt() { |
| 349 | final int answer = ConditionalOptionPaneUtil.showOptionDialog( |
| 350 | "rerun_validation_when_ignorelist_changed", |
| 351 | MainApplication.getMainFrame(), |
| 352 | tr("Should the validation be rerun?"), |
| 353 | tr("ignorederrors list changed"), |
| 354 | JOptionPane.YES_NO_CANCEL_OPTION, |
| 355 | JOptionPane.QUESTION_MESSAGE, |
| 356 | null, |
| 357 | null); |
| 358 | if (answer == JOptionPane.YES_OPTION) { |
| 359 | validateAction.doValidate(true); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Reset the error list by deleting ignorederrors |
| 365 | */ |
| 366 | public void resetErrorList() { |
| 367 | OsmValidator.saveIgnoredErrors(); |
| 368 | File ignoredErrors = new File(OsmValidator.getValidatorDir(), "ignorederrors"); |
| 369 | if (!ignoredErrors.isFile()) return; |
| 370 | File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak"); |
| 371 | try { |
| 372 | Files.move(ignoredErrors.toPath(), ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| 373 | } catch (IOException e) { |
| 374 | ignoredErrors.delete(); |
| 375 | } |
| 376 | OsmValidator.initialize(); |
| 377 | rerunValidatorPrompt(); |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Restore the error list by copying ignorederrors.bak to ignorederrors |
| 382 | */ |
| 383 | public void restoreErrorList() { |
| 384 | OsmValidator.saveIgnoredErrors(); |
| 385 | File ignoredErrors = new File(OsmValidator.getValidatorDir(), "ignorederrors"); |
| 386 | File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak"); |
| 387 | if (!ignoredErrors.isFile() || !ignoredErrorsBak.isFile()) return; |
| 388 | File ignoredErrorsBak2 = new File(ignoredErrorsBak.getAbsolutePath() + "2"); |
| 389 | try { |
| 390 | Files.move(ignoredErrors.toPath(), |
| 391 | ignoredErrorsBak2.toPath(), |
| 392 | StandardCopyOption.REPLACE_EXISTING); |
| 393 | if (ignoredErrorsBak.isFile()) { |
| 394 | Files.move(ignoredErrorsBak.toPath(), |
| 395 | ignoredErrors.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| 396 | } |
| 397 | Files.move(ignoredErrorsBak2.toPath(), |
| 398 | ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| 399 | } catch (IOException e) { |
| 400 | Logging.debug(e); |
| 401 | } |
| 402 | OsmValidator.initialize(); |
| 403 | rerunValidatorPrompt(); |
| 404 | } |
| 405 | |
| 406 | /** |