Esempio n. 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);
  }
  public void activarFiltrosTabla() {
    TableRowSorter<TableModel> modeloOrdenado;
    // model.setRowFilter(RowFilter.regexFilter("2", 1));
    modeloOrdenado = new TableRowSorter<TableModel>(model);
    tablaCapacitadores.setRowSorter(modeloOrdenado);

    if (filtroBuscarActivado) {
      String[] cadena = txtBuscar.getText().split(" ");
      List<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>();
      for (int i = 0; i < cadena.length; i++) {
        filters.add(RowFilter.regexFilter("(?i)" + cadena[i]));
      }
      if (rbFiltroActivos.isSelected()) {
        filters.add(RowFilter.regexFilter(gestor.nombreEstadoCapacitadorActivo(), 3));
      }
      RowFilter<Object, Object> cadenaFilter = RowFilter.andFilter(filters);
      modeloOrdenado.setRowFilter(cadenaFilter);

    } else {
      if (rbFiltroActivos.isSelected()) {
        modeloOrdenado.setRowFilter(
            RowFilter.regexFilter(gestor.nombreEstadoCapacitadorActivo(), 3));
      }
    }
  }
Esempio n. 3
0
 public void filter() {
   String expr = filterField.getText().trim();
   if (expr.length() == 0) {
     expr = null;
   }
   try {
     final TableRowSorter<? extends TableModel> sorter =
         ((TableRowSorter<? extends TableModel>) shortcutTable.getRowSorter());
     if (expr == null) {
       sorter.setRowFilter(null);
     } else {
       expr = expr.replace("+", "\\+");
       // split search string on whitespace, do case-insensitive AND search
       ArrayList<RowFilter<Object, Object>> andFilters =
           new ArrayList<RowFilter<Object, Object>>();
       for (String word : expr.split("\\s+")) {
         andFilters.add(RowFilter.regexFilter("(?i)" + word));
       }
       sorter.setRowFilter(RowFilter.andFilter(andFilters));
     }
     model.fireTableDataChanged();
   } catch (PatternSyntaxException ex) {
   } catch (ClassCastException ex2) {
     /* eliminate warning */
   }
 }
  /**
   * @param sorter come from the same class of table
   * @param table need a array
   * @param stringFiltre1 filtre no1
   * @param idColFiltre1 col that apply the filtre no1
   * @param stringFiltre2 filtre no2
   * @param idColFiltre2 col that apply the filtre no2
   *     <p>This method handle the double filtrate of an array
   */
  public void doubleFilter(
      TableRowSorter<DefaultTableModel> sorter,
      JTable table,
      String stringFiltre1,
      int idColFiltre1,
      String stringFiltre2,
      int idColFiltre2) {

    RowFilter<DefaultTableModel, Object> rfType = null;
    RowFilter<DefaultTableModel, Object> rfStatus = null;

    System.out.println("double filtre, string 1 :" + stringFiltre1);
    System.out.println("double filtre, string 2 :" + stringFiltre2);

    if (stringFiltre1 == "Tout") {
      stringFiltre1 = "";
    }
    if (stringFiltre2 == "Tout") {
      stringFiltre2 = "";
    }
    rfType = RowFilter.regexFilter(stringFiltre1, idColFiltre1);
    rfStatus = RowFilter.regexFilter(stringFiltre2, idColFiltre2);

    ArrayList<RowFilter<DefaultTableModel, Object>> andFilters =
        new ArrayList<RowFilter<DefaultTableModel, Object>>();
    andFilters.add(rfType);
    andFilters.add(rfStatus);

    sorter.setRowFilter(RowFilter.andFilter(andFilters));

    nbRowsField.setText(table.getRowCount() + " trouvés");
    System.out.println(table.getRowCount());

    setAllAvgField(table, 1, 1, 3, 2);
  }
Esempio n. 5
0
 private void updateFilter() {
   DefaultRowSorter<TableModel, Object> sorter =
       (DefaultRowSorter<TableModel, Object>) otherTable.getRowSorter();
   String key = keyFilter.getSelectedItem().toString();
   RowFilter<TableModel, Object> filter = null;
   if (!key.isEmpty()) {
     Object method = keyFilterMethod.getSelectedItem();
     if (method == STARTS_WITH) {
       filter = RowFilter.regexFilter('^' + Pattern.quote(key), UITableModel.KEY_COLUMN_INDEX);
     } else if (method == ENDS_WITH) {
       filter = RowFilter.regexFilter(Pattern.quote(key) + '$', UITableModel.KEY_COLUMN_INDEX);
     } else if (method == CONTAINS) {
       filter = RowFilter.regexFilter(Pattern.quote(key), UITableModel.KEY_COLUMN_INDEX);
     } else {
       filter = RowFilter.regexFilter(key, UITableModel.KEY_COLUMN_INDEX);
     }
   }
   String type = typeFilter.getSelectedItem().toString();
   if (!type.isEmpty()) {
     RowFilter<TableModel, Object> typeFilter =
         RowFilter.regexFilter('^' + type + '$', UITableModel.TYPE_COLUMN_INDEX);
     filter =
         filter == null
             ? typeFilter
             : RowFilter.<TableModel, Object>andFilter(Arrays.asList(filter, typeFilter));
   }
   sorter.setRowFilter(filter);
 }
  private void filterButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_filterButtonActionPerformed
    m = monthComboBox.getSelectedIndex();
    String yearString = yearField.getText();
    if (yearString.equals("")) {
      JOptionPane.showMessageDialog(null, "Введите год", "Ошибка", JOptionPane.ERROR_MESSAGE);
      return;
    }
    int year = Integer.valueOf(yearString);
    infoLabel.setText(
        "Отображаются записи за "
            + monthComboBox.getSelectedItem().toString()
            + " "
            + yearString
            + " года.");
    infoLabel.setVisible(true);
    Date beginDate = new Date();
    Date endDate = new Date();
    beginDate.setYear(year - 1900);
    beginDate.setMonth(m);
    beginDate.setDate(0);
    endDate.setYear(year - 1900);
    endDate.setMonth(m);
    endDate.setDate(SaldoCalculator.daysQuantity(m, year));

    List<RowFilter<Object, Object>> filters = new ArrayList<>(2);
    filters.add(RowFilter.dateFilter(ComparisonType.AFTER, beginDate));
    filters.add(RowFilter.dateFilter(ComparisonType.BEFORE, endDate));

    TableRowSorter moneySorter = new TableRowSorter(moneyTable.getModel());
    moneySorter.setRowFilter(RowFilter.andFilter(filters));
    moneyTable.setRowSorter(moneySorter);

    TableRowSorter productSorter = new TableRowSorter(productTable.getModel());
    productSorter.setRowFilter(RowFilter.andFilter(filters));
    productTable.setRowSorter(productSorter);
  } // GEN-LAST:event_filterButtonActionPerformed
  /**
   * 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);
  }
Esempio n. 8
0
 private void updateFilters() {
   List<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>(2);
   if (clientFilter != null) {
     filters.add(clientFilter);
   }
   if (numberFilter != null) {
     filters.add(numberFilter);
   }
   if (fromDateFilter != null) {
     filters.add(fromDateFilter);
   }
   if (toDateFilter != null) {
     filters.add(toDateFilter);
   }
   RowFilter<Object, Object> comboFilter = RowFilter.andFilter(filters);
   invoiceTable.setRowFilter(comboFilter);
 }
  /**
   * Update the display after filtering
   *
   * @see org.scilab.modules.ui_data.variablebrowser.SimpleVariableBrowser#updateRowFiltering()
   */
  public void updateRowFiltering() {
    if (isSetData == false) {
        /* If the pull of the data has not been done, do it (please) */
      try {
        ScilabInterpreterManagement.synchronousScilabExec("browsevar");
        isSetData = true;
      } catch (InterpreterException e) {
        System.err.println(e);
      }
    }
    VariableBrowserRowTypeFilter rowTypeFilter =
        new VariableBrowserRowTypeFilter(getFilteredTypeValues());
    VariableBrowserRowDataFilter rowDataFilter =
        new VariableBrowserRowDataFilter(getFilteredDataValues());

    List<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>();
    RowFilter<Object, Object> compoundRowFilter = null;
    filters.add(rowTypeFilter);
    filters.add(rowDataFilter);
    compoundRowFilter = RowFilter.andFilter(filters);

    rowSorter.setRowFilter(compoundRowFilter);
    table.setRowSorter(rowSorter);
  }
  /** Filters table by name, by code, by price. */
  private void applyFilters() {
    List<RowFilter<DiscountCardsTableModel, Integer>> andFilters = new ArrayList<>();
    for (final FilterUnit filterUnit : filters) {
      final int columnIndex = tableModel.findColumn(filterUnit.columnTitle);

      RowFilter<DiscountCardsTableModel, Integer> filter = null;
      if (FilterType.PART_TEXT == filterUnit.filterType) {
        filter =
            RowFilter.regexFilter(("(?iu)" + filterUnit.textField.getText().trim()), columnIndex);
      } else if (FilterType.FULL_TEXT == filterUnit.filterType) {
        filter = RowFilter.regexFilter(filterUnit.textField.getText().trim(), columnIndex);
      } else if (FilterType.NUMBER == filterUnit.filterType
          || FilterType.NUMBER_DIAPASON == filterUnit.filterType
              && !filterUnit.textField.getText().contains("-")) {
        if (filterUnit.textField.getText().length() > 0) {
          String numberStr =
              filterUnit.textField.getText().trim().replace(",", ".").replaceAll("[^0-9.]", "");
          Double number = Double.parseDouble(numberStr);
          filter = RowFilter.numberFilter(RowFilter.ComparisonType.EQUAL, number, columnIndex);
        }
      } else if (FilterType.NUMBER_DIAPASON == filterUnit.filterType) {
        if (filterUnit.textField.getText().length() > 0) {
          String[] numbers = filterUnit.textField.getText().split("-", 2);
          if (numbers.length > 1 && !numbers[0].trim().isEmpty() && !numbers[1].trim().isEmpty()) {
            String numbers0 = numbers[0].replace(",", ".").replaceAll("[^0-9.]", "");
            String numbers1 = numbers[1].replace(",", ".").replaceAll("[^0-9.]", "");
            final Double number1 = Double.parseDouble(numbers0);
            final Double number2 = Double.parseDouble(numbers1);
            filter =
                new RowFilter<DiscountCardsTableModel, Integer>() {
                  @Override
                  public boolean include(
                      Entry<? extends DiscountCardsTableModel, ? extends Integer> entry) {
                    Double number =
                        (Double) tableModel.getRawValueAt(entry.getIdentifier(), columnIndex);
                    return number > number1 && number < number2;
                  }
                };
          }
        }
      } else if (FilterType.NUMBER_MORE == filterUnit.filterType) {
        if (filterUnit.textField.getText().length() > 0) {
          String numberStr =
              filterUnit.textField.getText().trim().replace(",", ".").replaceAll("[^0-9.]", "");
          final Double number = Double.parseDouble(numberStr);
          filter =
              new RowFilter<DiscountCardsTableModel, Integer>() {
                @Override
                public boolean include(
                    Entry<? extends DiscountCardsTableModel, ? extends Integer> entry) {
                  Double numberEntry =
                      (Double) tableModel.getRawValueAt(entry.getIdentifier(), columnIndex);
                  return numberEntry >= number;
                }
              };
        }

      } else if (FilterType.DATE == filterUnit.filterType
          || FilterType.DATE_DIAPASON == filterUnit.filterType
              && !filterUnit.textField.getText().contains("-")) {
        if (filterUnit.textField.getText().length() > 0) {
          final Date correctedDate = getCorrectedDate(filterUnit.textField.getText().trim());
          filter =
              new RowFilter<DiscountCardsTableModel, Integer>() {
                @Override
                public boolean include(
                    Entry<? extends DiscountCardsTableModel, ? extends Integer> entry) {
                  Object dateObject = tableModel.getRawValueAt(entry.getIdentifier(), columnIndex);
                  if (dateObject != null) {
                    Date date;
                    if (dateObject instanceof Date) {
                      date = (Date) dateObject;
                    } else if (dateObject instanceof Calendar) {
                      date = ((Calendar) dateObject).getTime();
                    } else {
                      throw new RuntimeException(
                          "Unsupported class for DATE filterType! " + dateObject.getClass());
                    }
                    return date.after(addDays(correctedDate, -1))
                        && date.before(addDays(correctedDate, 1));
                  } else {
                    return false;
                  }
                }
              };
        }
      } else if (FilterType.DATE_DIAPASON == filterUnit.filterType) {
        if (filterUnit.textField.getText().length() > 0) {
          String[] dates = filterUnit.textField.getText().split("-", 2);
          if (dates.length > 1 && !dates[0].trim().isEmpty() && !dates[1].trim().isEmpty()) {
            final Date correctedDate1 = getCorrectedDate(dates[0]);
            final Date correctedDate2 = getCorrectedDate(dates[1]);
            filter =
                new RowFilter<DiscountCardsTableModel, Integer>() {
                  @Override
                  public boolean include(
                      Entry<? extends DiscountCardsTableModel, ? extends Integer> entry) {
                    Object saleDateObj =
                        tableModel.getRawValueAt(entry.getIdentifier(), columnIndex);
                    if (saleDateObj != null) {
                      Date date =
                          ((Calendar) tableModel.getRawValueAt(entry.getIdentifier(), columnIndex))
                              .getTime();
                      return date.after(addDays(correctedDate1, -1))
                          && date.before(addDays(correctedDate2, 1));
                    } else {
                      return false;
                    }
                  }
                };
          }
        }
      } else if (FilterType.CHECKBOXES == filterUnit.filterType) {
        if (anyDeselected(filterUnit.checkBoxes)) {
          filter =
              new RowFilter<DiscountCardsTableModel, Integer>() {
                @Override
                public boolean include(
                    Entry<? extends DiscountCardsTableModel, ? extends Integer> entry) {
                  Object columnObject =
                      tableModel.getRawValueAt(entry.getIdentifier(), columnIndex);
                  return correspondsToCheckBoxes(filterUnit.checkBoxes, columnObject);
                }
              };
        }
      }
      if (filter != null) {
        andFilters.add(filter);
      }
      sorter.setRowFilter(RowFilter.andFilter(andFilters));
    }
  }