KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > refactoring > ui > HighlightProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.refactoring.ui;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25 import org.netbeans.modules.xml.schema.model.SchemaComponent;
26 import org.netbeans.modules.xml.xam.ui.highlight.Highlight;
27 import org.netbeans.modules.xml.xam.ui.highlight.HighlightGroup;
28 import org.netbeans.modules.xml.xam.ui.highlight.HighlightManager;
29 import org.netbeans.modules.xml.xam.Component;
30 import org.openide.util.Lookup;
31
32 /**
33  * Provides utility methods for the Find Usages highlighting provider implementations.
34  * copied from org.netbeans.modules.xml.schema.ui.basic.search.Providers
35  *
36  * @author Jeri Lockhart
37  *
38  */

39 public class HighlightProvider {
40     
41     public static final String JavaDoc FIND_USAGES = "find-usages";
42
43     /**
44      * Creates a new instance of HighlightProvider.
45      */

46     private HighlightProvider() {
47     }
48
49     /**
50      * Finds all of the search-related highlight groups and hides and removes them.
51      *
52      * @param lookup where to get the HighlightManager.
53      */

54     public static void hideResults(Lookup lookup) {
55         HighlightManager hm = HighlightManager.getDefault();
56         List JavaDoc<HighlightGroup> groups = hm.getHighlightGroups(FIND_USAGES);
57         if (groups != null) {
58             for (HighlightGroup group : groups) {
59                 hm.removeHighlightGroup(group);
60             }
61         }
62     }
63
64     /**
65      * Create the HighlightGroup to contain the set of matching components.
66      * The parents of the results will be a different highlight type than
67      * the results themselves.
68      *
69      * @param results set of matching results.
70      * @param lookup where to get the HighlightManager.
71      */

72     public static void showResults(Set JavaDoc<SchemaComponent> results, Lookup lookup) {
73         HighlightManager hm = HighlightManager.getDefault();
74         HighlightGroup group = new HighlightGroup(FIND_USAGES);
75         // Generate Highlight instances for each matching result, and its
76
// parents, grand parents, and so on, up to the root component.
77
Iterator JavaDoc<SchemaComponent> iter = results.iterator();
78         while (iter.hasNext()) {
79             SchemaComponent comp = iter.next();
80             FindUsagesHighlight h = new FindUsagesHighlight(comp, Highlight.FIND_USAGES_RESULT);
81             group.addHighlight(h);
82             SchemaComponent parent = comp.getParent();
83             while (parent != null) {
84                 h = new FindUsagesHighlight(parent, Highlight.FIND_USAGES_RESULT_PARENT);
85                 group.addHighlight(h);
86                 parent = parent.getParent();
87             }
88         }
89         hm.addHighlightGroup(group);
90     }
91     
92     public static class FindUsagesHighlight extends Highlight{
93         public FindUsagesHighlight(Component comp, String JavaDoc searchResults) {
94             super(comp, searchResults);
95         }
96     }
97 }
98
Popular Tags