1 19 20 package org.netbeans.core.multiview; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Component ; 24 import java.awt.DefaultKeyboardFocusManager ; 25 import java.awt.KeyboardFocusManager ; 26 import java.awt.event.ActionEvent ; 27 import java.beans.FeatureDescriptor ; 28 import java.beans.PropertyChangeListener ; 29 import java.util.*; 30 import javax.swing.AbstractAction ; 31 import javax.swing.ActionMap ; 32 import javax.swing.JTextField ; 33 34 import junit.framework.*; 35 import org.netbeans.core.api.multiview.MultiViewHandler; 36 import org.netbeans.core.api.multiview.MultiViews; 37 import org.netbeans.core.spi.multiview.MultiViewDescription; 38 import org.netbeans.core.spi.multiview.MultiViewFactory; 39 40 import org.netbeans.junit.*; 41 import org.openide.nodes.Node; 42 43 import org.openide.util.lookup.AbstractLookup; 44 import org.openide.util.lookup.InstanceContent; 45 import org.openide.windows.TopComponent; 46 47 51 public class MVInnerComponentGetLookupTest extends org.openide.windows.TopComponentGetLookupTest { 52 53 private TopComponent mvtc; 54 private TopComponent top2; 55 private TopComponent top3; 56 MultiViewDescription desc1; 57 MultiViewDescription desc2; 58 MultiViewDescription desc3; 59 60 public MVInnerComponentGetLookupTest(String testName) { 61 super(testName); 62 } 63 64 65 public static void main(String [] args) { 66 junit.textui.TestRunner.run(suite()); 67 } 68 69 public static Test suite() { 70 return new NbTestSuite(MVInnerComponentGetLookupTest.class); 71 } 72 73 74 protected boolean runInEQ () { 75 return true; 76 } 77 78 protected int checkAtLeastCount() { 79 return 0; 80 } 81 82 83 85 protected void setUp () { 86 final MVElemTopComponent elem1 = new MVElemTopComponent(); 87 final MVElemTopComponent elem2 = new MVElemTopComponent(); 88 final MVElemTopComponent elem3 = new MVElemTopComponent(); 89 desc1 = new MVDesc("desc1", null, 0, elem1); 90 desc2 = new MVDesc("desc2", null, 0, elem2); 91 desc3 = new MVDesc("desc3", null, 0, elem3); 92 MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 }; 93 TopComponent mvtop = MultiViewFactory.createMultiView(descs, desc1); 94 top = (TopComponent)elem1; 95 top2 = (TopComponent)elem2; 96 top3 = (TopComponent)elem3; 97 lookup = mvtop.getLookup(); 98 mvtop.open(); 99 mvtop.requestActive(); 100 mvtc = mvtop; 101 } 102 103 public void testMVTCActivatedNodes() throws Exception { 104 ProChange change = new ProChange(); 105 106 TopComponent.getRegistry().addPropertyChangeListener(change); 107 Node[] nodes = new Node[] {new N("one"), new N("two")}; 108 109 assertEquals(TopComponent.getRegistry().getActivated(), mvtc); 110 top.setActivatedNodes(nodes); 111 Node[] ret = mvtc.getActivatedNodes(); 112 assertNotNull(ret); 113 assertEquals(ret.length, 2); 114 115 assertTrue(ret[0] == nodes[1] || ret[0] == nodes[0]); 116 assertTrue(ret[1] == nodes[0] || ret[1] == nodes[1]); 117 Node[] activ = TopComponent.getRegistry().getActivatedNodes(); 118 assertEquals(activ.length, 2); 119 assertTrue(activ[0] == nodes[1] || activ[0] == nodes[0]); 120 assertTrue(activ[1] == nodes[0] || activ[1] == nodes[1]); 121 123 124 125 Node[] nodes2 = new Node[] {new N("three")}; 126 top.setActivatedNodes(nodes2); 127 ret = mvtc.getActivatedNodes(); 128 assertNotNull(ret); 129 assertEquals(ret.length, 1); 130 assertEquals(ret[0], nodes2[0]); 131 activ = TopComponent.getRegistry().getActivatedNodes(); 132 assertEquals(activ.length, 1); 133 assertEquals(activ[0], nodes2[0]); 134 136 } 137 138 public void testMVTCActivatedNodesOnElementChange() throws Exception { 139 Node[] nodes1 = new Node[] {new N("one"), new N("two")}; 140 Node[] nodes2 = new Node[] {new N("three"), new N("four"), new N("five")}; 141 Node[] nodes3 = new Node[] {new N("six")}; 142 top.setActivatedNodes(nodes1); 143 top2.setActivatedNodes(nodes2); 144 top3.setActivatedNodes(nodes3); 145 146 assertEquals(TopComponent.getRegistry().getActivated(), mvtc); 147 Node[] ret = mvtc.getActivatedNodes(); 149 assertNotNull(ret); 150 assertEquals(ret.length, 2); 151 152 MultiViewHandler handler = MultiViews.findMultiViewHandler(mvtc); 153 handler.requestActive(Accessor.DEFAULT.createPerspective(desc2)); 155 ret = mvtc.getActivatedNodes(); 156 assertNotNull(ret); 157 assertEquals(ret.length, 3); 158 handler.requestActive(Accessor.DEFAULT.createPerspective(desc3)); 159 ret = mvtc.getActivatedNodes(); 160 assertNotNull(ret); 161 assertEquals(ret.length, 1); 162 handler.requestActive(Accessor.DEFAULT.createPerspective(desc1)); 163 ret = mvtc.getActivatedNodes(); 164 assertNotNull(ret); 165 assertEquals(ret.length, 2); 166 167 } 168 169 170 private class ProChange implements PropertyChangeListener { 171 public int count = 0; 172 173 public void propertyChange(java.beans.PropertyChangeEvent evt) { 174 if ("activatedNodes".equals(evt.getPropertyName())) { 175 count = count + 1; 176 } 177 } 178 179 } 180 181 } 182 | Popular Tags |