org.netbeans.spi.quicksearch.SearchResponse Java Examples
The following examples show how to use
org.netbeans.spi.quicksearch.SearchResponse.
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: NodeQuickSearch.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private List<InputNode> findMatches(String name, String value, InputGraph inputGraph, SearchResponse response) { try { RegexpPropertyMatcher matcher = new RegexpPropertyMatcher(name, value, Pattern.CASE_INSENSITIVE); Properties.PropertySelector<InputNode> selector = new Properties.PropertySelector<>(inputGraph.getNodes()); List<InputNode> matches = selector.selectMultiple(matcher); return matches.size() == 0 ? null : matches; } catch (Exception e) { final String msg = e.getMessage(); response.addResult(new Runnable() { @Override public void run() { Message desc = new NotifyDescriptor.Message("An exception occurred during the search, " + "perhaps due to a malformed query string:\n" + msg, NotifyDescriptor.WARNING_MESSAGE); DialogDisplayer.getDefault().notify(desc); } }, "(Error during search)" ); } return null; }
Example #2
Source File: SearchProviderImpl.java From netbeans with Apache License 2.0 | 6 votes |
@Messages({"# {0} - server label", "# {1} - job name", "search_response=Hudson job {1} on {0}"}) private void work(String text, SearchResponse response) { for (final HudsonInstance instance : HudsonManager.getAllInstances()) { for (HudsonJob job : instance.getJobs()) { final String name = job.getName(); // XXX could also search for text in instance name, and/or Maven modules if (name.toLowerCase(Locale.ENGLISH).contains(text.toLowerCase(Locale.ENGLISH))) { if (!response.addResult(new Runnable() { @Override public void run() { UI.selectNode(instance.getUrl(), name); } }, Bundle.search_response(instance.getName(), name))) { return; } } } } }
Example #3
Source File: CommandEvaluator.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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 |
@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 |
@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: DataAccessSearchProvider.java From constellation with Apache License 2.0 | 6 votes |
@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 #7
Source File: SlowProviderTest.java From netbeans with Apache License 2.0 | 5 votes |
public void evaluate(SearchRequest request, SearchResponse response) { try { Thread.sleep(5000); } catch (InterruptedException ex) { System.err.println("SlowProvider interrupted..."); } }
Example #8
Source File: SearchProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
@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: GoToSymbolProvider.java From netbeans with Apache License 2.0 | 5 votes |
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 #10
Source File: JavaTypeSearchProvider.java From netbeans with Apache License 2.0 | 5 votes |
@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 #11
Source File: SearchForProjectsQuickSearch.java From netbeans with Apache License 2.0 | 5 votes |
@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 #12
Source File: RecentProvider.java From netbeans with Apache License 2.0 | 5 votes |
@NbBundle.Messages("RecentSearches.clear=(Clear recent searches)") private void addClearAction(SearchResponse response) { boolean add = response.addResult(new Runnable() { @Override public void run() { RecentSearches.getDefault().clear(); } }, "<html><i>" + Bundle.RecentSearches_clear() + "</i></html>");//NOI18N }
Example #13
Source File: CommandEvaluator.java From netbeans with Apache License 2.0 | 5 votes |
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 #14
Source File: WebQuickSearchProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
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 #15
Source File: JavaHelpQuickSearchProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
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 #16
Source File: ActionsSearchProvider.java From netbeans with Apache License 2.0 | 5 votes |
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 #17
Source File: ProviderModelTest.java From netbeans with Apache License 2.0 | 4 votes |
public void evaluate(SearchRequest request, SearchResponse response) { // no operation }
Example #18
Source File: ProviderModelTest.java From netbeans with Apache License 2.0 | 4 votes |
public void evaluate(SearchRequest request, SearchResponse response) { // no operation }
Example #19
Source File: MavenRepoProvider.java From netbeans with Apache License 2.0 | 4 votes |
/** * 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 #20
Source File: Accessor.java From netbeans with Apache License 2.0 | votes |
public abstract SearchResponse createResponse (CategoryResult catResult, SearchRequest sRequest);