1 19 20 package org.openide.explorer.propertysheet; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Component ; 24 import java.awt.Container ; 25 import java.lang.reflect.InvocationTargetException ; 26 import java.util.Collection ; 27 import java.util.LinkedList ; 28 import javax.swing.JFrame ; 29 import org.openide.explorer.propertysheet.ExtTestCase.WaitWindow; 30 import org.openide.nodes.AbstractNode; 31 import org.openide.nodes.Children; 32 import org.openide.nodes.Node; 33 import org.openide.nodes.PropertySupport; 34 import org.openide.nodes.Sheet; 35 import org.openide.util.HelpCtx; 36 37 41 public class FindHelpTest extends ExtTestCase { 42 43 public FindHelpTest(String name) { 44 super(name); 45 } 46 47 protected boolean runInEQ() { 48 return false; 49 } 50 51 private PropertySheet sheet = null; 52 private JFrame frame = null; 53 protected void setUp() throws Exception { 54 JFrame jf = new JFrame (); 55 jf.getContentPane().setLayout(new BorderLayout ()); 56 sheet = new PropertySheet(); 57 jf.getContentPane().add(sheet); 58 59 jf.setBounds(20, 20, 200, 400); 60 frame = jf; 61 new WaitWindow(jf); 62 } 63 64 public void testFindHelpOnProperty() throws Exception { 65 Node n = new WithPropertyHelpNode(); 66 setCurrentNode(n, sheet); 67 68 sleep(); 69 70 PropertySheet.HelpAction act = sheet.helpAction; 71 72 assertTrue("No help context found", act.getContext() != null); 73 74 assertTrue("Help action should be enabled", act.isEnabled()); 75 76 } 77 78 public void testFindPropertiesHelpOnNode() throws Exception { 79 Node n = new WithPropertiesHelpNode(); 80 setCurrentNode(n, sheet); 81 82 sleep(); 83 84 PropertySheet.HelpAction act = sheet.helpAction; 85 86 assertTrue("No help context found", act.getContext() != null); 87 88 assertTrue("Help action should be enabled", act.isEnabled()); 89 } 90 91 public void testNoHelpProvided() throws Exception { 92 Node n = new HelplessNode(); 93 setCurrentNode(n, sheet); 94 95 sleep(); 96 97 PropertySheet.HelpAction act = sheet.helpAction; 98 99 assertFalse("A help context was found on a node with no properties help", act.getContext() != null); 100 101 assertFalse("Help action should be disabled", act.isEnabled()); 102 103 } 104 105 public void testSetHelpProvided() throws Exception { 106 Node n = new WithTabsSetHelpNode(); 107 setCurrentNode(n, sheet); 108 109 sleep(); 110 111 PropertySheet.HelpAction act = sheet.helpAction; 112 113 HelpCtx ctx = act.getContext(); 114 assertTrue("A help context should have been found", ctx != null); 115 116 assertTrue("Wrong help context returned: " + ctx.getHelpID(), "set-help-id".equals(ctx.getHelpID())); 117 } 118 119 121 private static Collection findChildren(Component p, Class c) { 122 Collection x = new LinkedList (); 123 findChildren(p, c, x); 124 return x; 125 } 126 127 private static void findChildren(Component p, Class c, Collection x) { 128 if (c.isInstance(p)) { 129 x.add(p); 130 } else if (p instanceof Container ) { 131 Component [] k = ((Container )p).getComponents(); 132 for (int i = 0; i < k.length; i++) { 133 findChildren(k[i], c, x); 134 } 135 } 136 } 137 138 141 private static final class HelplessNode extends AbstractNode { 142 public HelplessNode() { 143 super(Children.LEAF); 144 } 145 public HelpCtx getHelpCtx() { 146 return HelpCtx.DEFAULT_HELP; 147 } 148 protected Sheet createSheet() { 149 Sheet s = super.createSheet(); 150 Sheet.Set ss = Sheet.createPropertiesSet(); 151 ss.put(new WithHelpProperty("prop1", "row-help-1")); 152 ss.put(new WithHelpProperty("prop2", "row-help-2")); 153 ss.put(new WithHelpProperty("prop3", null)); 154 s.put(ss); 155 ss = Sheet.createExpertSet(); 156 ss.put(new WithHelpProperty("prop4", "row-help-4")); 157 ss.put(new WithHelpProperty("prop5", null)); 158 s.put(ss); 159 return s; 160 } 161 } 162 163 166 private static final class WithPropertyHelpNode extends AbstractNode { 167 public WithPropertyHelpNode() { 168 super(Children.LEAF); 169 } 170 public HelpCtx getHelpCtx() { 171 return new HelpCtx("node-help"); 172 } 173 protected Sheet createSheet() { 174 Sheet s = super.createSheet(); 175 Sheet.Set ss = Sheet.createPropertiesSet(); 176 ss.setValue("helpID", "properties-help"); 177 ss.put(new WithHelpProperty("prop1", "row-help-1")); 178 ss.put(new WithHelpProperty("prop2", "row-help-2")); 179 ss.put(new WithHelpProperty("prop3", null)); 180 s.put(ss); 181 ss = Sheet.createExpertSet(); 182 ss.put(new WithHelpProperty("prop4", "row-help-4")); 183 ss.put(new WithHelpProperty("prop5", null)); 184 s.put(ss); 185 return s; 186 } 187 } 188 189 193 private static final class WithPropertiesHelpNode extends AbstractNode { 194 public WithPropertiesHelpNode() { 195 super(Children.LEAF); 196 setValue("propertiesHelpID", "propertiesHelp"); 197 } 198 public HelpCtx getHelpCtx() { 199 return new HelpCtx("node-help"); 200 } 201 protected Sheet createSheet() { 202 Sheet s = super.createSheet(); 203 Sheet.Set ss = Sheet.createPropertiesSet(); 204 ss.put(new WithoutHelpProperty("prop1")); 205 ss.put(new WithoutHelpProperty("prop2")); 206 ss.put(new WithoutHelpProperty("prop3")); 207 s.put(ss); 208 ss = Sheet.createExpertSet(); 209 ss.put(new WithoutHelpProperty("prop4")); 210 ss.put(new WithoutHelpProperty("prop5")); 211 s.put(ss); 212 return s; 213 } 214 } 215 216 private static final class WithTabsSetHelpNode extends AbstractNode { 217 public WithTabsSetHelpNode() { 218 super(Children.LEAF); 219 } 220 public HelpCtx getHelpCtx() { 221 return new HelpCtx("node-help"); 222 } 223 protected Sheet createSheet() { 224 Sheet s = super.createSheet(); 225 Sheet.Set ss = Sheet.createPropertiesSet(); 226 ss.put(new WithoutHelpProperty("prop1")); 227 ss.put(new WithoutHelpProperty("prop2")); 228 ss.put(new WithoutHelpProperty("prop3")); 229 ss.setValue("tabName", "Tab 1"); 230 ss.setValue("helpID", "set-help-id"); 231 s.put(ss); 232 ss = Sheet.createExpertSet(); 233 ss.put(new WithoutHelpProperty("prop4")); 234 ss.put(new WithoutHelpProperty("prop5")); 235 ss.setValue("tabName", "Tab 2"); 236 s.put(ss); 237 return s; 238 } 239 } 240 241 242 private static final class WithHelpProperty extends PropertySupport.ReadOnly { 243 public WithHelpProperty(String name, String helpID) { 244 super(name, String .class, name, name); 245 if (helpID != null) { 246 setValue("helpID", helpID); 247 } 248 } 249 public Object getValue() throws IllegalAccessException , InvocationTargetException { 250 return "value-" + getName(); 251 } 252 } 253 254 private static final class WithoutHelpProperty extends PropertySupport.ReadOnly { 255 public WithoutHelpProperty(String name) { 256 super(name, String .class, name, name); 257 } 258 public Object getValue() throws IllegalAccessException , InvocationTargetException { 259 return "value-" + getName(); 260 } 261 } 262 263 264 } 265 | Popular Tags |