1 7 package org.ejtools.adwt.editor; 8 9 import java.awt.Component ; 10 import java.awt.Container ; 11 import java.awt.GridBagConstraints ; 12 import java.awt.GridBagLayout ; 13 import java.awt.event.ActionEvent ; 14 import java.awt.event.ActionListener ; 15 import java.awt.event.FocusAdapter ; 16 import java.awt.event.FocusEvent ; 17 import java.util.ResourceBundle ; 18 19 import javax.management.ObjectName ; 20 import javax.swing.JButton ; 21 import javax.swing.JPanel ; 22 import javax.swing.JTextField ; 23 import javax.swing.SwingUtilities ; 24 25 import org.ejtools.adwt.util.ObjectSearcher; 26 27 34 public class ObjectNameEditor extends GenericEditor 35 { 36 37 protected JButton button; 38 39 protected Container panel; 40 41 protected JTextField text; 42 43 private final static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.adwt.editor.Resources"); 44 45 46 47 public ObjectNameEditor() 48 { 49 this.text = new JTextField (30); 50 51 this.text.addFocusListener( 53 new FocusAdapter () 54 { 55 public void focusLost(FocusEvent e) 56 { 57 setAsText(text.getText()); 58 } 59 } 60 ); 61 } 62 63 64 69 public String getAsText() 70 { 71 if (this.value != null) 72 { 73 return ((ObjectName ) this.value).getCanonicalName(); 74 } 75 return ""; 76 } 77 78 79 84 public Component getCustomEditor() 85 { 86 if (Boolean.getBoolean("ejtools.objectname.hyperlink")) 87 { 88 if (this.panel == null) 89 { 90 GridBagConstraints gridbagconstraints = new GridBagConstraints (); 91 92 this.panel = new JPanel (); 93 this.panel.setLayout(new GridBagLayout ()); 94 this.button = new JButton (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 () 106 { 107 110 public void actionPerformed(ActionEvent 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 135 public void setAsText(String s) 136 { 137 try 138 { 139 this.value = new ObjectName (s); 140 } 141 catch (Exception e) 142 { 143 this.value = null; 144 } 145 this.text.setText(this.getAsText()); 146 this.firePropertyChange(); 147 } 148 149 150 155 public void setValue(Object object) 156 { 157 super.setValue(object); 158 if (this.value != null) 159 { 160 this.text.setText(this.getAsText()); 161 } 162 } 163 164 165 170 public boolean supportsCustomEditor() 171 { 172 return true; 173 } 174 } 175 176 | Popular Tags |