KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > multiview > MultiViewFactoryTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.multiview;
21
22 import java.awt.Image JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import javax.swing.JPanel JavaDoc;
25 import javax.swing.JToolBar JavaDoc;
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 /**
41  *
42  * @author Milos Kleint
43  */

44 public class MultiViewFactoryTest extends NbTestCase {
45     
46     /** Creates a new instance of SFSTest */
47     public MultiViewFactoryTest(String JavaDoc name) {
48         super (name);
49     }
50     
51     /**
52      * @param args the command line arguments
53      */

54     public static void main(java.lang.String JavaDoc[] 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 JavaDoc {
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 JavaDoc {
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         // just one element as shown..
96
tc.close();
97         // the close handler is not used, becasue all the elements are in consistent state
98
assertFalse(close.wasUsed);
99         
100     }
101     
102    public void testCreateCloneableMultiView () throws Exception JavaDoc {
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 JavaDoc {
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         // just one element as shown..
129
tc.close();
130         // the close handler is not used, becasue all the elements are in consistent state
131
assertFalse(close.wasUsed);
132         
133     }
134
135
136 // public void testCreateSafeCloseState () throws Exception {
137
// CloseOperationState state = MultiViewFactory.createSafeCloseState();
138
// assertNotNull(state);
139
// assertTrue(state.canClose());
140
// assertNotNull(state.getDiscardAction());
141
// assertNotNull(state.getProceedAction());
142
// assertNotNull(state.getCloseWarningID());
143
//
144
// }
145

146     
147     public void testCreateUnsafeCloseState () throws Exception JavaDoc {
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