- Added the editing feature to the schedulables tree widget
- Value of dialog is now resetted, so they no more show up with the last data that was given git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@938 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
50929d9a94
commit
34c65f42d1
4 changed files with 261 additions and 84 deletions
|
@ -38,6 +38,7 @@ using namespace sgpem;
|
|||
using namespace Gtk;
|
||||
using namespace Glib;
|
||||
using Gnome::Glade::Xml;
|
||||
using std::vector;
|
||||
|
||||
AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr<Xml>& glade) :
|
||||
Dialog(cobject), _glade(glade)
|
||||
|
@ -47,6 +48,9 @@ AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr<Xml>& g
|
|||
_glade->get_widget("Remove", _remove_button);
|
||||
_glade->get_widget("Resource.Combo", _resource_combo);
|
||||
_glade->get_widget("OK.Button", _ok_button);
|
||||
_glade->get_widget("Instant.Spin", _instant_spin);
|
||||
_glade->get_widget("Duration.Spin", _duration_spin);
|
||||
|
||||
|
||||
/** ATTACH SIGNAL HANDLERS FOR BUTTONS **/
|
||||
|
||||
|
@ -95,31 +99,89 @@ AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr<Xml>& g
|
|||
sigc::mem_fun(*this, &AddRequestDialog::_on_list_selection_changed));
|
||||
}
|
||||
|
||||
Request&
|
||||
AddRequestDialog::construct_request(Thread& owner)
|
||||
Request*
|
||||
AddRequestDialog::run_add(Thread& owner)
|
||||
{
|
||||
assert(_list_model->children());
|
||||
update_combo();
|
||||
|
||||
SpinButton* instant_spin;
|
||||
_glade->get_widget("Instant.Spin", instant_spin);
|
||||
|
||||
History& h = Simulation::get_instance().get_history();
|
||||
Request* r = NULL;
|
||||
|
||||
Request& r = h.add_request(owner, instant_spin->get_value_as_int());
|
||||
|
||||
TreeNodeChildren sreq_container = _list_model->children();
|
||||
// reset the dialog data
|
||||
_list_model->clear();
|
||||
_instant_spin->set_value(0.0);
|
||||
_duration_spin->set_value(0.0);
|
||||
|
||||
for(Iseq<TreeIter> it = iseq(sreq_container); it; ++it)
|
||||
h.add_subrequest(r, (*it)[_list_key_column], (*it)[_list_length_column]);
|
||||
if(run() == RESPONSE_OK)
|
||||
{
|
||||
assert(_list_model->children());
|
||||
|
||||
History& h = Simulation::get_instance().get_history();
|
||||
|
||||
r = &h.add_request(owner, _instant_spin->get_value_as_int());
|
||||
|
||||
TreeNodeChildren sreq_container = _list_model->children();
|
||||
|
||||
for(Iseq<TreeIter> it = iseq(sreq_container); it; ++it)
|
||||
h.add_subrequest(*r, (*it)[_list_key_column], (*it)[_list_length_column]);
|
||||
}
|
||||
|
||||
hide();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void
|
||||
AddRequestDialog::on_show()
|
||||
AddRequestDialog::run_edit(Request& request)
|
||||
{
|
||||
//TODO is this a reasonable place where to fill the combo model?
|
||||
update_combo();
|
||||
|
||||
_list_model->clear();
|
||||
|
||||
History& history = Simulation::get_instance().get_history();
|
||||
const Environment::Resources& resources = history.get_last_environment().get_resources();
|
||||
|
||||
_instant_spin->set_value(static_cast<double>(request.get_instant()));
|
||||
|
||||
// PLEASE KEEP THIS A COPY, WE *NEED* TO COPY IT
|
||||
vector<SubRequest*> subrequests = request.get_subrequests();
|
||||
|
||||
for(Iseq<vector<SubRequest*>::iterator> it = iseq(subrequests); it; ++it)
|
||||
{
|
||||
SubRequest& sr = *(*it);
|
||||
|
||||
TreeModel::Row row = *(_list_model->append());
|
||||
|
||||
unsigned int key = sr.get_resource_key();
|
||||
row[_list_key_column] = key;
|
||||
|
||||
const ustring name = resources.find(key)->second->get_name();
|
||||
row[_list_resource_column] = name;
|
||||
|
||||
row[_list_length_column] = sr.get_length();
|
||||
}
|
||||
|
||||
if(run() == RESPONSE_OK)
|
||||
{
|
||||
assert(_list_model->children());
|
||||
|
||||
// I know it's a bit hack-ish, but do you know an elegant alternative way?
|
||||
for(Iseq<vector<SubRequest*>::iterator> it = iseq(subrequests); it; ++it)
|
||||
history.remove(*(*it));
|
||||
|
||||
history.edit_request(request, _instant_spin->get_value_as_int());
|
||||
|
||||
TreeNodeChildren sreq_container = _list_model->children();
|
||||
|
||||
for(Iseq<TreeIter> it = iseq(sreq_container); it; ++it)
|
||||
history.add_subrequest(request, (*it)[_list_key_column], (*it)[_list_length_column]);
|
||||
}
|
||||
|
||||
hide();
|
||||
}
|
||||
|
||||
void
|
||||
AddRequestDialog::update_combo()
|
||||
{
|
||||
typedef Environment::Resources::const_iterator ResourceIt;
|
||||
|
||||
const Environment::Resources& resources =
|
||||
|
@ -142,10 +204,6 @@ AddRequestDialog::_on_add()
|
|||
{
|
||||
TreeModel::iterator sel = _resource_combo->get_active();
|
||||
|
||||
SpinButton* duration_spin;
|
||||
|
||||
_glade->get_widget("Duration.Spin", duration_spin);
|
||||
|
||||
TreeModel::Row row = *(_list_model->append());
|
||||
|
||||
const unsigned int key = (*sel)[_combo_key_column];
|
||||
|
@ -154,7 +212,7 @@ AddRequestDialog::_on_add()
|
|||
const ustring resource = (*sel)[_combo_resource_column];
|
||||
row[_list_resource_column] = resource;
|
||||
|
||||
const unsigned int length = duration_spin->get_value_as_int();
|
||||
const unsigned int length = _duration_spin->get_value_as_int();
|
||||
row[_list_length_column] = length;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue