- Completed the AddRequestDialog dialog. It`s of little use without resources handling, anyway..

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@912 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-20 17:52:46 +00:00
parent 894784463f
commit b554a43f30
4 changed files with 56 additions and 12 deletions

View File

@ -30,18 +30,21 @@
#include "gettext.h"
#include <gtkmm/spinbutton.h>
using namespace sgpem;
using namespace Gtk;
using namespace Glib;
using Gnome::Glade::Xml;
AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr<Xml>& 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,25 +57,32 @@ AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr<Xml>& 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()
{
typedef Environment::Resources::const_iterator ResourceIt;
//TODO is this a reasonable place where to fill the combo model?
Dialog::on_show();
typedef Environment::Resources::const_iterator ResourceIt;
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);
}

View File

@ -42,10 +42,13 @@ namespace sgpem
private:
void _on_add();
void _on_remove();
void _on_selection_changed();
Glib::RefPtr<Gnome::Glade::Xml> _glade;
Gtk::TreeView* _list;
Glib::RefPtr<Gtk::ListStore> _list_model;
Gtk::TreeModelColumnRecord _list_columns;
Gtk::TreeModelColumn<unsigned int> _list_key_column;
Gtk::TreeModelColumn<Glib::ustring> _list_resource_column;
Gtk::TreeModelColumn<unsigned int> _list_length_column;

View File

@ -25,6 +25,7 @@
#include "backend/process.hh"
#include "backend/thread.hh"
#include "backend/resource.hh"
#include "add_request_dialog.hh"
#include <iostream>
#include <sstream>
@ -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);

View File

@ -25,6 +25,7 @@ namespace sgpem
{
class Process;
class Thread;
class AddRequestDialog;
}
#include "config.h"
@ -84,7 +85,7 @@ namespace sgpem
Glib::RefPtr<Gnome::Glade::Xml> _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