KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > execution > beaninfo > editors > NbClassPathEditor


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.netbeans.core.execution.beaninfo.editors;
21
22 import java.awt.*;
23 import java.beans.*;
24 import org.openide.execution.NbClassPath;
25 import org.openide.explorer.propertysheet.ExPropertyEditor;
26 import org.openide.explorer.propertysheet.PropertyEnv;
27 import org.openide.nodes.Node;
28
29 /** A property editor for NbClassPath.
30 * @author Jaroslav Tulach
31 */

32 public class NbClassPathEditor extends Object JavaDoc implements ExPropertyEditor {
33     private NbClassPath pd;
34     private PropertyChangeSupport support;
35     private boolean editable = true;
36
37     public NbClassPathEditor () {
38         support = new PropertyChangeSupport (this);
39     }
40
41     public Object JavaDoc getValue () {
42         return pd;
43     }
44
45     public void setValue (Object JavaDoc value) {
46         Object JavaDoc old = pd;
47         pd = (NbClassPath) value;
48         support.firePropertyChange ("value", old, pd); // NOI18N
49
}
50
51     public String JavaDoc getAsText () {
52         if ( pd != null )
53             return pd.getClassPath ();
54         else
55             return "null"; // NOI18N
56
}
57
58     public void setAsText (String JavaDoc string) {
59         if ( ! "null".equals( string ) )
60             setValue (new NbClassPath (string));
61     }
62
63     public String JavaDoc getJavaInitializationString () {
64         return "new NbClassPath (" + getAsText () + ")"; // NOI18N
65
}
66
67     public String JavaDoc[] getTags () {
68         return null;
69     }
70
71     public boolean isPaintable () {
72         return false;
73     }
74
75     public void paintValue (Graphics g, Rectangle rectangle) {
76     }
77
78     public boolean supportsCustomEditor () {
79         return true;
80     }
81
82     public Component getCustomEditor () {
83         return new NbClassPathCustomEditor (this);
84     }
85
86     public void addPropertyChangeListener (PropertyChangeListener propertyChangeListener) {
87         support.addPropertyChangeListener (propertyChangeListener);
88     }
89
90     public void removePropertyChangeListener (PropertyChangeListener propertyChangeListener) {
91         support.removePropertyChangeListener (propertyChangeListener);
92     }
93
94     /** gets information if the text in editor should be editable or not */
95     public boolean isEditable(){
96         return editable;
97     }
98     
99     public void attachEnv(PropertyEnv env) {
100         FeatureDescriptor desc = env.getFeatureDescriptor();
101         if (desc instanceof Node.Property){
102             Node.Property prop = (Node.Property)desc;
103             editable = prop.canWrite();
104         }
105     }
106 }
107
Popular Tags