KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 package org.netbeans.core.execution.beaninfo.editors;
22
23
24 import java.awt.Component JavaDoc;
25 import java.awt.Graphics JavaDoc;
26 import java.awt.Rectangle JavaDoc;
27 import java.beans.PropertyChangeListener JavaDoc;
28 import java.beans.PropertyChangeSupport JavaDoc;
29 import java.io.File JavaDoc;
30 import org.openide.execution.NbProcessDescriptor;
31 import org.openide.explorer.propertysheet.ExPropertyEditor;
32 import org.openide.explorer.propertysheet.PropertyEnv;
33
34
35 /**
36  * A property editor for <code>NbProcessDescriptor</code>.
37  *
38  * @author Ian Formanek
39  */

40 public class NbProcessDescriptorEditor extends Object JavaDoc implements ExPropertyEditor {
41     private PropertyEnv env;
42
43     /** <code>NbProcessDescriptor</code> to custmize. */
44     NbProcessDescriptor pd;
45     /** Property support, helper instance. */
46     private PropertyChangeSupport JavaDoc support;
47
48     
49     /** Creates property editor. */
50     public NbProcessDescriptorEditor() {
51         support = new PropertyChangeSupport JavaDoc (this);
52     }
53
54     
55     /** Gets value. Implements <code>PropertyEditor</code> interface. */
56     public Object JavaDoc getValue () {
57         return pd;
58     }
59
60     /** Sets value. Implements <code>PropertyEditor</code> interface. */
61     public void setValue (Object JavaDoc value) {
62         pd = (NbProcessDescriptor) value;
63         support.firePropertyChange("", null, null); // NOI18N
64
}
65
66     /** Gets value as text. Implements <code>PropertyEditor</code> interface. */
67     public String JavaDoc getAsText () {
68         if ( pd == null )
69             return "null"; // NOI18N
70
return pd.getProcessName () + " " + pd.getArguments (); // NOI18N
71
}
72
73     /** Sets value as text. Implemetns <code>ProepertyEditor</code> interface. */
74     public void setAsText(String JavaDoc string) {
75         string = string.trim ();
76
77         int indx = string.indexOf(' ');
78         
79         String JavaDoc prg;
80         String JavaDoc args;
81         
82         // Fix #13186. If the string represents path
83
// with directories containing white spaces don't separate them to args.
84
if(indx == -1 || new File JavaDoc(string).exists()) {
85             prg = string;
86             args = ""; // NOI18N
87
} else {
88             prg = string.substring(0, indx);
89             args = string.substring(indx + 1);
90         }
91
92         NbProcessDescriptor newPD = null;
93         if ( pd == null )
94             newPD = new NbProcessDescriptor (
95                         prg,
96                         args
97                     );
98         else
99             newPD = new NbProcessDescriptor (
100                         prg,
101                         args,
102                         pd.getInfo()
103                     );
104         
105         setValue(newPD);
106     }
107
108     /** Gets java initialization string. Implements <code>PropertyEditor</code>
109      * interface.
110      * @return <code>null</code> */

111     public String JavaDoc getJavaInitializationString () {
112         return null; // no code generation
113
}
114
115     /** Gets tags. Implements <code>PropertyEditor</code> interface.
116      * @return <code>null</code> */

117     public String JavaDoc[] getTags () {
118         return null;
119     }
120
121     /** Indicates wheter this editor paints itself the value. Implements
122      * <code>PropertyEditor</code> interface.
123      * @return <code>null</code> */

124     public boolean isPaintable () {
125         return false;
126     }
127
128     /** Dummy implementation of <code>PropertyEditor</code> interface method.
129      * @see #isPaintable */

130     public void paintValue (Graphics JavaDoc g, Rectangle JavaDoc rectangle) {
131     }
132
133     /** Inidicates whether this editor supports custom editing. Implements
134      * <code>PropertyEdtitor</code> interface.
135      * @return <code>true</code> */

136     public boolean supportsCustomEditor () {
137         return true;
138     }
139
140     /** Gets custom editor. Implements <code>PropertyEditor</code> interface.
141      * @return <code>NbProcessDescriptorCustomEditor</code>
142      * @see NbProcessDescriptorCustomEditor */

143     public Component JavaDoc getCustomEditor () {
144         return new NbProcessDescriptorCustomEditor (this, env);
145     }
146
147     /** Adds <code>PropertyChangeListener</code>. Implements
148      * <code>PropertyEditor</code> interface. */

149     public void addPropertyChangeListener (PropertyChangeListener JavaDoc propertyChangeListener) {
150         support.addPropertyChangeListener (propertyChangeListener);
151     }
152
153     /** Removes <code>PropertyChangeListner</code>. Implements
154      * <code>PropertyEditor</code> interface. */

155     public void removePropertyChangeListener(PropertyChangeListener JavaDoc propertyChangeListener) {
156         support.removePropertyChangeListener(propertyChangeListener);
157     }
158     
159     /**
160      * This method is called by the IDE to pass
161      * the environment to the property editor.
162      * @param env Environment passed by the ide.
163      */

164     public void attachEnv(PropertyEnv env) {
165         this.env = env;
166     }
167 }
168
Popular Tags