| | 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 | if (!validateAction.isEnabled()) return; |
| | 350 | final int answer = ConditionalOptionPaneUtil.showOptionDialog( |
| | 351 | "rerun_validation_when_ignorelist_changed", |
| | 352 | MainApplication.getMainFrame(), |
| | 353 | "<hmtl><h3>" + tr("Should the validation be rerun?") + "</h3></html>", |
| | 354 | tr("Ignored error filter changed"), |
| | 355 | JOptionPane.YES_NO_CANCEL_OPTION, |
| | 356 | JOptionPane.QUESTION_MESSAGE, |
| | 357 | null, |
| | 358 | null); |
| | 359 | if (answer == JOptionPane.YES_OPTION) { |
| | 360 | validateAction.doValidate(true); |
| | 361 | } |
| | 362 | } |
| | 363 | |
| | 364 | /** |
| | 365 | * Reset the error list by deleting ignorederrors |
| | 366 | */ |
| | 367 | public void resetErrorList() { |
| | 368 | OsmValidator.saveIgnoredErrors(); |
| | 369 | File ignoredErrors = new File(OsmValidator.getValidatorDir(), "ignorederrors"); |
| | 370 | if (!ignoredErrors.isFile()) return; |
| | 371 | File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak"); |
| | 372 | try { |
| | 373 | Files.move(ignoredErrors.toPath(), ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | 374 | } catch (IOException e) { |
| | 375 | ignoredErrors.delete(); |
| | 376 | } |
| | 377 | OsmValidator.initialize(); |
| | 378 | rerunValidatorPrompt(); |
| | 379 | } |
| | 380 | |
| | 381 | /** |
| | 382 | * Restore the error list by copying ignorederrors.bak to ignorederrors |
| | 383 | */ |
| | 384 | public void restoreErrorList() { |
| | 385 | OsmValidator.saveIgnoredErrors(); |
| | 386 | File ignoredErrors = new File(OsmValidator.getValidatorDir(), "ignorederrors"); |
| | 387 | File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak"); |
| | 388 | if (!ignoredErrors.isFile() || !ignoredErrorsBak.isFile()) return; |
| | 389 | File ignoredErrorsBak2 = new File(ignoredErrorsBak.getAbsolutePath() + "2"); |
| | 390 | try { |
| | 391 | Files.move(ignoredErrors.toPath(), |
| | 392 | ignoredErrorsBak2.toPath(), |
| | 393 | StandardCopyOption.REPLACE_EXISTING); |
| | 394 | if (ignoredErrorsBak.isFile()) { |
| | 395 | Files.move(ignoredErrorsBak.toPath(), |
| | 396 | ignoredErrors.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | 397 | } |
| | 398 | Files.move(ignoredErrorsBak2.toPath(), |
| | 399 | ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | 400 | } catch (IOException e) { |
| | 401 | Logging.debug(e); |
| | 402 | } |
| | 403 | OsmValidator.initialize(); |
| | 404 | rerunValidatorPrompt(); |
| | 405 | } |
| | 406 | |
| | 407 | /** |