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 MultiViewFactoryTest extends NbTestCase { 45 46 47 public MultiViewFactoryTest(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(MultiViewFactoryTest.class); 60 61 return suite; 62 } 63 64 protected boolean runInEQ () { 65 return true; 66 } 67 68 69 public void testcreateMultiView () throws Exception { 70 MultiViewDescription desc1 = new MVDesc("desc1", null, 0, new MVElem()); 71 MultiViewDescription desc2 = new MVDesc("desc2", null, 0, new MVElem()); 72 MultiViewDescription desc3 = new MVDesc("desc3", null, 0, new MVElem()); 73 MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 }; 74 TopComponent tc = MultiViewFactory.createMultiView(descs, desc1); 75 assertNotNull(tc); 76 77 tc = MultiViewFactory.createMultiView(descs, null); 78 assertNotNull(tc); 79 80 tc = MultiViewFactory.createMultiView(null, null); 81 assertNull(tc); 82 } 83 84 85 public void testCreateMultiView2 () throws Exception { 86 MultiViewDescription desc1 = new MVDesc("desc1", null, 0, new MVElem()); 87 MultiViewDescription desc2 = new MVDesc("desc2", null, 0, new MVElem()); 88 MultiViewDescription desc3 = new MVDesc("desc3", null, 0, new MVElem()); 89 MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 }; 90 MyClose close = new MyClose(); 91 TopComponent tc = MultiViewFactory.createMultiView(descs, desc1, close); 92 assertNotNull(tc); 93 94 tc.open(); 95 tc.close(); 97 assertFalse(close.wasUsed); 99 100 } 101 102 public void testCreateCloneableMultiView () throws Exception { 103 MultiViewDescription desc1 = new MVDesc("desc1", null, 0, new MVElem()); 104 MultiViewDescription desc2 = new MVDesc("desc2", null, 0, new MVElem()); 105 MultiViewDescription desc3 = new MVDesc("desc3", null, 0, new MVElem()); 106 MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 }; 107 CloneableTopComponent tc = MultiViewFactory.createCloneableMultiView(descs, desc1); 108 assertNotNull(tc); 109 110 tc = MultiViewFactory.createCloneableMultiView(descs, null); 111 assertNotNull(tc); 112 113 tc = MultiViewFactory.createCloneableMultiView(null, null); 114 assertNull(tc); 115 } 116 117 118 public void testCreateCloneableMultiView2 () throws Exception { 119 MultiViewDescription desc1 = new MVDesc("desc1", null, 0, new MVElem()); 120 MultiViewDescription desc2 = new MVDesc("desc2", null, 0, new MVElem()); 121 MultiViewDescription desc3 = new MVDesc("desc3", null, 0, new MVElem()); 122 MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 }; 123 MyClose close = new MyClose(); 124 TopComponent tc = MultiViewFactory.createCloneableMultiView(descs, desc1, close); 125 assertNotNull(tc); 126 127 tc.open(); 128 tc.close(); 130 assertFalse(close.wasUsed); 132 133 } 134 135 136 146 147 public void testCreateUnsafeCloseState () throws Exception { 148 CloseOperationState state = MultiViewFactory.createUnsafeCloseState("ID_UNSAFE", 149 MultiViewFactory.NOOP_CLOSE_ACTION, MultiViewFactory.NOOP_CLOSE_ACTION); 150 assertNotNull(state); 151 assertFalse(state.canClose()); 152 assertNotNull(state.getDiscardAction()); 153 assertNotNull(state.getProceedAction()); 154 assertEquals("ID_UNSAFE", state.getCloseWarningID()); 155 156 state = MultiViewFactory.createUnsafeCloseState( null, null, null); 157 assertNotNull(state); 158 assertFalse(state.canClose()); 159 assertNotNull(state.getDiscardAction()); 160 assertNotNull(state.getProceedAction()); 161 assertNotNull(state.getCloseWarningID()); 162 163 } 164 165 166 private class MyClose implements CloseOperationHandler { 167 168 public boolean wasUsed = false; 169 public int supposed = 0; 170 public boolean canClose = true; 171 172 public boolean resolveCloseOperation(CloseOperationState[] elements) { 173 wasUsed = true; 174 return canClose; 175 } 176 177 178 } 179 180 } 181 182 | Popular Tags |