1 19 20 package org.openide.explorer.propertysheet; 21 22 import java.awt.Component ; 23 import java.awt.event.ActionListener ; 24 import java.awt.event.InputEvent ; 25 import java.beans.PropertyEditor ; 26 import java.beans.PropertyEditorSupport ; 27 import java.lang.reflect.InvocationTargetException ; 28 import javax.swing.JComponent ; 29 import javax.swing.KeyStroke ; 30 import org.netbeans.junit.NbTestCase; 31 import org.openide.nodes.PropertySupport; 32 33 39 public class CustomInplaceEditorTest extends NbTestCase { 40 public CustomInplaceEditorTest(String name) { 41 super(name); 42 } 43 44 Component edComp = null; 45 PropertyEditor ped = null; 46 InplaceEditor ied = null; 47 InplaceEditor ied2 = null; 48 private static InplaceEditorFactory factory = new InplaceEditorFactory(true, new ReusablePropertyEnv()); 49 50 protected void setUp() throws Exception { 51 tp = new TProperty("TProperty", true); 53 te = new TEditor(); 55 56 TProperty2 tp2 = new TProperty2("TProperty2", true); 57 58 try { 59 ied = factory.getInplaceEditor(tp, false); 60 ied2 = factory.getInplaceEditor(tp2, false); 61 edComp = ied.getComponent(); 62 ped = ied.getPropertyEditor(); 63 } catch (Exception e) { 64 e.printStackTrace(); 65 fail("FAILED - Exception thrown "+e.getClass().toString()); 66 } 67 } 68 69 public void testRegisterInplaceEditorViaPropertyEnv() throws Exception { 70 assertTrue("Inplace editor should be instance of test class registered by PropertyEnv.registerInplaceEditor, but is instance of " + ied.getClass(), ied instanceof TInplaceEditor); 71 } 72 73 public void testRegisterInplaceEditorViaHint() throws Exception { 74 assertTrue("Inplace editor should be instance of test class as returned by TProperty2.getValue(\"inplaceEditor\"), but is instance of " + ied2.getClass(), ied2 instanceof TInplaceEditor); 75 } 76 77 public class TProperty2 extends PropertySupport { 79 private Boolean myValue = Boolean.TRUE; 80 public TProperty2(String name, boolean isWriteable) { 82 super(name, Boolean .class, name, "", true, isWriteable); 83 } 84 public Object getValue() { 86 return myValue; 87 } 88 89 public Object getValue(String key) { 90 if ("inplaceEditor".equals(key)) { 91 return new TInplaceEditor(); 92 } else { 93 return super.getValue(key); 94 } 95 } 96 97 public void setValue(Object value) throws IllegalArgumentException ,IllegalAccessException , InvocationTargetException { 99 myValue = (Boolean ) value; 100 } 101 } 102 103 public class TProperty extends PropertySupport { 105 private String myValue = "foo"; 106 public TProperty(String name, boolean isWriteable) { 108 super(name, String .class, name, "", true, isWriteable); 109 } 110 public Object getValue() { 112 return myValue; 113 } 114 public void setValue(Object value) throws IllegalArgumentException ,IllegalAccessException , InvocationTargetException { 116 Object oldVal = myValue; 117 myValue = value.toString(); 118 } 119 public PropertyEditor getPropertyEditor() { 121 return te; 122 } 123 } 124 125 public class TEditor extends PropertyEditorSupport implements ExPropertyEditor, InplaceEditor.Factory { 126 PropertyEnv env; 127 128 public TEditor() { 129 } 130 131 public void attachEnv(PropertyEnv env) { 132 this.env = env; 133 env.registerInplaceEditorFactory(this); 134 } 135 136 public boolean supportsCustomEditor() { 137 return false; 138 } 139 140 public void setValue(Object newValue) { 141 super.setValue(newValue); 142 } 143 144 public InplaceEditor getInplaceEditor() { 145 return new TInplaceEditor(); 146 } 147 148 } 149 150 public class TInplaceEditor extends JComponent implements InplaceEditor { 151 PropertyEditor pe=null; 152 public void clear() { 153 } 154 155 public void connect(PropertyEditor pe, PropertyEnv env) { 156 this.pe = pe; 157 } 158 159 public JComponent getComponent() { 160 return this; 161 } 162 163 public KeyStroke [] getKeyStrokes() { 164 return null; 165 } 166 167 public PropertyEditor getPropertyEditor() { 168 return pe; 169 } 170 171 public PropertyModel getPropertyModel() { 172 return null; 173 } 174 175 public Object getValue() { 176 return null; 177 } 178 179 public void handleInitialInputEvent(InputEvent e) { 180 } 181 182 public boolean isKnownComponent(Component c) { 183 return false; 184 } 185 186 public void reset() { 187 } 188 189 public void setPropertyModel(PropertyModel pm) { 190 } 191 192 public void setValue(Object o) { 193 } 194 195 public boolean supportsTextEntry() { 196 return false; 197 } 198 199 public void addActionListener(ActionListener al) { 200 } 201 202 public void removeActionListener(ActionListener al) { 203 } 204 205 } 206 207 private TProperty tp; 208 private TEditor te; 209 private String initEditorValue; 210 private String initPropertyValue; 211 private String postChangePropertyValue; 212 private String postChangeEditorValue; 213 } 214 | Popular Tags |