/* 
 * © 2007-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef _GRTDBCONNECTIONEDITOR_H_
#define _GRTDBCONNECTIONEDITOR_H_

#include "wb_config.h"

#include <mforms/mforms.h>

#include "db_conn_be.h"
#include "grtdb_connect_panel.h"
#include "grt/grt_manager.h"

namespace grtui
{

class WBPUBLICBACKEND_PUBLIC_FUNC DbConnectionEditor : public mforms::Form
{
public:
  DbConnectionEditor(const db_mgmt_ManagementRef &mgmt);
  ~DbConnectionEditor();

  void run();
  db_mgmt_ConnectionRef run(const db_mgmt_ConnectionRef &connection);
  
protected:
  db_mgmt_ManagementRef _mgmt;
  DbConnectPanel _panel;

  mforms::Box _top_vbox;
  mforms::Box _top_hbox;
  
  mforms::Box    _conn_list_buttons_hbox;
  mforms::Button _add_conn_button;
  mforms::Button _del_conn_button;
  mforms::TreeView _stored_connection_list;
  mforms::TextEntry *_conn_name;

  mforms::Box _bottom_hbox;
  mforms::Button _ok_button;
  mforms::Button _cancel_button;
  mforms::Button _test_button;
  
  //! Called from selector/list of connections to tell that things changed
  void change_active_stored_conn();
  
  void name_changed();
private:
  void add_stored_conn();
  void del_stored_conn();

  void ok_clicked();
  void cancel_clicked();
  void test_clicked();
  
  void reset_stored_conn_list();
  
  bool rename_stored_conn(const std::string &oname, const std::string &name);
};

};

#endif /* _GRTDBCONNECTIONEDITOR_H_ */
