|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ObjectNameEditor.java | 0% | 6,1% | 12,5% | 5,9% |
|
||||||||||||||
| 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;
|
|
| 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 |
/**
|
|
| 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 button;
|
|
| 38 |
/** Description of the Field */
|
|
| 39 |
protected Container panel;
|
|
| 40 |
/** Description of the Field */
|
|
| 41 |
protected JTextField text;
|
|
| 42 |
/** Description of the Field */
|
|
| 43 |
private final static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.adwt.editor.Resources"); |
|
| 44 |
|
|
| 45 |
|
|
| 46 |
/** Constructor */
|
|
| 47 | 8 |
public ObjectNameEditor()
|
| 48 |
{
|
|
| 49 | 8 |
this.text = new JTextField(30); |
| 50 |
|
|
| 51 |
// Update value when edited
|
|
| 52 | 8 |
this.text.addFocusListener(
|
| 53 |
new FocusAdapter()
|
|
| 54 |
{
|
|
| 55 | 0 |
public void focusLost(FocusEvent e) |
| 56 |
{
|
|
| 57 | 0 |
setAsText(text.getText()); |
| 58 |
} |
|
| 59 |
} |
|
| 60 |
); |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
|
|
| 64 |
/**
|
|
| 65 |
* Getter for the asText attribute
|
|
| 66 |
*
|
|
| 67 |
* @return The value
|
|
| 68 |
*/
|
|
| 69 | 0 |
public String getAsText()
|
| 70 |
{
|
|
| 71 | 0 |
if (this.value != null) |
| 72 |
{
|
|
| 73 | 0 |
return ((ObjectName) this.value).getCanonicalName(); |
| 74 |
} |
|
| 75 | 0 |
return ""; |
| 76 |
} |
|
| 77 |
|
|
| 78 |
|
|
| 79 |
/**
|
|
| 80 |
* Gets the customEditor attribute of the ObjectNameEditor object
|
|
| 81 |
*
|
|
| 82 |
* @return The customEditor value
|
|
| 83 |
*/
|
|
| 84 | 0 |
public Component getCustomEditor()
|
| 85 |
{
|
|
| 86 | 0 |
if (Boolean.getBoolean("ejtools.objectname.hyperlink")) |
| 87 |
{
|
|
| 88 | 0 |
if (this.panel == null) |
| 89 |
{
|
|
| 90 | 0 |
GridBagConstraints gridbagconstraints = new GridBagConstraints();
|
| 91 |
|
|
| 92 | 0 |
this.panel = new JPanel(); |
| 93 | 0 |
this.panel.setLayout(new GridBagLayout()); |
| 94 | 0 |
this.button = new JButton(resources.getString("ObjectNameEditor.button.view")); |
| 95 |
|
|
| 96 | 0 |
gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE; |
| 97 | 0 |
this.panel.add(button, gridbagconstraints);
|
| 98 |
|
|
| 99 | 0 |
gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; |
| 100 | 0 |
gridbagconstraints.weightx = 1.0; |
| 101 | 0 |
gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; |
| 102 | 0 |
this.panel.add(text, gridbagconstraints);
|
| 103 |
|
|
| 104 | 0 |
this.button.addActionListener(
|
| 105 |
new ActionListener()
|
|
| 106 |
{
|
|
| 107 |
/**
|
|
| 108 |
* @param e Event action
|
|
| 109 |
*/
|
|
| 110 | 0 |
public void actionPerformed(ActionEvent e) |
| 111 |
{
|
|
| 112 | 0 |
ObjectSearcher finder = (ObjectSearcher) SwingUtilities.getAncestorOfClass(ObjectSearcher.class, ObjectNameEditor.this.panel); |
| 113 | 0 |
if ((finder != null) && (ObjectNameEditor.this.value != null)) |
| 114 |
{
|
|
| 115 | 0 |
finder.find(ObjectNameEditor.this.getAsText());
|
| 116 |
} |
|
| 117 |
} |
|
| 118 |
} |
|
| 119 |
); |
|
| 120 |
} |
|
| 121 | 0 |
return this.panel; |
| 122 |
} |
|
| 123 |
else
|
|
| 124 |
{
|
|
| 125 | 0 |
return this.text; |
| 126 |
} |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
|
|
| 130 |
/**
|
|
| 131 |
* Setter for the asText attribute
|
|
| 132 |
*
|
|
| 133 |
* @param s The new value
|
|
| 134 |
*/
|
|
| 135 | 0 |
public void setAsText(String s) |
| 136 |
{
|
|
| 137 | 0 |
try
|
| 138 |
{
|
|
| 139 | 0 |
this.value = new ObjectName(s); |
| 140 |
} |
|
| 141 |
catch (Exception e)
|
|
| 142 |
{
|
|
| 143 | 0 |
this.value = null; |
| 144 |
} |
|
| 145 | 0 |
this.text.setText(this.getAsText()); |
| 146 | 0 |
this.firePropertyChange();
|
| 147 |
} |
|
| 148 |
|
|
| 149 |
|
|
| 150 |
/**
|
|
| 151 |
* Setter for the value attribute
|
|
| 152 |
*
|
|
| 153 |
* @param object The new value value
|
|
| 154 |
*/
|
|
| 155 | 0 |
public void setValue(Object object) |
| 156 |
{
|
|
| 157 | 0 |
super.setValue(object);
|
| 158 | 0 |
if (this.value != null) |
| 159 |
{
|
|
| 160 | 0 |
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 | 0 |
public boolean supportsCustomEditor() |
| 171 |
{
|
|
| 172 | 0 |
return true; |
| 173 |
} |
|
| 174 |
} |
|
| 175 |
|
|
| 176 |
|
|
||||||||||