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.ui.basic;
043:
044: import java.awt.Image;
045: import javax.swing.Icon;
046: import javax.swing.ImageIcon;
047: import org.netbeans.modules.xml.schema.model.SchemaComponent;
048: import org.netbeans.modules.xml.schema.model.SchemaModel;
049: import org.netbeans.modules.xml.schema.ui.basic.SchemaSettings.ViewMode;
050: import org.netbeans.modules.xml.schema.ui.basic.search.AttributeNameSearchProvider;
051: import org.netbeans.modules.xml.schema.ui.basic.search.AttributeValueSearchProvider;
052: import org.netbeans.modules.xml.schema.ui.basic.search.ComponentNameSearchProvider;
053: import org.netbeans.modules.xml.schema.ui.basic.search.ComponentTypeSearchProvider;
054: import org.netbeans.modules.xml.schema.ui.basic.search.NameSpaceSearchProvider;
055: import org.netbeans.modules.xml.xam.Component;
056: import org.netbeans.modules.xml.xam.ui.category.AbstractCategory;
057: import org.openide.util.Lookup;
058: import org.openide.util.NbBundle;
059: import org.openide.util.Utilities;
060: import org.openide.util.lookup.Lookups;
061: import org.openide.util.lookup.ProxyLookup;
062:
063: /**
064: * Displays the categorized version of the schema tree view.
065: *
066: * @author Nathan Fiedler
067: */
068: public class SchemaTreeCategory extends AbstractCategory {
069: /** Associated schema model. */
070: private SchemaModel schemaModel;
071: /** Our visual component. */
072: private SchemaTreeView component;
073: /** Our lookup. */
074: private Lookup lookup;
075:
076: /**
077: * Creates a new instance of SchemaCategory.
078: *
079: * @param model schema model to display.
080: * @param lookup associated Lookup instance.
081: */
082: public SchemaTreeCategory(SchemaModel model, Lookup lookup) {
083: this .schemaModel = model;
084: Object[] searchers = new Object[] {
085: new ComponentNameSearchProvider(model, this ),
086: new ComponentTypeSearchProvider(model, this ),
087: new AttributeNameSearchProvider(model, this ),
088: new AttributeValueSearchProvider(model, this ),
089: new NameSpaceSearchProvider(model, this ),
090: // The XPath query is too slow; re-enable when model is faster.
091: // new XPathSearchProvider(model, this),
092: };
093: this .lookup = new ProxyLookup(new Lookup[] { lookup,
094: Lookups.fixed(searchers) });
095: }
096:
097: public void componentHidden() {
098: }
099:
100: public void componentShown() {
101: initComponents();
102: SchemaSettings.getDefault().setViewMode(ViewMode.TREE);
103: }
104:
105: public java.awt.Component getComponent() {
106: initComponents();
107: return component;
108: }
109:
110: public String getDescription() {
111: return NbBundle.getMessage(SchemaTreeCategory.class,
112: "HINT_SchemaCategory_Tree");
113: }
114:
115: public Icon getIcon() {
116: String url = NbBundle.getMessage(SchemaTreeCategory.class,
117: "IMG_SchemaCategory_Tree");
118: Image img = Utilities.loadImage(url);
119: return new ImageIcon(img);
120: }
121:
122: public Lookup getLookup() {
123: return lookup;
124: }
125:
126: public String getTitle() {
127: return NbBundle.getMessage(SchemaTreeCategory.class,
128: "LBL_SchemaCategory_Tree");
129: }
130:
131: /**
132: * Construct our visual components, if they have not been already.
133: */
134: private void initComponents() {
135: if (component == null) {
136: component = new SchemaTreeView(schemaModel,
137: SchemaTreeView.ViewType.CATEGORIZED, getLookup());
138: }
139: }
140:
141: public void showComponent(Component comp) {
142: if (comp instanceof SchemaComponent) {
143: component.showComponent((SchemaComponent) comp);
144: }
145: }
146: }
|