KickJava   Java API By Example, From Geeks To Geeks.

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


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;
21
22 import java.awt.Image JavaDoc;
23 import javax.swing.Icon JavaDoc;
24 import javax.swing.ImageIcon JavaDoc;
25 import org.netbeans.modules.xml.schema.model.SchemaComponent;
26 import org.netbeans.modules.xml.schema.model.SchemaModel;
27 import org.netbeans.modules.xml.schema.ui.basic.SchemaSettings.ViewMode;
28 import org.netbeans.modules.xml.schema.ui.basic.search.AttributeNameSearchProvider;
29 import org.netbeans.modules.xml.schema.ui.basic.search.AttributeValueSearchProvider;
30 import org.netbeans.modules.xml.schema.ui.basic.search.ComponentNameSearchProvider;
31 import org.netbeans.modules.xml.schema.ui.basic.search.ComponentTypeSearchProvider;
32 import org.netbeans.modules.xml.schema.ui.basic.search.NameSpaceSearchProvider;
33 import org.netbeans.modules.xml.xam.Component;
34 import org.netbeans.modules.xml.xam.ui.category.AbstractCategory;
35 import org.openide.util.Lookup;
36 import org.openide.util.NbBundle;
37 import org.openide.util.Utilities;
38 import org.openide.util.lookup.Lookups;
39 import org.openide.util.lookup.ProxyLookup;
40
41 /**
42  * Displays the categorized version of the schema column view.
43  *
44  * @author Nathan Fiedler
45  */

46 public class SchemaColumnsCategory extends AbstractCategory {
47     /** Associated schema model. */
48     private SchemaModel schemaModel;
49     /** Our visual component. */
50     private SchemaColumnsView component;
51     /** Our lookup. */
52     private Lookup lookup;
53
54     /**
55      * Creates a new instance of SchemaCategory.
56      *
57      * @param model schema model to display.
58      * @param lookup associated Lookup instance.
59      */

60     public SchemaColumnsCategory(SchemaModel model, Lookup lookup) {
61         this.schemaModel = model;
62         Object JavaDoc[] searchers = new Object JavaDoc[] {
63             new ComponentNameSearchProvider(model, this),
64             new ComponentTypeSearchProvider(model, this),
65             new AttributeNameSearchProvider(model, this),
66             new AttributeValueSearchProvider(model, this),
67             new NameSpaceSearchProvider(model, this),
68 // The XPath query is too slow; re-enable when model is faster.
69
// new XPathSearchProvider(model, this),
70
};
71         this.lookup = new ProxyLookup(new Lookup[] {
72             lookup,
73             Lookups.fixed(searchers)
74         });
75     }
76
77     public void componentHidden() {
78     }
79
80     public void componentShown() {
81         initComponents();
82         SchemaSettings.getDefault().setViewMode(ViewMode.COLUMN);
83     }
84
85     public java.awt.Component JavaDoc getComponent() {
86         initComponents();
87         return component;
88     }
89
90     public String JavaDoc getDescription() {
91         return NbBundle.getMessage(SchemaColumnsCategory.class,
92                 "HINT_SchemaCategory_Categorized");
93     }
94
95     public Icon JavaDoc getIcon() {
96         String JavaDoc url = NbBundle.getMessage(SchemaColumnsCategory.class,
97                 "IMG_SchemaCategory_Categorized");
98         Image JavaDoc img = Utilities.loadImage(url);
99         return new ImageIcon JavaDoc(img);
100     }
101
102     public Lookup getLookup() {
103         return lookup;
104     }
105
106     public String JavaDoc getTitle() {
107         return NbBundle.getMessage(SchemaColumnsCategory.class,
108                 "LBL_SchemaCategory_Categorized");
109     }
110
111     /**
112      * Construct our visual components, if they have not been already.
113      */

114     private void initComponents() {
115         if (component == null) {
116             component = new SchemaColumnsView(schemaModel,
117                     SchemaColumnsView.ViewType.CATEGORIZED, getLookup());
118         }
119     }
120
121     public void showComponent(Component comp) {
122         if (comp instanceof SchemaComponent) {
123             component.showComponent((SchemaComponent) comp);
124         }
125     }
126 }
127
Popular Tags