Java Code Examples for org.netbeans.spi.quicksearch.SearchResponse#addResult()

The following examples show how to use org.netbeans.spi.quicksearch.SearchResponse#addResult() . 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: 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 3
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 4
Source File: SearchProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: NodeQuickSearch.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 6
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 7
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 8
Source File: RecentProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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 9
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 10
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 11
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 12
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;
        }
    }
}