org.netbeans.spi.quicksearch.SearchRequest Java Examples

The following examples show how to use org.netbeans.spi.quicksearch.SearchRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataAccessSearchProvider.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void evaluate(final SearchRequest request, final SearchResponse response) {
    final String text = request.getText().toLowerCase();
    final Map<String, List<DataAccessPlugin>> plugins = DataAccessPane.lookupPlugins();

    final List<String> pluginNames = new ArrayList<>();
    plugins.values().stream().forEach(dapl -> {
        for (final DataAccessPlugin dap : dapl) {
            if (dap.getName().toLowerCase().contains(text)) {
                pluginNames.add(dap.getName());
            }
        }
    });

    Collections.sort(pluginNames, (a, b) -> a.compareToIgnoreCase(b));

    for (final String name : pluginNames) {
        if (!response.addResult(new PluginDisplayer(name), name)) {
            return;
        }
    }
}
 
Example #2
Source File: ResultsModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String highlightSubstring (String text, SearchRequest sRequest) {
    if (text.startsWith(HTML)) {
        // provider handles highliting itself, okay
        return text;
    }
    // try to find substring
    String searchedText = sRequest.getText();
    int index = text.toLowerCase(Locale.ENGLISH).indexOf(searchedText.toLowerCase(Locale.ENGLISH));
    if (index == -1) {
        return HTML + safeEscape(text);
    }
    // found, bold it
    int endIndex = index + searchedText.length();
    StringBuilder sb = new StringBuilder(HTML);
    if (index > 0) {
        sb.append(safeEscape(text.substring(0, index)));
    }
    sb.append("<b>");
    sb.append(safeEscape(text.substring(index, endIndex)));
    sb.append("</b>");
    if (endIndex < text.length()) {
        sb.append(safeEscape(text.substring(endIndex, text.length())));
    }
    return sb.toString();
}
 
Example #3
Source File: CommandEvaluator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Runs evaluation.
 *
 * @param command text to evauate, to search for
 *
 * @return task of this evaluation, which waits for all providers to complete
 * execution. Use returned instance to recognize if this evaluation still
 * runs and when it actually will finish.
 */
public static org.openide.util.Task evaluate (String command, ResultsModel model) {
    List<CategoryResult> l = new ArrayList<CategoryResult>();
    String[] commands = parseCommand(command);
    SearchRequest sRequest = Accessor.DEFAULT.createRequest(commands[1], null);
    List<Task> tasks = new ArrayList<Task>();

    List<Category> provCats = new ArrayList<Category>();
    boolean allResults = getProviderCategories(commands, provCats);

    for (ProviderModel.Category curCat : provCats) {
        CategoryResult catResult = new CategoryResult(curCat, allResults);
        SearchResponse sResponse = Accessor.DEFAULT.createResponse(catResult, sRequest);
        for (SearchProvider provider : curCat.getProviders()) {
            Task t = runEvaluation(provider, sRequest, sResponse, curCat);
            if (t != null) {
                tasks.add(t);
            }
        }
        l.add(catResult);
    }

    model.setContent(l);

    return new Wait4AllTask(tasks);
}
 
Example #4
Source File: RecentProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void evaluate(SearchRequest request, SearchResponse response) {
    boolean atLeastOne = false;
    boolean limitReached = false;
    for (ItemResult itemR : RecentSearches.getDefault().getSearches()) {
        if (itemR.getDisplayName().toLowerCase().indexOf(request.getText().toLowerCase()) != -1) {
            if (!response.addResult(itemR.getAction(), itemR.getDisplayName(),
                    itemR.getDisplayHint(), itemR.getShortcut())) {
                limitReached = true;
                break;
            } else {
                atLeastOne = true;
            }
        }
    }
    if (atLeastOne && !limitReached && request.getText().isEmpty()) {
        addClearAction(response);
    }
}
 
Example #5
Source File: QuickSearchProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
   public void evaluate(SearchRequest request, SearchResponse response) {
readKeywordsFromNewAnnotation();
       for (Lookup.Item<OptionsCategory> entry : getODCategories()) {
           for (Map.Entry<String, Set<String>> kw : getKeywords(entry).entrySet()) {
               for (String keywords : kw.getValue()) {
	    for (String keyword : Arrays.asList(keywords.split(","))) {
		if (keyword.toLowerCase().indexOf(request.getText().toLowerCase()) > -1) {
		    String path = entry.getId().substring(entry.getId().indexOf("/") + 1);  // NOI18N
		    if (kw.getKey().contains("/")) {
			path = path + kw.getKey().substring(kw.getKey().indexOf("/")); //NOI18N
		    }
		    if (!response.addResult(new OpenOption(path), keyword)) {
			return;
		    }
		}
	    }
               }
           }
       }
   }
 
Example #6
Source File: ActionsSearchProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean doEvaluation(String name, SearchRequest request,
        ActionInfo actInfo, SearchResponse response, List<ActionInfo> possibleResults, Map<Object, String> duplicateCheck) {
    int index = name.toLowerCase().indexOf(request.getText().toLowerCase());
    if (index == 0) {
        return addAction(actInfo, response, duplicateCheck);
    } else if (index != -1) {
        // typed text is contained in action name, but not as prefix,
        // store such actions if there are not enough "prefix" actions
        possibleResults.add(actInfo);
    }
    return true;
}
 
Example #7
Source File: JavaHelpQuickSearchProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void evaluate(SearchRequest request, SearchResponse response) {
    synchronized( this ) {
        if( null == query ) {
            query = JavaHelpQuery.getDefault();
        }
    }
    List<SearchTOCItem> res = query.search( request.getText() );
    for( SearchTOCItem item : res ) {
        if( !response.addResult( createAction( item.getURL() ), item.getName() ) )
            return;
    }
}
 
Example #8
Source File: SearchProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override public void evaluate(SearchRequest request, SearchResponse response) {
    String text = request.getText();
    if (text == null) {
        return;
    }
    if (!Utilities.isHudsonSupportActive()) {
        return;
    }
    work(text, response);
}
 
Example #9
Source File: ResultsModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ItemResult (CategoryResult category, SearchRequest sRequest, 
        Runnable action, String displayName, List<? extends KeyStroke> shortcut,
        String displayHint) {
    this.category = category;
    this.action = action;
    this.displayName = sRequest != null ?
        highlightSubstring(displayName, sRequest) : displayName;
    this.shortcut = shortcut;
    this.displayHint = displayHint;
}
 
Example #10
Source File: WebQuickSearchProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void evaluate(SearchRequest request, SearchResponse response) {
    if( null == query ) {
        query = Query.getDefault();
    }
    Result res = query.search( request.getText() );
    do {
        for( Item item : res.getItems() ) {
            if( !response.addResult( createAction( item.getUrl() ), item.getTitle() ) )
                return;
        }
        res = query.searchMore( request.getText() );
    } while( !res.isSearchFinished() );
}
 
Example #11
Source File: CommandEvaluator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Task runEvaluation (final SearchProvider provider, final SearchRequest request,
                            final SearchResponse response, final ProviderModel.Category cat) {
    return RP.post(new Runnable() {
        @Override
        public void run() {
            provider.evaluate(request, response);
        }
    });
}
 
Example #12
Source File: GoToSymbolProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void evaluate(SearchRequest request, SearchResponse response) {
    String text = removeNonJavaChars(request.getText());
    if(text.length() == 0) {
        return;
    }
    GoToSymbolWorker local;
    synchronized(this) {
        if (worker!=null) {
            worker.cancel();
        }
        worker = new GoToSymbolWorker(text);
        local = worker;
    }
    local.run();
    
    for (SymbolDescriptor td : local.getTypes()) {
        String displayHint = td.getFileDisplayPath();
        String htmlDisplayName = escapeLtGt(td.getSymbolName()) + " " + NbBundle.getMessage(GoToSymbolAction.class, "MSG_DeclaredIn",escapeLtGt(td.getOwnerName()));
        final String projectName = td.getProjectName();
        if (projectName != null && !projectName.isEmpty()) {
            htmlDisplayName = String.format(
                "%s [%s]",  //NOI18N
                htmlDisplayName,
                projectName);
        }
        if (!response.addResult(new GoToSymbolCommand(td),
                                htmlDisplayName,
                                displayHint,
                                null)) {
            break;
        }
    }
}
 
Example #13
Source File: JavaTypeSearchProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate(SearchRequest request, SearchResponse response) {
    String text = removeNonJavaChars(request.getText());
    if(text.length() == 0) {
        return;
    }

    final GoToTypeWorker newWorker = new GoToTypeWorker(text);
    final GoToTypeWorker toCancel = workerRef.getAndSet(newWorker);
    if (toCancel != null) {
        toCancel.cancel();
    }
    try {
        newWorker.run();
    } finally {
        workerRef.compareAndSet(newWorker, null);
    }
    
    for (TypeDescriptor td : newWorker.getTypes()) {
        String displayHint = td.getFileDisplayPath();
        String htmlDisplayName = td.getSimpleName() + td.getContextName();
        final String projectName = td.getProjectName();
        if (projectName != null && !projectName.isEmpty()) {
            htmlDisplayName = String.format(
                "%s [%s]",  //NOI18N
                htmlDisplayName,
                projectName);
        }
        if (!response.addResult(new GoToTypeCommand(td),
                                htmlDisplayName,
                                displayHint,
                                null)) {
            break;
        }
    }
}
 
Example #14
Source File: SlowProviderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void evaluate(SearchRequest request, SearchResponse response) {
    try {
        Thread.sleep(5000);
    } catch (InterruptedException ex) {
        System.err.println("SlowProvider interrupted...");
    }
}
 
Example #15
Source File: SearchForProjectsQuickSearch.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate(SearchRequest request, SearchResponse response) {
    final String searchText = request.getText().toLowerCase();

    for (final Project project : OpenProjects.getDefault().getOpenProjects()) {
        final ProjectInformation info = ProjectUtils.getInformation(project);
        if (info == null || info.getDisplayName() == null) {
            continue;
        }
        final String projectName = info.getDisplayName();
        final String projectNameLower = projectName.toLowerCase();

        if (projectNameLower.contains(searchText)) {
            final boolean result = response.addResult(new Runnable() {
                @Override
                public void run() {
                    //see http://forums.netbeans.org/post-140855.html#140855
                    ProjectUtilities.selectAndExpandProject(project);
                    ProjectUtilities.makeProjectTabVisible();
                }
            }, projectName);
            if (!result) {
                break;
            }
        }
    }
}
 
Example #16
Source File: MavenRepoProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Method is called by infrastructure when search operation was requested.
 * Implementors should evaluate given request and fill response object with
 * appropriate results
 *
 * @param request Search request object that contains information what to search for
 * @param response Search response object that stores search results. Note that it's important to react to return value of SearchResponse.addResult(...) method and stop computation if false value is returned.
 */
@Override
public void evaluate(final SearchRequest request, final SearchResponse response) {
    final ArtifactNodeSelector s = Lookup.getDefault().lookup(ArtifactNodeSelector.class);
    if (s == null) {
        return;
    }
    final String q = request.getText();
    if (q == null || q.trim().isEmpty()) {
        //#205552
        return;
    }
    
    final List<RepositoryInfo> loadedRepos = RepositoryQueries.getLoadedContexts();
    if (loadedRepos.isEmpty()) {
        return;
    }

    List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>();
    final List<NBVersionInfo> tempInfos = new ArrayList<NBVersionInfo>();

    final RequestProcessor.Task searchTask = RP.post(new Runnable() {
        @Override
        public void run() {
            try {
                Result<NBVersionInfo> result = RepositoryQueries.findResult(getQuery(q), loadedRepos);
                synchronized (tempInfos) {
                    tempInfos.addAll(result.getResults());
                }
            } catch (BooleanQuery.TooManyClauses exc) {
                // query too general, just ignore it
                synchronized (tempInfos) {
                    tempInfos.clear();
                }
            } catch (OutOfMemoryError oome) {
                // running into OOME may still happen in Lucene despite the fact that
                // we are trying hard to prevent it in NexusRepositoryIndexerImpl
                // (see #190265)
                // in the bad circumstances theoretically any thread may encounter OOME
                // but most probably this thread will be it
                synchronized (tempInfos) {
                    tempInfos.clear();
                }
            }
        }
    });
    try {
        // wait maximum 5 seconds for the repository search to complete
        // after the timeout tempInfos should contain at least partial results
        // we are not waiting longer, repository index download may be running on the background
        // because NexusRepositoryIndexerImpl.getLoaded() might have returned also repos
        // which are not available for the search yet
        searchTask.waitFinished(5000);
    } catch (InterruptedException ex) {
    }
    synchronized (tempInfos) {
        infos.addAll(tempInfos);
    }
    searchTask.cancel();

    Collections.sort(infos);
    Set<String> artifacts = new HashSet<String>();
    String ql = q.toLowerCase(Locale.ENGLISH);
    for (final NBVersionInfo art : infos) {
        String label = art.getGroupId() + " : " + art.getArtifactId();
        if (!artifacts.add(label)) {
            continue; // ignore older versions
        }
        if (!label.toLowerCase(Locale.ENGLISH).contains(ql)) {
            String projectName = art.getProjectName();
            String projectDescription = art.getProjectDescription();
            if (projectName != null && projectName.toLowerCase(Locale.ENGLISH).contains(ql)) {
                label += " (" + projectName + ")";
            } else if (projectDescription != null && projectDescription.toLowerCase(Locale.ENGLISH).contains(ql)) {
                label += " \"" + projectDescription + "\"";
            }
        }
        if (!response.addResult(new Runnable() {
            @Override public void run() {
                s.select(art);
            }
        }, label)) {
            return;
        }
    }
}
 
Example #17
Source File: ProviderModelTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void evaluate(SearchRequest request, SearchResponse response) {
    // no operation
}
 
Example #18
Source File: ProviderModelTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void evaluate(SearchRequest request, SearchResponse response) {
    // no operation
}
 
Example #19
Source File: ResultsModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ItemResult (CategoryResult category, SearchRequest sRequest,
        Runnable action, String displayName) {
    this(category, sRequest, action, displayName, null, null);
}
 
Example #20
Source File: Accessor.java    From netbeans with Apache License 2.0 votes vote down vote up
public abstract SearchResponse createResponse (CategoryResult catResult, SearchRequest sRequest); 
Example #21
Source File: Accessor.java    From netbeans with Apache License 2.0 votes vote down vote up
public abstract SearchRequest createRequest (String text, List<? extends KeyStroke> stroke);