1 19 20 package org.netbeans.core; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.SwingUtilities ; 24 import org.netbeans.core.actions.GlobalPropertiesAction; 25 import org.netbeans.junit.NbTestCase; 26 import org.openide.nodes.AbstractNode; 27 import org.openide.nodes.Children; 28 import org.openide.nodes.Node; 29 import org.openide.windows.TopComponent; 30 31 35 public class NbSheetTest extends NbTestCase { 36 static { 37 System.setProperty("org.openide.windows.DummyWindowManager.VISIBLE", "false"); 38 } 39 40 NbSheet s; 41 GlobalPropertiesAction a; 42 TopComponent tc; 43 44 public NbSheetTest(String testName) { 45 super(testName); 46 } 47 48 protected void setUp() throws Exception { 49 super.setUp(); 50 s = NbSheet.findDefault(); 51 assertNotNull("Sheet found", s); 52 assertFalse("Not yet visible", s.isShowing()); 53 a = GlobalPropertiesAction.get(GlobalPropertiesAction.class); 54 tc = new TopComponent(); 55 } 56 57 protected void tearDown() throws Exception { 58 super.tearDown(); 59 } 60 61 public void testIssue97069EgUseSetActivatedNodesNull() throws Exception { 62 class Empty implements Runnable { 63 public void run() { } 64 } 65 Empty empty = new Empty(); 66 67 class R implements Runnable { 68 N node = new N("node1"); 69 public void run() { 70 tc.setActivatedNodes(new Node[] { node }); 71 tc.open(); 72 tc.requestActive(); 73 74 assertTrue("action enabled", a.isEnabled()); 75 a.actionPerformed(new ActionEvent (a, 0, "")); 76 } 77 } 78 R activate = new R(); 79 SwingUtilities.invokeAndWait(activate); 80 SwingUtilities.invokeAndWait(empty); 81 82 for (int i = 0; i < 5; i++) { 83 if (s == TopComponent.getRegistry().getActivated()) { 84 break; 85 } 86 Thread.sleep(500); 87 } 88 assertEquals("sheet activated", s, TopComponent.getRegistry().getActivated()); 89 assertEquals("One node displayed", 1, s.getNodes().length); 90 assertEquals("it is node", activate.node, s.getNodes()[0]); 91 assertEquals("No activated nodes", null, s.getActivatedNodes()); 92 93 s.close(); 94 95 final N another = new N("another"); 96 97 tc.setActivatedNodes(new Node[] { another }); 98 tc.requestActive(); 99 100 101 class R2 implements Runnable { 102 public void run() { 103 assertTrue("action enabled", a.isEnabled()); 104 a.actionPerformed(new ActionEvent (a, 0, "")); 105 } 106 } 107 R2 anotherAct = new R2(); 108 SwingUtilities.invokeAndWait(anotherAct); 109 SwingUtilities.invokeAndWait(empty); 110 111 for (int i = 0; i < 5; i++) { 112 if (s == TopComponent.getRegistry().getActivated()) { 113 break; 114 } 115 Thread.sleep(500); 116 } 117 assertEquals("sheet activated another time", s, TopComponent.getRegistry().getActivated()); 118 119 assertEquals("One node displayed", 1, s.getNodes().length); 120 assertEquals("it is another", another, s.getNodes()[0]); 121 assertEquals("No activated nodes", null, s.getActivatedNodes()); 122 123 } 124 125 private static final class N extends AbstractNode { 126 public N(String n) { 127 super(Children.LEAF); 128 setName(n); 129 } 130 } 131 } 132 133 134 | Popular Tags |