Ticket #17268: clear_ignored_errors_v26.patch

File clear_ignored_errors_v26.patch, 26.6 KB (added by taylor.smock, 6 years ago)

Remove some debug statements

  • src/org/openstreetmap/josm/data/preferences/sources/ValidatorPrefHelper.java

     
    4444    /** The preferences for ignored severity other */
    4545    public static final BooleanProperty PREF_OTHER = new BooleanProperty(PREFIX + ".other", false);
    4646
     47    /** The preferences key for the ignorelist */
     48    public static final String PREF_IGNORELIST = PREFIX + ".ignorelist";
     49
     50    /** The preferences key for the ignorelist backup */
     51    public static final String PREF_IGNORELIST_BACKUP = PREFIX + ".ignorelist.bak";
     52
     53    /** The preferences key for whether or not the ignorelist backup should be cleared on start */
     54    public static final BooleanProperty PREF_IGNORELIST_KEEP_BACKUP = new BooleanProperty(PREFIX + ".ignorelist.bak.keep", false);
     55
    4756    /**
    4857     * The preferences key for enabling the permanent filtering
    4958     * of the displayed errors in the tree regarding the current selection
  • src/org/openstreetmap/josm/data/validation/OsmValidator.java

     
    77import java.io.File;
    88import java.io.FileNotFoundException;
    99import java.io.IOException;
    10 import java.io.PrintWriter;
    1110import java.nio.charset.StandardCharsets;
    1211import java.nio.file.Files;
    1312import java.nio.file.Path;
     
    1716import java.util.Collection;
    1817import java.util.Collections;
    1918import java.util.EnumMap;
     19import java.util.Enumeration;
    2020import java.util.HashMap;
     21import java.util.Iterator;
    2122import java.util.List;
    2223import java.util.Map;
     24import java.util.Map.Entry;
    2325import java.util.SortedMap;
    2426import java.util.TreeMap;
    2527import java.util.TreeSet;
     
    2729import java.util.stream.Collectors;
    2830
    2931import javax.swing.JOptionPane;
     32import javax.swing.JTree;
     33import javax.swing.tree.DefaultMutableTreeNode;
     34import javax.swing.tree.TreeModel;
     35import javax.swing.tree.TreeNode;
    3036
    3137import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
    3238import org.openstreetmap.josm.data.projection.ProjectionRegistry;
     
    8894    /** Grid detail, multiplier of east,north values for valuable cell sizing */
    8995    private static double griddetail;
    9096
    91     private static final Collection<String> ignoredErrors = new TreeSet<>();
    92 
     97    private static final SortedMap<String, String> ignoredErrors = new TreeMap<>();
    9398    /**
    9499     * All registered tests
    95100     */
     
    169174    public static void initialize() {
    170175        checkValidatorDir();
    171176        initializeGridDetail();
    172         loadIgnoredErrors(); //FIXME: load only when needed
     177        loadIgnoredErrors();
    173178    }
    174179
    175180    /**
     
    204209    private static void loadIgnoredErrors() {
    205210        ignoredErrors.clear();
    206211        if (ValidatorPrefHelper.PREF_USE_IGNORE.get()) {
     212            Config.getPref().getListOfMaps(ValidatorPrefHelper.PREF_IGNORELIST).forEach(ignoredErrors::putAll);
    207213            Path path = Paths.get(getValidatorDir()).resolve("ignorederrors");
    208214            try {
    209215                if (path.toFile().exists()) {
    210216                    try {
    211                         ignoredErrors.addAll(Files.readAllLines(path, StandardCharsets.UTF_8));
     217                        TreeSet<String> treeSet = new TreeSet<>();
     218                        treeSet.addAll(Files.readAllLines(path, StandardCharsets.UTF_8));
     219                        treeSet.forEach(ignore -> ignoredErrors.putIfAbsent(ignore, ""));
     220
     221                        saveIgnoredErrors();
     222                        Files.deleteIfExists(path);
     223
    212224                    } catch (FileNotFoundException e) {
    213225                        Logging.debug(Logging.getErrorMessage(e));
    214226                    } catch (IOException e) {
     
    228240     * @see TestError#getIgnoreSubGroup()
    229241     */
    230242    public static void addIgnoredError(String s) {
    231         ignoredErrors.add(s);
     243        addIgnoredError(s, "");
    232244    }
    233245
    234246    /**
     247     * Adds an ignored error
     248     * @param s The ignore group / sub group name
     249     * @param description What the error actually is
     250     * @see TestError#getIgnoreGroup()
     251     * @see TestError#getIgnoreSubGroup()
     252     */
     253    public static void addIgnoredError(String s, String description) {
     254        if (description == null) description = "";
     255        ignoredErrors.put(s, description);
     256        if (s.split(":(r|w|n)_[0-9]+($|:)").length == 1) {
     257            cleanupIgnoredErrors();
     258        }
     259    }
     260
     261    /**
     262     *  Make sure that we don't keep single entries for a "group ignore" or
     263     *  multiple different entries for the single entries that are in the same group.
     264     */
     265    private static void cleanupIgnoredErrors() {
     266        if (ignoredErrors.size() > 1) {
     267            List<String> toRemove = new ArrayList<>();
     268
     269            Iterator<Entry<String, String>> iter = ignoredErrors.entrySet().iterator();
     270            Entry<String, String> last = iter.next();
     271            while (iter.hasNext()) {
     272                Entry<String, String> entry = iter.next();
     273                if (entry.getKey().startsWith(last.getKey())) {
     274                    toRemove.add(entry.getKey());
     275                } else {
     276                    last = entry;
     277                }
     278            }
     279            toRemove.forEach(ignoredErrors::remove);
     280            Map<String, String> tmap = buildIgnore(buildJTreeList());
     281            if (tmap != null && !tmap.isEmpty()) {
     282                ignoredErrors.clear();
     283                ignoredErrors.putAll(tmap);
     284            }
     285        }
     286    }
     287
     288    /**
    235289     * Check if a error should be ignored
    236290     * @param s The ignore group / sub group name
    237291     * @return <code>true</code> to ignore that error
    238292     */
    239293    public static boolean hasIgnoredError(String s) {
    240         return ignoredErrors.contains(s);
     294        return ignoredErrors.containsKey(s);
    241295    }
    242296
    243297    /**
    244      * Saves the names of the ignored errors to a file
     298     * Get the list of all ignored errors
     299     * @return The <code>Collection&ltString&gt</code> of errors that are ignored
    245300     */
     301    public static SortedMap<String, String> getIgnoredErrors() {
     302        return ignoredErrors;
     303    }
     304
     305    /**
     306     * Build a JTree with a list
     307     * @return &lttype&gtlist as a {@code JTree}
     308     */
     309    public static JTree buildJTreeList() {
     310        DefaultMutableTreeNode root = new DefaultMutableTreeNode(tr("Ignore list"));
     311
     312        for (Entry<String, String> e: ignoredErrors.entrySet()) {
     313            String key = e.getKey();
     314            String value = e.getValue();
     315            String[] osmobjects = key.split(":(r|w|n)_");
     316            DefaultMutableTreeNode trunk;
     317            DefaultMutableTreeNode branch;
     318
     319            if (value != null && !value.isEmpty()) {
     320                trunk = inTree(root, value);
     321                branch = inTree(trunk, osmobjects[0]);
     322                trunk.add(branch);
     323            } else {
     324                trunk = inTree(root, osmobjects[0]);
     325                branch = trunk;
     326            }
     327            for (int i = 1; i < osmobjects.length; i++) {
     328                String osmid = osmobjects[i];
     329                int index = key.indexOf(osmid);
     330                char type = key.charAt(index - 2);
     331                DefaultMutableTreeNode leaf = new DefaultMutableTreeNode(type + "_" + osmid);
     332                branch.add(leaf);
     333            }
     334            root.add(trunk);
     335        }
     336        return new JTree(root);
     337    }
     338
     339    private static DefaultMutableTreeNode inTree(DefaultMutableTreeNode root, String name) {
     340        @SuppressWarnings("unchecked")
     341        Enumeration<TreeNode> trunks = root.children();
     342        while (trunks.hasMoreElements()) {
     343            TreeNode ttrunk = trunks.nextElement();
     344            if (ttrunk instanceof DefaultMutableTreeNode) {
     345                DefaultMutableTreeNode trunk = (DefaultMutableTreeNode) ttrunk;
     346                if (name.equals(trunk.getUserObject())) {
     347                    return trunk;
     348                }
     349            }
     350        }
     351        return new DefaultMutableTreeNode(name);
     352    }
     353
     354    /**
     355     * Build a {@code HashMap} from a tree of ignored errors
     356     * @param tree The JTree of ignored errors
     357     * @return A {@code HashMap} of the ignored errors for comparison
     358     */
     359    public static Map<String, String> buildIgnore(JTree tree) {
     360        TreeModel model = tree.getModel();
     361        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
     362        return buildIgnore(model, root);
     363    }
     364
     365    private static Map<String, String> buildIgnore(TreeModel model, DefaultMutableTreeNode node) {
     366        HashMap<String, String> rHashMap = new HashMap<>();
     367
     368        String osmids = node.getUserObject().toString();
     369        String description = "";
     370
     371        if (!model.getRoot().equals(node)) description = ((DefaultMutableTreeNode) node.getParent()).getUserObject().toString();
     372        if (!osmids.matches("^[0-9]+_.*")) osmids = "";
     373
     374        for (int i = 0; i < model.getChildCount(node); i++) {
     375            DefaultMutableTreeNode child = (DefaultMutableTreeNode) model.getChild(node, i);
     376            if (model.getChildCount(child) == 0) {
     377                String ignoreName = child.getUserObject().toString();
     378                if (ignoreName.matches("^(r|w|n)_.*")) {
     379                    osmids += ":" + child.getUserObject().toString();
     380                } else if (ignoreName.matches("^[0-9]+_.*")) {
     381                    rHashMap.put(ignoreName, description);
     382                }
     383            } else {
     384                rHashMap.putAll(buildIgnore(model, child));
     385            }
     386        }
     387        if (!osmids.isEmpty() && osmids.indexOf(':') != 0) rHashMap.put(osmids, description);
     388        return rHashMap;
     389    }
     390
     391    /**
     392     * Reset the error list by deleting {@code validator.ignorelist}
     393     */
     394    public static void resetErrorList() {
     395        saveIgnoredErrors();
     396        backupErrorList();
     397        Config.getPref().putListOfMaps(ValidatorPrefHelper.PREF_IGNORELIST, null);
     398        OsmValidator.initialize();
     399    }
     400
     401    /**
     402     * Restore the error list by copying {@code validator.ignorelist.bak} to
     403     * {@code validator.ignorelist}
     404     */
     405    public static void restoreErrorList() {
     406        saveIgnoredErrors();
     407        List<Map<String, String>> tlist = Config.getPref().getListOfMaps(ValidatorPrefHelper.PREF_IGNORELIST_BACKUP);
     408        backupErrorList();
     409        Config.getPref().putListOfMaps(ValidatorPrefHelper.PREF_IGNORELIST, tlist);
     410        OsmValidator.initialize();
     411    }
     412
     413    private static void backupErrorList() {
     414        List<Map<String, String>> tlist = Config.getPref().getListOfMaps(ValidatorPrefHelper.PREF_IGNORELIST, null);
     415        Config.getPref().putListOfMaps(ValidatorPrefHelper.PREF_IGNORELIST_BACKUP, tlist);
     416    }
     417
     418    /**
     419     * Saves the names of the ignored errors to a preference
     420     */
    246421    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);
     422        cleanupIgnoredErrors();
     423        List<Map<String, String>> list = new ArrayList<>();
     424        list.add(ignoredErrors);
     425        int i = 0;
     426        while (i < list.size()) {
     427            if (list.get(i) == null || list.get(i).isEmpty()) {
     428                list.remove(i);
     429                continue;
    250430            }
    251         } catch (IOException e) {
    252             Logging.error(e);
     431            i++;
    253432        }
     433        if (list.isEmpty()) list = null;
     434        Config.getPref().putListOfMaps(ValidatorPrefHelper.PREF_IGNORELIST, list);
    254435    }
    255436
    256437    /**
  • src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

     
    6363import org.openstreetmap.josm.tools.ImageProvider;
    6464import org.openstreetmap.josm.tools.InputMapUtils;
    6565import org.openstreetmap.josm.tools.JosmRuntimeException;
     66import org.openstreetmap.josm.tools.Pair;
    6667import org.openstreetmap.josm.tools.Shortcut;
    6768import org.xml.sax.SAXException;
    6869
     
    8586    private final SideButton fixButton;
    8687    /** The ignore button */
    8788    private final SideButton ignoreButton;
     89    /** The reset ignorelist button */
     90    private final SideButton ignorelistManagement;
    8891    /** The select button */
    8992    private final SideButton selectButton;
    9093    /** The lookup button */
     
    174177            });
    175178            ignoreButton.setEnabled(false);
    176179            buttons.add(ignoreButton);
     180
     181            if (!ValidatorPrefHelper.PREF_IGNORELIST_KEEP_BACKUP.get()) {
     182                // Clear the backup ignore list
     183                Config.getPref().putListOfMaps(ValidatorPrefHelper.PREF_IGNORELIST_BACKUP, null);
     184            }
     185            ignorelistManagement = new SideButton(new AbstractAction() {
     186                {
     187                    putValue(NAME, tr("Manage Ignore"));
     188                    putValue(SHORT_DESCRIPTION, tr("Manage the ignore list"));
     189                    new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true);
     190                }
     191
     192                @Override
     193                public void actionPerformed(ActionEvent e) {
     194                    ValidatorListManagementDialog dialog = new ValidatorListManagementDialog("Ignore");
     195                    if (dialog.getValue() == 1) {
     196                        // TODO save
     197                    }
     198                }
     199            });
     200            buttons.add(ignorelistManagement);
    177201        } else {
    178202            ignoreButton = null;
     203            ignorelistManagement = null;
    179204        }
     205
    180206        createLayout(tree, true, buttons);
    181207    }
    182208
     
    245271
    246272            Object mainNodeInfo = node.getUserObject();
    247273            if (!(mainNodeInfo instanceof TestError)) {
    248                 Set<String> state = new HashSet<>();
     274                Set<Pair<String, String>> state = new HashSet<>();
    249275                // ask if the whole set should be ignored
    250276                if (asked == JOptionPane.DEFAULT_OPTION) {
    251277                    String[] a = new String[] {tr("Whole group"), tr("Single elements"), tr("Nothing")};
     
    257283                    ValidatorTreePanel.visitTestErrors(node, err -> {
    258284                        err.setIgnored(true);
    259285                        changed.set(true);
    260                         state.add(node.getDepth() == 1 ? err.getIgnoreSubGroup() : err.getIgnoreGroup());
     286                        state.add(new Pair<>(node.getDepth() == 1 ? err.getIgnoreSubGroup() : err.getIgnoreGroup(), err.getMessage()));
    261287                    }, processedNodes);
    262                     for (String s : state) {
    263                         OsmValidator.addIgnoredError(s);
     288                    for (Pair<String, String> s : state) {
     289                        OsmValidator.addIgnoredError(s.a, s.b);
    264290                    }
    265291                    continue;
    266292                } else if (asked == JOptionPane.CANCEL_OPTION || asked == JOptionPane.CLOSED_OPTION) {
     
    271297            ValidatorTreePanel.visitTestErrors(node, error -> {
    272298                String state = error.getIgnoreState();
    273299                if (state != null) {
    274                     OsmValidator.addIgnoredError(state);
     300                    OsmValidator.addIgnoredError(state, error.getMessage());
    275301                }
    276302                changed.set(true);
    277303                error.setIgnored(true);
     
    287313    /**
    288314     * Sets the selection of the map to the current selected items.
    289315     */
    290     @SuppressWarnings("unchecked")
    291316    private void setSelectedItems() {
    292317        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    293318        if (tree == null || ds == null)
  • src/org/openstreetmap/josm/gui/dialogs/ValidatorListManagementDialog.java

     
     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.GridBagLayout;
     7import java.awt.Rectangle;
     8import java.awt.event.ActionEvent;
     9import java.awt.event.KeyEvent;
     10import java.awt.event.KeyListener;
     11import java.awt.event.MouseAdapter;
     12import java.awt.event.MouseEvent;
     13import java.util.List;
     14import java.util.Locale;
     15import java.util.Map;
     16
     17import javax.swing.AbstractAction;
     18import javax.swing.ImageIcon;
     19import javax.swing.JMenuItem;
     20import javax.swing.JOptionPane;
     21import javax.swing.JPanel;
     22import javax.swing.JPopupMenu;
     23import javax.swing.JScrollPane;
     24import javax.swing.JTree;
     25import javax.swing.tree.DefaultMutableTreeNode;
     26import javax.swing.tree.TreePath;
     27
     28import org.openstreetmap.josm.actions.ValidateAction;
     29import org.openstreetmap.josm.data.validation.OsmValidator;
     30import org.openstreetmap.josm.data.validation.TestError;
     31import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
     32import org.openstreetmap.josm.gui.ExtendedDialog;
     33import org.openstreetmap.josm.gui.MainApplication;
     34import org.openstreetmap.josm.gui.MapFrame;
     35import org.openstreetmap.josm.gui.util.GuiHelper;
     36import org.openstreetmap.josm.tools.GBC;
     37import org.openstreetmap.josm.tools.ImageProvider;
     38import org.openstreetmap.josm.tools.Logging;
     39
     40
     41/**
     42 * A management window for the validator's ignorelist
     43 * @author Taylor Smock
     44 * @since xxx
     45 */
     46public class ValidatorListManagementDialog extends ExtendedDialog {
     47    enum BUTTONS {
     48        OK(0, tr("OK"), new ImageProvider("ok")),
     49        CLEAR(1, tr("Clear All"), new ImageProvider("dialogs", "fix")),
     50        RESTORE(2, tr("Restore"), new ImageProvider("copy")),
     51        CANCEL(3, tr("Cancel"), new ImageProvider("cancel"));
     52
     53        private int index;
     54        private String name;
     55        private ImageIcon icon;
     56
     57        BUTTONS(int index, String name, ImageProvider image) {
     58            this.index = index;
     59            this.name = name;
     60            this.icon = image.getResource().getImageIcon();
     61        }
     62
     63        public ImageIcon getImageIcon() {
     64            return icon;
     65        }
     66
     67        public int getIndex() {
     68            return index;
     69        }
     70
     71        public String getName() {
     72            return name;
     73        }
     74    }
     75
     76    private static final String[] BUTTON_TEXTS = {BUTTONS.OK.getName(), BUTTONS.CLEAR.getName(),
     77            BUTTONS.RESTORE.getName(), BUTTONS.CANCEL.getName()
     78    };
     79
     80    private static final ImageIcon[] BUTTON_IMAGES = {BUTTONS.OK.getImageIcon(), BUTTONS.CLEAR.getImageIcon(),
     81            BUTTONS.RESTORE.getImageIcon(), BUTTONS.CANCEL.getImageIcon()
     82    };
     83
     84    private final JPanel panel = new JPanel(new GridBagLayout());
     85
     86    private final JTree ignoreErrors;
     87
     88    private final String type;
     89
     90    /**
     91     * Create a new {@link ValidatorListManagementDialog}
     92     * @param type The type of list to create (first letter may or may not be
     93     * capitalized, it is put into all lowercase after building the title)
     94     */
     95    public ValidatorListManagementDialog(String type) {
     96        super(MainApplication.getMainFrame(), tr("Validator {0} List Management", type), BUTTON_TEXTS, false);
     97        this.type = type.toLowerCase(Locale.ENGLISH);
     98        setButtonIcons(BUTTON_IMAGES);
     99
     100        ignoreErrors = buildList();
     101        JScrollPane scroll = GuiHelper.embedInVerticalScrollPane(ignoreErrors);
     102
     103        panel.add(scroll, GBC.eol().fill(GBC.BOTH).anchor(GBC.CENTER));
     104        setContent(panel);
     105        setDefaultButton(1);
     106        setupDialog();
     107        showDialog();
     108    }
     109
     110    @Override
     111    public void buttonAction(int buttonIndex, ActionEvent evt) {
     112        // Currently OK/Cancel buttons do nothing
     113        final int answer;
     114        if (buttonIndex == BUTTONS.RESTORE.getIndex()) {
     115            dispose();
     116            answer = rerunValidatorPrompt();
     117            if (answer == JOptionPane.YES_OPTION || answer == JOptionPane.NO_OPTION) {
     118                OsmValidator.restoreErrorList();
     119            }
     120        } else if (buttonIndex == BUTTONS.CLEAR.getIndex()) {
     121            dispose();
     122            answer = rerunValidatorPrompt();
     123            if (answer == JOptionPane.YES_OPTION || answer == JOptionPane.NO_OPTION) {
     124                OsmValidator.resetErrorList();
     125            }
     126        } else if (buttonIndex == BUTTONS.OK.getIndex()) {
     127            Map<String, String> errors = OsmValidator.getIgnoredErrors();
     128            Map<String, String> tree = OsmValidator.buildIgnore(ignoreErrors);
     129            if (!errors.equals(tree)) {
     130                answer = rerunValidatorPrompt();
     131                if (answer == JOptionPane.YES_OPTION || answer == JOptionPane.NO_OPTION) {
     132                    OsmValidator.resetErrorList();
     133                    tree.forEach((ignore, description) -> {
     134                        OsmValidator.addIgnoredError(ignore, description);
     135                    });
     136                    OsmValidator.saveIgnoredErrors();
     137                    OsmValidator.initialize();
     138                }
     139            }
     140            dispose();
     141        } else {
     142            super.buttonAction(buttonIndex, evt);
     143        }
     144    }
     145
     146    /**
     147     * Build a JTree with a list
     148     * @return &lttype&gtlist as a {@code JTree}
     149     */
     150    public JTree buildList() {
     151        JTree tree;
     152
     153        if ("ignore".equals(type)) {
     154            tree = OsmValidator.buildJTreeList();
     155        } else {
     156            Logging.error(tr("Cannot understand the following type: {0}", type));
     157            return null;
     158        }
     159        tree.setRootVisible(false);
     160        tree.setShowsRootHandles(true);
     161        tree.addMouseListener(new MouseAdapter() {
     162            @Override
     163            public void mousePressed(MouseEvent e) {
     164                process(e);
     165            }
     166
     167            @Override
     168            public void mouseReleased(MouseEvent e) {
     169                process(e);
     170            }
     171
     172            private void process(MouseEvent e) {
     173                if (e.isPopupTrigger()) {
     174                    TreePath[] paths = tree.getSelectionPaths();
     175                    if (paths == null) return;
     176                    Rectangle bounds = tree.getUI().getPathBounds(tree, paths[0]);
     177                    if (bounds != null) {
     178                        JPopupMenu menu = new JPopupMenu();
     179                        JMenuItem delete = new JMenuItem(new AbstractAction(tr("Delete")) {
     180                            @Override
     181                            public void actionPerformed(ActionEvent e1) {
     182                                deleteAction(tree, paths);
     183                            }
     184                        });
     185                        menu.add(delete);
     186                        menu.show(e.getComponent(), e.getX(), e.getY());
     187                    }
     188                }
     189            }
     190        });
     191
     192        tree.addKeyListener(new KeyListener() {
     193
     194            @Override
     195            public void keyTyped(KeyEvent e) {
     196                // Do nothing
     197            }
     198
     199            @Override
     200            public void keyPressed(KeyEvent e) {
     201                // Do nothing
     202            }
     203
     204            @Override
     205            public void keyReleased(KeyEvent e) {
     206                TreePath[] paths = tree.getSelectionPaths();
     207                if (e.getKeyCode() == KeyEvent.VK_DELETE && paths != null) {
     208                    deleteAction(tree, paths);
     209                }
     210            }
     211        });
     212        return tree;
     213    }
     214
     215    private void deleteAction(JTree tree, TreePath[] paths) {
     216        for (TreePath path : paths) {
     217            tree.clearSelection();
     218            tree.addSelectionPath(path);
     219            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
     220            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
     221            node.removeAllChildren();
     222            while (node.getChildCount() == 0) {
     223                node.removeFromParent();
     224                node = parent;
     225                if (parent == null || parent.isRoot()) break;
     226                parent = (DefaultMutableTreeNode) node.getParent();
     227            }
     228        }
     229        tree.updateUI();
     230    }
     231
     232
     233    /**
     234     * Prompt to rerun the validator when the ignore list changes
     235     * @return {@code JOptionPane.YES_OPTION}, {@code JOptionPane.NO_OPTION},
     236     *  or {@code JOptionPane.CANCEL_OPTION}
     237     */
     238    public int rerunValidatorPrompt() {
     239        MapFrame map = MainApplication.getMap();
     240        List<TestError> errors = map.validatorDialog.tree.getErrors();
     241        ValidateAction validateAction = ValidatorDialog.validateAction;
     242        if (!validateAction.isEnabled() || errors == null || errors.isEmpty()) return JOptionPane.NO_OPTION;
     243        final int answer = ConditionalOptionPaneUtil.showOptionDialog(
     244                "rerun_validation_when_ignorelist_changed",
     245                MainApplication.getMainFrame(),
     246                tr("{0}Should the validation be rerun?{1}", "<hmtl><h3>", "</h3></html>"),
     247                tr("Ignored error filter changed"),
     248                JOptionPane.YES_NO_CANCEL_OPTION,
     249                JOptionPane.QUESTION_MESSAGE,
     250                null,
     251                null);
     252        if (answer == JOptionPane.YES_OPTION) {
     253            validateAction.doValidate(true);
     254        }
     255        return answer;
     256    }
     257}
  • src/org/openstreetmap/josm/spi/preferences/MapListSetting.java

     
    66import java.util.LinkedHashMap;
    77import java.util.List;
    88import java.util.Map;
     9import java.util.SortedMap;
    910
    1011/**
    1112 * Setting containing a {@link List} of {@link Map}s of {@link String} values.
     
    4041        if (value.contains(null))
    4142            throw new IllegalArgumentException("Error: Null as list element in preference setting");
    4243        for (Map<String, String> map : value) {
    43             if (map.containsKey(null))
     44            if (!(map instanceof SortedMap) && map.containsKey(null))
    4445                throw new IllegalArgumentException("Error: Null as map key in preference setting");
    4546            if (map.containsValue(null))
    4647                throw new IllegalArgumentException("Error: Null as map value in preference setting");