001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.schema.refactoring.ui;
043:
044: import java.util.Iterator;
045: import java.util.List;
046: import java.util.Set;
047: import org.netbeans.modules.xml.schema.model.SchemaComponent;
048: import org.netbeans.modules.xml.xam.ui.highlight.Highlight;
049: import org.netbeans.modules.xml.xam.ui.highlight.HighlightGroup;
050: import org.netbeans.modules.xml.xam.ui.highlight.HighlightManager;
051: import org.netbeans.modules.xml.xam.Component;
052: import org.openide.util.Lookup;
053:
054: /**
055: * Provides utility methods for the Find Usages highlighting provider implementations.
056: * copied from org.netbeans.modules.xml.schema.ui.basic.search.Providers
057: *
058: * @author Jeri Lockhart
059: *
060: */
061: public class HighlightProvider {
062:
063: public static final String FIND_USAGES = "find-usages";
064:
065: /**
066: * Creates a new instance of HighlightProvider.
067: */
068: private HighlightProvider() {
069: }
070:
071: /**
072: * Finds all of the search-related highlight groups and hides and removes them.
073: *
074: * @param lookup where to get the HighlightManager.
075: */
076: public static void hideResults(Lookup lookup) {
077: HighlightManager hm = HighlightManager.getDefault();
078: List<HighlightGroup> groups = hm
079: .getHighlightGroups(FIND_USAGES);
080: if (groups != null) {
081: for (HighlightGroup group : groups) {
082: hm.removeHighlightGroup(group);
083: }
084: }
085: }
086:
087: /**
088: * Create the HighlightGroup to contain the set of matching components.
089: * The parents of the results will be a different highlight type than
090: * the results themselves.
091: *
092: * @param results set of matching results.
093: * @param lookup where to get the HighlightManager.
094: */
095: public static void showResults(Set<SchemaComponent> results,
096: Lookup lookup) {
097: HighlightManager hm = HighlightManager.getDefault();
098: HighlightGroup group = new HighlightGroup(FIND_USAGES);
099: // Generate Highlight instances for each matching result, and its
100: // parents, grand parents, and so on, up to the root component.
101: Iterator<SchemaComponent> iter = results.iterator();
102: while (iter.hasNext()) {
103: SchemaComponent comp = iter.next();
104: FindUsagesHighlight h = new FindUsagesHighlight(comp,
105: Highlight.FIND_USAGES_RESULT);
106: group.addHighlight(h);
107: SchemaComponent parent = comp.getParent();
108: while (parent != null) {
109: h = new FindUsagesHighlight(parent,
110: Highlight.FIND_USAGES_RESULT_PARENT);
111: group.addHighlight(h);
112: parent = parent.getParent();
113: }
114: }
115: hm.addHighlightGroup(group);
116: }
117:
118: public static class FindUsagesHighlight extends Highlight {
119: public FindUsagesHighlight(Component comp, String searchResults) {
120: super(comp, searchResults);
121: }
122: }
123: }
|