KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > adwt > editor > ObjectNameEditor


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.adwt.editor;
8
9 import java.awt.Component JavaDoc;
10 import java.awt.Container JavaDoc;
11 import java.awt.GridBagConstraints JavaDoc;
12 import java.awt.GridBagLayout JavaDoc;
13 import java.awt.event.ActionEvent JavaDoc;
14 import java.awt.event.ActionListener JavaDoc;
15 import java.awt.event.FocusAdapter JavaDoc;
16 import java.awt.event.FocusEvent JavaDoc;
17 import java.util.ResourceBundle JavaDoc;
18
19 import javax.management.ObjectName JavaDoc;
20 import javax.swing.JButton JavaDoc;
21 import javax.swing.JPanel JavaDoc;
22 import javax.swing.JTextField JavaDoc;
23 import javax.swing.SwingUtilities JavaDoc;
24
25 import org.ejtools.adwt.util.ObjectSearcher;
26
27 /**
28  * Description of the Class
29  *
30  * @author Laurent Etiemble
31  * @version $Revision: 1.7 $
32  * @todo Javadoc to complete
33  */

34 public class ObjectNameEditor extends GenericEditor
35 {
36    /** Description of the Field */
37    protected JButton JavaDoc button;
38    /** Description of the Field */
39    protected Container JavaDoc panel;
40    /** Description of the Field */
41    protected JTextField JavaDoc text;
42    /** Description of the Field */
43    private final static ResourceBundle JavaDoc resources = ResourceBundle.getBundle("org.ejtools.adwt.editor.Resources");
44
45
46    /** Constructor */
47    public ObjectNameEditor()
48    {
49       this.text = new JTextField JavaDoc(30);
50
51       // Update value when edited
52
this.text.addFocusListener(
53          new FocusAdapter JavaDoc()
54          {
55             public void focusLost(FocusEvent JavaDoc e)
56             {
57                setAsText(text.getText());
58             }
59          }
60          );
61    }
62
63
64    /**
65     * Getter for the asText attribute
66     *
67     * @return The value
68     */

69    public String JavaDoc getAsText()
70    {
71       if (this.value != null)
72       {
73          return ((ObjectName JavaDoc) this.value).getCanonicalName();
74       }
75       return "";
76    }
77
78
79    /**
80     * Gets the customEditor attribute of the ObjectNameEditor object
81     *
82     * @return The customEditor value
83     */

84    public Component JavaDoc getCustomEditor()
85    {
86       if (Boolean.getBoolean("ejtools.objectname.hyperlink"))
87       {
88          if (this.panel == null)
89          {
90             GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
91
92             this.panel = new JPanel JavaDoc();
93             this.panel.setLayout(new GridBagLayout JavaDoc());
94             this.button = new JButton JavaDoc(resources.getString("ObjectNameEditor.button.view"));
95
96             gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE;
97             this.panel.add(button, gridbagconstraints);
98
99             gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
100             gridbagconstraints.weightx = 1.0;
101             gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
102             this.panel.add(text, gridbagconstraints);
103
104             this.button.addActionListener(
105                new ActionListener JavaDoc()
106                {
107                   /**
108                    * @param e Event action
109                    */

110                   public void actionPerformed(ActionEvent JavaDoc e)
111                   {
112                      ObjectSearcher finder = (ObjectSearcher) SwingUtilities.getAncestorOfClass(ObjectSearcher.class, ObjectNameEditor.this.panel);
113                      if ((finder != null) && (ObjectNameEditor.this.value != null))
114                      {
115                         finder.find(ObjectNameEditor.this.getAsText());
116                      }
117                   }
118                }
119                );
120          }
121          return this.panel;
122       }
123       else
124       {
125          return this.text;
126       }
127    }
128
129
130    /**
131     * Setter for the asText attribute
132     *
133     * @param s The new value
134     */

135    public void setAsText(String JavaDoc s)
136    {
137       try
138       {
139          this.value = new ObjectName JavaDoc(s);
140       }
141       catch (Exception JavaDoc e)
142       {
143          this.value = null;
144       }
145       this.text.setText(this.getAsText());
146       this.firePropertyChange();
147    }
148
149
150    /**
151     * Setter for the value attribute
152     *
153     * @param object The new value value
154     */

155    public void setValue(Object JavaDoc object)
156    {
157       super.setValue(object);
158       if (this.value != null)
159       {
160          this.text.setText(this.getAsText());
161       }
162    }
163
164
165    /**
166     * Description of the Method
167     *
168     * @return Description of the Return Value
169     */

170    public boolean supportsCustomEditor()
171    {
172       return true;
173    }
174 }
175
176
Popular Tags