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-2006 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.spi.palette;
043:
044: import java.beans.BeanInfo;
045: import org.netbeans.modules.palette.Category;
046: import org.netbeans.modules.palette.Item;
047: import org.netbeans.modules.palette.Model;
048: import org.netbeans.modules.palette.Settings;
049: import org.netbeans.modules.palette.ui.PalettePanel;
050: import org.openide.filesystems.FileObject;
051: import org.openide.nodes.Node;
052: import org.openide.util.HelpCtx;
053:
054: /**
055: *
056: * @author S. Aubrecht
057: */
058: public class HelpTest extends AbstractPaletteTestHid {
059:
060: public HelpTest(String testName) {
061: super (testName);
062: }
063:
064: public void testItemHelp() throws Exception {
065: FileObject item1 = getItemFile(categoryNames[0],
066: itemNames[0][0]);
067: FileObject item2 = getItemFile(categoryNames[0],
068: itemNames[0][1]);
069:
070: item1.setAttribute(PaletteController.ATTR_HELP_ID,
071: "DummyHelpId");
072:
073: PaletteController pc = PaletteFactory.createPalette(
074: getRootFolderName(), new DummyActions());
075: Model model = pc.getModel();
076: Category[] categories = model.getCategories();
077: Item[] items = categories[0].getItems();
078:
079: Node node1 = items[0].getLookup().lookup(Node.class);
080: Node node2 = items[1].getLookup().lookup(Node.class);
081:
082: HelpCtx help1 = node1.getHelpCtx();
083: HelpCtx help2 = node2.getHelpCtx();
084:
085: assertEquals("Custom help", "DummyHelpId", help1.getHelpID());
086: assertEquals("Default help", HelpCtx.DEFAULT_HELP, help2);
087: }
088:
089: public void testCategoryHelp() throws Exception {
090: FileObject cat1 = getCategoryFile(categoryNames[0]);
091: FileObject cat2 = getCategoryFile(categoryNames[1]);
092:
093: cat1
094: .setAttribute(PaletteController.ATTR_HELP_ID,
095: "DummyHelpId");
096:
097: PaletteController pc = PaletteFactory.createPalette(
098: getRootFolderName(), new DummyActions());
099: Model model = pc.getModel();
100: Category[] categories = model.getCategories();
101:
102: Node node1 = categories[0].getLookup().lookup(Node.class);
103: Node node2 = categories[1].getLookup().lookup(Node.class);
104:
105: HelpCtx help1 = node1.getHelpCtx();
106: HelpCtx help2 = node2.getHelpCtx();
107:
108: assertEquals("Custom help", "DummyHelpId", help1.getHelpID());
109: assertNull("Default help", help2);
110: }
111:
112: public void testRootHelpCustom() throws Exception {
113: paletteRootFolder.setAttribute(PaletteController.ATTR_HELP_ID,
114: "DummyHelpId");
115:
116: PaletteController pc = PaletteFactory.createPalette(
117: getRootFolderName(), new DummyActions());
118: Model model = pc.getModel();
119: Node node = model.getRoot().lookup(Node.class);
120:
121: HelpCtx help = node.getHelpCtx();
122:
123: assertEquals("Custom help", "DummyHelpId", help.getHelpID());
124: }
125:
126: public void testRootHelpDefault() throws Exception {
127: PaletteController pc = PaletteFactory.createPalette(
128: getRootFolderName(), new DummyActions());
129: Model model = pc.getModel();
130: Node node = model.getRoot().lookup(Node.class);
131:
132: HelpCtx help = node.getHelpCtx();
133:
134: assertNull("Custom help", help);
135: }
136:
137: public void testPalettePanelCustom() throws Exception {
138: FileObject item1 = getItemFile(categoryNames[0],
139: itemNames[0][0]);
140: FileObject cat2 = getCategoryFile(categoryNames[1]);
141:
142: item1.setAttribute(PaletteController.ATTR_HELP_ID,
143: "DummyItemHelpId");
144: cat2.setAttribute(PaletteController.ATTR_HELP_ID,
145: "DummyCategoryHelpId");
146: paletteRootFolder.setAttribute(PaletteController.ATTR_HELP_ID,
147: "DummyRootHelpId");
148:
149: PaletteController pc = PaletteFactory.createPalette(
150: getRootFolderName(), new DummyActions());
151: Model model = pc.getModel();
152: PalettePanel panel = PalettePanel.getDefault();
153: panel.setContent(pc, model, pc.getSettings());
154: panel.refresh();
155:
156: HelpCtx help = panel.getHelpCtx();
157: assertNotNull(help);
158: assertEquals("No category, no item selected",
159: "DummyRootHelpId", help.getHelpID());
160:
161: //UI is not fully initialized at this point
162: // pc.setSelectedItem( model.getCategories()[1].getLookup(), model.getCategories()[1].getItems()[0].getLookup() );
163: // help = panel.getHelpCtx();
164: // assertNotNull( help );
165: // assertEquals( "Category selected, selected item has no custom help", "DummyCategoryHelpId", help.getHelpID() );
166:
167: pc.setSelectedItem(model.getCategories()[0].getLookup(), model
168: .getCategories()[0].getItems()[0].getLookup());
169: help = panel.getHelpCtx();
170: assertNotNull(help);
171: assertEquals(
172: "Category selected, selected item has custom help",
173: "DummyItemHelpId", help.getHelpID());
174: }
175:
176: public void testPalettePanelDefault() throws Exception {
177: PaletteController pc = PaletteFactory.createPalette(
178: getRootFolderName(), new DummyActions());
179: Model model = pc.getModel();
180: PalettePanel panel = PalettePanel.getDefault();
181: panel.setContent(pc, model, pc.getSettings());
182:
183: HelpCtx help = panel.getHelpCtx();
184: assertNotNull(help);
185: assertEquals("No custom help defined", "CommonPalette", help
186: .getHelpID());
187:
188: pc.setSelectedItem(model.getCategories()[0].getLookup(), model
189: .getCategories()[0].getItems()[0].getLookup());
190: help = panel.getHelpCtx();
191: assertNotNull(help);
192: assertEquals("No custom help defined", "CommonPalette", help
193: .getHelpID());
194: }
195: }
|