1 19 20 package org.openide.explorer.view; 21 22 import java.lang.reflect.InvocationTargetException ; 23 import javax.swing.JCheckBox ; 24 import org.netbeans.junit.NbTestCase; 25 import org.openide.nodes.Node; 26 27 30 public class NodeTableModelTest extends NbTestCase { 31 32 public NodeTableModelTest(String 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 checkBox; 45 46 p = new MyProperty(); 47 p.setDisplayName( "displayName1" ); 48 p.setShortDescription( "shortDescription1" ); 49 p.setValue( "ColumnMnemonicCharTTV", "" ); 50 51 checkBox = new JCheckBox ( "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 ( "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 ( "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 ( "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 .class ); 115 } 116 117 public void setValue(Object val) 118 throws IllegalAccessException , 119 IllegalArgumentException , 120 InvocationTargetException { 121 } 122 123 public Object getValue() 124 throws IllegalAccessException , 125 InvocationTargetException { 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 getValue(String attributeName) { 140 return null; 141 } 142 } 143 } 144 | Popular Tags |