KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > windows > PreventNeedlessChangesOfActionMapTest


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 package org.openide.windows;
20
21 import javax.swing.ActionMap JavaDoc;
22 import org.netbeans.junit.NbTestCase;
23 import org.openide.nodes.AbstractNode;
24 import org.openide.nodes.Children;
25 import org.openide.nodes.Node;
26 import org.openide.util.Lookup;
27 import org.openide.util.Lookup.Result;
28 import org.openide.util.Lookup.Template;
29 import org.openide.util.LookupEvent;
30 import org.openide.util.LookupListener;
31
32 /**
33  *
34  * @author Jaroslav Tulach
35  */

36 public class PreventNeedlessChangesOfActionMapTest extends NbTestCase
37 implements LookupListener {
38     private TopComponent tc;
39     private Lookup.Result res;
40     private int cnt;
41     
42     /** Creates a new instance of PreventNeedlessChangesOfActionMapTest */
43     public PreventNeedlessChangesOfActionMapTest(String JavaDoc s) {
44         super(s);
45     }
46     
47     protected void setUp() throws Exception JavaDoc {
48         tc = new TopComponent();
49         res = tc.getLookup().lookup(new Lookup.Template<ActionMap JavaDoc> (ActionMap JavaDoc.class));
50         assertEquals("One instance", 1, res.allItems().size());
51         
52         res.addLookupListener(this);
53     }
54     
55     public void testChangeOfNodeDoesNotFireChangeInActionMap() {
56         ActionMap JavaDoc am = (ActionMap JavaDoc)tc.getLookup().lookup(ActionMap JavaDoc.class);
57         assertNotNull(am);
58         
59         Node m1 = new AbstractNode(Children.LEAF);
60         m1.setName("old m1");
61         Node m2 = new AbstractNode(Children.LEAF);
62         m2.setName("new m2");
63         
64         tc.setActivatedNodes(new Node[] { m1 });
65         assertEquals("No change in ActionMap 1", 0, cnt);
66         tc.setActivatedNodes(new Node[] { m2 });
67         assertEquals("No change in ActionMap 2", 0, cnt);
68         tc.setActivatedNodes(new Node[0]);
69         assertEquals("No change in ActionMap 3", 0, cnt);
70         tc.setActivatedNodes(null);
71         assertEquals("No change in ActionMap 4", 0, cnt);
72         
73         ActionMap JavaDoc am2 = (ActionMap JavaDoc)tc.getLookup().lookup(ActionMap JavaDoc.class);
74         assertEquals("Still the same action map", am, am2);
75     }
76
77     public void resultChanged(LookupEvent ev) {
78         cnt++;
79     }
80     
81 }
82
Popular Tags