KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

55     public static void main(java.lang.String JavaDoc[] 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 JavaDoc {
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         // NOT OPENED YET.
86
assertEquals("",elem1.getLog());
87         assertEquals("",elem2.getLog());
88         
89         tc.open();
90         assertEquals("componentOpened-componentShowing-", elem1.getLog());
91         assertEquals("",elem2.getLog());
92         
93         // test related hack, easy establishing a connection from Desc->perspective
94
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         // test related hack, easy establishing a connection from Desc->perspective
102
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         // test related hack, easy establishing a connection from Desc->perspective
108
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 JavaDoc {
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         // NOT OPENED YET.
132
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         // test related hack, easy establishing a connection from Desc->perspective
142
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         // do request active the same element, nothing should happen.
148
// test related hack, easy establishing a connection from Desc->perspective
149
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