KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > propertysheet > InplaceEditorFactoryTest


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.propertysheet;
21
22 import java.awt.Component JavaDoc;
23 import java.beans.PropertyEditor JavaDoc;
24 import java.beans.PropertyEditorSupport JavaDoc;
25 import java.lang.reflect.InvocationTargetException JavaDoc;
26 import javax.swing.JComboBox JavaDoc;
27 import org.netbeans.junit.NbTestCase;
28 import org.openide.nodes.PropertySupport;
29
30 /** Tests basic functionality of InplaceEditorFactory and its code to
31  * correctly configure a property editor and associated InplaceEditor
32  * with the data encapsulated by a Node.Property.
33  *
34  * @author Tim Boudreau
35  */

36
37 public class InplaceEditorFactoryTest extends NbTestCase {
38     public InplaceEditorFactoryTest(String JavaDoc name) {
39         super(name);
40     }
41     
42     Component JavaDoc edComp = null;
43     PropertyEditor JavaDoc ped = null;
44     InplaceEditor ied = null;
45     
46     protected void setUp() throws Exception JavaDoc {
47         PropUtils.forceRadioButtons=false;
48         // Create new TestProperty
49
tp = new TProperty("TProperty", true);
50         // Create new TEditor
51
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 JavaDoc e) {
58             fail("FAILED - Exception thrown "+e.getClass().toString());
59         }
60     }
61     
62     public void testInplaceIsCombo() throws Exception JavaDoc {
63         assertTrue("Editor for tagged value not a combo box", edComp instanceof JComboBox JavaDoc);
64     }
65     
66     public void testCorrectInplaceEditorValue() throws Exception JavaDoc {
67         assertTrue("InplaceEditor.getValue() returns " + ied.getValue() + " should be \"Value\"", "Value".equals(ied.getValue()));
68     }
69     
70     public void testCorrectPropertyEditorValue() throws Exception JavaDoc {
71         assertTrue("PropertyEditor.getValue() returns " + ped.getValue() + " should be \"Value\"", "Value".equals(ped.getValue()));
72     }
73     
74     // Property definition
75
public class TProperty extends PropertySupport {
76         private String JavaDoc myValue = "Value";
77         // Create new Property
78
public TProperty(String JavaDoc name, boolean isWriteable) {
79             super(name, String JavaDoc.class, name, "", true, isWriteable);
80         }
81         // get property value
82
public Object JavaDoc getValue() {
83             return myValue;
84         }
85         // set property value
86
public void setValue(Object JavaDoc value) throws IllegalArgumentException JavaDoc,IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
87             Object JavaDoc oldVal = myValue;
88             myValue = value.toString();
89         }
90         // get the property editor
91
public PropertyEditor JavaDoc getPropertyEditor() {
92             return te;
93         }
94     }
95     
96     public class TagsEditor extends PropertyEditorSupport JavaDoc implements ExPropertyEditor {
97         PropertyEnv env;
98         
99         public TagsEditor() {
100         }
101         
102         public String JavaDoc[] getTags() {
103             return new String JavaDoc[] {"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 JavaDoc newValue) {
115             super.setValue(newValue);
116         }
117     }
118     
119     private TProperty tp;
120     private TagsEditor te;
121     private String JavaDoc initEditorValue;
122     private String JavaDoc initPropertyValue;
123     private String JavaDoc postChangePropertyValue;
124     private String JavaDoc postChangeEditorValue;
125 }
126
Popular Tags