Author: channa
Date: Mon Dec  3 23:05:36 2007
New Revision: 10466

Log:

Adding validation for edit fields in config screen and status bar to display 
errors.

Modified:
   
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/ConfigScreen.java
   
trunk/commons/monitor/modules/client/src/main/resources/properties/servicemonitor.properties

Modified: 
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/ConfigScreen.java
==============================================================================
--- 
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/ConfigScreen.java
       (original)
+++ 
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/ConfigScreen.java
       Mon Dec  3 23:05:36 2007
@@ -15,11 +15,14 @@
  */
 package org.wso2.monitor;
 
+import javax.management.remote.JMXServiceURL;
+import javax.swing.*;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.Border;
 import java.awt.*;
-import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;
-
-import javax.swing.*;
+import java.awt.event.ActionListener;
+import java.net.MalformedURLException;
 
 /**
  * Displays a simple configuration screen to change the JMX Connector URL and 
MBean name.
@@ -29,9 +32,11 @@
     JTextField serviceURLText;
     JTextField mBeanNameText;
     JMXClient jmxClient;
+    JLabel statusBar;
 
     /**
      * Sets up the configration screen frame.
+     *
      * @param jmxClient The JMX client which uses the configuration settings 
that can be changed.
      */
     public ConfigScreen(JMXClient jmxClient) {
@@ -53,7 +58,7 @@
         JLabel beanLabel = new 
JLabel(monitorProperties.getProperty("monitor.configmon.mbeanname"));
         mBeanNameText = new JTextField(jmxClient.getMBeanName());
 
-        // OK - Cancel buttons.
+        // OK, Cancel buttons and status bar.
         final JButton okButton = new JButton(
                 monitorProperties.getProperty("monitor.configmon.ok"));
         final JButton cancelButton = new JButton(
@@ -61,14 +66,26 @@
         okButton.addActionListener(this);
         cancelButton.addActionListener(this);
 
+        // Show initial status.
+        String initMessage;
+        if (jmxClient.isConnected()) {
+            initMessage = 
monitorProperties.getProperty("monitor.configmsg.connected");
+        } else {
+            initMessage = 
monitorProperties.getProperty("monitor.configmsg.notconnected");
+        }
+        statusBar = new JLabel(initMessage);
+        Border border = BorderFactory.createBevelBorder( BevelBorder.LOWERED );
+        statusBar.setBorder(border);
+
         // Add edit controls to frame using a panel.
         JPanel controlPanel = new JPanel(new GridBagLayout());
         GridBagConstraints constraints = new GridBagConstraints();
-        configFrame.add(controlPanel, BorderLayout.CENTER);
+        configFrame.add(controlPanel, BorderLayout.NORTH);
+        configFrame.add(statusBar, BorderLayout.SOUTH);
 
         constraints.gridx = 0;
         constraints.gridy = 0;
-        constraints.anchor = GridBagConstraints.EAST;
+        constraints.anchor = GridBagConstraints.WEST;
         controlPanel.add(urlLabel, constraints);
 
         constraints.gridx = 1;
@@ -87,7 +104,7 @@
         buttonPanel.add(okButton, constraints);
         constraints.gridx = 1;
         buttonPanel.add(cancelButton, constraints);
-        configFrame.add(buttonPanel, BorderLayout.SOUTH);
+        configFrame.add(buttonPanel, BorderLayout.CENTER);
 
         // Show everything.
         configFrame.setVisible(true);
@@ -103,28 +120,43 @@
         String buttonText = source.getText();
         if 
(buttonText.equals(monitorProperties.getProperty("monitor.configmon.cancel"))) {
             log.debug("Cancel Clicked.");
+            configFrame.setVisible(false);
         } else if 
(buttonText.equals(monitorProperties.getProperty("monitor.configmon.ok"))) {
             log.debug("OK Clicked.");
             reconnectToService();
         }
-        configFrame.setVisible(false);
     }
 
     /**
-     * Connects to the monitored service using the setting entered by the 
user. 
+     * Connects to the monitored service using the setting entered by the user.
      */
     private void reconnectToService() {
         String serviceURL = serviceURLText.getText();
         String mBeanName = mBeanNameText.getText();
 
-        // If valid data has been entered, disconnect the current connection 
and reconnect.
-        if (serviceURL != null && mBeanName != null &&
-                (!serviceURL.equalsIgnoreCase(jmxClient.getConnectorAddress()) 
||
-                        
!mBeanName.equalsIgnoreCase(jmxClient.getMBeanName()))) {
-            jmxClient.setConnectorAddress(serviceURL);
-            jmxClient.setMBeanName(mBeanName);
-            jmxClient.disconnectFromServer();
-            jmxClient.connectToServer();
+        // Check if valid data has been entered.
+        if (serviceURL != null && mBeanName != null) {
+            try {
+                JMXServiceURL validURL = new JMXServiceURL(serviceURL);
+
+                // If a new target server and/or bean has been specified, 
disconnect and reconnect.
+                if (!validURL.equals(new 
JMXServiceURL(jmxClient.getConnectorAddress())) ||
+                        !mBeanName.equalsIgnoreCase(jmxClient.getMBeanName())) 
{
+                    
statusBar.setText(monitorProperties.getProperty("monitor.configmsg.connecting"));
+                    jmxClient.setConnectorAddress(serviceURL);
+                    jmxClient.setMBeanName(mBeanName);
+                    jmxClient.disconnectFromServer();
+                    jmxClient.connectToServer();
+                    configFrame.setVisible(false);
+                } else {
+                    
statusBar.setText(monitorProperties.getProperty("monitor.configmsg.nochanges"));
+                }
+            } catch (MalformedURLException e) {
+                log.error("Invalid service URL specified", e);
+                
statusBar.setText(monitorProperties.getProperty("monitor.configmsg.invalidurl"));
+            }
+        } else {
+            
statusBar.setText(monitorProperties.getProperty("monitor.configmsg.invalidinput"));
         }
     }
 }

Modified: 
trunk/commons/monitor/modules/client/src/main/resources/properties/servicemonitor.properties
==============================================================================
--- 
trunk/commons/monitor/modules/client/src/main/resources/properties/servicemonitor.properties
        (original)
+++ 
trunk/commons/monitor/modules/client/src/main/resources/properties/servicemonitor.properties
        Mon Dec  3 23:05:36 2007
@@ -14,6 +14,13 @@
 monitor.configmon.mbeanname=MBean Name
 monitor.configmon.ok=OK
 monitor.configmon.cancel=Cancel
+# Config screen messages
+monitor.configmsg.connected=Connected
+monitor.configmsg.notconnected=Not connected
+monitor.configmsg.connecting=Connecting to specified server
+monitor.configmsg.nochanges=No changes detected - please cancel to exit 
configuration
+monitor.configmsg.invalidurl=Invalid server URL specified
+monitor.configmsg.invalidinput=Invalid input - please cancel to exit 
configuration
 # Monitor Configuration Settings 
 monitor.pollinterval=5000
 monitor.connectionretries=5

_______________________________________________
Commons-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/commons-dev

Reply via email to