Thread: [Ejtools-cvs] libraries/adwt/src/main/org/ejtools/adwt/jmx MBeanMethodDialog.java,1.2,1.3
Brought to you by:
letiemble
|
From: <let...@us...> - 2003-11-27 00:51:50
|
Update of /cvsroot/ejtools/libraries/adwt/src/main/org/ejtools/adwt/jmx In directory sc8-pr-cvs1:/tmp/cvs-serv8980/adwt/src/main/org/ejtools/adwt/jmx Modified Files: MBeanMethodDialog.java Log Message: Address Todo #755528 Remove @created tags Index: MBeanMethodDialog.java =================================================================== RCS file: /cvsroot/ejtools/libraries/adwt/src/main/org/ejtools/adwt/jmx/MBeanMethodDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MBeanMethodDialog.java 15 Sep 2003 22:37:13 -0000 1.2 --- MBeanMethodDialog.java 27 Nov 2003 00:51:45 -0000 1.3 *************** *** 1,277 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.adwt.jmx; ! ! import java.awt.Component; ! import java.awt.Dimension; ! import java.awt.Frame; ! import java.awt.GridBagConstraints; ! import java.awt.GridBagLayout; ! import java.awt.Insets; ! import java.awt.event.ActionEvent; ! import java.awt.event.ActionListener; ! import java.beans.PropertyEditor; ! import java.util.Arrays; ! import java.util.Iterator; ! import java.util.ResourceBundle; ! import java.util.Vector; ! ! import javax.management.MBeanOperationInfo; ! import javax.management.MBeanParameterInfo; ! import javax.swing.JButton; ! import javax.swing.JDialog; ! import javax.swing.JLabel; ! import javax.swing.JOptionPane; ! import javax.swing.JPanel; ! import javax.swing.SwingConstants; ! ! import org.ejtools.beans.CustomPropertyEditorManager; ! import org.ejtools.jmx.MBeanInvokeAccessor; ! import org.ejtools.util.ClassTools; ! ! import com.dreambean.awt.GenericPropertyCustomizer; ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class MBeanMethodDialog extends JDialog implements ActionListener ! { ! /** Description of the Field */ ! private Vector editors = new Vector(); ! /** Description of the Field */ ! private MBeanOperationInfo operationInfo = null; ! /** Description of the Field */ ! private MBeanInvokeAccessor resource = null; ! /** Description of the Field */ ! private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.adwt.jmx.Resources"); ! ! ! /** ! * Create a new dialog. ! * ! * @param resource Description of the Parameter ! * @param operationInfo Description of the Parameter ! * @param parent Description of the Parameter ! */ ! public MBeanMethodDialog(MBeanInvokeAccessor resource, MBeanOperationInfo operationInfo, Frame parent) ! { ! super(parent, true); ! this.setTitle(resources.getString("invoke.dialog.title")); ! ! // Check the parameters ! if (resource == null) ! { ! throw new IllegalArgumentException("MBeanAccessor must be defined"); ! } ! if (operationInfo == null) ! { ! throw new IllegalArgumentException("Operation must be defined"); ! } ! this.resource = resource; ! this.operationInfo = operationInfo; ! ! JPanel panel = (JPanel) this.getContentPane(); ! panel.setLayout(new GridBagLayout()); ! ! try ! { ! GridBagConstraints constraints = new GridBagConstraints(); ! constraints.insets = new Insets(2, 2, 2, 2); ! constraints.anchor = GridBagConstraints.NORTH; ! constraints.weighty = 1.0d; ! ! // Header ! StringBuffer display = new StringBuffer(); ! display.append(resources.getString("invoke.dialog.text.operation") + " : "); ! display.append(this.operationInfo.getName()); ! JLabel nameLabel = new JLabel(display.toString()); ! constraints.gridwidth = GridBagConstraints.REMAINDER; ! panel.add(nameLabel, constraints); ! ! // Parameters ! Iterator i = Arrays.asList(this.operationInfo.getSignature()).iterator(); ! while (i.hasNext()) ! { ! MBeanParameterInfo parameter = (MBeanParameterInfo) i.next(); ! Class clazz = ClassTools.getClass(parameter.getType()); ! ! nameLabel = new JLabel(parameter.getName() + ":", SwingConstants.RIGHT); ! constraints.gridwidth = GridBagConstraints.RELATIVE; ! constraints.fill = GridBagConstraints.NONE; ! constraints.weightx = 0.0d; ! panel.add(nameLabel, constraints); ! ! PropertyEditor editor = null; ! if (clazz != null) ! { ! editor = CustomPropertyEditorManager.findEditor(clazz); ! if (editor != null) ! { ! // Set initial value ! if (editor.getTags() != null) ! { ! // Set to first value ! editor.setAsText(editor.getTags()[0]); ! } ! ! Component component; ! if (editor.supportsCustomEditor()) ! { ! component = editor.getCustomEditor(); ! } ! else ! { ! String[] lTags = editor.getTags(); ! if (lTags != null) ! { ! component = new GenericPropertyCustomizer(editor, lTags); ! } ! else ! { ! component = new GenericPropertyCustomizer(editor); ! } ! } ! ! constraints.gridwidth = GridBagConstraints.REMAINDER; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! constraints.weightx = 1.0d; ! panel.add(component, constraints); ! ! this.editors.addElement(new Editor(editor, parameter.getType())); ! } ! } ! if (editor == null) ! { ! Component component; ! component = new JLabel(resources.getString("invoke.dialog.text.unloadable.class") + " " + parameter.getType()); ! ! constraints.gridwidth = GridBagConstraints.REMAINDER; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! constraints.weightx = 1.0d; ! panel.add(component, constraints); ! } ! constraints.weighty = 1.0d; ! } ! ! // Button ! constraints.gridwidth = GridBagConstraints.REMAINDER; ! JPanel buttons = new JPanel(); ! JButton invokeButton = new JButton(resources.getString("invoke.dialog.button.invoke")); ! invokeButton.setActionCommand("INVOKE"); ! buttons.add(invokeButton); ! invokeButton.addActionListener(this); ! JButton cancelButton = new JButton(resources.getString("invoke.dialog.button.cancel")); ! buttons.add(cancelButton); ! cancelButton.addActionListener(this); ! panel.add(buttons, constraints); ! ! if (this.editors.size() != this.operationInfo.getSignature().length) ! { ! invokeButton.setEnabled(false); ! } ! ! this.pack(); ! if (this.getWidth() < 300) ! { ! this.setSize(new Dimension(300, getHeight())); ! } ! this.setLocationRelativeTo(parent); ! } ! catch (Exception e) ! { ! e.printStackTrace(); ! } ! } ! ! ! /** ! * Ok or Cancel has been pressed. ! * ! * @param e the event ! */ ! public void actionPerformed(ActionEvent e) ! { ! if (e.getActionCommand().equals("INVOKE")) ! { ! Object[] parameters = new Object[this.editors.size()]; ! String[] types = new String[this.editors.size()]; ! int j = 0; ! for (Iterator i = this.editors.iterator(); i.hasNext(); j++) ! { ! Editor editor = (Editor) i.next(); ! parameters[j] = editor.getEditor().getValue(); ! types[j] = editor.getType(); ! } ! ! try ! { ! Object result = resource.invoke(this.operationInfo.getName(), parameters, types); ! } ! catch (Exception ex) ! { ! JOptionPane.showMessageDialog(this, resources.getString("invoke.dialog.text.error"), resources.getString("invoke.dialog.title.error"), JOptionPane.ERROR_MESSAGE); ! } ! } ! this.setVisible(false); ! } ! ! ! /** ! * Description of the Class ! * ! * @author letiembl ! * @version $Revision$ ! * @created 7 f?vrier 2002 ! */ ! private class Editor ! { ! /** Description of the Field */ ! private PropertyEditor editor; ! /** Description of the Field */ ! private String type; ! ! ! /** ! * Constructor for the Editor object ! * ! * @param editor Description of the Parameter ! * @param type Description of the Parameter ! */ ! public Editor(PropertyEditor editor, String type) ! { ! this.editor = editor; ! this.type = type; ! } ! ! ! /** ! * Getter for the editor attribute ! * ! * @return The value of editor attribute ! */ ! public PropertyEditor getEditor() ! { ! return this.editor; ! } ! ! ! /** ! * Getter for the type attribute ! * ! * @return The value of type attribute ! */ ! public String getType() ! { ! return this.type; ! } ! } ! ! } ! --- 1,276 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.adwt.jmx; ! ! import java.awt.Component; ! import java.awt.Dimension; ! import java.awt.Frame; ! import java.awt.GridBagConstraints; ! import java.awt.GridBagLayout; ! import java.awt.Insets; ! import java.awt.event.ActionEvent; ! import java.awt.event.ActionListener; ! import java.beans.PropertyEditor; ! import java.util.Arrays; ! import java.util.Iterator; ! import java.util.ResourceBundle; ! import java.util.Vector; ! ! import javax.management.MBeanOperationInfo; ! import javax.management.MBeanParameterInfo; ! import javax.swing.JButton; ! import javax.swing.JDialog; ! import javax.swing.JLabel; ! import javax.swing.JOptionPane; ! import javax.swing.JPanel; ! import javax.swing.SwingConstants; ! ! import org.ejtools.beans.CustomPropertyEditorManager; ! import org.ejtools.jmx.MBeanInvokeAccessor; ! import org.ejtools.util.ClassTools; ! ! import com.dreambean.awt.GenericPropertyCustomizer; ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class MBeanMethodDialog extends JDialog implements ActionListener ! { ! /** Description of the Field */ ! private Vector editors = new Vector(); ! /** Description of the Field */ ! private MBeanOperationInfo operationInfo = null; ! /** Description of the Field */ ! private MBeanInvokeAccessor resource = null; ! /** Description of the Field */ ! private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.adwt.jmx.Resources"); ! ! ! /** ! * Create a new dialog. ! * ! * @param resource Description of the Parameter ! * @param operationInfo Description of the Parameter ! * @param parent Description of the Parameter ! */ ! public MBeanMethodDialog(MBeanInvokeAccessor resource, MBeanOperationInfo operationInfo, Frame parent) ! { ! super(parent, true); ! this.setTitle(resources.getString("invoke.dialog.title")); ! ! // Check the parameters ! if (resource == null) ! { ! throw new IllegalArgumentException("MBeanAccessor must be defined"); ! } ! if (operationInfo == null) ! { ! throw new IllegalArgumentException("Operation must be defined"); ! } ! this.resource = resource; ! this.operationInfo = operationInfo; ! ! JPanel panel = (JPanel) this.getContentPane(); ! panel.setLayout(new GridBagLayout()); ! ! try ! { ! GridBagConstraints constraints = new GridBagConstraints(); ! constraints.insets = new Insets(2, 2, 2, 2); ! constraints.anchor = GridBagConstraints.NORTH; ! constraints.weighty = 1.0d; ! ! // Header ! StringBuffer display = new StringBuffer(); ! display.append(resources.getString("invoke.dialog.text.operation") + " : "); ! display.append(this.operationInfo.getName()); ! JLabel nameLabel = new JLabel(display.toString()); ! constraints.gridwidth = GridBagConstraints.REMAINDER; ! panel.add(nameLabel, constraints); ! ! // Parameters ! Iterator i = Arrays.asList(this.operationInfo.getSignature()).iterator(); ! while (i.hasNext()) ! { ! MBeanParameterInfo parameter = (MBeanParameterInfo) i.next(); ! Class clazz = ClassTools.getClass(parameter.getType()); ! ! nameLabel = new JLabel(parameter.getName() + ":", SwingConstants.RIGHT); ! constraints.gridwidth = GridBagConstraints.RELATIVE; ! constraints.fill = GridBagConstraints.NONE; ! constraints.weightx = 0.0d; ! panel.add(nameLabel, constraints); ! ! PropertyEditor editor = null; ! if (clazz != null) ! { ! editor = CustomPropertyEditorManager.findEditor(clazz); ! if (editor != null) ! { ! // Set initial value ! if (editor.getTags() != null) ! { ! // Set to first value ! editor.setAsText(editor.getTags()[0]); ! } ! ! Component component; ! if (editor.supportsCustomEditor()) ! { ! component = editor.getCustomEditor(); ! } ! else ! { ! String[] lTags = editor.getTags(); ! if (lTags != null) ! { ! component = new GenericPropertyCustomizer(editor, lTags); ! } ! else ! { ! component = new GenericPropertyCustomizer(editor); ! } ! } ! ! constraints.gridwidth = GridBagConstraints.REMAINDER; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! constraints.weightx = 1.0d; ! panel.add(component, constraints); ! ! this.editors.addElement(new Editor(editor, parameter.getType())); ! } ! } ! if (editor == null) ! { ! Component component; ! component = new JLabel(resources.getString("invoke.dialog.text.unloadable.class") + " " + parameter.getType()); ! ! constraints.gridwidth = GridBagConstraints.REMAINDER; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! constraints.weightx = 1.0d; ! panel.add(component, constraints); ! } ! constraints.weighty = 1.0d; ! } ! ! // Button ! constraints.gridwidth = GridBagConstraints.REMAINDER; ! JPanel buttons = new JPanel(); ! JButton invokeButton = new JButton(resources.getString("invoke.dialog.button.invoke")); ! invokeButton.setActionCommand("INVOKE"); ! buttons.add(invokeButton); ! invokeButton.addActionListener(this); ! JButton cancelButton = new JButton(resources.getString("invoke.dialog.button.cancel")); ! buttons.add(cancelButton); ! cancelButton.addActionListener(this); ! panel.add(buttons, constraints); ! ! if (this.editors.size() != this.operationInfo.getSignature().length) ! { ! invokeButton.setEnabled(false); ! } ! ! this.pack(); ! if (this.getWidth() < 300) ! { ! this.setSize(new Dimension(300, getHeight())); ! } ! this.setLocationRelativeTo(parent); ! } ! catch (Exception e) ! { ! e.printStackTrace(); ! } ! } ! ! ! /** ! * Ok or Cancel has been pressed. ! * ! * @param e the event ! */ ! public void actionPerformed(ActionEvent e) ! { ! if (e.getActionCommand().equals("INVOKE")) ! { ! Object[] parameters = new Object[this.editors.size()]; ! String[] types = new String[this.editors.size()]; ! int j = 0; ! for (Iterator i = this.editors.iterator(); i.hasNext(); j++) ! { ! Editor editor = (Editor) i.next(); ! parameters[j] = editor.getEditor().getValue(); ! types[j] = editor.getType(); ! } ! ! try ! { ! Object result = resource.invoke(this.operationInfo.getName(), parameters, types); ! } ! catch (Exception ex) ! { ! JOptionPane.showMessageDialog(this, resources.getString("invoke.dialog.text.error"), resources.getString("invoke.dialog.title.error"), JOptionPane.ERROR_MESSAGE); ! } ! } ! this.setVisible(false); ! } ! ! ! /** ! * Description of the Class ! * ! * @author letiembl ! * @version $Revision$ ! */ ! private class Editor ! { ! /** Description of the Field */ ! private PropertyEditor editor; ! /** Description of the Field */ ! private String type; ! ! ! /** ! * Constructor for the Editor object ! * ! * @param editor Description of the Parameter ! * @param type Description of the Parameter ! */ ! public Editor(PropertyEditor editor, String type) ! { ! this.editor = editor; ! this.type = type; ! } ! ! ! /** ! * Getter for the editor attribute ! * ! * @return The value of editor attribute ! */ ! public PropertyEditor getEditor() ! { ! return this.editor; ! } ! ! ! /** ! * Getter for the type attribute ! * ! * @return The value of type attribute ! */ ! public String getType() ! { ! return this.type; ! } ! } ! ! } ! |