1 19 20 package org.netbeans.spi.palette; 21 22 import java.beans.BeanInfo ; 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 36 public class HelpTest extends AbstractPaletteTestHid { 37 38 public HelpTest(String testName) { 39 super(testName); 40 } 41 42 public void testItemHelp() throws Exception { 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 { 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 { 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 { 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 { 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 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 { 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 |