Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

OperationCallDialog.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.gui.frames.jmxdesktop;
00026 
00027 import java.awt.Color;
00028 import java.awt.GridBagConstraints;
00029 import java.awt.GridBagLayout;
00030 import java.awt.GridLayout;
00031 import java.awt.HeadlessException;
00032 import java.awt.event.ActionEvent;
00033 import java.awt.event.ActionListener;
00034 import java.io.PrintWriter;
00035 
00036 import javax.management.MBeanOperationInfo;
00037 import javax.management.MBeanParameterInfo;
00038 import javax.management.ObjectName;
00039 import javax.swing.BorderFactory;
00040 import javax.swing.JButton;
00041 import javax.swing.JDialog;
00042 import javax.swing.JLabel;
00043 import javax.swing.JPanel;
00044 import javax.swing.JScrollPane;
00045 import javax.swing.JTextArea;
00046 import javax.swing.JTextField;
00047 
00048 import org.objectweb.cjdbc.common.jmx.JmxConstants;
00049 import org.objectweb.cjdbc.console.gui.CjdbcGui;
00050 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00051 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00052 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter;
00053 
00054 /**
00055  * This class defines a OperationCallDialog
00056  * 
00057  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00058  * @version 1.0
00059  */
00060 public class OperationCallDialog extends JDialog implements ActionListener
00061 {
00062 
00063   CjdbcGui                     gui;
00064   ObjectName                   objectN;
00065   MBeanOperationInfo           info;
00066   private JTextArea            area;
00067   private JScrollPane          scrollPane;
00068   private MBeanParameterInfo[] params;
00069   private int                  length;
00070   private JTextField[]         fields;
00071 
00072   /**
00073    * Creates a new <code>OperationCallDialog</code> object
00074    * 
00075    * @param info
00076    * @param name
00077    * @throws java.awt.HeadlessException
00078    */
00079   public OperationCallDialog(CjdbcGui gui, ObjectName name,
00080       MBeanOperationInfo info) throws HeadlessException
00081   {
00082     super(gui, "Operation Call Dialog", true);
00083     GuiConstants.centerComponent(this, 400, 500);
00084     this.gui = gui;
00085     this.objectN = name;
00086     this.info = info;
00087 
00088     // Define the panels and areas
00089     GridBagLayout gbl = new GridBagLayout();
00090     this.getContentPane().setLayout(gbl);
00091     this.setFont(GuiConstants.CENTER_PANE_FONT);
00092     GridBagConstraints gbc = new GridBagConstraints();
00093     gbc.fill = GridBagConstraints.BOTH;
00094     gbc.weightx = 1.0;
00095     gbc.gridheight = 1;
00096     gbc.gridwidth = GridBagConstraints.REMAINDER;
00097     this.getContentPane().setBackground(Color.white);
00098 
00099     JLabel objectName = new JLabel(name.toString());
00100     objectName.setBorder(BorderFactory.createTitledBorder(
00101         GuiConstants.LINE_BORDER, "MBean Name"));
00102     gbl.setConstraints(objectName, gbc);
00103     this.getContentPane().add(objectName);
00104 
00105     scrollPane = new JScrollPane();
00106     scrollPane.setBackground(Color.white);
00107     scrollPane.setViewportBorder(BorderFactory.createTitledBorder(
00108         GuiConstants.LINE_BORDER, "Operation Result"));
00109     area = new JTextArea();
00110     area.setBackground(Color.white);
00111     scrollPane.getViewport().add(area);
00112 
00113     JLabel operation = new JLabel(info.getName());
00114     operation.setBorder(BorderFactory.createTitledBorder(
00115         GuiConstants.LINE_BORDER, "Operation Name"));
00116     gbl.setConstraints(operation, gbc);
00117     this.getContentPane().add(operation);
00118 
00119     JPanel operationPane = new JPanel();
00120     operationPane.setBackground(Color.white);
00121     operationPane.setBorder(BorderFactory.createTitledBorder(
00122         GuiConstants.LINE_BORDER, "MBean parameters"));
00123     params = info.getSignature();
00124     length = params.length;
00125     GridLayout gl = new GridLayout(info.getSignature().length, 2);
00126     operationPane.setLayout(gl);
00127     fields = new JTextField[length];
00128     for (int i = 0; i < length; i++)
00129     {
00130       operationPane.add(new JLabel(params[i].getType()));
00131       fields[i] = new JTextField("");
00132       operationPane.add(fields[i]);
00133     }
00134     gbl.setConstraints(operationPane, gbc);
00135     this.getContentPane().add(operationPane);
00136 
00137     JButton ok = new JButton("Run Jmx operation");
00138     ok.setBackground(new Color(198, 226, 255));
00139     ok.setActionCommand(GuiCommands.COMMAND_CONFIRM_ACTION);
00140     ok.addActionListener(this);
00141     gbl.setConstraints(ok, gbc);
00142     this.getContentPane().add(ok);
00143 
00144     gbc.gridheight = GridBagConstraints.REMAINDER;
00145     gbc.weighty = 2.0;
00146     gbl.setConstraints(scrollPane, gbc);
00147     this.getContentPane().add(scrollPane);
00148 
00149     this.validate();
00150 
00151   }
00152 
00153   /**
00154    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
00155    */
00156   public void actionPerformed(ActionEvent event)
00157   {
00158     try
00159     {
00160       area.setForeground(Color.BLACK);
00161       if (gui.getCurrentJmxClient().isSubjectSet() == false
00162           && JmxConstants.mbeanNeedAuthentication(objectN))
00163         new SetSubjectDialog(gui);
00164       Object[] args = new Object[length];
00165       for (int i = 0; i < length; i++)
00166       {
00167         args[i] = getParameter(i);
00168       }
00169       Object result = gui.getCurrentJmxClient().invokeOperation(objectN, info,
00170           args);
00171       if (result != null)
00172         area.setText(result.toString());
00173       else
00174         area.setText("Command did not return a result");
00175 
00176       area.validate();
00177       scrollPane.validate();
00178     }
00179     catch (Exception e)
00180     {
00181       area.setForeground(Color.RED);
00182       area.setText(e.getMessage());
00183       JTextAreaWriter areaWriter = new JTextAreaWriter(area);
00184       PrintWriter writer = new PrintWriter(areaWriter);
00185       e.printStackTrace(writer);
00186     }
00187   }
00188 
00189   private Object getParameter(int i)
00190   {
00191     String value = fields[i].getText();
00192     String type = params[i].getType();
00193     return GuiConstants.convertType(value,type);
00194   }
00195 
00196 }

Generated on Mon Apr 11 22:01:33 2005 for C-JDBC by  doxygen 1.3.9.1