1 // Copyright (C) 2009-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "BL_GenericGui.hxx"
26 BL::GenericGui::GenericGui(BL::MainWindows_Wrap * wrapper) : QObject(wrapper->getDockParent())
28 DEBTRACE("Creating BL::GenericGui");
31 _job_name_selected = "";
33 _dock_parent = _wrapper->getDockParent();
35 // _salome_services is a servant
36 // POA wil destroy it at the end of the application
37 _salome_services = new BL::SALOMEServices();
40 BL::GenericGui::~GenericGui()
42 DEBTRACE("Destroying BL::GenericGui");
43 _salome_services->end();
47 BL::GenericGui::createDockWidgets()
49 DEBTRACE("createDockWidgets BL::GenericGui");
50 _jobs_manager = new BL::JobsManager_QT(_dock_parent, this, _salome_services);
51 _model_manager = new BL::QModelManager(this, _jobs_manager);
52 _model = _model_manager->getModel();
55 _dw_summary = new QDockWidget(_dock_parent);
56 _dw_summary->setWindowTitle("Summary");
57 _summary = new BL::Summary(_dw_summary, _jobs_manager);
58 _summary->setModel(_model);
59 QScrollArea * scroll_widget_summary = new QScrollArea(_dw_summary);
60 scroll_widget_summary->setWidget(_summary);
61 scroll_widget_summary->setWidgetResizable(true);
62 _dw_summary->setWidget(scroll_widget_summary);
65 _dw_resource_catalog = new QDockWidget(_dock_parent);
66 _dw_resource_catalog->setWindowTitle("Resource Catalog");
67 _resource_catalog = new JM::ResourceCatalog(_dw_resource_catalog, _salome_services, false);
68 QScrollArea * scroll_widget_resource = new QScrollArea(_dw_resource_catalog);
69 scroll_widget_resource->setWidget(_resource_catalog);
70 scroll_widget_resource->setWidgetResizable(true);
71 _dw_resource_catalog->setWidget(scroll_widget_resource);
73 /* Main Dock Window */
74 _dock_parent->addDockWidget(Qt::RightDockWidgetArea, _jobs_manager);
75 _dock_parent->addDockWidget(Qt::RightDockWidgetArea, _dw_summary);
76 _dock_parent->addDockWidget(Qt::RightDockWidgetArea, _dw_resource_catalog);
77 _dock_parent->splitDockWidget(_jobs_manager, _dw_summary, Qt::Vertical);
78 _dock_parent->tabifyDockWidget(_dw_summary, _dw_resource_catalog);
80 /* Signals and Slots */
81 // JobsManager -> Model
82 connect(_jobs_manager, SIGNAL(new_job_added(QString)), _model_manager, SLOT(new_job_added(QString)));
83 connect(_jobs_manager, SIGNAL(job_state_changed(QString)), _model_manager, SLOT(job_state_changed(QString)));
84 connect(_jobs_manager, SIGNAL(job_state_changed(QString)), this, SLOT(job_state_changed(QString)));
86 connect(_model, SIGNAL(rowsInserted(QModelIndex, int, int)), _summary, SLOT(rowsInserted(QModelIndex, int, int)));
87 connect(_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), _summary, SLOT(rowsRemoved(QModelIndex, int, int)));
88 connect(_model, SIGNAL(itemChanged(QStandardItem*)), _summary, SLOT(itemChanged(QStandardItem*)));
90 // Init at the end to be able to get jobs already in Launcher
91 if (_salome_services->initNS() == false)
92 DEBMSG("WARNING !!!!! SALOME IS NOT REACHABLE !!!!");
93 // refresh at the beacause we need that _salome_services be
95 _resource_catalog->refresh_resource_list();
99 BL::GenericGui::createCentralWidget()
101 DEBTRACE("createCentralWidget BL::GenericGui");
103 _tab_parent = _wrapper->getTabParent();
104 /* Tab Central Widget */
106 _buttons = new BL::Buttons(_tab_parent);
107 _buttons->setCreateButtonSlot(this, SLOT(create_job()));
108 _buttons->setEditCloneButtonSlot(this, SLOT(edit_clone_job()));
109 _buttons->setStartButtonSlot(this, SLOT(start_job()));
110 _buttons->setReStartButtonSlot(this, SLOT(restart_job()));
111 _buttons->setDeleteButtonSlot(this, SLOT(delete_job()));
112 _buttons->setStopButtonSlot(this, SLOT(stop_job()));
113 _buttons->setRefreshButtonSlot(this, SLOT(refresh_job()));
114 _buttons->setGetResultsButtonSlot(this, SLOT(get_results_job()));
117 _jobs_table = new BL::JobsTable(_tab_parent);
118 _jobs_table->setModel(_model);
119 _jobs_table->set_main_gui(this);
122 _job_tab = new BL::JobTab(_tab_parent, _jobs_manager);
123 _job_tab->setModel(_model);
126 QWidget * central_widget = new QWidget(_tab_parent);
127 QSplitter * tab_central_widget = new QSplitter(Qt::Vertical, _tab_parent);
128 tab_central_widget->addWidget(_jobs_table);
129 tab_central_widget->addWidget(_job_tab);
130 tab_central_widget->setChildrenCollapsible(false);
131 QVBoxLayout * central_layout = new QVBoxLayout;
132 central_layout->addWidget(_buttons);
133 central_layout->addWidget(tab_central_widget);
134 central_widget->setLayout(central_layout);
136 // Adding a scroll area for low resolution
137 QScrollArea * scroll_central_widget = new QScrollArea(_tab_parent);
138 scroll_central_widget->setWidget(central_widget);
139 scroll_central_widget->setWidgetResizable(true);
140 _tab_parent->setCentralWidget(scroll_central_widget);
142 /* Signals and Slots */
144 connect(_model, SIGNAL(itemChanged(QStandardItem*)), _job_tab, SLOT(itemChanged(QStandardItem*)));
147 connect(_jobs_table, SIGNAL(clicked(QModelIndex)), this, SLOT(job_selected(QModelIndex)));
148 connect(_jobs_table, SIGNAL(activated(QModelIndex)), this, SLOT(job_activated(QModelIndex)));
152 BL::GenericGui::deleteDockWidget()
154 // Specific for SALOME...
155 _dock_parent->removeDockWidget(_dw_summary);
157 _dock_parent->removeDockWidget(_dw_resource_catalog);
158 delete _dw_resource_catalog;
159 _dock_parent->removeDockWidget(_jobs_manager);
160 delete _jobs_manager;
164 BL::GenericGui::showDockWidgets(bool isVisible)
166 DEBTRACE("BL::GenericGui::showDockWidgets " << isVisible);
168 _jobs_manager->setVisible(isVisible);
169 _jobs_manager->toggleViewAction()->setVisible(isVisible);
172 _dw_summary->setVisible(isVisible);
173 _dw_summary->toggleViewAction()->setVisible(isVisible);
175 if (_dw_resource_catalog) {
176 _dw_resource_catalog->setVisible(isVisible);
177 _dw_resource_catalog->toggleViewAction()->setVisible(isVisible);
182 BL::GenericGui::createActions()
184 DEBTRACE("CreateActions BL::GenericGui");
185 _create_job_action = _wrapper->createAction("Create a Job", QIcon(), "Create a Job", "Create a Job", 0, _dock_parent, false, this, SLOT(create_job()));
186 _edit_clone_job_action = _wrapper->createAction("Edit/Clone a Job", QIcon(), "Edit/Clone a Job", "Edit/Clone a Job", 0, _dock_parent, false, this, SLOT(edit_clone_job()));
187 _start_job_action = _wrapper->createAction("Start a Job", QIcon(), "Start a Job", "Start a Job", 0, _dock_parent, false, this, SLOT(start_job()));
188 _restart_job_action = _wrapper->createAction("Restart a Job", QIcon(), "Restart a Job", "Restart a Job", 0, _dock_parent, false, this, SLOT(restart_job()));
189 _delete_job_action = _wrapper->createAction("Delete a Job", QIcon(), "Delete a Job", "Delete a Job", Qt::Key_Delete, _dock_parent, false, this, SLOT(delete_job()));
190 _refresh_job_action = _wrapper->createAction("Refresh Jobs", QIcon(), "Refresh Jobs", "Refresh Jobs", 0, _dock_parent, false, this, SLOT(refresh_job()));
191 _get_results_job_action = _wrapper->createAction("Get Job Results", QIcon(), "Get Job Results", "Get Job Results", 0, _dock_parent, false, this, SLOT(refresh_job()));
192 _stop_job_action = _wrapper->createAction("Stop a Job", QIcon(), "Stop a Job", "Stop a Job", 0, _dock_parent, false, this, SLOT(stop_job()));
196 BL::GenericGui::createMenus()
198 DEBTRACE("CreateMenus BL::GenericGui");
199 int menu_id = _wrapper->createTopMenu("JobManager");
200 _wrapper->addActionToMenu(_create_job_action, menu_id);
201 _wrapper->addActionToMenu(_edit_clone_job_action, menu_id);
202 _wrapper->addActionToMenu(_start_job_action, menu_id);
203 _wrapper->addActionToMenu(_restart_job_action, menu_id);
204 _wrapper->addActionToMenu(_stop_job_action, menu_id);
205 _wrapper->addActionToMenu(_delete_job_action, menu_id);
206 _wrapper->addActionToMenu(_get_results_job_action, menu_id);
207 _wrapper->addActionToMenu(_refresh_job_action, menu_id);
211 BL::GenericGui::create_job()
213 DEBTRACE("Create Job Slot BL::GenericGui");
214 _jobs_manager->create_job();
218 BL::GenericGui::edit_clone_job()
220 DEBTRACE("Edit/Clone Job Slot BL::GenericGui");
221 _jobs_manager->edit_clone_job(_job_name_selected.toStdString());
225 BL::GenericGui::start_job()
227 DEBTRACE("Start Job Slot BL::GenericGui");
228 _jobs_manager->start_job(_job_name_selected.toStdString());
229 updateButtonsStates();
233 BL::GenericGui::restart_job()
235 DEBTRACE("Restart Job Slot BL::GenericGui");
236 _jobs_manager->restart_job(_job_name_selected.toStdString());
237 updateButtonsStates();
241 BL::GenericGui::refresh_job()
243 DEBTRACE("Refresh Job Slot BL::GenericGui");
244 _jobs_manager->refresh_jobs();
248 BL::GenericGui::get_results_job()
250 DEBTRACE("Get Results Job Slot BL::GenericGui");
251 if (!_jobs_table->isMultipleSelected())
253 _jobs_manager->get_results_job(_job_name_selected.toStdString());
257 QModelIndexList selected_rows = _jobs_table->selectionModel()->selectedRows();
258 for (int i = 0; i < selected_rows.length(); ++i)
260 QString job_name = _model->itemFromIndex(selected_rows[i])->text();
261 _jobs_manager->get_results_job(job_name.toStdString());
267 BL::GenericGui::stop_job()
269 DEBTRACE("Stop Job Slot BL::GenericGui");
270 if (!_jobs_table->isMultipleSelected())
272 _jobs_manager->stop_job(_job_name_selected.toStdString());
276 QModelIndexList selected_rows = _jobs_table->selectionModel()->selectedRows();
277 for (int i = 0; i < selected_rows.length(); ++i)
279 QString job_name = _model->itemFromIndex(selected_rows[i])->text();
280 _jobs_manager->stop_job(job_name.toStdString());
287 BL::GenericGui::delete_job()
289 DEBTRACE("Delete Job Slot BL::GenericGui");
290 int ret = QMessageBox::Cancel;
292 if (!_jobs_table->isMultipleSelected())
294 ret = QMessageBox::warning(NULL, "Delete a job", "Do you really want to delete job " + _job_name_selected + " ? ",
295 QMessageBox::Ok|QMessageBox::Cancel,
300 ret = QMessageBox::warning(NULL, "Delete jobs", "Do you really want to delete these jobs ?",
301 QMessageBox::Ok|QMessageBox::Cancel,
304 if (ret == QMessageBox::Ok)
306 delete_job_internal();
311 BL::GenericGui::delete_job_external(const QString & name)
313 DEBTRACE("Delete Job External");
314 _jobs_manager->delete_job(name);
315 if (!_jobs_table->selectCurrent())
317 _job_name_selected = "";
318 updateButtonsStates();
323 BL::GenericGui::delete_job_internal()
325 if (!_jobs_table->isMultipleSelected())
327 QModelIndexList selected_list = _jobs_table->getSelectedIndexes();
328 QString job_name_to_delete = _model->itemFromIndex(selected_list[0])->text();
329 DEBTRACE("Single Deleting job: " << job_name_to_delete.toStdString());
330 _jobs_manager->delete_job(job_name_to_delete);
331 if (!_jobs_table->selectCurrent())
333 _job_name_selected = "";
334 updateButtonsStates();
339 QModelIndexList selected_list = _jobs_table->getSelectedIndexes();
340 QString job_name = _model->itemFromIndex(selected_list[0])->text();
341 DEBTRACE("Multiple Deleting job: " << job_name.toStdString());
342 _jobs_manager->delete_job(job_name);
343 delete_job_internal(); // Recursive delete
348 BL::GenericGui::reset_job_selection()
350 _job_name_selected = "";
352 updateButtonsStates();
356 BL::GenericGui::job_selected(const QModelIndex & index)
358 DEBTRACE("BL::GenericGui::job_selected");
360 //Find if a job is selected (ignore index)
361 //If Multiple job are selected, take first job
362 QItemSelectionModel * selection_model = _jobs_table->selectionModel();
363 QModelIndexList selected_rows = selection_model->selectedRows();
364 if (selected_rows.length() >= 1)
366 QModelIndex idx = selected_rows[0];
367 QStandardItem * item = _model->itemFromIndex(idx);
368 QStandardItem * item_name = _model->item(item->row());
369 _job_name_selected = item_name->text();
370 _job_tab->job_selected(idx);
371 DEBTRACE("BL::GenericGui::job_selected name is " << _job_name_selected.toStdString());
375 _job_name_selected = "";
377 DEBTRACE("BL::GenericGui::job_selected - no jobs are selected");
379 updateButtonsStates();
383 BL::GenericGui::job_activated(const QModelIndex & index)
385 DEBTRACE("BL::GenericGui::job_activated slot");
390 BL::GenericGui::job_state_changed(const QString & name)
392 if (name == _job_name_selected)
393 updateButtonsStates();
397 BL::GenericGui::updateButtonsStates()
399 if (!_jobs_table->isMultipleSelected())
401 updateButtonsStatesSingleSelection();
405 _start_job_action->setEnabled(false);
406 _edit_clone_job_action->setEnabled(false);
407 _restart_job_action->setEnabled(false);
408 _buttons->disable_start_button();
409 _buttons->disable_edit_clone_button();
410 _buttons->disable_restart_button();
412 // You can always delete jobs
413 _delete_job_action->setEnabled(true);
414 _buttons->enable_delete_button();
417 bool enable_stop = true;
418 QModelIndexList selected_rows = _jobs_table->selectionModel()->selectedRows();
419 for (int i = 0; i < selected_rows.length(); ++i)
421 QString job_name = _model->itemFromIndex(selected_rows[i])->text();
422 BL::Job * job = _jobs_manager->getJob(job_name.toStdString());
423 BL::Job::State job_state = job->getState();
424 if (job_state != BL::Job::QUEUED &&
425 job_state != BL::Job::RUNNING &&
426 job_state != BL::Job::PAUSED)
431 _stop_job_action->setEnabled(true);
432 _buttons->enable_stop_button();
436 _stop_job_action->setEnabled(false);
437 _buttons->disable_stop_button();
440 // Enable get_results ?
441 bool enable_results = true;
442 for (int i = 0; i < selected_rows.length(); ++i)
444 QString job_name = _model->itemFromIndex(selected_rows[i])->text();
445 BL::Job * job = _jobs_manager->getJob(job_name.toStdString());
446 BL::Job::State job_state = job->getState();
447 if (job_state != BL::Job::FINISHED &&
448 job_state != BL::Job::FAILED)
449 enable_results= false;
453 _get_results_job_action->setEnabled(true);
454 _buttons->enable_get_results_button();
458 _get_results_job_action->setEnabled(false);
459 _buttons->disable_get_results_button();
465 BL::GenericGui::updateButtonsStatesSingleSelection()
467 DEBTRACE("BL::GenericGui::updateButtonsStatesSingleSelection slot");
469 // First case: no job selected
470 if (_job_name_selected == "")
472 _start_job_action->setEnabled(false);
473 _delete_job_action->setEnabled(false);
474 _get_results_job_action->setEnabled(false);
475 _buttons->disable_start_button();
476 _buttons->disable_delete_button();
477 _buttons->disable_get_results_button();
478 _edit_clone_job_action->setEnabled(false);
479 _buttons->disable_edit_clone_button();
480 _restart_job_action->setEnabled(false);
481 _buttons->disable_restart_button();
482 _stop_job_action->setEnabled(false);
483 _buttons->disable_stop_button();
485 else if (_job_name_selected != "")
487 BL::Job * job = _jobs_manager->getJob(_job_name_selected.toStdString());
488 BL::Job::State job_state = job->getState();
490 _edit_clone_job_action->setEnabled(true);
491 _buttons->enable_edit_clone_button();
494 case BL::Job::CREATED:
495 _start_job_action->setEnabled(true);
496 _delete_job_action->setEnabled(true);
497 _get_results_job_action->setEnabled(false);
498 _buttons->enable_start_button();
499 _buttons->enable_delete_button();
500 _buttons->disable_get_results_button();
501 _restart_job_action->setEnabled(false);
502 _buttons->disable_restart_button();
503 _stop_job_action->setEnabled(false);
504 _buttons->disable_stop_button();
507 case BL::Job::IN_PROCESS:
508 _start_job_action->setEnabled(false);
509 _buttons->disable_start_button();
510 _delete_job_action->setEnabled(false);
511 _buttons->disable_delete_button();
512 _get_results_job_action->setEnabled(false);
513 _buttons->disable_get_results_button();
514 _restart_job_action->setEnabled(false);
515 _buttons->disable_restart_button();
516 _stop_job_action->setEnabled(false);
517 _buttons->disable_stop_button();
520 case BL::Job::QUEUED:
521 _start_job_action->setEnabled(false);
522 _buttons->disable_start_button();
523 _delete_job_action->setEnabled(true);
524 _buttons->enable_delete_button();
525 _get_results_job_action->setEnabled(false);
526 _buttons->disable_get_results_button();
527 _restart_job_action->setEnabled(false);
528 _buttons->disable_restart_button();
529 _stop_job_action->setEnabled(true);
530 _buttons->enable_stop_button();
533 case BL::Job::RUNNING:
534 _start_job_action->setEnabled(false);
535 _buttons->disable_start_button();
536 _delete_job_action->setEnabled(true);
537 _buttons->enable_delete_button();
538 _get_results_job_action->setEnabled(false);
539 _buttons->disable_get_results_button();
540 _restart_job_action->setEnabled(false);
541 _buttons->disable_restart_button();
542 _stop_job_action->setEnabled(true);
543 _buttons->enable_stop_button();
546 case BL::Job::PAUSED:
547 _start_job_action->setEnabled(false);
548 _buttons->disable_start_button();
549 _delete_job_action->setEnabled(true);
550 _buttons->enable_delete_button();
551 _get_results_job_action->setEnabled(false);
552 _buttons->disable_get_results_button();
553 _restart_job_action->setEnabled(false);
554 _buttons->disable_restart_button();
555 _stop_job_action->setEnabled(true);
556 _buttons->enable_stop_button();
560 _start_job_action->setEnabled(false);
561 _buttons->disable_start_button();
562 _delete_job_action->setEnabled(true);
563 _buttons->enable_delete_button();
564 _get_results_job_action->setEnabled(false);
565 _buttons->disable_get_results_button();
566 _restart_job_action->setEnabled(true);
567 _buttons->enable_restart_button();
568 _stop_job_action->setEnabled(false);
569 _buttons->disable_stop_button();
572 case BL::Job::FINISHED:
573 _start_job_action->setEnabled(false);
574 _buttons->disable_start_button();
575 _delete_job_action->setEnabled(true);
576 _buttons->enable_delete_button();
577 _get_results_job_action->setEnabled(true);
578 _buttons->enable_get_results_button();
579 _restart_job_action->setEnabled(true);
580 _buttons->enable_restart_button();
581 _stop_job_action->setEnabled(false);
582 _buttons->disable_stop_button();
585 case BL::Job::FAILED:
586 _start_job_action->setEnabled(false);
587 _buttons->disable_start_button();
588 _delete_job_action->setEnabled(true);
589 _buttons->enable_delete_button();
590 _get_results_job_action->setEnabled(true);
591 _buttons->enable_get_results_button();
592 _restart_job_action->setEnabled(true);
593 _buttons->enable_restart_button();
594 _stop_job_action->setEnabled(false);
595 _buttons->disable_stop_button();
598 case BL::Job::NOT_CREATED:
599 _start_job_action->setEnabled(false);
600 _buttons->disable_start_button();
601 _delete_job_action->setEnabled(true);
602 _buttons->enable_delete_button();
603 _get_results_job_action->setEnabled(false);
604 _buttons->disable_get_results_button();
605 _restart_job_action->setEnabled(true);
606 _buttons->enable_restart_button();
607 _stop_job_action->setEnabled(false);
608 _buttons->disable_stop_button();
614 DEBTRACE("ERROR in updateButtonsStates !!!!!!");