From 06ec8c88556b02782c7b91a233de91eaf4a1439d Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 09 Jun 2009 12:28:05 +0000
Subject: [PATCH] Fix for issue 3550 (Consider making the control panel able to manage remote servers)

---
 opends/src/guitools/org/opends/guitools/controlpanel/ui/MainMenuBar.java |   97 ++++++++++++++++++++++++++++++++++++------------
 1 files changed, 73 insertions(+), 24 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/MainMenuBar.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/MainMenuBar.java
index 70ad84c..57757e0 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/MainMenuBar.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/MainMenuBar.java
@@ -79,29 +79,7 @@
    */
   protected void addMenus()
   {
-    JMenu menu;
-    JMenuItem menuItem;
-
-    if (!Utilities.isMacOS())
-    {
-      menu = Utilities.createMenu(INFO_CTRL_PANEL_FILE_MENU.get(),
-          INFO_CTRL_PANEL_FILE_MENU_DESCRIPTION.get());
-      menu.setMnemonic(KeyEvent.VK_F);
-      menuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_EXIT_MENU.get());
-      menuItem.addActionListener(new ActionListener()
-      {
-        /**
-         * {@inheritDoc}
-         */
-        public void actionPerformed(ActionEvent ev)
-        {
-          quitClicked();
-        }
-      });
-      menu.add(menuItem);
-
-      add(menu);
-    }
+    add(createFileMenuBar());
     add(createViewMenuBar());
     add(createHelpMenuBar());
   }
@@ -138,7 +116,44 @@
     }
   }
 
-
+  /**
+   * Creates the File menu bar.
+   * @return the File menu bar.
+   */
+  protected JMenu createFileMenuBar()
+  {
+    JMenu menu = Utilities.createMenu(INFO_CTRL_PANEL_FILE_MENU.get(),
+        INFO_CTRL_PANEL_FILE_MENU_DESCRIPTION.get());
+    menu.setMnemonic(KeyEvent.VK_F);
+    if (!Utilities.isMacOS())
+    {
+      JMenuItem menuItem =
+        Utilities.createMenuItem(INFO_CTRL_PANEL_EXIT_MENU.get());
+      menuItem.addActionListener(new ActionListener()
+      {
+        /**
+         * {@inheritDoc}
+         */
+        public void actionPerformed(ActionEvent ev)
+        {
+          quitClicked();
+        }
+      });
+      menu.add(menuItem);
+    }
+    JMenuItem menuItem = Utilities.createMenuItem(
+        INFO_CTRL_PANEL_CONNECT_TO_SERVER_MENU.get());
+    menu.setMnemonic(KeyEvent.VK_R);
+    menuItem.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent ev)
+      {
+        connectToServerClicked();
+      }
+    });
+    menu.add(menuItem);
+    return menu;
+  }
 
   /**
    * Creates the View menu bar.
@@ -231,4 +246,38 @@
       getInfo().startPooling();
     }
   }
+
+  /**
+   * The method called when the user clicks on 'Connect to Server...'.
+   */
+  protected void connectToServerClicked()
+  {
+    Set<String> runningTasks = new HashSet<String>();
+    for (Task task : getInfo().getTasks())
+    {
+      if (task.getState() == Task.State.RUNNING)
+      {
+        runningTasks.add(task.getTaskDescription().toString());
+      }
+    }
+    boolean confirmed = true;
+    if (runningTasks.size() > 0)
+    {
+      String allTasks = Utilities.getStringFromCollection(runningTasks, "<br>");
+      Message title = INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get();
+      Message msg =
+        INFO_CTRL_PANEL_RUNNING_TASKS_CHANGE_SERVER_CONFIRMATION_DETAILS.get(
+            allTasks);
+      confirmed = Utilities.displayConfirmationDialog(
+          Utilities.getParentDialog(this), title, msg);
+    }
+    if (confirmed)
+    {
+      GenericDialog dlg =
+        ControlCenterMainPane.getLocalOrRemoteDialog(getInfo());
+      Utilities.centerGoldenMean(dlg,
+          Utilities.getFrame(MainMenuBar.this));
+      dlg.setVisible(true);
+    }
+  }
 }

--
Gitblit v1.10.0