01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * 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-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.xslt.tmap.nodes.properties;
20:
21: import java.awt.Component;
22: import java.beans.PropertyEditorSupport;
23: import org.netbeans.modules.xml.xam.Reference;
24: import org.openide.explorer.propertysheet.ExPropertyEditor;
25: import org.openide.explorer.propertysheet.PropertyEnv;
26:
27: /**
28: *
29: * @author Vitaly Bychkov
30: * @author nk160297
31: */
32: public class ModelReferenceEditor extends PropertyEditorSupport
33: implements ExPropertyEditor {
34:
35: private Reference myRef;
36: private static StringPropertyCustomizer customizer = null;
37: private PropertyEnv myPropertyEnv = null;
38:
39: /** Creates a new instance of ModelReferenceEditor */
40: public ModelReferenceEditor() {
41: }
42:
43: public String getAsText() {
44: return getAsText(myRef);
45: }
46:
47: public boolean supportsCustomEditor() {
48: return true;
49: }
50:
51: public Component getCustomEditor() {
52: customizer = PropertyUtils.propertyCustomizerPool
53: .getObjectByClass(StringPropertyCustomizer.class);
54: customizer.init(myPropertyEnv, this );
55: return customizer;
56: }
57:
58: public Object getValue() {
59: if (myRef != null) {
60: try {
61: //check if reference still pointing to valid element
62: myRef.get();
63: return myRef;
64: } catch (IllegalStateException ex) {
65: return null;
66: }
67: }
68: return null;
69: }
70:
71: public void setValue(Object newValue) {
72: if (newValue != null) {
73: assert newValue instanceof Reference;
74: }
75: myRef = (Reference) newValue;
76: firePropertyChange();
77: }
78:
79: public void setAsText(String text)
80: throws java.lang.IllegalArgumentException {
81: // DO NOTHING HERE!
82: }
83:
84: public static String getAsText(Reference ref) {
85: String result = ResolverUtility.getNameByRef(ref);
86: return result == null ? "" : result;
87: }
88:
89: public void attachEnv(PropertyEnv newPropertyEnv) {
90: myPropertyEnv = newPropertyEnv;
91: }
92:
93: }
|