KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > view > NodeTableModelTest


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.openide.explorer.view;
21
22 import java.lang.reflect.InvocationTargetException JavaDoc;
23 import javax.swing.JCheckBox JavaDoc;
24 import org.netbeans.junit.NbTestCase;
25 import org.openide.nodes.Node;
26
27 /*
28  * Tests for class NodeTableModelTest
29  */

30 public class NodeTableModelTest extends NbTestCase {
31
32     public NodeTableModelTest(String JavaDoc name) {
33         super(name);
34     }
35
36     protected boolean runInEQ() {
37         return true;
38     }
39
40     public void testMakeAccessibleCheckBox() {
41         MyNodeTableModel model = new MyNodeTableModel( 0 );
42
43         MyProperty p;
44         JCheckBox JavaDoc checkBox;
45
46         p = new MyProperty();
47         p.setDisplayName( "displayName1" );
48         p.setShortDescription( "shortDescription1" );
49         p.setValue( "ColumnMnemonicCharTTV", "" );
50         
51         checkBox = new JCheckBox JavaDoc( "displayName" );
52         model.makeAccessibleCheckBox( checkBox, p );
53         assertEquals( "Invalid accessible name", checkBox.getAccessibleContext().getAccessibleName(), p.getDisplayName() );
54         assertEquals( "Invalid accessible description", checkBox.getAccessibleContext().getAccessibleDescription(), p.getShortDescription() );
55         assertEquals( "Invalid mnemonic", checkBox.getMnemonic(), 0 );
56
57         
58         p = new MyProperty();
59         p.setDisplayName( "displayName" );
60         p.setShortDescription( "shortDescription2" );
61         p.setValue( "ColumnMnemonicCharTTV", "d" );
62         
63         checkBox = new JCheckBox JavaDoc( "displayName2" );
64         model.makeAccessibleCheckBox( checkBox, p );
65         assertEquals( "Invalid accessible name", checkBox.getAccessibleContext().getAccessibleName(), p.getDisplayName() );
66         assertEquals( "Invalid accessible description", checkBox.getAccessibleContext().getAccessibleDescription(), p.getShortDescription() );
67         assertEquals( "Invalid mnemonic", checkBox.getMnemonic(), 'D' );
68
69         
70         p = new MyProperty();
71         p.setDisplayName( "displayName3" );
72         p.setShortDescription( "shortDescription3" );
73         p.setValue( "ColumnMnemonicCharTTV", "N" );
74         
75         checkBox = new JCheckBox JavaDoc( "displayName" );
76         model.makeAccessibleCheckBox( checkBox, p );
77         assertEquals( "Invalid accessible name", checkBox.getAccessibleContext().getAccessibleName(), p.getDisplayName() );
78         assertEquals( "Invalid accessible description", checkBox.getAccessibleContext().getAccessibleDescription(), p.getShortDescription() );
79         assertEquals( "Invalid mnemonic", checkBox.getMnemonic(), 'N' );
80
81         
82         p = new NullGetValueProperty();
83         p.setDisplayName( "displayName4" );
84         p.setShortDescription( "shortDescription4" );
85         
86         checkBox = new JCheckBox JavaDoc( "displayName" );
87         model.makeAccessibleCheckBox( checkBox, p );
88         assertEquals( "Invalid accessible name", checkBox.getAccessibleContext().getAccessibleName(), p.getDisplayName() );
89         assertEquals( "Invalid accessible description", checkBox.getAccessibleContext().getAccessibleDescription(), p.getShortDescription() );
90         assertEquals( "Invalid mnemonic", checkBox.getMnemonic(), 0 );
91     }
92     
93
94     private static class MyNodeTableModel extends NodeTableModel {
95         public MyNodeTableModel( int columnCount ) {
96             this.allPropertyColumns = new NodeTableModel.ArrayColumn[columnCount];
97             for( int i=0; i<allPropertyColumns.length; i++ ) {
98                 allPropertyColumns[i] = new NodeTableModel.ArrayColumn();
99                 allPropertyColumns[i].setProperty( new MyProperty() );
100             }
101         }
102         
103         Node.Property getProperty( int index ) {
104             return allPropertyColumns[index].getProperty();
105         }
106         
107         void setProperty( int index, Node.Property p ) {
108             allPropertyColumns[index].setProperty( p );
109         }
110     }
111     
112     private static class MyProperty extends Node.Property {
113         public MyProperty() {
114             super( Object JavaDoc.class );
115         }
116         
117         public void setValue(Object JavaDoc val)
118             throws IllegalAccessException JavaDoc,
119                 IllegalArgumentException JavaDoc,
120                 InvocationTargetException JavaDoc {
121         }
122
123         public Object JavaDoc getValue()
124             throws IllegalAccessException JavaDoc,
125                 InvocationTargetException JavaDoc {
126             return null;
127         }
128
129         public boolean canWrite() {
130             return true;
131         }
132
133         public boolean canRead() {
134             return true;
135         }
136     }
137     
138     private static class NullGetValueProperty extends MyProperty {
139         public Object JavaDoc getValue(String JavaDoc attributeName) {
140             return null;
141         }
142     }
143 }
144
Popular Tags