1 19 20 21 package org.netbeans.core.multiview; 22 23 import org.netbeans.core.api.multiview.MultiViewHandler; 24 import org.netbeans.core.api.multiview.MultiViews; 25 import org.netbeans.core.spi.multiview.MultiViewDescription; 26 import org.netbeans.core.spi.multiview.MultiViewFactory; 27 28 import java.awt.Image ; 29 import java.io.DataOutputStream ; 30 import java.io.File ; 31 import java.io.FileInputStream ; 32 import java.io.FileOutputStream ; 33 import java.io.IOException ; 34 import java.io.ObjectInputStream ; 35 import java.io.ObjectOutputStream ; 36 import java.io.Serializable ; 37 import java.util.Collection ; 38 import javax.swing.Action ; 39 import javax.swing.JPanel ; 40 import javax.swing.JToolBar ; 41 import javax.swing.SwingUtilities ; 42 import junit.framework.*; 43 import org.netbeans.core.api.multiview.MultiViewPerspective; 44 import org.netbeans.core.spi.multiview.CloseOperationHandler; 45 import org.netbeans.core.spi.multiview.MultiViewElement; 46 import org.netbeans.junit.*; 47 import org.openide.awt.UndoRedo; 48 import org.openide.util.HelpCtx; 49 import org.openide.util.io.NbMarshalledObject; 50 import org.openide.util.lookup.Lookups; 51 52 import org.openide.windows.*; 53 54 55 59 public class MultiViewTopComponentTest extends AbstractMultiViewTopComponentTestCase { 60 61 62 public MultiViewTopComponentTest(String name) { 63 super (name); 64 } 65 66 69 public static void main(java.lang.String [] args) { 70 junit.textui.TestRunner.run(suite()); 71 } 72 73 public static Test suite() { 74 TestSuite suite = new NbTestSuite(MultiViewTopComponentTest.class); 75 76 return suite; 77 } 78 79 protected TopComponent callFactory(MultiViewDescription[] desc, MultiViewDescription def) { 80 return MultiViewFactory.createMultiView(desc, def); 81 } 82 83 protected TopComponent callFactory(MultiViewDescription[] desc, MultiViewDescription def, CloseOperationHandler close) { 84 return MultiViewFactory.createMultiView(desc, def, close); 85 } 86 87 protected Class getTopComponentClass() { 88 return MultiViewTopComponent.class; 89 } 90 91 public void testPersistence() throws Exception { 92 MVElem elem1 = new MVElem(new Action [] {new Act1("act1")} ); 93 SerMVElem elem2 = new SerMVElem(); 94 SerMVElem elem3 = new SerMVElem(); 95 elem2.deserializeTest = "testtesttest - 2"; 96 elem3.deserializeTest = "testtesttest - 3"; 97 98 MultiViewDescription desc1 = new SerMVDesc("desc1", null, TopComponent.PERSISTENCE_NEVER, elem1); 99 MultiViewDescription desc2 = new SerMVDesc("desc2", null, TopComponent.PERSISTENCE_ONLY_OPENED, elem2); 100 MultiViewDescription desc3 = new SerMVDesc("desc3", null, TopComponent.PERSISTENCE_ALWAYS, elem3); 101 102 MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2 }; 103 SerCloseHandler close = new SerCloseHandler("serializedvalue"); 104 105 TopComponent tc = callFactory(descs, desc2, close); 106 tc.open(); 107 tc.requestActive(); 108 tc.close(); 110 111 NbMarshalledObject mars = new NbMarshalledObject(tc); 112 Object obj = mars.get(); 113 assertNotNull(obj); 114 assertEquals(getTopComponentClass(), obj.getClass()); 115 tc = (MultiViewTopComponent)obj; 116 117 118 MultiViewHandler handler = MultiViews.findMultiViewHandler(tc); 119 MultiViewPerspective[] descsAfter = handler.getPerspectives(); 120 assertNotNull(descsAfter); 121 assertEquals(2, descsAfter.length); 122 MultiViewPerspective selDesc = handler.getSelectedPerspective(); 123 assertNotNull(selDesc); 124 assertEquals("desc2", selDesc.getDisplayName()); 125 tc.open(); 126 tc.requestActive(); 127 MultiViewTopComponent mvtc = (MultiViewTopComponent)tc; 128 Collection cold = mvtc.getModel().getCreatedElements(); 129 assertEquals(1, cold.size()); 131 132 SerMVElem elSelecto = (SerMVElem)mvtc.getModel().getActiveElement(); 134 assertEquals("testtesttest - 2", elSelecto.deserializeTest); 135 assertEquals("componentOpened-componentShowing-componentActivated-", elSelecto.getLog()); 136 137 tc.close(); 139 140 141 } 142 143 } 144 145 | Popular Tags |