Search in sources :

Example 1 with Category

use of org.netbeans.modules.quicksearch.ProviderModel.Category in project netbeans-rcp-lite by outersky.

the class RecentSearches method storeRecentToPrefs.

private void storeRecentToPrefs() {
    Iterator<ItemResult> it = recent.iterator();
    for (int i = 0; i < MAX_ITEMS; i++) {
        if (it.hasNext()) {
            ItemResult td = it.next();
            CategoryResult cr = td.getCategory();
            Category category = cr == null ? null : cr.getCategory();
            String categoryName = category == null ? null : stripHTMLnames(category.getDisplayName());
            prefs().put(RECENT_SEARCHES + i, stripHTMLnames(td.getDisplayName()) + dateSep + td.getDate().getTime() + (categoryName == null ? "" : dateSep + categoryName));
        } else {
            prefs().put(RECENT_SEARCHES + i, "");
        }
    }
}
Also used : Category(org.netbeans.modules.quicksearch.ProviderModel.Category) ItemResult(org.netbeans.modules.quicksearch.ResultsModel.ItemResult) CategoryResult(org.netbeans.modules.quicksearch.CategoryResult)

Example 2 with Category

use of org.netbeans.modules.quicksearch.ProviderModel.Category in project netbeans-rcp-lite by outersky.

the class CommandEvaluator method evaluate.

/**
 * 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);
}
Also used : SearchRequest(org.netbeans.spi.quicksearch.SearchRequest) Task(org.openide.util.RequestProcessor.Task) Category(org.netbeans.modules.quicksearch.ProviderModel.Category) ArrayList(java.util.ArrayList) SearchProvider(org.netbeans.spi.quicksearch.SearchProvider) Category(org.netbeans.modules.quicksearch.ProviderModel.Category) SearchResponse(org.netbeans.spi.quicksearch.SearchResponse)

Example 3 with Category

use of org.netbeans.modules.quicksearch.ProviderModel.Category in project netbeans-rcp-lite by outersky.

the class AbstractQuickSearchComboBar method setShowHint.

private void setShowHint(boolean showHint) {
    // remember orig color on first invocation
    if (origForeground == null) {
        origForeground = command.getForeground();
    }
    if (showHint) {
        command.setForeground(command.getDisabledTextColor());
        Set<Category> evalCats = CommandEvaluator.getEvalCats();
        if (evalCats.size() < 3 && !CommandEvaluator.isTemporaryCatSpecified()) {
            Category bestFound = null;
            for (Category c : evalCats) {
                if (bestFound == null || CommandEvaluator.RECENT.equals(bestFound.getName())) {
                    bestFound = c;
                }
            }
            command.setText(getHintText(bestFound));
        } else {
            command.setText(getHintText(null));
        }
    } else {
        command.setForeground(origForeground);
        command.setText("");
    }
}
Also used : Category(org.netbeans.modules.quicksearch.ProviderModel.Category)

Example 4 with Category

use of org.netbeans.modules.quicksearch.ProviderModel.Category in project netbeans-rcp-lite by outersky.

the class AbstractQuickSearchComboBar method computePrefWidth.

protected int computePrefWidth() {
    FontMetrics fm = command.getFontMetrics(command.getFont());
    ProviderModel pModel = ProviderModel.getInstance();
    int maxWidth = 0;
    for (Category cat : pModel.getCategories()) {
        // skip recent category
        if (CommandEvaluator.RECENT.equals(cat.getName())) {
            continue;
        }
        maxWidth = Math.max(maxWidth, fm.stringWidth(getHintText(cat)));
    }
    // don't allow width grow too much
    return Math.min(350, maxWidth);
}
Also used : Category(org.netbeans.modules.quicksearch.ProviderModel.Category) FontMetrics(java.awt.FontMetrics) Point(java.awt.Point)

Aggregations

Category (org.netbeans.modules.quicksearch.ProviderModel.Category)4 FontMetrics (java.awt.FontMetrics)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 CategoryResult (org.netbeans.modules.quicksearch.CategoryResult)1 ItemResult (org.netbeans.modules.quicksearch.ResultsModel.ItemResult)1 SearchProvider (org.netbeans.spi.quicksearch.SearchProvider)1 SearchRequest (org.netbeans.spi.quicksearch.SearchRequest)1 SearchResponse (org.netbeans.spi.quicksearch.SearchResponse)1 Task (org.openide.util.RequestProcessor.Task)1