KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > basic > search > Providers


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.ui.basic.search;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.SwingUtilities JavaDoc;
24 import org.netbeans.modules.xml.schema.model.SchemaComponent;
25 import org.netbeans.modules.xml.schema.ui.nodes.SchemaComponentNode;
26 import org.netbeans.modules.xml.schema.ui.nodes.categorized.CategoryNode;
27 import org.netbeans.modules.xml.xam.ui.category.Category;
28 import org.openide.nodes.Node;
29 import org.openide.windows.TopComponent;
30
31 /**
32  * Provides utility methods for the search provider implementations.
33  *
34  * @author Nathan Fiedler
35  */

36 public class Providers {
37
38     /**
39      * Creates a new instance of Providers.
40      */

41     private Providers() {
42     }
43
44     /**
45      * If a CategoryNode is selected, return the child type of that node.
46      *
47      * @param category Category for which to find selected component.
48      * @return schema component class, or null if none selected.
49      */

50     public static Class JavaDoc<? extends SchemaComponent> getSelectedChildType(
51             Category category) {
52         Component JavaDoc parent = category.getComponent().getParent();
53         TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(
54                 TopComponent.class, parent);
55         if (tc != null) {
56             Node[] nodes = tc.getActivatedNodes();
57             if (nodes != null && nodes.length > 0) {
58                 for (Node node : nodes) {
59                     CategoryNode cn = (CategoryNode) node.getCookie(
60                             CategoryNode.class);
61                     if (cn != null) {
62                         return cn.getChildType();
63                     }
64                 }
65             }
66         }
67         return null;
68     }
69
70     /**
71      * Retrieve the selected schema component for the given Category.
72      *
73      * @param category Category for which to find selected component.
74      * @return selected schema component, or null if none.
75      */

76     public static SchemaComponent getSelectedComponent(Category category) {
77         Component JavaDoc parent = category.getComponent().getParent();
78         TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(
79                 TopComponent.class, parent);
80         if (tc != null) {
81             Node[] nodes = tc.getActivatedNodes();
82             if (nodes != null && nodes.length > 0) {
83                 for (Node node : nodes) {
84                     SchemaComponentNode scn = (SchemaComponentNode) node.
85                             getCookie(SchemaComponentNode.class);
86                     if (scn != null) {
87                         return scn.getReference().get();
88                     }
89                 }
90             }
91         }
92         return null;
93     }
94 }
95
Popular Tags