source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java@ 14847

Last change on this file since 14847 was 14847, checked in by GerdP, 5 years ago

fix #17343 and #17344: Enable/Disable buttons in ValidatorDialog

  • Property svn:eol-style set to native
File size: 26.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.awt.event.MouseEvent;
9import java.io.IOException;
10import java.lang.reflect.InvocationTargetException;
11import java.util.ArrayList;
12import java.util.Collection;
13import java.util.Enumeration;
14import java.util.HashSet;
15import java.util.LinkedList;
16import java.util.List;
17import java.util.Set;
18import java.util.concurrent.atomic.AtomicBoolean;
19
20import javax.swing.AbstractAction;
21import javax.swing.Action;
22import javax.swing.JComponent;
23import javax.swing.JOptionPane;
24import javax.swing.JPopupMenu;
25import javax.swing.SwingUtilities;
26import javax.swing.event.TreeSelectionEvent;
27import javax.swing.event.TreeSelectionListener;
28import javax.swing.tree.DefaultMutableTreeNode;
29import javax.swing.tree.TreePath;
30
31import org.openstreetmap.josm.actions.AbstractSelectAction;
32import org.openstreetmap.josm.actions.AutoScaleAction;
33import org.openstreetmap.josm.actions.ValidateAction;
34import org.openstreetmap.josm.actions.relation.EditRelationAction;
35import org.openstreetmap.josm.command.Command;
36import org.openstreetmap.josm.command.SequenceCommand;
37import org.openstreetmap.josm.data.UndoRedoHandler;
38import org.openstreetmap.josm.data.osm.DataSelectionListener;
39import org.openstreetmap.josm.data.osm.DataSet;
40import org.openstreetmap.josm.data.osm.Node;
41import org.openstreetmap.josm.data.osm.OsmPrimitive;
42import org.openstreetmap.josm.data.osm.WaySegment;
43import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
44import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;
45import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
46import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
47import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
48import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
49import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
50import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
51import org.openstreetmap.josm.data.validation.OsmValidator;
52import org.openstreetmap.josm.data.validation.TestError;
53import org.openstreetmap.josm.data.validation.ValidatorVisitor;
54import org.openstreetmap.josm.gui.MainApplication;
55import org.openstreetmap.josm.gui.PleaseWaitRunnable;
56import org.openstreetmap.josm.gui.PopupMenuHandler;
57import org.openstreetmap.josm.gui.SideButton;
58import org.openstreetmap.josm.gui.dialogs.validator.ValidatorTreePanel;
59import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
60import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
61import org.openstreetmap.josm.gui.layer.OsmDataLayer;
62import org.openstreetmap.josm.gui.layer.ValidatorLayer;
63import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference;
64import org.openstreetmap.josm.gui.progress.ProgressMonitor;
65import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
66import org.openstreetmap.josm.io.OsmTransferException;
67import org.openstreetmap.josm.spi.preferences.Config;
68import org.openstreetmap.josm.tools.ImageProvider;
69import org.openstreetmap.josm.tools.InputMapUtils;
70import org.openstreetmap.josm.tools.JosmRuntimeException;
71import org.openstreetmap.josm.tools.Pair;
72import org.openstreetmap.josm.tools.Shortcut;
73import org.xml.sax.SAXException;
74
75/**
76 * A small tool dialog for displaying the current errors. The selection manager
77 * respects clicks into the selection list. Ctrl-click will remove entries from
78 * the list while single click will make the clicked entry the only selection.
79 *
80 * @author frsantos
81 */
82public class ValidatorDialog extends ToggleDialog
83 implements DataSelectionListener, ActiveLayerChangeListener, DataSetListenerAdapter.Listener {
84
85 /** The display tree */
86 public ValidatorTreePanel tree;
87
88 /** The validate action */
89 public static final ValidateAction validateAction = new ValidateAction();
90
91 /** The fix action */
92 private final transient Action fixAction;
93 /** The ignore action */
94 private final transient Action ignoreAction;
95 /** The ignore-list management action */
96 private final transient Action ignorelistManagementAction;
97 /** The select action */
98 private final transient Action selectAction;
99 /** The lookup action */
100 private final transient LookupAction lookupAction;
101
102 private final JPopupMenu popupMenu = new JPopupMenu();
103 private final transient PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu);
104 private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this);
105
106 /** Last selected element */
107 private DefaultMutableTreeNode lastSelectedNode;
108
109 /**
110 * Constructor
111 */
112 public ValidatorDialog() {
113 super(tr("Validation Results"), "validator", tr("Open the validation window."),
114 Shortcut.registerShortcut("subwindow:validator", tr("Toggle: {0}", tr("Validation Results")),
115 KeyEvent.VK_V, Shortcut.ALT_SHIFT), 150, false, ValidatorPreference.class);
116
117 popupMenuHandler.addAction(MainApplication.getMenu().autoScaleActions.get("problem"));
118 popupMenuHandler.addAction(new EditRelationAction());
119
120 tree = new ValidatorTreePanel();
121 tree.addMouseListener(new MouseEventHandler());
122 addTreeSelectionListener(new SelectionWatch());
123 InputMapUtils.unassignCtrlShiftUpDown(tree, JComponent.WHEN_FOCUSED);
124
125 List<SideButton> buttons = new LinkedList<>();
126
127 selectAction = new AbstractSelectAction() {
128 @Override
129 public void actionPerformed(ActionEvent e) {
130 setSelectedItems();
131 }
132 };
133 selectAction.setEnabled(false);
134 InputMapUtils.addEnterAction(tree, selectAction);
135 buttons.add(new SideButton(selectAction));
136
137 lookupAction = new LookupAction();
138 buttons.add(new SideButton(lookupAction));
139
140 buttons.add(new SideButton(validateAction));
141
142 fixAction = new AbstractAction() {
143 {
144 putValue(NAME, tr("Fix"));
145 putValue(SHORT_DESCRIPTION, tr("Fix the selected issue."));
146 new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true);
147 }
148 @Override
149 public void actionPerformed(ActionEvent e) {
150 fixErrors();
151 }
152 };
153 fixAction.setEnabled(false);
154 buttons.add(new SideButton(fixAction));
155
156 if (ValidatorPrefHelper.PREF_USE_IGNORE.get()) {
157 ignoreAction = new AbstractAction() {
158 {
159 putValue(NAME, tr("Ignore"));
160 putValue(SHORT_DESCRIPTION, tr("Ignore the selected issue next time."));
161 new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true);
162 }
163 @Override
164 public void actionPerformed(ActionEvent e) {
165 ignoreErrors();
166 }
167 };
168 ignoreAction.setEnabled(false);
169 buttons.add(new SideButton(ignoreAction));
170
171 ignorelistManagementAction = new IgnorelistManagementAction();
172 buttons.add(new SideButton(ignorelistManagementAction));
173 } else {
174 ignoreAction = null;
175 ignorelistManagementAction = null;
176 }
177
178 createLayout(tree, true, buttons);
179 }
180
181 /**
182 * The action to manage the ignore list.
183 */
184 static class IgnorelistManagementAction extends AbstractAction {
185 IgnorelistManagementAction() {
186 putValue(NAME, tr("Manage Ignore"));
187 putValue(SHORT_DESCRIPTION, tr("Manage the ignore list"));
188 new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true);
189 }
190
191 @Override
192 public void actionPerformed(ActionEvent e) {
193 new ValidatorListManagementDialog("Ignore");
194 }
195 }
196
197 /**
198 * The action to lookup the selection in the error tree.
199 */
200 class LookupAction extends AbstractAction {
201 LookupAction() {
202 putValue(NAME, tr("Lookup"));
203 putValue(SHORT_DESCRIPTION, tr("Looks up the selected primitives in the error list."));
204 new ImageProvider("dialogs", "search").getResource().attachImageIcon(this, true);
205 updateEnabledState();
206 }
207
208 @Override
209 public void actionPerformed(ActionEvent e) {
210 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
211 if (ds == null) {
212 return;
213 }
214 tree.selectRelatedErrors(ds.getSelected());
215 }
216
217 public void updateEnabledState() {
218 boolean found = false;
219 for (TestError e : tree.getErrors()) {
220 for (OsmPrimitive p : e.getPrimitives()) {
221 if (p.isSelected()) {
222 found = true;
223 break;
224 }
225 }
226 }
227 setEnabled(found);
228 }
229 }
230
231 @Override
232 public void showNotify() {
233 DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED);
234 SelectionEventManager.getInstance().addSelectionListener(this);
235 DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
236 if (ds != null) {
237 updateSelection(ds.getAllSelected());
238 }
239 MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this);
240
241 }
242
243 @Override
244 public void hideNotify() {
245 DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter);
246 MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
247 SelectionEventManager.getInstance().removeSelectionListener(this);
248 }
249
250 @Override
251 public void setVisible(boolean v) {
252 if (tree != null) {
253 tree.setVisible(v);
254 }
255 super.setVisible(v);
256 }
257
258 /**
259 * Fix selected errors
260 */
261 private void fixErrors() {
262 TreePath[] selectionPaths = tree.getSelectionPaths();
263 if (selectionPaths == null)
264 return;
265
266 Set<DefaultMutableTreeNode> processedNodes = new HashSet<>();
267
268 List<TestError> errorsToFix = new LinkedList<>();
269 for (TreePath path : selectionPaths) {
270 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
271 if (node != null) {
272 ValidatorTreePanel.visitTestErrors(node, errorsToFix::add, processedNodes);
273 }
274 }
275
276 // run fix task asynchronously
277 MainApplication.worker.submit(new FixTask(errorsToFix));
278 }
279
280 /**
281 * Set selected errors to ignore state
282 */
283 private void ignoreErrors() {
284 int asked = JOptionPane.DEFAULT_OPTION;
285 AtomicBoolean changed = new AtomicBoolean();
286 TreePath[] selectionPaths = tree.getSelectionPaths();
287 if (selectionPaths == null)
288 return;
289
290 Set<DefaultMutableTreeNode> processedNodes = new HashSet<>();
291 for (TreePath path : selectionPaths) {
292 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
293 if (node == null) {
294 continue;
295 }
296
297 Object mainNodeInfo = node.getUserObject();
298 final int depth = node.getDepth();
299 if (depth <= 1) {
300 if (!(mainNodeInfo instanceof TestError)) {
301 Set<Pair<String, String>> state = new HashSet<>();
302 // ask if the whole set should be ignored
303 if (asked == JOptionPane.DEFAULT_OPTION) {
304 String[] a = new String[] {tr("Whole group"), tr("Single elements"), tr("Nothing")};
305 asked = JOptionPane.showOptionDialog(MainApplication.getMainFrame(), tr("Ignore whole group or individual elements?"),
306 tr("Ignoring elements"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
307 a, a[1]);
308 }
309 if (asked == JOptionPane.YES_NO_OPTION) {
310 ValidatorTreePanel.visitTestErrors(node, err -> {
311 err.setIgnored(true);
312 changed.set(true);
313 state.add(new Pair<>(node.getDepth() == 1 ? err.getIgnoreSubGroup() : err.getIgnoreGroup(), err.getMessage()));
314 }, processedNodes);
315 for (Pair<String, String> s : state) {
316 OsmValidator.addIgnoredError(s.a, s.b);
317 }
318 continue;
319 } else if (asked == JOptionPane.CANCEL_OPTION || asked == JOptionPane.CLOSED_OPTION) {
320 continue;
321 }
322 }
323
324 ValidatorTreePanel.visitTestErrors(node, error -> {
325 String state = error.getIgnoreState();
326 if (state != null) {
327 OsmValidator.addIgnoredError(state, error.getMessage());
328 }
329 changed.set(true);
330 error.setIgnored(true);
331 }, processedNodes);
332 }
333 }
334 if (changed.get()) {
335 tree.resetErrors();
336 OsmValidator.saveIgnoredErrors();
337 invalidateValidatorLayers();
338 }
339 }
340
341 /**
342 * Sets the selection of the map to the current selected items.
343 */
344 private void setSelectedItems() {
345 DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
346 if (tree == null || ds == null)
347 return;
348
349 TreePath[] selectedPaths = tree.getSelectionPaths();
350 if (selectedPaths == null)
351 return;
352
353 Collection<OsmPrimitive> sel = new HashSet<>(40);
354 for (TreePath path : selectedPaths) {
355 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
356 Enumeration<?> children = node.breadthFirstEnumeration();
357 while (children.hasMoreElements()) {
358 DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement();
359 Object nodeInfo = childNode.getUserObject();
360 if (nodeInfo instanceof TestError) {
361 TestError error = (TestError) nodeInfo;
362 error.getPrimitives().stream()
363 .filter(OsmPrimitive::isSelectable)
364 .forEach(sel::add);
365 }
366 }
367 }
368 ds.setSelected(sel);
369 }
370
371 /**
372 * Checks for fixes in selected element and, if needed, adds to the sel
373 * parameter all selected elements
374 *
375 * @param sel
376 * The collection where to add all selected elements
377 * @param addSelected
378 * if true, add all selected elements to collection
379 * @return whether the selected elements has any fix
380 */
381 private boolean setSelection(Collection<OsmPrimitive> sel, boolean addSelected) {
382 AtomicBoolean hasFixes = new AtomicBoolean();
383
384 DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
385 if (lastSelectedNode != null && !lastSelectedNode.equals(node)) {
386 ValidatorTreePanel.visitTestErrors(lastSelectedNode, error -> error.setSelected(false));
387 }
388
389 lastSelectedNode = node;
390 if (node != null) {
391 ValidatorTreePanel.visitTestErrors(node, error -> {
392 error.setSelected(true);
393
394 hasFixes.set(hasFixes.get() || error.isFixable());
395 if (addSelected) {
396 error.getPrimitives().stream()
397 .filter(OsmPrimitive::isSelectable)
398 .forEach(sel::add);
399 }
400 });
401 selectAction.setEnabled(true);
402 if (ignoreAction != null) {
403 ignoreAction.setEnabled(node.getDepth() <= 1);
404 }
405 }
406
407 return hasFixes.get();
408 }
409
410 @Override
411 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
412 OsmDataLayer editLayer = e.getSource().getEditLayer();
413 if (editLayer == null) {
414 tree.setErrorList(new ArrayList<TestError>());
415 } else {
416 tree.setErrorList(editLayer.validationErrors);
417 }
418 }
419
420 /**
421 * Add a tree selection listener to the validator tree.
422 * @param listener the TreeSelectionListener
423 * @since 5958
424 */
425 public void addTreeSelectionListener(TreeSelectionListener listener) {
426 tree.addTreeSelectionListener(listener);
427 }
428
429 /**
430 * Remove the given tree selection listener from the validator tree.
431 * @param listener the TreeSelectionListener
432 * @since 5958
433 */
434 public void removeTreeSelectionListener(TreeSelectionListener listener) {
435 tree.removeTreeSelectionListener(listener);
436 }
437
438 /**
439 * Replies the popup menu handler.
440 * @return The popup menu handler
441 * @since 5958
442 */
443 public PopupMenuHandler getPopupMenuHandler() {
444 return popupMenuHandler;
445 }
446
447 /**
448 * Replies the currently selected error, or {@code null}.
449 * @return The selected error, if any.
450 * @since 5958
451 */
452 public TestError getSelectedError() {
453 Object comp = tree.getLastSelectedPathComponent();
454 if (comp instanceof DefaultMutableTreeNode) {
455 Object object = ((DefaultMutableTreeNode) comp).getUserObject();
456 if (object instanceof TestError) {
457 return (TestError) object;
458 }
459 }
460 return null;
461 }
462
463 /**
464 * Watches for double clicks and launches the popup menu.
465 */
466 class MouseEventHandler extends PopupMenuLauncher {
467
468 MouseEventHandler() {
469 super(popupMenu);
470 }
471
472 @Override
473 public void mouseClicked(MouseEvent e) {
474 TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
475 if (selPath == null) {
476 tree.clearSelection();
477 }
478
479 fixAction.setEnabled(false);
480 if (ignoreAction != null) {
481 ignoreAction.setEnabled(false);
482 }
483 selectAction.setEnabled(false);
484
485 boolean isDblClick = isDoubleClick(e);
486
487 Collection<OsmPrimitive> sel = isDblClick ? new HashSet<>(40) : null;
488
489 boolean hasFixes = setSelection(sel, isDblClick);
490 fixAction.setEnabled(hasFixes);
491
492 if (isDblClick) {
493 DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
494 if (ds != null) {
495 ds.setSelected(sel);
496 }
497 if (Config.getPref().getBoolean("validator.autozoom", false)) {
498 AutoScaleAction.zoomTo(sel);
499 }
500 }
501 }
502
503 @Override
504 public void launch(MouseEvent e) {
505 TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
506 if (selPath == null)
507 return;
508 DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getPathComponent(selPath.getPathCount() - 1);
509 if (!(node.getUserObject() instanceof TestError))
510 return;
511 super.launch(e);
512 }
513 }
514
515 /**
516 * Watches for tree selection.
517 */
518 public class SelectionWatch implements TreeSelectionListener {
519 @Override
520 public void valueChanged(TreeSelectionEvent e) {
521 if (ignoreAction != null) {
522 ignoreAction.setEnabled(false);
523 }
524 selectAction.setEnabled(false);
525
526 Collection<OsmPrimitive> sel = new HashSet<>();
527 boolean hasFixes = setSelection(sel, true);
528 fixAction.setEnabled(hasFixes);
529 popupMenuHandler.setPrimitives(sel);
530 invalidateValidatorLayers();
531 }
532 }
533
534 /**
535 * A visitor that is used to compute the bounds of an error.
536 */
537 public static class ValidatorBoundingXYVisitor extends BoundingXYVisitor implements ValidatorVisitor {
538 @Override
539 public void visit(OsmPrimitive p) {
540 if (p.isUsable()) {
541 p.accept((PrimitiveVisitor) this);
542 }
543 }
544
545 @Override
546 public void visit(WaySegment ws) {
547 if (ws.lowerIndex < 0 || ws.lowerIndex + 1 >= ws.way.getNodesCount())
548 return;
549 visit(ws.getFirstNode());
550 visit(ws.getSecondNode());
551 }
552
553 @Override
554 public void visit(List<Node> nodes) {
555 for (Node n: nodes) {
556 visit(n);
557 }
558 }
559
560 @Override
561 public void visit(TestError error) {
562 if (error != null) {
563 error.visitHighlighted(this);
564 }
565 }
566 }
567
568 /**
569 * Called when the selection was changed to update the list of displayed errors
570 * @param newSelection The new selection
571 */
572 public void updateSelection(Collection<? extends OsmPrimitive> newSelection) {
573 if (!Config.getPref().getBoolean(ValidatorPrefHelper.PREF_FILTER_BY_SELECTION, false))
574 return;
575 if (newSelection.isEmpty()) {
576 tree.setFilter(null);
577 }
578 tree.setFilter(new HashSet<>(newSelection));
579 }
580
581 @Override
582 public void selectionChanged(SelectionChangeEvent event) {
583 updateSelection(event.getSelection());
584 lookupAction.updateEnabledState();
585 }
586
587 /**
588 * Task for fixing a collection of {@link TestError}s. Can be run asynchronously.
589 */
590 class FixTask extends PleaseWaitRunnable {
591 private final Collection<TestError> testErrors;
592 private final List<Command> fixCommands = new ArrayList<>();
593 private boolean canceled;
594
595 FixTask(Collection<TestError> testErrors) {
596 super(tr("Fixing errors ..."), false /* don't ignore exceptions */);
597 this.testErrors = testErrors == null ? new ArrayList<>() : testErrors;
598 }
599
600 @Override
601 protected void cancel() {
602 this.canceled = true;
603 }
604
605 @Override
606 protected void finish() {
607 // do nothing
608 }
609
610 protected void fixError(TestError error) throws InterruptedException, InvocationTargetException {
611 if (error.isFixable()) {
612 if (error.getPrimitives().stream().noneMatch(OsmPrimitive::isDeleted)) {
613 final Command fixCommand = error.getFix();
614 if (fixCommand != null) {
615 SwingUtilities.invokeAndWait(fixCommand::executeCommand);
616 fixCommands.add(fixCommand);
617 }
618 }
619 // It is wanted to ignore an error if it said fixable, even if fixCommand was null
620 // This is to fix #5764 and #5773:
621 // a delete command, for example, may be null if all concerned primitives have already been deleted
622 error.setIgnored(true);
623 }
624 }
625
626 @Override
627 protected void realRun() throws SAXException, IOException, OsmTransferException {
628 ProgressMonitor monitor = getProgressMonitor();
629 try {
630 monitor.setTicksCount(testErrors.size());
631 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
632 int i = 0;
633 SwingUtilities.invokeAndWait(ds::beginUpdate);
634 try {
635 for (TestError error: testErrors) {
636 i++;
637 monitor.subTask(tr("Fixing ({0}/{1}): ''{2}''", i, testErrors.size(), error.getMessage()));
638 if (this.canceled)
639 return;
640 fixError(error);
641 monitor.worked(1);
642 }
643 } finally {
644 SwingUtilities.invokeAndWait(ds::endUpdate);
645 }
646 monitor.subTask(tr("Updating map ..."));
647 SwingUtilities.invokeAndWait(() -> {
648 if (!fixCommands.isEmpty()) {
649 UndoRedoHandler.getInstance().add(
650 fixCommands.size() > 1 ? new AutofixCommand(fixCommands) : fixCommands.get(0), false);
651 }
652 invalidateValidatorLayers();
653 tree.resetErrors();
654 });
655 } catch (InterruptedException e) {
656 tryUndo();
657 throw new JosmRuntimeException(e);
658 } catch (InvocationTargetException e) {
659 // FIXME: signature of realRun should have a generic checked exception we could throw here
660 throw new JosmRuntimeException(e);
661 } finally {
662 if (monitor.isCanceled()) {
663 tryUndo();
664 }
665 monitor.finishTask();
666 }
667 }
668
669 /**
670 * Undo commands as they were not yet added to the UndoRedo Handler
671 */
672 private void tryUndo() {
673 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
674 int i = fixCommands.size() - 1;
675 ds.beginUpdate();
676 for (; i >= 0; i--) {
677 fixCommands.get(i).undoCommand();
678 }
679 ds.endUpdate();
680 }
681
682 }
683
684 private static void invalidateValidatorLayers() {
685 MainApplication.getLayerManager().getLayersOfType(ValidatorLayer.class).forEach(ValidatorLayer::invalidate);
686 }
687
688 @Override
689 public void processDatasetEvent(AbstractDatasetChangedEvent event) {
690 validateAction.updateEnabledState();
691 }
692
693 private static class AutofixCommand extends SequenceCommand {
694 AutofixCommand(Collection<Command> sequenz) {
695 super(tr("auto-fixed validator issues"), sequenz, true);
696 setSequenceComplete(true);
697 }
698
699 @Override
700 public void undoCommand() {
701 getAffectedDataSet().beginUpdate();
702 super.undoCommand();
703 getAffectedDataSet().endUpdate();
704 }
705
706 @Override
707 public boolean executeCommand() {
708 getAffectedDataSet().beginUpdate();
709 boolean rc = super.executeCommand();
710 getAffectedDataSet().endUpdate();
711 return rc;
712 }
713 }
714}
Note: See TracBrowser for help on using the repository browser.