diff --git a/src/add_request_dialog.cc b/src/add_request_dialog.cc index d6e31e0..d93c223 100644 --- a/src/add_request_dialog.cc +++ b/src/add_request_dialog.cc @@ -30,18 +30,21 @@ #include "gettext.h" +#include + using namespace sgpem; using namespace Gtk; using namespace Glib; using Gnome::Glade::Xml; AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr& glade) : - Dialog(cobject) + Dialog(cobject), _glade(glade) { - glade->get_widget("SubRequests.View", _list); - glade->get_widget("Add", _add_button); - glade->get_widget("Add", _remove_button); - glade->get_widget("Resource.Combo", _resource_combo); + _glade->get_widget("SubRequests.View", _list); + _glade->get_widget("Add", _add_button); + _glade->get_widget("Remove", _remove_button); + _glade->get_widget("Resource.Combo", _resource_combo); + /** ATTACH SIGNAL HANDLERS FOR BUTTONS **/ @@ -54,26 +57,33 @@ AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr& g _combo_model = ListStore::create(_combo_columns); _resource_combo->set_model(_combo_model); + _resource_combo->pack_start(_combo_key_column, false); + _resource_combo->pack_start(_combo_resource_column, true); /** INITIALIZE LISTVIEW **/ + _list_columns.add(_list_key_column); _list_columns.add(_list_resource_column); _list_columns.add(_list_length_column); _list_model = ListStore::create(_list_columns); _list->set_model(_list_model); + _list->append_column(_("key"), _list_key_column); _list->append_column(_("resource"), _list_resource_column); _list->append_column(_("length"), _list_length_column); + + _list->get_selection()->signal_changed().connect( + sigc::mem_fun(*this, &AddRequestDialog::_on_selection_changed)); } void AddRequestDialog::on_show() { + //TODO is this a reasonable place where to fill the combo model? + typedef Environment::Resources::const_iterator ResourceIt; - Dialog::on_show(); - const Environment::Resources& resources = Simulation::get_instance().get_history().get_last_environment().get_resources(); @@ -85,17 +95,45 @@ AddRequestDialog::on_show() row[_combo_key_column] = it->first; row[_combo_resource_column] = it->second->get_name(); } + + Dialog::on_show(); } void AddRequestDialog::_on_add() { - //TODO + TreeModel::iterator sel = _resource_combo->get_active(); + + if(sel) + { + SpinButton* duration_spin; + + _glade->get_widget("Duration.Spin", duration_spin); + + TreeModel::Row row = *(_list_model->append()); + + const unsigned int key = (*sel)[_combo_key_column]; + row[_list_key_column] = key; + + const ustring resource = (*sel)[_combo_resource_column]; + row[_list_resource_column] = resource; + + const unsigned int length = duration_spin->get_value_as_int(); + row[_list_length_column] = length; + } } void AddRequestDialog::_on_remove() { - //TODO + TreeModel::iterator it = _list->get_selection()->get_selected(); + _list_model->erase(it); +} + +void +AddRequestDialog::_on_selection_changed() +{ + _remove_button->set_sensitive( + _list->get_selection()->count_selected_rows() > 0); } diff --git a/src/add_request_dialog.hh b/src/add_request_dialog.hh index 768c9d7..72ac757 100644 --- a/src/add_request_dialog.hh +++ b/src/add_request_dialog.hh @@ -42,10 +42,13 @@ namespace sgpem private: void _on_add(); void _on_remove(); + void _on_selection_changed(); + Glib::RefPtr _glade; Gtk::TreeView* _list; Glib::RefPtr _list_model; Gtk::TreeModelColumnRecord _list_columns; + Gtk::TreeModelColumn _list_key_column; Gtk::TreeModelColumn _list_resource_column; Gtk::TreeModelColumn _list_length_column; diff --git a/src/schedulables_tree_widget.cc b/src/schedulables_tree_widget.cc index 630c1a4..85d3d43 100644 --- a/src/schedulables_tree_widget.cc +++ b/src/schedulables_tree_widget.cc @@ -25,6 +25,7 @@ #include "backend/process.hh" #include "backend/thread.hh" #include "backend/resource.hh" +#include "add_request_dialog.hh" #include #include @@ -60,8 +61,9 @@ SchedulablesTreeWidget::SchedulablesTreeWidget() : /** DIALOGS **/ _add_process_dialog_glade->get_widget("AddProcessDialog", _add_process_dialog); _add_thread_dialog_glade->get_widget("AddThreadDialog", _add_thread_dialog); - // TODO use a derived widget - _add_request_dialog_glade->get_widget("AddRequestDialog", _add_request_dialog); + // NOTE This is *not* reflective programming! AddRequestDialog is the name of + // the base widget in the glade file. + _add_request_dialog_glade->get_widget_derived("AddRequestDialog", _add_request_dialog); set_headers_visible(false); diff --git a/src/schedulables_tree_widget.hh b/src/schedulables_tree_widget.hh index 088e0f8..b0d9a3d 100644 --- a/src/schedulables_tree_widget.hh +++ b/src/schedulables_tree_widget.hh @@ -25,6 +25,7 @@ namespace sgpem { class Process; class Thread; + class AddRequestDialog; } #include "config.h" @@ -84,7 +85,7 @@ namespace sgpem Glib::RefPtr _add_request_dialog_glade; Gtk::Dialog* _add_process_dialog; Gtk::Dialog* _add_thread_dialog; - Gtk::Dialog* _add_request_dialog; + AddRequestDialog* _add_request_dialog; }; } //~ namespace sgpem