示例#1
0
 private void updateFilters() {
   try {
     filterMatcher.update(filters);
     executeFilters();
   } catch (ParseError e) {
     JOptionPane.showMessageDialog(
         Main.parent, e.getMessage(), tr("Error in filter"), JOptionPane.ERROR_MESSAGE);
   }
 }
示例#2
0
    @Override
    protected void realRun() {
      try {
        foundMatches = 0;
        SearchCompiler.Match matcher = SearchCompiler.compile(setting);

        if (setting.mode == SearchMode.replace) {
          selection.clear();
        } else if (setting.mode == SearchMode.in_selection) {
          foundMatches = selection.size();
        }

        Collection<OsmPrimitive> all;
        if (setting.allElements) {
          all = ds.allPrimitives();
        } else {
          all = ds.getPrimitives(OsmPrimitive::isSelectable);
        }
        final ProgressMonitor subMonitor =
            getProgressMonitor().createSubTaskMonitor(all.size(), false);
        subMonitor.beginTask(
            trn("Searching in {0} object", "Searching in {0} objects", all.size(), all.size()));

        for (OsmPrimitive osm : all) {
          if (canceled) {
            return;
          }
          if (setting.mode == SearchMode.replace) {
            if (matcher.match(osm)) {
              selection.add(osm);
              ++foundMatches;
            }
          } else if (setting.mode == SearchMode.add && !predicate.test(osm) && matcher.match(osm)) {
            selection.add(osm);
            ++foundMatches;
          } else if (setting.mode == SearchMode.remove
              && predicate.test(osm)
              && matcher.match(osm)) {
            selection.remove(osm);
            ++foundMatches;
          } else if (setting.mode == SearchMode.in_selection
              && predicate.test(osm)
              && !matcher.match(osm)) {
            selection.remove(osm);
            --foundMatches;
          }
          subMonitor.worked(1);
        }
        subMonitor.finishTask();
      } catch (ParseError e) {
        Main.debug(e);
        JOptionPane.showMessageDialog(
            Main.parent, e.getMessage(), tr("Error"), JOptionPane.ERROR_MESSAGE);
      }
    }