- 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
|
@ -185,6 +185,15 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
|
|||
|
||||
action_group->add( Gtk::Action::create("AddRequest", "Add Request"),
|
||||
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_request) );
|
||||
|
||||
action_group->add( Gtk::Action::create("EditProcess", "Edit Process"),
|
||||
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_process) );
|
||||
|
||||
action_group->add( Gtk::Action::create("EditThread", "Edit Thread"),
|
||||
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_thread) );
|
||||
|
||||
action_group->add( Gtk::Action::create("EditRequest", "Edit Request"),
|
||||
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_request) );
|
||||
|
||||
action_group->add( Gtk::Action::create("RemoveProcess", "Remove Process"),
|
||||
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_process) );
|
||||
|
@ -203,43 +212,42 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
|
|||
|
||||
const HandleType selection_type = get_selection_type();
|
||||
|
||||
Glib::ustring ui_info =
|
||||
"<ui>"
|
||||
" <popup name='PopupMenu'>";
|
||||
|
||||
if(selection_type == htype_process)
|
||||
ui_info +=
|
||||
" <menuitem action='AddThread'/>";
|
||||
else if(selection_type == htype_thread)
|
||||
ui_info +=
|
||||
" <menuitem action='AddRequest'/>";
|
||||
|
||||
ui_info +=
|
||||
" <menuitem action='AddProcess'/>";
|
||||
Glib::ustring adds;
|
||||
Glib::ustring edits;
|
||||
Glib::ustring removes;
|
||||
Glib::ustring separator;
|
||||
|
||||
if(selection_type != htype_undefined)
|
||||
ui_info +=
|
||||
" <separator/>";
|
||||
separator = "<separator/>";
|
||||
|
||||
switch(selection_type)
|
||||
{
|
||||
case htype_process:
|
||||
ui_info +=
|
||||
" <menuitem action='RemoveProcess'/>";
|
||||
adds = "<menuitem action='AddThread'/>";
|
||||
edits = "<menuitem action='EditProcess'/>";
|
||||
removes = "<menuitem action='RemoveProcess'/>";
|
||||
break;
|
||||
case htype_thread:
|
||||
ui_info +=
|
||||
" <menuitem action='RemoveThread'/>";
|
||||
adds = "<menuitem action='AddRequest'/>";
|
||||
edits = "<menuitem action='EditThread'/>";
|
||||
removes = "<menuitem action='RemoveThread'/>";
|
||||
break;
|
||||
case htype_request:
|
||||
ui_info +=
|
||||
" <menuitem action='RemoveRequest'/>";
|
||||
edits = "<menuitem action='EditRequest'/>";
|
||||
removes = "<menuitem action='RemoveRequest'/>";
|
||||
break;
|
||||
case htype_subrequest:
|
||||
ui_info +=
|
||||
" <menuitem action='RemoveSubrequest'/>";
|
||||
removes = "<menuitem action='RemoveSubrequest'/>";
|
||||
}
|
||||
|
||||
adds += "<menuitem action='AddProcess'/>";
|
||||
|
||||
Glib::ustring ui_info =
|
||||
"<ui>"
|
||||
" <popup name='PopupMenu'>";
|
||||
|
||||
ui_info += adds + separator + edits + ((edits.size() == 0) ? ustring() : separator) + removes;
|
||||
|
||||
ui_info +=
|
||||
" </popup>"
|
||||
"</ui>";
|
||||
|
@ -327,19 +335,63 @@ SchedulablesTreeWidget::update(const History& history)
|
|||
void
|
||||
SchedulablesTreeWidget::_on_add_process()
|
||||
{
|
||||
add_edit_process(true);
|
||||
}
|
||||
|
||||
void
|
||||
SchedulablesTreeWidget::_on_edit_process()
|
||||
{
|
||||
add_edit_process(false);
|
||||
}
|
||||
|
||||
void
|
||||
SchedulablesTreeWidget::add_edit_process(bool adding)
|
||||
{
|
||||
/** This is ugly, I know, we should be using derived widgets, but I also believe we
|
||||
* have little time, and I'm not going to waste too much of it on the frontend */
|
||||
|
||||
Entry* name_entry;
|
||||
SpinButton* arrival_time_spin;
|
||||
SpinButton* base_priority_spin;
|
||||
|
||||
_add_process_dialog_glade->get_widget("Name.Entry", name_entry);
|
||||
_add_process_dialog_glade->get_widget("ArrivalTime.Spin", arrival_time_spin);
|
||||
_add_process_dialog_glade->get_widget("BasePriority.Spin", base_priority_spin);
|
||||
|
||||
Process* selection = NULL;
|
||||
|
||||
if(!adding)
|
||||
{
|
||||
selection = get_selected<Process>();
|
||||
|
||||
name_entry->set_text(selection->get_name());
|
||||
arrival_time_spin->set_value(static_cast<double>(selection->get_arrival_time()));
|
||||
base_priority_spin->set_value(static_cast<double>(selection->get_base_priority()));
|
||||
}
|
||||
else
|
||||
{
|
||||
name_entry->set_text("");
|
||||
arrival_time_spin->set_value(0.0);
|
||||
base_priority_spin->set_value(0.0);
|
||||
}
|
||||
|
||||
|
||||
if(_add_process_dialog->run() == RESPONSE_OK)
|
||||
{
|
||||
Entry* name_entry;
|
||||
SpinButton* arrival_time_spin;
|
||||
SpinButton* base_priority_spin;
|
||||
|
||||
_add_process_dialog_glade->get_widget("Name.Entry", name_entry);
|
||||
_add_process_dialog_glade->get_widget("ArrivalTime.Spin", arrival_time_spin);
|
||||
_add_process_dialog_glade->get_widget("BasePriority.Spin", base_priority_spin);
|
||||
|
||||
Simulation::get_instance().get_history().add_process(name_entry->get_text(),
|
||||
arrival_time_spin->get_value_as_int(),
|
||||
base_priority_spin->get_value_as_int());
|
||||
if(adding)
|
||||
{
|
||||
Simulation::get_instance().get_history().add_process(name_entry->get_text(),
|
||||
arrival_time_spin->get_value_as_int(),
|
||||
base_priority_spin->get_value_as_int());
|
||||
}
|
||||
else
|
||||
{
|
||||
Simulation::get_instance().get_history().edit_process(*selection,
|
||||
name_entry->get_text(),
|
||||
arrival_time_spin->get_value_as_int(),
|
||||
base_priority_spin->get_value_as_int());
|
||||
}
|
||||
}
|
||||
|
||||
_add_process_dialog->hide();
|
||||
|
@ -348,27 +400,74 @@ SchedulablesTreeWidget::_on_add_process()
|
|||
void
|
||||
SchedulablesTreeWidget::_on_add_thread()
|
||||
{
|
||||
Process* p = get_selected<Process>();
|
||||
if(p == NULL)
|
||||
return;
|
||||
add_edit_thread(true);
|
||||
}
|
||||
|
||||
void
|
||||
SchedulablesTreeWidget::_on_edit_thread()
|
||||
{
|
||||
add_edit_thread(false);
|
||||
}
|
||||
|
||||
void
|
||||
SchedulablesTreeWidget::add_edit_thread(bool adding)
|
||||
{
|
||||
/** This is ugly, I know, we should be using derived widgets, but I also believe we
|
||||
* have little time, and I'm not going to waste too much of it on the frontend */
|
||||
|
||||
Entry* name_entry;
|
||||
SpinButton* cpu_time_spin;
|
||||
SpinButton* arrival_time_spin;
|
||||
SpinButton* base_priority_spin;
|
||||
|
||||
_add_thread_dialog_glade->get_widget("Name.Entry", name_entry);
|
||||
_add_thread_dialog_glade->get_widget("CpuTime.Spin", cpu_time_spin);
|
||||
_add_thread_dialog_glade->get_widget("ArrivalTime.Spin", arrival_time_spin);
|
||||
_add_thread_dialog_glade->get_widget("BasePriority.Spin", base_priority_spin);
|
||||
|
||||
Thread* t = NULL;
|
||||
|
||||
if(!adding)
|
||||
{
|
||||
t = get_selected<Thread>();
|
||||
|
||||
name_entry->set_text(t->get_name());
|
||||
cpu_time_spin->set_value(static_cast<double>(t->get_total_cpu_time()));
|
||||
arrival_time_spin->set_value(static_cast<double>(t->get_arrival_time()));
|
||||
base_priority_spin->set_value(static_cast<double>(t->get_base_priority()));
|
||||
}
|
||||
else
|
||||
{
|
||||
name_entry->set_text("");
|
||||
cpu_time_spin->set_value(1.0);
|
||||
arrival_time_spin->set_value(0.0);
|
||||
base_priority_spin->set_value(0.0);
|
||||
}
|
||||
|
||||
|
||||
if(_add_thread_dialog->run() == RESPONSE_OK)
|
||||
{
|
||||
Entry* name_entry;
|
||||
SpinButton* cpu_time_spin;
|
||||
SpinButton* arrival_time_spin;
|
||||
SpinButton* base_priority_spin;
|
||||
|
||||
_add_thread_dialog_glade->get_widget("Name.Entry", name_entry);
|
||||
_add_thread_dialog_glade->get_widget("CpuTime.Spin", cpu_time_spin);
|
||||
_add_thread_dialog_glade->get_widget("ArrivalTime.Spin", arrival_time_spin);
|
||||
_add_thread_dialog_glade->get_widget("BasePriority.Spin", base_priority_spin);
|
||||
|
||||
Simulation::get_instance().get_history().add_thread(name_entry->get_text(),
|
||||
*p,
|
||||
cpu_time_spin->get_value_as_int(),
|
||||
arrival_time_spin->get_value_as_int(),
|
||||
base_priority_spin->get_value_as_int());
|
||||
if(adding)
|
||||
{
|
||||
Process* p = get_selected<Process>();
|
||||
assert(p != NULL);
|
||||
|
||||
Simulation::get_instance().get_history().add_thread(name_entry->get_text(),
|
||||
*p,
|
||||
cpu_time_spin->get_value_as_int(),
|
||||
arrival_time_spin->get_value_as_int(),
|
||||
base_priority_spin->get_value_as_int());
|
||||
}
|
||||
else
|
||||
{
|
||||
Simulation::get_instance().get_history().edit_thread(*t,
|
||||
name_entry->get_text(),
|
||||
cpu_time_spin->get_value_as_int(),
|
||||
arrival_time_spin->get_value_as_int(),
|
||||
base_priority_spin->get_value_as_int());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -380,13 +479,19 @@ SchedulablesTreeWidget::_on_add_request()
|
|||
{
|
||||
Thread* t = get_selected<Thread>();
|
||||
|
||||
if(t == NULL)
|
||||
return;
|
||||
|
||||
if(_add_request_dialog->run() == RESPONSE_OK)
|
||||
_add_request_dialog->construct_request(*t);
|
||||
assert(t != NULL);
|
||||
|
||||
_add_request_dialog->hide();
|
||||
_add_request_dialog->run_add(*t);
|
||||
}
|
||||
|
||||
void
|
||||
SchedulablesTreeWidget::_on_edit_request()
|
||||
{
|
||||
Request* r = get_selected<Request>();
|
||||
|
||||
assert(r != NULL);
|
||||
|
||||
_add_request_dialog->run_edit(*r);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue