1 19 20 package org.openide.explorer.propertysheet; 21 22 import java.awt.Component ; 23 import java.beans.PropertyEditor ; 24 import java.beans.PropertyEditorSupport ; 25 import java.lang.reflect.InvocationTargetException ; 26 import javax.swing.JComboBox ; 27 import org.netbeans.junit.NbTestCase; 28 import org.openide.nodes.PropertySupport; 29 30 36 37 public class InplaceEditorFactoryTest extends NbTestCase { 38 public InplaceEditorFactoryTest(String name) { 39 super(name); 40 } 41 42 Component edComp = null; 43 PropertyEditor ped = null; 44 InplaceEditor ied = null; 45 46 protected void setUp() throws Exception { 47 PropUtils.forceRadioButtons=false; 48 tp = new TProperty("TProperty", true); 50 te = new TagsEditor(); 52 53 try { 54 ied = new InplaceEditorFactory(true, new ReusablePropertyEnv()).getInplaceEditor(tp, false); 55 edComp = ied.getComponent(); 56 ped = ied.getPropertyEditor(); 57 } catch (Exception e) { 58 fail("FAILED - Exception thrown "+e.getClass().toString()); 59 } 60 } 61 62 public void testInplaceIsCombo() throws Exception { 63 assertTrue("Editor for tagged value not a combo box", edComp instanceof JComboBox ); 64 } 65 66 public void testCorrectInplaceEditorValue() throws Exception { 67 assertTrue("InplaceEditor.getValue() returns " + ied.getValue() + " should be \"Value\"", "Value".equals(ied.getValue())); 68 } 69 70 public void testCorrectPropertyEditorValue() throws Exception { 71 assertTrue("PropertyEditor.getValue() returns " + ped.getValue() + " should be \"Value\"", "Value".equals(ped.getValue())); 72 } 73 74 public class TProperty extends PropertySupport { 76 private String myValue = "Value"; 77 public TProperty(String name, boolean isWriteable) { 79 super(name, String .class, name, "", true, isWriteable); 80 } 81 public Object getValue() { 83 return myValue; 84 } 85 public void setValue(Object value) throws IllegalArgumentException ,IllegalAccessException , InvocationTargetException { 87 Object oldVal = myValue; 88 myValue = value.toString(); 89 } 90 public PropertyEditor getPropertyEditor() { 92 return te; 93 } 94 } 95 96 public class TagsEditor extends PropertyEditorSupport implements ExPropertyEditor { 97 PropertyEnv env; 98 99 public TagsEditor() { 100 } 101 102 public String [] getTags() { 103 return new String [] {"a","b","c","d","Value"}; 104 } 105 106 public void attachEnv(PropertyEnv env) { 107 this.env = env; 108 } 109 110 public boolean supportsCustomEditor() { 111 return false; 112 } 113 114 public void setValue(Object newValue) { 115 super.setValue(newValue); 116 } 117 } 118 119 private TProperty tp; 120 private TagsEditor te; 121 private String initEditorValue; 122 private String initPropertyValue; 123 private String postChangePropertyValue; 124 private String postChangeEditorValue; 125 } 126 | Popular Tags |