KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > palette > HelpTest


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.palette;
21
22 import java.beans.BeanInfo JavaDoc;
23 import org.netbeans.modules.palette.Category;
24 import org.netbeans.modules.palette.Item;
25 import org.netbeans.modules.palette.Model;
26 import org.netbeans.modules.palette.Settings;
27 import org.netbeans.modules.palette.ui.PalettePanel;
28 import org.openide.filesystems.FileObject;
29 import org.openide.nodes.Node;
30 import org.openide.util.HelpCtx;
31
32 /**
33  *
34  * @author S. Aubrecht
35  */

36 public class HelpTest extends AbstractPaletteTestHid {
37
38     public HelpTest(String JavaDoc testName) {
39         super(testName);
40     }
41
42     public void testItemHelp() throws Exception JavaDoc {
43         FileObject item1 = getItemFile( categoryNames[0], itemNames[0][0] );
44         FileObject item2 = getItemFile( categoryNames[0], itemNames[0][1] );
45         
46         item1.setAttribute( PaletteController.ATTR_HELP_ID, "DummyHelpId" );
47         
48         PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() );
49         Model model = pc.getModel();
50         Category[] categories = model.getCategories();
51         Item[] items = categories[0].getItems();
52         
53         Node node1 = items[0].getLookup().lookup( Node.class );
54         Node node2 = items[1].getLookup().lookup( Node.class );
55         
56         HelpCtx help1 = node1.getHelpCtx();
57         HelpCtx help2 = node2.getHelpCtx();
58
59         assertEquals( "Custom help", "DummyHelpId", help1.getHelpID() );
60         assertEquals( "Default help", HelpCtx.DEFAULT_HELP, help2 );
61     }
62
63     public void testCategoryHelp() throws Exception JavaDoc {
64         FileObject cat1 = getCategoryFile( categoryNames[0] );
65         FileObject cat2 = getCategoryFile( categoryNames[1] );
66         
67         cat1.setAttribute( PaletteController.ATTR_HELP_ID, "DummyHelpId" );
68         
69         PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() );
70         Model model = pc.getModel();
71         Category[] categories = model.getCategories();
72         
73         Node node1 = categories[0].getLookup().lookup( Node.class );
74         Node node2 = categories[1].getLookup().lookup( Node.class );
75         
76         HelpCtx help1 = node1.getHelpCtx();
77         HelpCtx help2 = node2.getHelpCtx();
78
79         assertEquals( "Custom help", "DummyHelpId", help1.getHelpID() );
80         assertNull( "Default help", help2 );
81     }
82
83     public void testRootHelpCustom() throws Exception JavaDoc {
84         paletteRootFolder.setAttribute( PaletteController.ATTR_HELP_ID, "DummyHelpId" );
85         
86         PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() );
87         Model model = pc.getModel();
88         Node node = model.getRoot().lookup( Node.class );
89         
90         HelpCtx help = node.getHelpCtx();
91
92         assertEquals( "Custom help", "DummyHelpId", help.getHelpID() );
93     }
94
95     public void testRootHelpDefault() throws Exception JavaDoc {
96         PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() );
97         Model model = pc.getModel();
98         Node node = model.getRoot().lookup( Node.class );
99         
100         HelpCtx help = node.getHelpCtx();
101
102         assertNull( "Custom help", help );
103     }
104
105     public void testPalettePanelCustom() throws Exception JavaDoc {
106         FileObject item1 = getItemFile( categoryNames[0], itemNames[0][0] );
107         FileObject cat2 = getCategoryFile( categoryNames[1] );
108         
109         item1.setAttribute( PaletteController.ATTR_HELP_ID, "DummyItemHelpId" );
110         cat2.setAttribute( PaletteController.ATTR_HELP_ID, "DummyCategoryHelpId" );
111         paletteRootFolder.setAttribute( PaletteController.ATTR_HELP_ID, "DummyRootHelpId" );
112         
113         PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() );
114         Model model = pc.getModel();
115         PalettePanel panel = PalettePanel.getDefault();
116         panel.setContent( pc, model, pc.getSettings() );
117         panel.refresh();
118         
119         HelpCtx help = panel.getHelpCtx();
120         assertNotNull( help );
121         assertEquals( "No category, no item selected", "DummyRootHelpId", help.getHelpID() );
122
123         //UI is not fully initialized at this point
124
// pc.setSelectedItem( model.getCategories()[1].getLookup(), model.getCategories()[1].getItems()[0].getLookup() );
125
// help = panel.getHelpCtx();
126
// assertNotNull( help );
127
// assertEquals( "Category selected, selected item has no custom help", "DummyCategoryHelpId", help.getHelpID() );
128

129         pc.setSelectedItem( model.getCategories()[0].getLookup(), model.getCategories()[0].getItems()[0].getLookup() );
130         help = panel.getHelpCtx();
131         assertNotNull( help );
132         assertEquals( "Category selected, selected item has custom help", "DummyItemHelpId", help.getHelpID() );
133     }
134
135     public void testPalettePanelDefault() throws Exception JavaDoc {
136         PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() );
137         Model model = pc.getModel();
138         PalettePanel panel = PalettePanel.getDefault();
139         panel.setContent( pc, model, pc.getSettings() );
140         
141         HelpCtx help = panel.getHelpCtx();
142         assertNotNull( help );
143         assertEquals( "No custom help defined", "CommonPalette", help.getHelpID() );
144         
145         pc.setSelectedItem( model.getCategories()[0].getLookup(), model.getCategories()[0].getItems()[0].getLookup() );
146         help = panel.getHelpCtx();
147         assertNotNull( help );
148         assertEquals( "No custom help defined", "CommonPalette", help.getHelpID() );
149     }
150 }
151
Popular Tags