示例#1
1
 // Фильтрация классификаторов
 public void setClassifierFilter(String beginsWith) {
   TableRowSorter<AbstractTableModel> sorter = new TableRowSorter<>(table.getModel());
   RowFilter<Object, Object> rf = RowFilter.regexFilter("^" + beginsWith, 0);
   table.setRowSorter(sorter);
   sorter.setRowFilter(rf);
 }
示例#2
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);
  }
  /**
   * @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);
  }
  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));
      }
    }
  }
示例#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);
 }
 public void actionPerformed(ActionEvent arg0) {
   if (cmbEstablecimientos.getSelectedIndex() != 0) {
     trsfiltro.setRowFilter(
         RowFilter.regexFilter(cmbEstablecimientos.getSelectedItem() + "", 3));
   } else {
     trsfiltro.setRowFilter(RowFilter.regexFilter("", 2));
   }
 }
示例#7
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 */
   }
 }
示例#8
0
 private void buscarJtblPagos() throws Exception {
   if (jtable.getModel().getRowCount() > 0) {
     String msg = jtfBuscar.getText();
     javax.swing.table.TableRowSorter modeloOrdenado =
         new javax.swing.table.TableRowSorter(jtable.getModel());
     modeloOrdenado.setRowFilter(javax.swing.RowFilter.regexFilter(msg));
     jtable.setRowSorter(modeloOrdenado);
   }
 }
 // This method is used to filter table by column
 protected void update_filter() {
   txt_search_word.setText("");
   Object selected = cmb_search_catagory.getSelectedItem();
   TableRowSorter<?> sorter = (TableRowSorter<?>) tbl_service_details.getRowSorter();
   String text = "(?i)" + txt_search_text.getText();
   if ("Nothing".equals(selected)) {
     sorter.setRowFilter(null);
   } else {
     int col = -1;
     if ("Customer Name".equals(selected)) {
       col = 1;
     } else if ("Vehicle Number".equals(selected)) {
       col = 3;
     }
     sorter.setRowFilter(RowFilter.regexFilter(text, col));
   }
 }
示例#10
0
  private void jBPesquisarActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jBPesquisarActionPerformed
    // TODO add your handling code here:

    String text = jTFPesquisar.getText();

    if (text.length() == 0) {
      sorter.setRowFilter(null);
    } else {
      try {
        sorter.setRowFilter(RowFilter.regexFilter(text));
      } catch (PatternSyntaxException pse) {
        JOptionPane.showMessageDialog(null, "Bad regex pattern");

      } catch (RuntimeException ex2) {
        JOptionPane.showMessageDialog(null, "Erro: " + ex2.getMessage());
      }
    }
  } // GEN-LAST:event_jBPesquisarActionPerformed
示例#11
0
  public static void cargarjugadorestorneo() {

    id_torneo = Principal.labelserialtorneo.getText();
    equipo = id_torneo + labelserial.getText();

    try {
      String[] titulos = {"N°", "Cedula", "Nombre", "Apellido"};
      String[] registro = new String[4];
      String sql =
          "Select hj.n_nomina ,j.cedula, j.nombre_j, j.apellido_j from jugador j, h_jugador hj where hj.cedula=j.cedula and hj.id_torneo='"
              + id_torneo
              + "' and hj.id_equipo='"
              + equipo
              + "' order by hj.n_nomina;";
      Conexion parametro = new Conexion();
      Class.forName(parametro.getDriver());
      Connection con =
          DriverManager.getConnection(
              parametro.getURL(), parametro.getUsuario(), parametro.getPass());
      modelo1 = new DefaultTableModel(null, titulos);
      Statement st =
          con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = st.executeQuery(sql);
      while (rs.next()) {
        registro[0] = rs.getString("hj.n_nomina");
        registro[1] = rs.getString("j.cedula");
        registro[2] = rs.getString("j.nombre_j");
        registro[3] = rs.getString("j.apellido_j");
        modelo1.addRow(registro);
      }
      jugadorestorneo.setModel(modelo1);
      jugadorestorneo.getColumnModel().getColumn(0).setPreferredWidth(27);
      jugadorestorneo.getColumnModel().getColumn(1).setPreferredWidth(135);
      jugadorestorneo.getColumnModel().getColumn(2).setPreferredWidth(135);
      jugadorestorneo.getColumnModel().getColumn(3).setPreferredWidth(135);
      TableRowSorter modeloordenado = new TableRowSorter(modelo1);
      jugadorestorneo.setRowSorter(modeloordenado);
      modeloordenado.setRowFilter(RowFilter.regexFilter(filtro2.getText()));

    } catch (SQLException | ClassNotFoundException ex) {
      Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
示例#12
0
  public void Pesquisar(String texto) {

    String textoInicialMaiuscula = "";

    if (texto != null && !texto.trim().equals("")) {
      textoInicialMaiuscula = texto.substring(0, 1).toUpperCase().concat(texto.substring(1));
    }

    if (textoInicialMaiuscula.length() == 0) {
      sorter.setRowFilter(null);
    } else {
      try {
        sorter.setRowFilter(RowFilter.regexFilter(textoInicialMaiuscula));
      } catch (PatternSyntaxException pse) {
        JOptionPane.showMessageDialog(null, "Bad regex pattern");

      } catch (RuntimeException ex2) {
        JOptionPane.showMessageDialog(null, "Erro: " + ex2.getMessage());
      }
    }

    tabela.grabFocus();
  }
 private void procurar(String texto) {
   TableRowSorter<AbstractTableModel> tr = new TableRowSorter<AbstractTableModel>(table);
   jTable1.setRowSorter(tr);
   tr.setRowFilter(RowFilter.regexFilter("(?i)" + texto));
 }
  /** 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));
    }
  }
示例#15
0
 protected void do_button_actionPerformed(ActionEvent e) {
   sorter.setRowFilter(RowFilter.regexFilter(textField.getText()));
 }
 public void keyReleased(KeyEvent arg0) {
   trsfiltro.setRowFilter(RowFilter.regexFilter(txtFolio.getText(), 1));
 }
 public void keyReleased(KeyEvent arg0) {
   trsfiltro.setRowFilter(
       RowFilter.regexFilter(txtNombre_Completo.getText().toUpperCase().trim(), 2));
 }
示例#18
-1
  private void jBPesquisarKeyTyped(
      java.awt.event.KeyEvent evt) { // GEN-FIRST:event_jBPesquisarKeyTyped

    if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
      if (evt.getSource() == jBPesquisar) {

        String text = jTFPesquisar.getText();

        if (text.length() == 0) {
          sorter.setRowFilter(null);
        } else {
          try {
            sorter.setRowFilter(RowFilter.regexFilter(text));
            int total = calculaTotalPecas(text);
            jLabelTotalPecas.setText(String.valueOf(total));
          } catch (PatternSyntaxException pse) {
            JOptionPane.showMessageDialog(this, "Erro na pesquisa");
          } catch (RuntimeException ex2) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex2.getMessage());
          }
        }
      }
    }
    tabela.grabFocus();
  } // GEN-LAST:event_jBPesquisarKeyTyped