예제 #1
1
  public void filterBase(String ft) {
    if (ft.contains("-i")) {
      RowFilter<Storage, Object> tmpFilter = null;
      try {
        tmpFilter = RowFilter.regexFilter("^new$", Storage.COL_TAGS);
      } catch (Exception e) {
        System.err.println("Failed to filter new ones");
      }
      tableSorter.setRowFilter(tmpFilter);
      return;
    }

    boolean names = false;
    boolean bads = false;
    boolean exclusive = true;
    if (ft.contains("-n")) {
      names = true;
      ft = ft.substring(0, ft.indexOf("-n")) + ft.substring(ft.indexOf("-n") + 2);
    }
    if (ft.contains("-z")) {
      bads = true;
      ft = ft.substring(0, ft.indexOf("-z")) + ft.substring(ft.indexOf("-z") + 2);
    }
    if (ft.contains("-x")) {
      exclusive = false;
      ft = ft.substring(0, ft.indexOf("-x")) + ft.substring(ft.indexOf("-x") + 2);
    }

    ft = ft.replaceAll("[^a-zA-Z0-9]", " ").replaceAll("  *", " ").trim().toLowerCase();
    String[] terms = ft.split(" ");
    ArrayList<RowFilter<Storage, Object>> termFilters = new ArrayList<RowFilter<Storage, Object>>();
    for (int i = 0; i < terms.length; i++) {
      if (terms[i].length() > 0) {
        try {
          RowFilter<Storage, Object> tmp =
              RowFilter.regexFilter(".*" + terms[i] + ".*", Storage.COL_TAGS);
          if (names) tmp = RowFilter.regexFilter(".*" + terms[i] + ".*", Storage.COL_NAME);
          termFilters.add(tmp);
        } catch (Exception e) {
          // do nothing
          System.err.println("Term filter error for term " + terms[i]);
        }
      }
    }

    RowFilter<Storage, Object> badFilter = RowFilter.regexFilter(".*zz.*", Storage.COL_TAGS);
    if (!bads) badFilter = RowFilter.notFilter(badFilter);

    RowFilter<Storage, Object> omniFilter = badFilter;
    if (termFilters.size() != 0) {
      ArrayList<RowFilter<Storage, Object>> tmpFilters =
          new ArrayList<RowFilter<Storage, Object>>();
      RowFilter<Storage, Object> orFilter =
          (exclusive ? RowFilter.andFilter(termFilters) : RowFilter.orFilter(termFilters));
      tmpFilters.add(orFilter);
      tmpFilters.add(badFilter);
      omniFilter = RowFilter.andFilter(tmpFilters);
    }

    tableSorter.setRowFilter(omniFilter);
  }
  /**
   * Update the filter for the {@link #projectsTable}, depending on the state of the check boxes
   * that are associated with the {@link #hideSkippedBuildsAction}, {@link
   * #hideBuildsWithoutMessagesAction} and {@link #hideBuildsWithoutIncludesAction}
   */
  private void updateProjectsTableFilter() {
    RowFilter<TableModel, Object> isSkipped = booleanValueFilter(SKIPPED_COLUMN_INDEX);

    RowFilter<TableModel, Object> hasCompilerWarnings =
        RowFilter.numberFilter(ComparisonType.AFTER, 0, COMPILER_WARNINGS_COLUMN_INDEX);

    RowFilter<TableModel, Object> hasCompilerErrors =
        RowFilter.numberFilter(ComparisonType.AFTER, 0, COMPILER_ERRORS_COLUMN_INDEX);

    RowFilter<TableModel, Object> hasLinkerWarnings =
        RowFilter.numberFilter(ComparisonType.AFTER, 0, LINKER_WARNINGS_COLUMN_INDEX);

    RowFilter<TableModel, Object> hasLinkerErrors =
        RowFilter.numberFilter(ComparisonType.AFTER, 0, LINKER_ERRORS_COLUMN_INDEX);

    RowFilter<TableModel, Object> hasMessages =
        RowFilter.orFilter(
            Arrays.asList(
                hasCompilerWarnings, hasCompilerErrors,
                hasLinkerWarnings, hasLinkerErrors));

    RowFilter<TableModel, Object> hasIncludes = booleanValueFilter(INCLUDE_COLUMN_INDEX);

    RowFilter<TableModel, Object> r = trueFilter();
    if (isSelected(hideSkippedBuildsAction)) {
      r = RowFilter.andFilter(Arrays.asList(r, RowFilter.notFilter(isSkipped)));
    }
    if (isSelected(hideBuildsWithoutMessagesAction)) {
      r = RowFilter.andFilter(Arrays.asList(r, hasMessages));
    }
    if (isSelected(hideBuildsWithoutIncludesAction)) {
      r = RowFilter.andFilter(Arrays.asList(r, hasIncludes));
    }
    projectsTableRowSorter.setRowFilter(r);
    JTables.adjustColumnWidths(projectsTable, Short.MAX_VALUE);
  }