00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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.event.ActionEvent;
00032 import java.awt.event.ActionListener;
00033
00034 import javax.management.MBeanAttributeInfo;
00035 import javax.management.ObjectName;
00036 import javax.swing.BorderFactory;
00037 import javax.swing.JButton;
00038 import javax.swing.JDialog;
00039 import javax.swing.JLabel;
00040 import javax.swing.JPanel;
00041 import javax.swing.JScrollPane;
00042 import javax.swing.JTextArea;
00043 import javax.swing.JTextField;
00044
00045 import org.objectweb.cjdbc.console.gui.CjdbcGui;
00046 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00047 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00048
00049
00050
00051
00052
00053
00054
00055 public class AttributeChangeDialog extends JDialog implements ActionListener
00056 {
00057
00058 private static final Color BUTTON_COLOR = new Color(198, 226, 255);
00059 private static final Color WARNING_COLOR = new Color(238, 169, 184);
00060 private JScrollPane scrollPane;
00061 private JTextArea area;
00062 private MBeanAttributeInfo info;
00063 private CjdbcGui gui;
00064 private ObjectName objectName;
00065 private JTextField newValue;
00066
00067
00068
00069
00070
00071
00072
00073
00074 public AttributeChangeDialog(CjdbcGui gui, ObjectName name,
00075 MBeanAttributeInfo info)
00076 {
00077
00078 super(gui, "Attribute Change", true);
00079
00080 this.info = info;
00081 this.gui = gui;
00082 this.objectName = name;
00083 GuiConstants.centerComponent(this, 400, 300);
00084
00085 this.setFont(GuiConstants.CENTER_PANE_FONT);
00086
00087
00088 GridBagLayout gbl = new GridBagLayout();
00089 this.getContentPane().setLayout(gbl);
00090 GridBagConstraints gbc = new GridBagConstraints();
00091 gbc.fill = GridBagConstraints.BOTH;
00092 gbc.weightx = 1.0;
00093 gbc.gridheight = 1;
00094 gbc.gridwidth = GridBagConstraints.REMAINDER;
00095 this.getContentPane().setBackground(Color.white);
00096
00097 JLabel objectName = new JLabel(name.toString());
00098 objectName.setBorder(BorderFactory.createTitledBorder(
00099 GuiConstants.LINE_BORDER, "MBean Name"));
00100 gbl.setConstraints(objectName, gbc);
00101 this.getContentPane().add(objectName);
00102
00103 JLabel attribute = new JLabel(info.getName());
00104 attribute.setBorder(BorderFactory.createTitledBorder(
00105 GuiConstants.LINE_BORDER, "Attribute Name (" + info.getType() + ")"));
00106 gbl.setConstraints(attribute, gbc);
00107 this.getContentPane().add(attribute);
00108
00109 JPanel values = new JPanel();
00110 values.setBorder(BorderFactory.createTitledBorder(GuiConstants.LINE_BORDER,
00111 "Attribute Value"));
00112 values.setBackground(Color.white);
00113 values.setLayout(new GridLayout(2, 2));
00114 values.add(new JLabel("Old Value"));
00115
00116 JTextField oldValue = new JTextField();
00117 Object attributeValue = null;
00118 try
00119 {
00120 attributeValue = gui.getCurrentJmxClient().getAttributeValue(name,
00121 info.getName());
00122 }
00123 catch (Exception e)
00124 {
00125 oldValue.setForeground(WARNING_COLOR);
00126 attributeValue = "<error>";
00127 }
00128 finally
00129 {
00130 if (attributeValue == null)
00131 attributeValue = "";
00132 }
00133 oldValue.setText(attributeValue.toString());
00134 oldValue.setEditable(false);
00135 values.add(oldValue);
00136 values.add(new JLabel("New Value"));
00137 newValue = new JTextField();
00138 if (!info.isWritable())
00139 {
00140 newValue.setText(" ");
00141 newValue.setEnabled(false);
00142 }
00143 values.add(newValue);
00144 gbl.setConstraints(values, gbc);
00145 this.getContentPane().add(values);
00146
00147 JButton ok;
00148 if (!info.isWritable())
00149 {
00150 ok = new JButton("Cannot change attribute value");
00151 ok.setBackground(WARNING_COLOR);
00152 ok.setEnabled(false);
00153 }
00154 else
00155 {
00156 ok = new JButton("Change attribute value");
00157 ok.setBackground(BUTTON_COLOR);
00158 ok.setEnabled(true);
00159 }
00160 ok.setActionCommand(GuiCommands.COMMAND_CONFIRM_ACTION);
00161 ok.addActionListener(this);
00162 gbl.setConstraints(ok, gbc);
00163 this.getContentPane().add(ok);
00164
00165 scrollPane = new JScrollPane();
00166 scrollPane.setBackground(Color.white);
00167 scrollPane.setViewportBorder(BorderFactory.createTitledBorder(
00168 GuiConstants.LINE_BORDER, "Attribute Change Result"));
00169 area = new JTextArea();
00170 area.setBackground(Color.white);
00171 scrollPane.getViewport().add(area);
00172 gbc.gridheight = GridBagConstraints.REMAINDER;
00173 gbc.weighty = 2.0;
00174 gbl.setConstraints(scrollPane, gbc);
00175 this.getContentPane().add(scrollPane);
00176
00177 this.validate();
00178
00179 }
00180
00181
00182
00183
00184 public void actionPerformed(ActionEvent e)
00185 {
00186 if (!info.isWritable())
00187 {
00188 area.setForeground(WARNING_COLOR);
00189 area.setText("This attribute cannot be changed");
00190 }
00191 else
00192 {
00193 try
00194 {
00195 Object o = GuiConstants.convertType(newValue.getText(), info.getType());
00196 gui.getCurrentJmxClient().setAttributeValue(objectName, info.getName(),
00197 o);
00198 area.setForeground(Color.BLACK);
00199 area.setText("Attribute value chaned");
00200 }
00201 catch (Exception e1)
00202 {
00203 area.setForeground(WARNING_COLOR);
00204 area.setText(e1.getMessage());
00205 }
00206 }
00207 }
00208 }