예제 #1
0
 /* (non-Javadoc)
  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 public void actionPerformed(ActionEvent evt) {
   isSearchDown = true;
   Object source = evt.getSource();
   TableSearcher tableSearcher = createTableSearcher();
   if (source == nextButton) {
     log.debug("nextButton --------------------------------------------------------");
     isSearchDown = true;
   } else if (source == previousButton) {
     log.debug("previousButton --------------------------------------------------------");
     isSearchDown = false;
   }
   int replacementCount = 0;
   UsageTracker.incrUsageCount("WB.FindButton");
   setCheckAndSetWrapOption();
   log.debug("action performed");
   final String findValue = getFindFieldValue();
   int curRow = foundCell == null ? table.getSelectedRow() : foundCell.getRow();
   int curCol = foundCell == null ? table.getSelectedColumn() - 1 : foundCell.getColumn();
   TableSearcherCell cell =
       tableSearcher.findNext(
           findValue,
           curRow,
           curCol,
           isSearchDown(),
           getWrapSearchFlag(),
           getMatchCaseFlag(),
           isSearchSelection());
   if (cell.isFound()) {
     replacementCount++;
     foundCell = cell;
   } else {
     // foundCell = null;
   }
   updateTableUiForFoundValue(cell, replacementCount, false);
 }
예제 #2
0
 /**
  * @param shouldShow - flag noting whether the panel should be visible
  * @return the find/replace panel to be displayed
  */
 protected JPanel showFindAndReplacePanel(boolean shouldShow) {
   if (!shouldShow) {
     this.setVisible(false);
   } else {
     stopTableEditing();
     this.setVisible(true);
     findField.requestFocusInWindow();
     UsageTracker.incrUsageCount("WB.ShowFindReplace");
   }
   return this;
 }
예제 #3
0
    /* (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent evt) {
      Object source = evt.getSource();
      setCheckAndSetWrapOption();
      final String replaceValue = getRepalceFieldValue();
      final String findValue = getFindFieldValue();
      TableSearcherCell cell = null;
      if (source == replaceAllButton) {
        log.debug("replaceAllButton --------------------------------------------------------");
        TableSearcher tableSearcher = createTableSearcher();
        int selectedCol = 0;
        int selectedRow = 0;
        int rowCount = table.getModel().getRowCount();
        int colCount = table.getModel().getColumnCount();
        boolean found = false;
        boolean oldBatchMode = table.getModel().isBatchMode();
        cell =
            tableSearcher.checkCell(
                getFindFieldValue(),
                selectedRow,
                selectedCol,
                getMatchCaseFlag(),
                isSearchSelection());
        try {
          table.getModel().setBatchMode(true);
          while ((selectedRow > -1)
              && (selectedCol > -1)
              && (selectedRow <= rowCount - 1)
              && (selectedCol <= colCount - 1)) {
            found = cell.isFound();
            if (found) {
              tableSearcher.replace(
                  cell, findValue, replaceValue, getMatchCaseFlag(), isSearchSelection());
            }
            cell =
                tableSearcher.findNext(
                    findValue,
                    selectedRow,
                    selectedCol,
                    true,
                    false,
                    getMatchCaseFlag(),
                    isSearchSelection());
            selectedCol = cell.getColumn();
            selectedRow = cell.getRow();
          }
        } finally {
          table.getModel().setBatchMode(oldBatchMode);
        }
        tableSearcher.replacementCleanup();
        updateTableUiForFoundValue(cell, tableSearcher.getReplacementCount(), true);
        UsageTracker.incrUsageCount("WB.ReplaceAllButton");
      } else if (source == replaceButton) {
        if (!canReplace()) {
          if (isSearchSelection()) {
            UIRegistry.displayInfoMsgDlgLocalized("SearchReplacePanel.UnableToReplaceSelection");
          } else {
            UIRegistry.displayInfoMsgDlgLocalized("SearchReplacePanel.UnableToReplace");
          }
          return;
        }
        log.debug("replaceButton --------------------------------------------------------");
        TableSearcher tableSearcher = createTableSearcher();
        int selectedCol = foundCell == null ? table.getSelectedColumn() - 1 : foundCell.getColumn();
        int selectedRow = foundCell == null ? table.getSelectedRow() : foundCell.getRow();

        cell =
            tableSearcher.checkCell(
                getFindFieldValue(),
                selectedRow,
                selectedCol,
                getMatchCaseFlag(),
                isSearchSelection());
        if (cell.isFound()) {
          tableSearcher.replace(
              cell, findValue, replaceValue, getMatchCaseFlag(), isSearchSelection());
          tableSearcher.replacementCleanup();
          selectedCol = cell.getColumn();
          selectedRow = cell.getRow();

          cell =
              tableSearcher.findNext(
                  findValue,
                  selectedRow,
                  selectedCol,
                  isSearchDown(),
                  getWrapSearchFlag(),
                  getMatchCaseFlag(),
                  isSearchSelection());
          if (cell.isFound()) {
            foundCell = cell;
            updateTableUiForFoundValue(foundCell, tableSearcher.getReplacementCount(), true);
          } else {
            foundCell = null;
          }
        } else {
          setStatusLabelWithFailedFind();
        }
        UsageTracker.incrUsageCount("WB.ReplaceButton");
      }
    }