sgpemv2/src/schedulables_tree_widget.cc

154 lines
4.6 KiB
C++
Raw Normal View History

// src/schedulables_tree_widget.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "schedulables_tree_widget.hh"
#include "templates/sequences.tcc"
#include "backend/history.hh"
#include "backend/simulation.hh"
#include "backend/process.hh"
#include <iostream>
#include <gtk/gtk.h>
#include <gtkmm/entry.h>
#include <gtkmm/spinbutton.h>
using namespace sgpem;
using namespace Gtk;
using namespace Glib;
using Gnome::Glade::Xml;
SchedulablesTreeWidget::SchedulablesTreeWidget() :
_add_process_dialog_glade(Xml::create(GLADEDIR "/add-process-dialog.glade"))
{
_columns.add(_main_column);
_columns.add(_handles_column);
_model = TreeStore::create(_columns);
set_model(_model);
/** JUST A BIT OF DATA FOR TESTING **/
//Gtk::TreeModel::Row row1 = *(_model->append());
//row1[_main_column] = ustring("ciccio");
// Gtk::TreeModel::Row row2 = *(_model->append());
// row2[_main_column] = ustring("pippo");
append_column("schedulables", _main_column);
//invisible
// append_column("handles", _handles_column);
/** POPUP MENU **/
_action_group = Gtk::ActionGroup::create();
// _action_group->add( Gtk::Action::create("ContextMenu", "Schedulables") );
// _action_group->add( Gtk::Action::create("Add Process", Gtk::Stock::NEW),
// sigc::mem_fun(*this, &SchedulablesTreeWidget::on_action_file_new) );
_action_group->add( Gtk::Action::create("AddProcess", "Add Process"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_process) );
//_action_group->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
// sigc::mem_fun(*this, &SchedulablesTreeWidget::on_action_file_quit) );
_UIManager = Gtk::UIManager::create();
_UIManager->insert_action_group(_action_group);
Glib::ustring ui_info =
"<ui>"
" <popup name='PopupMenu'>"
// " <menuitem action='ContextMenu'/>"
" <menuitem action='AddProcess'/>"
" </popup>"
"</ui>";
_UIManager->add_ui_from_string(ui_info);
_menu = dynamic_cast<Gtk::Menu*>(_UIManager->get_widget("/PopupMenu"));
/** DIALOGS **/
_add_process_dialog_glade->get_widget("AddProcessDialog", _add_process_dialog);
//FIXME why do I need to call this? Is it reasonable?
_add_process_dialog->hide();
set_headers_visible(false);
Simulation::get_instance().get_history().attach(*this);
}
SchedulablesTreeWidget::~SchedulablesTreeWidget()
{
Simulation::get_instance().get_history().detach(*this);
}
bool
SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
{
TreeView::on_button_press_event(event);
if( (event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
{
_menu->popup(event->button, event->time);
return true; //It has been handled.
}
else
return false;
}
void
SchedulablesTreeWidget::update(const History& history)
{
const Environment::Processes& processes =
Simulation::get_instance().get_history().get_last_environment().get_processes();
_model->clear();
for(unsigned int i = 0; i < processes.size(); ++i)
{
Process& p = *processes[i];
TreeModel::Row row = *(_model->append());
row[_main_column] = p.get_name();
row[_handles_column] = &p;
}
}
void
SchedulablesTreeWidget::_on_add_process()
{
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());
}
_add_process_dialog->hide();
}