Search in sources :

Example 1 with SearchInfoDefinition

use of org.netbeans.spi.search.SearchInfoDefinition in project netbeans-rcp-lite by outersky.

the class SearchInfoUtils method findDefinedSearchInfo.

/**
 * Get a search info for a node, if it was explicitly defined in node's
 * lookup, or in lookup of a ancestor node. Default search info is not
 * created.
 *
 * @see #getSearchInfoForNode(org.openide.nodes.Node)
 *
 * @return Defined SearchInfo, or null if not available.
 */
@CheckForNull
public static SearchInfo findDefinedSearchInfo(@NonNull Node node) {
    // NOI18N
    Parameters.notNull("node", node);
    SearchInfoDefinition sid = SearchInfoDefinitionUtils.findSearchInfoDefinition(node);
    if (sid != null) {
        return new DelegatingSearchInfo(sid);
    } else {
        return null;
    }
}
Also used : SearchInfoDefinition(org.netbeans.spi.search.SearchInfoDefinition) DelegatingSearchInfo(org.netbeans.api.search.provider.impl.DelegatingSearchInfo) CheckForNull(org.netbeans.api.annotations.common.CheckForNull)

Example 2 with SearchInfoDefinition

use of org.netbeans.spi.search.SearchInfoDefinition in project netbeans-rcp-lite by outersky.

the class SearchInfoUtils method getSearchInfoForNode.

/**
 * Gets a search info for node.
 *
 * <div class="nonnormative">
 * <p>
 *   Algorithm for getting search info:
 * </p>
 * <ol>
 *    <li>Look for SearchInfoDefinition in lookup of the node. If found,
 *    create and return search info for this definition.</li>
 *    <li>Look for SubTreeSearchOptions in lookups of this node and its
 *    ancestors. If found, check if the node has a {@link FileObject}
 *    (possibly as primary file of a {@link DataObject}) in its lookup,
 *    and, if so, create search info for recursive searching in the file
 *    object, using filters defined in found {@link SubTreeSearchOptions}.
 *    </li>
 *    <li>Check whether the node has a {@link FileObject}
 *    (possibly as primary file of a {@link DataObject}) in is lookup. If
 *    so, create default search info for that file object. Default means
 *    that the file object will be searched recursively, using default
 *    filters.
 *    </li>
 *    <li>
 *    Return null.
 *    </li>
 * </ol>
 * </div>
 *
 * @see FileObject
 * @see DataObject
 * @see SearchInfoDefinition
 * @see SubTreeSearchOptions
 * @see #findDefinedSearchInfo(org.openide.nodes.Node)
 *
 * @return Search info for a node. If no search info was defined and it
 * cannot be created for this node, null is returned.
 */
@CheckForNull
public static SearchInfo getSearchInfoForNode(@NonNull Node node) {
    // NOI18N
    Parameters.notNull("node", node);
    SearchInfoDefinition sid = SearchInfoDefinitionUtils.getSearchInfoDefinition(node);
    if (sid == null) {
        return null;
    } else {
        return new DelegatingSearchInfo(sid);
    }
}
Also used : SearchInfoDefinition(org.netbeans.spi.search.SearchInfoDefinition) DelegatingSearchInfo(org.netbeans.api.search.provider.impl.DelegatingSearchInfo) CheckForNull(org.netbeans.api.annotations.common.CheckForNull)

Example 3 with SearchInfoDefinition

use of org.netbeans.spi.search.SearchInfoDefinition in project netbeans-rcp-lite by outersky.

the class SubnodesSearchInfoDefinition method getSearchRoots.

@Override
public List<SearchRoot> getSearchRoots() {
    final Node[] nodes = children.getNodes(true);
    if (nodes.length == 0) {
        return Collections.emptyList();
    }
    List<SearchRoot> allRoots = new LinkedList<SearchRoot>();
    for (Node subNode : nodes) {
        SearchInfoDefinition subInfo = SearchInfoDefinitionUtils.getSearchInfoDefinition(subNode);
        if (subInfo != null && subInfo.canSearch()) {
            allRoots.addAll(subInfo.getSearchRoots());
        }
    }
    return allRoots;
}
Also used : SearchRoot(org.netbeans.api.search.SearchRoot) Node(org.openide.nodes.Node) SearchInfoDefinition(org.netbeans.spi.search.SearchInfoDefinition) LinkedList(java.util.LinkedList)

Example 4 with SearchInfoDefinition

use of org.netbeans.spi.search.SearchInfoDefinition in project netbeans-rcp-lite by outersky.

the class SearchInfoDefinitionUtils method getSearchInfoDefinition.

/**
 * Get a SearchInfoDefinition for a node.
 *
 * @param node Node for which the definition should be created.
 * @param createDefault If true, default definition will be created even if
 * no explicit settings are defined. If false, null will be returned in such
 * case.
 */
private static SearchInfoDefinition getSearchInfoDefinition(Node node, boolean createDefault) {
    /*
         * 1st try - is the SearchInfo object in the node's lookup?
         */
    SearchInfoDefinition info = node.getLookup().lookup(SearchInfoDefinition.class);
    if (info != null) {
        return info;
    }
    /*
         * 2nd try - does the node represent a DataObject.Container?
         */
    FileObject fileObject = node.getLookup().lookup(FileObject.class);
    if (fileObject == null) {
        DataObject dataObject = node.getLookup().lookup(DataObject.class);
        if (dataObject != null) {
            fileObject = dataObject.getPrimaryFile();
        }
    }
    if (fileObject == null) {
        return null;
    } else {
        SubTreeSearchOptions subTreeSearchOptions = findSubTreeSearchOptions(node);
        if (subTreeSearchOptions == null && !createDefault) {
            return null;
        } else {
            return SearchInfoDefinitionFactory.createSearchInfo(fileObject, getFiltersForNode(subTreeSearchOptions));
        }
    }
}
Also used : DataObject(org.openide.loaders.DataObject) SubTreeSearchOptions(org.netbeans.spi.search.SubTreeSearchOptions) SearchInfoDefinition(org.netbeans.spi.search.SearchInfoDefinition) FileObject(org.openide.filesystems.FileObject)

Aggregations

SearchInfoDefinition (org.netbeans.spi.search.SearchInfoDefinition)4 CheckForNull (org.netbeans.api.annotations.common.CheckForNull)2 DelegatingSearchInfo (org.netbeans.api.search.provider.impl.DelegatingSearchInfo)2 LinkedList (java.util.LinkedList)1 SearchRoot (org.netbeans.api.search.SearchRoot)1 SubTreeSearchOptions (org.netbeans.spi.search.SubTreeSearchOptions)1 FileObject (org.openide.filesystems.FileObject)1 DataObject (org.openide.loaders.DataObject)1 Node (org.openide.nodes.Node)1