1 19 20 21 package org.netbeans.core.multiview; 22 23 import java.awt.Image ; 24 import javax.swing.Action ; 25 import javax.swing.JPanel ; 26 import javax.swing.JToolBar ; 27 import javax.swing.SwingUtilities ; 28 import junit.framework.*; 29 import org.netbeans.core.api.multiview.MultiViewHandler; 30 import org.netbeans.core.api.multiview.MultiViewPerspective; 31 import org.netbeans.core.api.multiview.MultiViews; 32 import org.netbeans.core.spi.multiview.MultiViewDescription; 33 import org.netbeans.core.spi.multiview.MultiViewFactory; 34 import org.netbeans.junit.*; 35 import org.openide.util.HelpCtx; 36 import org.openide.util.lookup.Lookups; 37 38 import org.openide.windows.*; 39 40 41 45 public class MultiViewHandlerTest extends NbTestCase { 46 47 48 public MultiViewHandlerTest(String name) { 49 super (name); 50 } 51 52 55 public static void main(java.lang.String [] args) { 56 junit.textui.TestRunner.run(suite()); 57 } 58 59 public static Test suite() { 60 TestSuite suite = new NbTestSuite(MultiViewHandlerTest.class); 61 62 return suite; 63 } 64 65 protected boolean runInEQ () { 66 return true; 67 } 68 69 70 public void testRequestVisible() throws Exception { 71 MVElem elem1 = new MVElem(); 72 MVElem elem2 = new MVElem(); 73 MVElem elem3 = new MVElem(); 74 MultiViewDescription desc1 = new MVDesc("desc1", null, 0, elem1); 75 MultiViewDescription desc2 = new MVDesc("desc2", null, 0, elem2); 76 MultiViewDescription desc3 = new MVDesc("desc3", null, 0, elem3); 77 MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 }; 78 TopComponent tc = MultiViewFactory.createMultiView(descs, desc1); 79 MultiViewHandler hand = MultiViews.findMultiViewHandler(tc); 80 assertNotNull(hand); 81 assertEquals(hand.getPerspectives().length, 3); 82 MultiViewPerspective pers = hand.getSelectedPerspective(); 83 84 assertEquals(Accessor.DEFAULT.extractDescription(pers), desc1); 85 assertEquals("",elem1.getLog()); 87 assertEquals("",elem2.getLog()); 88 89 tc.open(); 90 assertEquals("componentOpened-componentShowing-", elem1.getLog()); 91 assertEquals("",elem2.getLog()); 92 93 hand.requestVisible(Accessor.DEFAULT.createPerspective(desc2)); 95 96 assertEquals(Accessor.DEFAULT.extractDescription(hand.getSelectedPerspective()), desc2); 97 assertEquals("componentOpened-componentShowing-componentHidden-", elem1.getLog()); 98 assertEquals("componentOpened-componentShowing-", elem2.getLog()); 99 assertEquals("", elem3.getLog()); 100 101 hand.requestVisible(Accessor.DEFAULT.createPerspective(desc3)); 103 assertEquals("componentOpened-componentShowing-componentHidden-", elem1.getLog()); 104 assertEquals("componentOpened-componentShowing-componentHidden-", elem2.getLog()); 105 assertEquals("componentOpened-componentShowing-", elem3.getLog()); 106 107 hand.requestVisible(Accessor.DEFAULT.createPerspective(desc1)); 109 assertEquals("componentOpened-componentShowing-componentHidden-", elem3.getLog()); 110 assertEquals("componentOpened-componentShowing-componentHidden-componentShowing-", elem1.getLog()); 111 112 } 113 114 115 public void testRequestActive() throws Exception { 116 final MVElem elem1 = new MVElem(); 117 final MVElem elem2 = new MVElem(); 118 final MVElem elem3 = new MVElem(); 119 MultiViewDescription desc1 = new MVDesc("desc1", null, 0, elem1); 120 MultiViewDescription desc2 = new MVDesc("desc2", null, 0, elem2); 121 MultiViewDescription desc3 = new MVDesc("desc3", null, 0, elem3); 122 MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 }; 123 TopComponent tc = MultiViewFactory.createMultiView(descs, desc2); 124 MultiViewHandler hand = MultiViews.findMultiViewHandler(tc); 125 assertNotNull(hand); 126 assertEquals(hand.getPerspectives().length, 3); 127 128 MultiViewPerspective pers = hand.getSelectedPerspective(); 129 130 assertEquals(Accessor.DEFAULT.extractDescription(pers), desc2); 131 assertEquals("",elem1.getLog()); 133 assertEquals("",elem2.getLog()); 134 135 tc.open(); 136 tc.requestActive(); 137 assertEquals("",elem1.getLog()); 138 assertEquals("componentOpened-componentShowing-componentActivated-", elem2.getLog()); 139 assertEquals("",elem3.getLog()); 140 141 hand.requestActive(Accessor.DEFAULT.createPerspective(desc1)); 143 assertEquals("componentOpened-componentShowing-componentActivated-", elem1.getLog()); 144 assertEquals("componentOpened-componentShowing-componentActivated-componentDeactivated-componentHidden-", elem2.getLog()); 145 assertEquals("",elem3.getLog()); 146 147 hand.requestActive(Accessor.DEFAULT.createPerspective(desc1)); 150 assertEquals("componentOpened-componentShowing-componentActivated-", elem1.getLog()); 151 assertEquals("componentOpened-componentShowing-componentActivated-componentDeactivated-componentHidden-", elem2.getLog()); 152 assertEquals("",elem3.getLog()); 153 154 } 155 156 157 } 158 159 | Popular Tags |