1 19 20 package org.netbeans.core.multiview; 21 22 import java.awt.Image ; 23 import javax.swing.Action ; 24 import javax.swing.JPanel ; 25 import javax.swing.JToolBar ; 26 import junit.framework.*; 27 import org.netbeans.core.api.multiview.MultiViewHandler; 28 import org.netbeans.core.api.multiview.MultiViews; 29 import org.netbeans.core.spi.multiview.CloseOperationHandler; 30 import org.netbeans.core.spi.multiview.CloseOperationState; 31 import org.netbeans.core.spi.multiview.MultiViewDescription; 32 import org.netbeans.core.spi.multiview.MultiViewFactory; 33 import org.netbeans.junit.*; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.lookup.Lookups; 36 37 import org.openide.windows.*; 38 39 40 44 public class CloseOperationHandlerTest extends NbTestCase { 45 46 47 public CloseOperationHandlerTest(String name) { 48 super (name); 49 } 50 51 54 public static void main(java.lang.String [] args) { 55 junit.textui.TestRunner.run(suite()); 56 } 57 58 public static Test suite() { 59 TestSuite suite = new NbTestSuite(CloseOperationHandlerTest.class); 60 61 return suite; 62 } 63 64 protected boolean runInEQ () { 65 return true; 66 } 67 68 69 public void testCreateMultiView2 () throws Exception { 70 MultiViewDescription desc1 = new MVDesc("desc1", null, 0, new NonClosableElem()); 71 MultiViewDescription desc2 = new MVDesc("desc2", null, 0, new NonClosableElem()); 72 MultiViewDescription desc3 = new MVDesc("desc3", null, 0, new MVElem()); 73 MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 }; 74 MyCloseHandler close = new MyCloseHandler(); 75 TopComponent tc = MultiViewFactory.createMultiView(descs, desc1, close); 76 assertNotNull(tc); 77 78 tc.open(); 79 close.supposed = 1; 81 tc.close(); 82 assertTrue(close.wasUsed); 83 84 tc.open(); 85 MultiViewHandler handler = MultiViews.findMultiViewHandler(tc); 86 handler.requestActive(handler.getPerspectives()[2]); 87 close.supposed = 1; 89 close.canClose = false; 91 92 tc.close(); 93 assertTrue(tc.isOpened()); 94 95 96 handler.requestActive(handler.getPerspectives()[1]); 97 close.supposed = 2; 99 close.canClose = true; 101 102 tc.close(); 103 assertTrue(!tc.isOpened()); 104 105 } 106 107 108 private class MyCloseHandler implements CloseOperationHandler { 109 110 public boolean wasUsed = false; 111 public int supposed = 0; 112 public boolean canClose = true; 113 114 public boolean resolveCloseOperation(CloseOperationState[] elements) { 115 wasUsed = true; 116 if (supposed != elements.length) { 117 throw new IllegalStateException ("A different number of elements returned. Expected=" + supposed + " but was:" + elements.length); 118 } 119 return canClose; 120 } 121 122 123 } 124 125 private class NonClosableElem extends MVElem { 126 127 public CloseOperationState canCloseElement() { 128 return MultiViewFactory.createUnsafeCloseState("ID", MultiViewFactory.NOOP_CLOSE_ACTION, MultiViewFactory.NOOP_CLOSE_ACTION); 129 } 130 131 } 132 133 } 134 135 | Popular Tags |