
#include "model_sidebar.h"


#include "workbench/wb_context_ui.h"

#include "user_types_box.h"
#include "catalog_tree.h"
#include "layer_tree.h"
#include "properties_tree.h"
#include "navigator_box.h"
#include "history_tree.h"
#include "info_box.h"
#include "documentation_box.h"

#include "gtk_helpers.h"
#include <gtkmm/paned.h>
#include <gtkmm/notebook.h>
#include <gtkmm/frame.h>

ModelSidebar::ModelSidebar(wb::WBContextUI *wb)
  : _wbui(wb)
{
  _ui= new MGGladeXML(wb->get_wb()->get_grt_manager()->get_data_file_path("model_sidebar.glade").c_str(), "", "");


  Gtk::Paned *paned, *bottom_paned;
  Gtk::Notebook *note;
  Gtk::Frame *frame;
  
  _ui->get("model_sidebar", &paned);
  
  paned->reference();
  paned->unparent();

  _ui->get("side_model_pane2", &bottom_paned);
  paned->set_position(150);

  // setup sidebar stuff for model
  _ui->get("side_model_note0", &note);
  _navigator_box= Gtk::manage(new NavigatorBox(wb));
  note->append_page(*_navigator_box, create_icon_label("navigator.png", _("<small>Navigator</small>")));

 _info_box= Gtk::manage(new InfoBox(wb));
  note->append_page(*_info_box, create_icon_label("info.png", _("<small>Info</small>")));

  bottom_paned->set_position(300);

  _ui->get("side_model_note1", &note);
  _catalog_tree= Gtk::manage(new CatalogTree(wb));
  note->append_page(*_catalog_tree, create_icon_label("schemata.png", _("<small>Catalog</small>")));
  
  _layer_tree= Gtk::manage(new LayerTree(wb));
  note->append_page(*_layer_tree, create_icon_label("layers.png", _("<small>Layers</small>")));
  
  _usertypes_box= Gtk::manage(new UserTypesBox(wb));
  note->append_page(*_usertypes_box, create_icon_label("user_datatypes.png", _("<small>User Types</small>")));
  
  
  _ui->get("side_model_note2", &note);
  _documentation_box= Gtk::manage(new DocumentationBox(wb));
  note->append_page(*_documentation_box, create_icon_label("comment.png", _("<small>Description</small>")));
  
  _properties_tree= Gtk::manage(new PropertiesTree(wb));
  note->append_page(*_properties_tree, create_icon_label("properties.png", _("<small>Properties</small>")));
  
  _history_tree= Gtk::manage(new HistoryTree(wb));
  note->append_page(*_history_tree, create_icon_label("history.png", _("<small>History</small>")));

}
  

ModelSidebar::~ModelSidebar()
{
  Gtk::Paned *paned;
  
  _ui->get("model_sidebar", &paned);
  
  paned->unreference();

  delete _ui;
}


void ModelSidebar::refresh_all()
{
  _catalog_tree->refresh();
}


void ModelSidebar::refresh_layers()
{
  _layer_tree->refresh();
}


void ModelSidebar::refresh_catalog()
{
  _catalog_tree->refresh();
}


void ModelSidebar::refresh_properties()
{
  if (_properties_tree)
    _properties_tree->update();
}
  
void ModelSidebar::refresh_documentation(bec::UIForm *form)
{
  if (_documentation_box)
    _documentation_box->update_for_form(form);
}


void ModelSidebar::refresh_history()
{
  _history_tree->refresh();
}


void ModelSidebar::refresh_navigator()
{
  _navigator_box->refresh();
  _info_box->refresh();
}


void ModelSidebar::refresh_usertypes()
{
  if (_usertypes_box)
    _usertypes_box->refresh();
}


void ModelSidebar::reset_layout()
{
}


Gtk::Widget *ModelSidebar::get_base()
{
  Gtk::Paned *paned;
  
  _ui->get("model_sidebar", &paned);

  return paned;
}


std::string ModelSidebar::get_title()
{
  return _("Model");
}

