FELIX-159
----------
Fix some bugs:

  - Gateway tree:
    - Can't anymore associate a gateway to a previously removed gateway
    - The gateway association choice is now a combo box, instead of one button per gateway
    - Can not create a gateway with an even registered nickname
    - "Remove selected gateway" button, asks user to select a gateway if it's not the case
    - Pooling interval of gateways is now into seconds unit and value range is 1 to 1000 (instead of 500 to 10000 milliseconds)

  - General:
    - Some English correction trying
    - Sometimes, the remote loger panel did not works, because it's start to listen gateway properties change event after a gateway connection. Now, gateway tree is not anymore a propertyChangeListener, but the node panel ask for an other new connection event propagation if a CommonPlugin (like remote loger) arrived after a gateway connection.



git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@669818 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/mosgi/console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger_jtable.java b/mosgi/console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger_jtable.java
index 192fa6d..fa7c2e5 100644
--- a/mosgi/console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger_jtable.java
+++ b/mosgi/console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger_jtable.java
@@ -62,7 +62,6 @@
 
   public RemoteLogger_jtable (){
     super(new String[]{"Date","Time", "Src", "Id", "Name", "State", "Lvl", "Msg"},1);
-    System.out.println("JTable Remote logger");
 
     jp=new JPanel();
     jp.setLayout(new BorderLayout());
diff --git a/mosgi/console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger_jtree.java b/mosgi/console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger_jtree.java
index a75ad25..fc3a02f 100644
--- a/mosgi/console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger_jtree.java
+++ b/mosgi/console.component/src/main/java/org/apache/felix/mosgi/console/component/RemoteLogger_jtree.java
@@ -118,7 +118,7 @@
       });
       jpopup.add(jmiRemove);
       if (selPath.getPath().length==3) {
-        JMenuItem jmiLogLvl=new JMenuItem("Set log lvl");
+        JMenuItem jmiLogLvl=new JMenuItem("Set log level");
         jmiLogLvl.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
             setLogLvl(selPath);
@@ -180,12 +180,6 @@
   /* fin a supprimer */
  
   public void propertyChange(PropertyChangeEvent e){
-    // TODO : DEBUG
-    // Sometimes ???
-    //   *1)  when stay with "return" key pressed => JoptionPane miss getValue()
-    //   *2)  when commonPanel started after a new_node_connection event.
-    //        Slow or slowed (by a key pressed for exemple) computer.
-    //        => gui.NodesTree fireNewNodeConnection after each PCE_common_plugin_added for each connected nodes
     if (e.getPropertyName().equals(Plugin.NEW_NODE_CONNECTION)){
       try {
         MBeanServerConnection mbsc=(MBeanServerConnection)e.getNewValue();
@@ -296,22 +290,15 @@
       MBeanServerConnection mb=(MBeanServerConnection) ht_connectedGateway.get(connString);
       Integer curentVal=(Integer) mb.getAttribute(Activator.REMOTE_LOGGER_ON, "LogLvl");
 
-      JOptionPane jop = new JOptionPane("Select a log level for \""+connString+"\" :", JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, LOG_LVL, LOG_LVL[curentVal.intValue()-1]);
-      JDialog dialog = jop.createDialog(jp, "Log level");
-      dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
-      dialog.show();
-      String choice = (String) jop.getValue();
-      Integer newVal=new Integer(4);
-      if (choice.equals("Error")) {newVal=new Integer(1);}
-      else if (choice.equals("Warning")) {newVal=new Integer(2);}
-      else if (choice.equals("Info")) {newVal=new Integer(3);}
-      else if (choice.equals("Debug")) {newVal=new Integer(4);}
+      int val = JOptionPane.showOptionDialog(jp, "Select a log level for \"..."+connString+"\" :", "Log level", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, LOG_LVL, LOG_LVL[curentVal.intValue()-1]);
+      if ( val == JOptionPane.CLOSED_OPTION ) { return; }
+      Integer newVal = new Integer(val+1);
 
       mb.setAttribute(Activator.REMOTE_LOGGER_ON, new Attribute("LogLvl", newVal));
       DefaultMutableTreeNode ddmmttnn=(DefaultMutableTreeNode) tp.getLastPathComponent();
       ht_logLvl.put(ddmmttnn, newVal);
     } catch (Exception ex) {
-      JOptionPane.showMessageDialog(jp,"Error with \""+connString+"\" :\n"+ex, "Error :", JOptionPane.ERROR_MESSAGE);
+      JOptionPane.showMessageDialog(jp,"Error with \"..."+connString+"\" :\n"+ex, "Error :", JOptionPane.ERROR_MESSAGE);
       ex.printStackTrace();
     }
   }
diff --git a/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/Gateway.java b/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/Gateway.java
index d2b5c46..8916caa 100644
--- a/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/Gateway.java
+++ b/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/Gateway.java
@@ -36,7 +36,7 @@
   private static final String JMX_SERVICE = "service:jmx:";
   private static final String DEFAULT_JMXSURL = JMX_SERVICE+"rmi:///jndi/rmi://127.0.0.1:1099/core";
 
-  private static Hashtable HT_GATEWAY = new Hashtable();
+  protected static Hashtable HT_GATEWAY = new Hashtable();
 
   private JMXConnector jmxc;
   private MBeanServerConnection mbsc;
@@ -82,6 +82,9 @@
 
   // Intermediate private Gateway creator
   private static Gateway newGateway(String nickname, String serviceURL, String parent_gateway) throws Exception {
+    if ( HT_GATEWAY.containsKey(nickname) ) {
+      throw new Exception("Gateway nickname \""+nickname+"\" even exist.");
+    }
     if ( !serviceURL.startsWith(JMX_SERVICE) ) {
       serviceURL = JMX_SERVICE+serviceURL;
     }
@@ -134,6 +137,9 @@
   public static Gateway newGateway(Gateway ref) throws Exception {
     String nickname = JOptionPane.showInputDialog("Profil nickname", "");
     if ( nickname == null) return null;
+    if ( HT_GATEWAY.containsKey(nickname) ) {
+      throw new Exception("Gateway nickname \""+nickname+"\" even exist.");
+    }
     String gateway_ref = ref!=null?ref+"":"";
     String str_jmxsurl = JOptionPane.showInputDialog("JMX service URL", gateway_ref);
     if ( str_jmxsurl == null) return null;
@@ -142,10 +148,12 @@
     System.arraycopy(gateway_list, 0, gateway_list2, 1, gateway_list.length);
     gateway_list2[0] = "None";
     java.util.Arrays.sort(gateway_list);
-    int val = JOptionPane.showOptionDialog(new javax.swing.JFrame(), "Link to another gateway ?", "Gateway association", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, gateway_list2, gateway_list2[0]);
-    String str_parent = "";
-    if ( val != JOptionPane.CLOSED_OPTION ) { str_parent = ""+gateway_list2[val]; }
-    if ( val == 0 ) { str_parent = ""; }
+    Object val = JOptionPane.showInputDialog(new javax.swing.JFrame(), "Link to another gateway ?", "Gateway association", JOptionPane.QUESTION_MESSAGE, null, gateway_list2, gateway_list2[0]);
+    if ( val == null) return null;
+    if ( val.toString().equals("None") ) {
+      val = new String("");
+    }
+    String str_parent = val.toString();
     return Gateway.newGateway(nickname, str_jmxsurl, str_parent);
   }
 
diff --git a/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/NodePanel.java b/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/NodePanel.java
index db66c67..6230427 100644
--- a/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/NodePanel.java
+++ b/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/NodePanel.java
@@ -19,6 +19,7 @@
 package org.apache.felix.mosgi.console.gui;
 
 import org.apache.felix.mosgi.console.ifc.Plugin;
+import org.apache.felix.mosgi.console.ifc.CommonPlugin;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -98,6 +99,14 @@
       MBeanServerConnection mbsc = (MBeanServerConnection)event.getNewValue();
       String connString = (String) event.getOldValue();
       startMBeanTabBundles(connString, mbsc);
+    }else if (event.getPropertyName().equals(CommonPlugin.COMMON_PLUGIN_ADDED)) {
+      Iterator it = Gateway.HT_GATEWAY.values().iterator();
+      while (it.hasNext()) {
+        Gateway g = (Gateway) it.next();
+	if ( g.isConnected() ) {
+          a.firePropertyChangedEvent(Plugin.NEW_NODE_CONNECTION, g.toString(), g.getMbsc());
+        }
+      }
     }
   }
 
diff --git a/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/NodesTree.java b/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/NodesTree.java
index 01cae00..364ee59 100644
--- a/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/NodesTree.java
+++ b/mosgi/console.gui/src/main/java/org/apache/felix/mosgi/console/gui/NodesTree.java
@@ -45,16 +45,16 @@
 import java.util.Hashtable;
 import org.osgi.framework.BundleContext;
 import org.apache.felix.mosgi.console.ifc.Plugin;
-import org.apache.felix.mosgi.console.ifc.CommonPlugin;
 import javax.management.NotificationListener;
 import javax.management.Notification;
 import javax.management.remote.JMXConnectionNotification;
 
-public class NodesTree extends JPanel implements TreeSelectionListener, NotificationListener, ActionListener, PropertyChangeListener {
+public class NodesTree extends JPanel implements TreeSelectionListener, NotificationListener, ActionListener {
 
   private static Hashtable PROTOCOL_PACKAGE_PROVIDER = new Hashtable();
   protected static final String TOP_NAME = "Servers";
-  private static int POOLING_TIME = 2500;
+  private static int POOLING_TIME = 3;
+  private static boolean needToRefreshPoolingTime = false;
   
   private Activator activator;
   private static BundleContext bc;
@@ -100,23 +100,6 @@
     tree.expandPath(new TreePath(((DefaultMutableTreeNode)(dtm.getRoot())).getPath())); // expand root node
   }
 
-  //////////////////////////////////////////////////
-  //          PropertyChangeListener              //
-  //////////////////////////////////////////////////
-  public void propertyChange(PropertyChangeEvent event) {
-    if (event.getPropertyName().equals(CommonPlugin.COMMON_PLUGIN_ADDED)) {
-      Enumeration enu = top.breadthFirstEnumeration();
-      enu.nextElement(); // Skip top node
-      while ( enu.hasMoreElements() ) {
-        // Common plugin added after a gateway connection so firePCE(Plugin.NEW_NODE_CONNECTION, connString , mbsc) again :
-	Gateway g = (Gateway) ((DefaultMutableTreeNode) enu.nextElement()).getUserObject();
-	if ( g.isConnected() ) {
-          activator.firePropertyChangedEvent(Plugin.NEW_NODE_CONNECTION, g.toString(), g.getMbsc());
-        }
-      }
-    }
-  }
-
   //////////////////////////////////////////////////////
   //               TreeSelectionListener              //
   //////////////////////////////////////////////////////
@@ -195,12 +178,15 @@
       }
     } else if ( object == jb_removeNode ) { // Remove a node from tree
       DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
-      if ( node != top) {
+      if ( node == null || !node.isLeaf() ) {
+        JOptionPane.showMessageDialog(null, "Please select a gateway (without child gateway) to remove.", "Warning", JOptionPane.WARNING_MESSAGE);
+      } else if ( node != top) {
         Gateway g = (Gateway) node.getUserObject();
         if ( !node.equals(top) ){
-	  if( JOptionPane.showConfirmDialog(null, "Sure we remove this gateway \""+g.getNickname()+"\" ?\n "+g.toString()) == JOptionPane.YES_OPTION ) {
+	  if( JOptionPane.showConfirmDialog(null, "Sure we remove gateway \""+g.getNickname()+"\" ?\n "+g.toString(), "Confirmation", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION ) {
             g.disconnect(this);
 	    dtm.removeNodeFromParent(node);
+	    Gateway.HT_GATEWAY.remove(g.getNickname());
 	    System.out.println("Remove node : "+g);
           }
 	}
@@ -208,22 +194,21 @@
     } else if ( object == jtf_pool) {
       try {
         POOLING_TIME = Integer.parseInt(jtf_pool.getText());
-	if ( POOLING_TIME > 0 & POOLING_TIME < 500 ) {
-          POOLING_TIME = 500;
-	} else if ( POOLING_TIME < 0 ) {
+	if ( POOLING_TIME < 0 ) {
 	  POOLING_TIME = 0;
-	} else if ( POOLING_TIME > 9999 ) {
-          POOLING_TIME = 9999;
+	} else if ( POOLING_TIME > 999 ) {
+          POOLING_TIME = 999;
 	}
       } catch (Exception exep) {
         //
       }
-      if ( POOLING_TIME >= 500 ) {
+      if ( POOLING_TIME > 0 ) {
         jb_refresh.setEnabled(false);
       } else {
         jb_refresh.setEnabled(true);
       }
       jtf_pool.setText(""+POOLING_TIME);
+      needToRefreshPoolingTime = true;
     } else if ( object == jb_refresh) {
       tryToConnectAllNodes();
     }
@@ -232,7 +217,7 @@
   ///////////////////////////////////////////////////
   //           Private part                        //
   ///////////////////////////////////////////////////
-  private void tryToConnectAllNodes(){
+  private void tryToConnectAllNodes() {
     isAllNodesConnected = true;
     Enumeration enu = top.breadthFirstEnumeration();
     enu.nextElement(); // Skip top node
@@ -264,11 +249,15 @@
         if ( !isAllNodesConnected && POOLING_TIME > 0 ) {
 	  tryToConnectAllNodes();
         } 
-	try {
-          Thread.sleep(POOLING_TIME);
-        } catch(InterruptedException e) {
-          //e.printStackTrace();
-        }
+	int loop = POOLING_TIME;
+	while ( loop-- > 0 & !needToRefreshPoolingTime ) {
+	  try {
+            Thread.sleep(1000);
+          } catch(InterruptedException ie) {
+            //ie.printStackTrace();
+          }
+	}
+	needToRefreshPoolingTime = false;
       }
     }
   }
@@ -320,14 +309,14 @@
     buttonPanel.add(Box.createHorizontalGlue());
     jtf_pool = new JTextField(""+POOLING_TIME);
     jtf_pool.addActionListener(this);
-    jtf_pool.setToolTipText("<html>Pooling time in millisecond<br>Value range is 500 to 9999<br>A value of 0 means no refresh.</html>");
+    jtf_pool.setToolTipText("<html>Pooling interval in seconds<br>Value range is 1 to 999<br>A value of 0 means no refresh.</html>");
     jtf_pool.setPreferredSize(new Dimension(40,21));
     jtf_pool.setMaximumSize(new Dimension(40,21));
     buttonPanel.add(jtf_pool);
     buttonPanel.add(Box.createRigidArea(new Dimension(2,0)));
     jb_refresh = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(bc.getBundle().getResource("images/"+"REFRESH.gif"))));
     jb_refresh.setOpaque(true);
-    jb_refresh.setToolTipText("<html>Try to connect gateways now.<br>Enable only if there is no pooling time.</html>");
+    jb_refresh.setToolTipText("<html>Try to connect to gateways now.<br>Enabled only if there is no pooling time.</html>");
     jb_refresh.addActionListener(this);
     jb_refresh.setPreferredSize(new Dimension(18, 18));
     jb_refresh.setEnabled(false);