Exemplo n.º 1
0
  /**
   * @see
   *     org.eclipse.search.internal.ui.text.FileSearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
   */
  public IStatus run(final IProgressMonitor monitor) {
    AbstractTextSearchResult textResult = (AbstractTextSearchResult) this.getSearchResult();
    textResult.removeAll();

    Pattern searchPattern = this.getSearchPattern();
    boolean isFileSearchOnly = searchPattern.pattern().length() == 0;
    boolean searchInBinaries = !this.isScopeAllFileTypes();

    if (this.directory != null || this.isOpenEditorsOnly) {
      boolean onlyFilesEditorInput = isAllOpenEditorsOnWorkspace();
      if (!onlyFilesEditorInput || !isOpenEditorsOnly) {
        FileTextSearchResultCollector fcollector =
            new FileTextSearchResultCollector(textResult, isFileSearchOnly, searchInBinaries);
        String fs = directory == null ? "." : directory; // $NON-NLS-1$
        FileSystemTextSearchScope newSearchScope =
            FileNamePatternSearchScope.newSearchScope(
                new File[] {new File(fs)}, this.fScope.getFileNamePatterns());
        newSearchScope.setOpenEditors(this.isOpenEditorsOnly);
        return FileTextSearchEngine.createDefault()
            .search(newSearchScope, fcollector, searchPattern, monitor);
      }
    }
    TextSearchResultCollector collector =
        new TextSearchResultCollector(textResult, isFileSearchOnly, searchInBinaries);
    AptanaTextEngine aptanaTextEngine = new AptanaTextEngine();
    aptanaTextEngine.setOpenEditorsOnly(this.isOpenEditorsOnly);
    aptanaTextEngine.needsRefresh(this.refresh);
    return aptanaTextEngine.search(this.fScope, collector, searchPattern, monitor);
  }
Exemplo n.º 2
0
  private String getColoredLabelWithCounts(Object element, String coloredName) {
    AbstractTextSearchResult result = fPage.getInput();
    if (result == null) return coloredName;

    int matchCount = result.getMatchCount(element);
    if (matchCount <= 1) return coloredName;

    String countInfo =
        Messages.format(SearchMessages.FileLabelProvider_count_format, new Integer(matchCount));
    coloredName += " ";
    coloredName += countInfo;
    return coloredName;
  }
  private StyledString getColoredLabelWithCounts(Object element, StyledString coloredName) {
    AbstractTextSearchResult result = fPage.getInput();
    if (result == null) {
      return coloredName;
    }

    int matchCount = result.getMatchCount(element);
    if (matchCount <= 1) {
      return coloredName;
    }

    String countInfo = MessageFormat.format("({0} matches)", matchCount);
    coloredName.append(' ').append(countInfo, StyledString.COUNTER_STYLER);
    return coloredName;
  }
Exemplo n.º 4
0
 private boolean hasMatches(Object element) {
   if (element instanceof LineElement) {
     LineElement lineElement = (LineElement) element;
     return lineElement.getNumberOfMatches(fResult) > 0;
   }
   return fResult.getMatchCount(element) > 0;
 }
Exemplo n.º 5
0
 public int getNumberOfMatches(AbstractTextSearchResult result) {
   int count = 0;
   Match[] matches = result.getMatches(fParent);
   for (int i = 0; i < matches.length; i++) {
     AbstractMatch curr = (AbstractMatch) matches[i];
     if (curr.getLineElement() == this) {
       count++;
     }
   }
   return count;
 }
Exemplo n.º 6
0
 public AbstractMatch[] getMatches(AbstractTextSearchResult result) {
   List<AbstractMatch> res = new ArrayList<AbstractMatch>();
   Match[] matches = result.getMatches(fParent);
   for (int i = 0; i < matches.length; i++) {
     AbstractMatch curr = (AbstractMatch) matches[i];
     if (curr.getLineElement() == this) {
       res.add(curr);
     }
   }
   return res.toArray(new AbstractMatch[res.size()]);
 }
Exemplo n.º 7
0
  private synchronized void initialize(AbstractTextSearchResult result) {
    fResult = result;
    fChildrenMap = new HashMap();
    boolean showLineMatches = !((Q7SearchQuery) fResult.getQuery()).isFileNameSearch();

    if (result != null) {
      Object[] elements = result.getElements();
      for (int i = 0; i < elements.length; i++) {
        if (showLineMatches) {
          Match[] matches = result.getMatches(elements[i]);
          for (int j = 0; j < matches.length; j++) {
            insert(
                ((org.eclipse.search.internal.ui.text.FileMatch) matches[j]).getLineElement(),
                false);
          }
        } else {
          insert(elements[i], false);
        }
      }
    }
  }
Exemplo n.º 8
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.search.internal.ui.text.IFileSearchContentProvider#
  * elementsChanged(java.lang.Object[])
  */
 public synchronized void elementsChanged(Object[] updatedElements) {
   for (int i = 0; i < updatedElements.length; i++) {
     if (!(updatedElements[i] instanceof LineElement)) {
       // change events to elements are reported in file search
       if (fResult.getMatchCount(updatedElements[i]) > 0) insert(updatedElements[i], true);
       else remove(updatedElements[i], true);
     } else {
       // change events to line elements are reported in text search
       LineElement lineElement = (LineElement) updatedElements[i];
       int nMatches = lineElement.getNumberOfMatches(fResult);
       if (nMatches > 0) {
         if (hasChild(lineElement.getParent(), lineElement)) {
           fTreeViewer.update(new Object[] {lineElement, lineElement.getParent()}, null);
         } else {
           insert(lineElement, true);
         }
       } else {
         remove(lineElement, true);
       }
     }
   }
 }
Exemplo n.º 9
0
 private void insert(Object child, boolean refreshViewer) {
   int searchFor = ((Q7SearchQuery) fResult.getQuery()).getSearchFor();
   boolean isDependencySearch =
       searchFor == Q7SearchQuery.CONTEXTS_BY_ID
           || searchFor == Q7SearchQuery.TESTCASE_BY_ID
           || searchFor == Q7SearchQuery.VERIFICATION_BY_ID;
   if (isDependencySearch) {
     child = getParent(child);
   }
   Object parent = getParent(child);
   while (parent != null) {
     if (insertChild(parent, child)) {
       if (refreshViewer) fTreeViewer.add(parent, child);
     } else {
       if (refreshViewer) fTreeViewer.refresh(parent);
       return;
     }
     child = parent;
     parent = getParent(child);
   }
   if (insertChild(fResult, child)) {
     if (refreshViewer) fTreeViewer.add(fResult, child);
   }
 }