]> SALOME platform Git repositories - modules/jobmanager.git/blob - src/genericgui/BL_CreateJobWizard.cxx
Salome HOME
Update copyrights
[modules/jobmanager.git] / src / genericgui / BL_CreateJobWizard.cxx
1 // Copyright (C) 2009-2019  CEA/DEN, EDF R&D
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "BL_CreateJobWizard.hxx"
21 #include "BL_JobsManager_QT.hxx"
22
23 #include <QFileDialog>
24 #include <QMessageBox>
25 #include <QTreeView>
26
27 #ifndef WNT
28 #include <unistd.h>
29 #include <pwd.h>
30 #endif
31 #include <sys/types.h>
32 #include <stdlib.h>
33 #include <time.h>
34
35 #include <ui_ResourceRequirementsWizardPage.h>
36 #include <ui_FilesWizardPage.h>
37 #include <ui_AdvancedParametersWizardPage.h>
38
39 #ifdef WNT
40 #undef ERROR
41 #endif
42
43 using namespace std;
44 using namespace BL;
45
46 BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services)
47 {
48   DEBTRACE("Creating BL::CreateJobWizard");
49   BL_ASSERT(jobs_manager);
50   BL_ASSERT(salome_services);
51   _jobs_manager = jobs_manager;
52   _salome_services = salome_services;
53
54   job_name = "";
55   job_type = YACS;
56   yacs_file = "";
57   command = "";
58   python_salome_file = "";
59   env_file = "";
60   pre_command = "";
61   batch_directory = "";
62
63   // For COORM
64   coorm_batch_directory = "";
65
66   maximum_duration = "";
67   mem_limit = 0;
68   mem_req_type = BL::Job::MEM_PER_NODE;
69   nb_proc = 1;
70   nb_node = 0;
71
72   // Parameters for COORM
73   launcher_file = "";
74   launcher_args = "";
75
76   result_directory = "";
77
78   resource_choosed = "";
79   batch_queue = "";
80   batch_partition = "";
81
82   start_job = false;
83   dump_yacs_state = -1;
84   yacs_driver_options = "";
85   ll_jobtype = "";
86
87   setOptions(QWizard::NoBackButtonOnStartPage);
88
89   // Common pages
90   _job_name_page = new BL::JobNamePage(this, _jobs_manager);
91   _batch_parameters_page = new BL::BatchParametersPage(this, salome_services);
92
93   setPage(Page_JobName, _job_name_page);
94   setPage(Page_BatchParameters, _batch_parameters_page);
95
96   // For COORM
97   setPage(Page_COORM_BatchParameters, new BL::COORM_BatchParametersPage(this, salome_services));
98
99   setPage(Page_Files, new BL::FilesPage(this, salome_services));
100   setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
101   setPage(Page_Advanced, new BL::AdvancedParametersPage(this));
102   setPage(Page_Conclusion, new BL::ConclusionPage(this));
103
104   // Specific pages
105   setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
106   setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
107   setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
108
109   setWindowTitle("Create Job Wizard");
110   connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
111 }
112
113 BL::CreateJobWizard::~CreateJobWizard()
114 {
115   DEBTRACE("Destroying BL::CreateJobWizard");
116 }
117
118 void
119 BL::CreateJobWizard::clone(const std::string & name)
120 {
121   if (_jobs_manager->job_already_exist(name) == true)
122   {
123     BL::Job * job = _jobs_manager->getJob(name);
124
125     // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
126     if (job->getState() == BL::Job::CREATED ||
127         job->getState() == BL::Job::ERROR   ||
128         job->getState() == BL::Job::FAILED  ||
129         job->getState() == BL::Job::NOT_CREATED)
130     { 
131       setField("job_name", QString(name.c_str()));
132       _job_name_page->_check_name = false;
133     }
134
135     if (job->getType() == BL::Job::YACS_SCHEMA)
136     {
137       setField("yacs_file", QString(job->getJobFile().c_str()));
138       setField("job_type_yacs", true);
139       setField("env_yacs_file", QString(job->getEnvFile().c_str()));
140       setField("pre_yacs_file", QString(job->getPreCommand().c_str()));
141       if (job->getDumpYACSState() != -1)
142       {
143         QString value;
144         value.setNum(job->getDumpYACSState());
145         setField("dump_yacs_state", value);
146       }
147       if (!job->getYacsDriverOptions().empty())
148       {
149         setField("yacs_driver_options", job->getYacsDriverOptions().c_str());
150       }
151     }
152     else if (job->getType() == BL::Job::COMMAND)
153     {
154       setField("command", QString(job->getJobFile().c_str()));
155       setField("job_type_command", true);
156       setField("env_command_file", QString(job->getEnvFile().c_str()));
157       setField("pre_command_file", QString(job->getPreCommand().c_str()));
158     }
159     else if (job->getType() == BL::Job::COMMAND_SALOME)
160     {
161       setField("command", QString(job->getJobFile().c_str()));
162       setField("job_type_command_salome", true);
163       setField("env_command_file", QString(job->getEnvFile().c_str()));
164       setField("pre_command_file", QString(job->getPreCommand().c_str()));
165     }
166     else if (job->getType() == BL::Job::PYTHON_SALOME)
167     {
168       setField("PythonSalome", QString(job->getJobFile().c_str()));
169       setField("job_type_python_salome", true);
170       setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
171       setField("pre_PythonSalome_file", QString(job->getPreCommand().c_str()));
172     }
173
174
175     // For COORM
176     BL::Job::BatchParam batch_params = job->getBatchParameters();
177     BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str());
178     std::string batch = resource_descr.batch.c_str();
179     if (batch == "coorm")
180     {
181       setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str()));
182       setField("launcher_file", QString(batch_params.launcher_file.c_str()));
183       setField("launcher_args", QString(batch_params.launcher_args.c_str()));
184     }
185     else
186     {
187       setField("batch_directory", QString(batch_params.batch_directory.c_str()));
188     }
189
190     QString proc_value;
191     proc_value.setNum(batch_params.nb_proc);
192     setField("proc_value", proc_value);
193
194     QString node_value;
195     node_value.setNum(batch_params.nb_node);
196     setField("node_value", node_value);
197
198     setField("exclusive", batch_params.exclusive);
199
200     if (batch_params.maximum_duration == "")
201     {
202       setField("default_time", true);
203       setField("duration_hour", 0);
204       setField("duration_min", 0);
205     }
206     else
207     {
208       setField("user_time", true);
209       std::size_t pos = batch_params.maximum_duration.find(":");
210       std::string hour_str = batch_params.maximum_duration.substr(0, pos);
211       int hour; 
212       std::istringstream iss_hour(hour_str);
213       iss_hour >> hour;
214       setField("duration_hour", hour);
215
216       std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
217       int min; 
218       std::istringstream iss_min(min_str);
219       iss_min >> min;
220       setField("duration_min", min);
221     }
222
223     long long mem_mb = batch_params.mem_limit;
224     if (mem_mb < 1)
225     {
226       setField("default_mem", true);
227     }
228     else
229     {
230       setField("user_mem", true);
231       if (mem_mb % 1024 == 0)
232       {
233         setField("mem_value", mem_mb / 1024);
234         _batch_parameters_page->setMemUnit(BatchParametersPage::GB);
235       }
236       else
237       {
238         setField("mem_value", mem_mb);
239         _batch_parameters_page->setMemUnit(BatchParametersPage::MB);
240       }
241       _batch_parameters_page->setMemReqType(batch_params.mem_req_type);
242     }
243
244     BL::Job::FilesParam files_params = job->getFilesParameters();
245
246     std::list<std::string>::iterator it = files_params.input_files_list.begin();
247     for (; it != files_params.input_files_list.end(); it++)
248       _input_files_list->addItem(QString((*it).c_str()));
249     it = files_params.output_files_list.begin();
250     for (; it != files_params.output_files_list.end(); it++)
251       _output_files_list->addItem(QString((*it).c_str()));
252
253     setField("result_directory", QString(files_params.result_directory.c_str()));
254     setField("resource_choosed", QString(job->getResource().c_str()));
255     setField("batch_queue", QString(job->getBatchQueue().c_str()));
256     setField("batch_partition", QString(job->getBatchPartition().c_str()));
257     setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
258     setField("wckey", QString(job->getWCKey().c_str()));
259     setField("extra_params", QString(job->getExtraParams().c_str()));
260   }
261 }
262
263 void
264 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
265 {
266   _input_files_list = input_files_list;
267   _output_files_list = output_files_list;
268 }
269
270 void
271 BL::CreateJobWizard::end(int result)
272 {
273   DEBTRACE("End of BL::CreateJobWizard");
274   if (result)
275   {
276     // Job Name Panel
277     QString f_job_name = field("job_name").toString();
278     job_name = f_job_name.trimmed().toUtf8().constData();
279     if (field("job_type_yacs").toBool())
280       job_type = YACS;
281     else if (field("job_type_command").toBool())
282       job_type = COMMAND;
283     else if (field("job_type_command_salome").toBool())
284       job_type = COMMAND_SALOME;
285     else
286       job_type = PYTHON_SALOME;
287
288     // YACS Schema Panel
289     QString f_yacs_file = field("yacs_file").toString();
290     yacs_file = f_yacs_file.trimmed().toUtf8().constData();
291     dump_yacs_state = field("dump_yacs_state").toInt();
292     yacs_driver_options = field("yacs_driver_options").toString().trimmed().toUtf8().constData();
293
294     // Command Panel
295     QString f_command = field("command").toString();
296     command = f_command.trimmed().toUtf8().constData();
297
298     // Command Panel
299     QString f_python_salome_file = field("PythonSalome").toString();
300     python_salome_file = f_python_salome_file.trimmed().toUtf8().constData();
301
302     QString f_env_file;
303     if (job_type == YACS)
304       f_env_file = field("env_yacs_file").toString();
305     else if (job_type == COMMAND || job_type == COMMAND_SALOME)
306       f_env_file = field("env_command_file").toString();
307     else if (job_type == PYTHON_SALOME)
308       f_env_file = field("env_PythonSalome_file").toString();
309     env_file = f_env_file.trimmed().toUtf8().constData();
310
311     QString f_pre_command_file;
312     if (job_type == YACS)
313       f_pre_command_file = field("pre_yacs_file").toString();
314     else if (job_type == COMMAND || job_type == COMMAND_SALOME)
315       f_pre_command_file = field("pre_command_file").toString();
316     else if (job_type == PYTHON_SALOME)
317       f_pre_command_file = field("pre_PythonSalome_file").toString();
318     pre_command = f_pre_command_file.trimmed().toUtf8().constData();
319
320     // Batch Panel
321     QString f_batch_directory = field("batch_directory").toString();
322     batch_directory = f_batch_directory.trimmed().toUtf8().constData();
323
324     // For COORM
325     QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
326     coorm_batch_directory = f_coorm_batch_directory.toUtf8().constData();
327
328         // For COORM
329     QString f_launcher_file = field("launcher_file").toString();
330     launcher_file = f_launcher_file.toUtf8().constData();
331     QString f_launcher_args = field("launcher_args").toString();
332     launcher_args = f_launcher_args.toUtf8().constData();
333
334     QString time_hour;
335     QString time_min;
336     if (field("default_time").toBool() ||
337         (field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0))
338     {
339       maximum_duration = "";
340     }
341     else
342     {
343       if (field("duration_hour").toInt() < 10)
344         time_hour = "0" + field("duration_hour").toString().trimmed();
345       else
346         time_hour = field("duration_hour").toString().trimmed();
347       if (field("duration_min").toInt() < 10)
348         time_min = "0" + field("duration_min").toString().trimmed();
349       else
350         time_min = field("duration_min").toString().trimmed();
351       maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
352     }
353
354     if(field("default_mem").toBool())
355     {
356       mem_limit = -1;
357     }
358     else
359     {
360       unsigned long mem = field("mem_value").toULongLong();
361       BatchParametersPage::MemUnit mem_unit = _batch_parameters_page->getMemUnit();
362       switch (mem_unit)
363       {
364       case BatchParametersPage::MB:
365         mem_limit = mem;
366         break;
367       case BatchParametersPage::GB:
368         mem_limit = mem * 1024;
369         break;
370       default:
371         throw Exception("Invalid memory unit");
372       }
373       mem_req_type = _batch_parameters_page->getMemReqType();
374     }
375
376     nb_proc = field("proc_value").toInt();
377     nb_node = field("node_value").toInt();
378     exclusive = field("exclusive").toBool();
379
380     // Files Panel
381     QString f_result_directory = field("result_directory").toString();
382     result_directory = f_result_directory.trimmed().toUtf8().constData();
383     for (int i = 0; i < _input_files_list->count(); ++i)
384     {
385       QListWidgetItem * item = _input_files_list->item(i);
386       QString item_text = item->text();
387       input_files_list.push_back(item_text.trimmed().toUtf8().constData());
388     }
389     for (int i = 0; i < _output_files_list->count(); ++i)
390     {
391       QListWidgetItem * item = _output_files_list->item(i);
392       QString item_text = item->text();
393       output_files_list.push_back(item_text.trimmed().toUtf8().constData());
394     }
395
396     // Resource list
397     QString f_resource_choosed = field("resource_choosed").toString();
398     resource_choosed = f_resource_choosed.trimmed().toUtf8().constData();
399
400     // Batch Queue
401     QString f_batch_queue = field("batch_queue").toString();
402     batch_queue = f_batch_queue.trimmed().toUtf8().constData();
403
404     // Batch Partition
405     QString f_batch_partition = field("batch_partition").toString();
406     batch_partition = f_batch_partition.trimmed().toUtf8().constData();
407
408     // LoadLeveler JobType
409     BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
410     std::string batch = resource_descr.batch.c_str();
411     if (batch == "ll")
412     {
413       QString f_ll_jobtype = field("ll_jobtype").toString();
414       ll_jobtype = f_ll_jobtype.trimmed().toStdString();
415     }
416     else
417     {
418       ll_jobtype = "";
419     }
420
421     // WC Key
422     QString f_wckey = field("wckey").toString();
423     wckey = f_wckey.trimmed().toUtf8().constData();
424
425     // Extra params
426     QString f_extra_params = field("extra_params").toString();
427     extra_params = f_extra_params.trimmed().toUtf8().constData();
428
429     start_job = field("start_job").toBool();
430   }
431 }
432
433 // Job Name Page
434 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
435 : QWizardPage(parent)
436 {
437   _jobs_manager = jobs_manager;
438   _check_name = true;
439   setTitle("Create a new job");
440
441   QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
442   label->setWordWrap(true);
443   QLabel * nameLabel = new QLabel("Job Name:");
444   QLineEdit * _nameLineEdit = new QLineEdit(this);
445   registerField("job_name", _nameLineEdit);
446
447   QLabel * label_type = new QLabel("Choose type of batch job:");
448   QGroupBox *groupBox = new QGroupBox("Type of job");
449   QRadioButton * _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
450   _yacs_schema_button->setChecked(true);
451   QRadioButton * _command_button = new QRadioButton(tr("Command"));
452   QRadioButton * _command_salome_button = new QRadioButton(tr("Command in salome shell"));
453   QRadioButton * _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
454   QVBoxLayout *vbox = new QVBoxLayout;
455   vbox->addWidget(_yacs_schema_button);
456   vbox->addWidget(_command_button);
457   vbox->addWidget(_command_salome_button);
458   vbox->addWidget(_python_salome_button);
459   vbox->addStretch(1);
460   groupBox->setLayout(vbox);
461   registerField("job_type_yacs", _yacs_schema_button);
462   registerField("job_type_command", _command_button);
463   registerField("job_type_command_salome", _command_salome_button);
464   registerField("job_type_python_salome", _python_salome_button);
465
466   QGroupBox * explanationBox = new QGroupBox("Explanation");
467   QVBoxLayout *explanationvbox = new QVBoxLayout;
468   _explanation = new QLabel();
469   _explanation->setWordWrap(true);
470   explanationvbox->addWidget(_explanation);
471   explanationvbox->addStretch(1);
472   explanationBox->setLayout(explanationvbox);
473
474   // Layouts
475   QVBoxLayout * main_layout = new QVBoxLayout;
476   main_layout->addWidget(label);
477   QGridLayout *layout = new QGridLayout;
478   layout->addWidget(nameLabel, 0, 0);
479   layout->addWidget(_nameLineEdit, 0, 1);
480   main_layout->insertLayout(-1, layout);
481   layout->addWidget(label_type, 2, 0);
482   layout->addWidget(groupBox, 3, 0, 1, -1);
483   layout->addWidget(explanationBox, 4, 0, 1, -1);
484   setLayout(main_layout);
485
486   connect(_yacs_schema_button, SIGNAL(toggled(bool)), this, SLOT(yacs_schema_button(bool)));
487   connect(_command_button, SIGNAL(toggled(bool)), this, SLOT(command_button(bool)));
488   connect(_command_salome_button, SIGNAL(toggled(bool)), this, SLOT(command_salome_button(bool)));
489   connect(_python_salome_button, SIGNAL(toggled(bool)), this, SLOT(python_salome_button(bool)));
490
491   // Default button
492   yacs_schema_button(true);
493 }
494
495 BL::JobNamePage::~JobNamePage()
496 {}
497
498 void
499 BL::JobNamePage::yacs_schema_button(bool checked)
500 {
501   if (checked)
502   {
503     _explanation->setText("Launch a YACS schema.");
504     setField("exclusive", true);
505   }
506 }
507
508 void
509 BL::JobNamePage::command_button(bool checked)
510 {
511   if (checked)
512   {
513     _explanation->setText("Launch a script on a remote resource without using "
514                           "SALOME environment.");
515     setField("exclusive", false);
516   }
517 }
518
519 void
520 BL::JobNamePage::command_salome_button(bool checked)
521 {
522   if (checked)
523   {
524     _explanation->setText("Launch a script on a remote resource within SALOME "
525                           "environment but whitout the SALOME application.");
526     setField("exclusive", false);
527   }
528 }
529
530 void
531 BL::JobNamePage::python_salome_button(bool checked)
532 {
533   if (checked)
534   {
535     _explanation->setText("Launch a python script into a SALOME application.");
536     setField("exclusive", true);
537   }
538 }
539
540 bool
541 BL::JobNamePage::validatePage()
542 {
543   DEBTRACE("Calling validatePage of BL::JobNamePage");
544   bool return_value;
545   QString job_name = field("job_name").toString();
546
547   // Check if job name is empty
548   if (job_name == "")
549   {
550     QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
551     return_value = false;
552   }
553
554   // Check if job name already exists
555   else {
556     if (_jobs_manager->job_already_exist(job_name.toUtf8().constData()) == false || _check_name == false)
557     {
558       return_value = true;
559     }
560     else
561     {
562       QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
563       QString value("");
564       setField("job_name", value);
565       return_value = false;
566     }
567   }
568
569   return return_value;
570 }
571
572 int
573 BL::JobNamePage::nextId() const
574 {
575   if (field("job_type_yacs").toBool())
576   {
577     return BL::CreateJobWizard::Page_YACSSchema;
578   } 
579   else if (field("job_type_command").toBool() ||
580            field("job_type_command_salome").toBool())
581   {
582     return BL::CreateJobWizard::Page_Command_Main_Definitions;
583   }
584   else
585   {
586     return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
587   }
588 }
589
590 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
591 : QWizardPage(parent)
592 {
593   setTitle("Configure YACS Execution");
594
595   QLabel *label = new QLabel("In this step you have to configure your YACS execution");
596   label->setWordWrap(true);
597
598   QGroupBox * files_param_box = new QGroupBox("YACS job files");
599   QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
600   connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
601   _yacs_file_text = new QLineEdit(this);
602   _yacs_file_text->setText("");
603   registerField("yacs_file", _yacs_file_text);
604   _yacs_file_text->setReadOnly(true);
605   QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
606   connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
607   _line_env_file = new QLineEdit(this);
608   registerField("env_yacs_file", _line_env_file);
609   _line_env_file->setReadOnly(true);
610   QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script"));
611   connect(command_pre_command_button, SIGNAL(clicked()),
612           this, SLOT(choose_pre_command_file()));
613   _line_pre_command = new QLineEdit(this);
614   registerField("pre_yacs_file", _line_pre_command);
615   _line_pre_command->setReadOnly(true);
616   QGridLayout * files_layout = new QGridLayout;
617   files_layout->addWidget(yacs_file_button, 0, 0);
618   files_layout->addWidget(_yacs_file_text, 0, 1);
619   files_layout->addWidget(command_env_file_button, 1, 0);
620   files_layout->addWidget(_line_env_file, 1, 1);
621   files_layout->addWidget(command_pre_command_button, 2, 0);
622   files_layout->addWidget(_line_pre_command, 2, 1);
623   files_param_box->setLayout(files_layout);
624
625   QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
626   QLabel * label_dump =  new QLabel("Dump YACS state each secs (0 disable this feature)");
627   QLabel * label_driver_options = new QLabel("YACS driver options - see YACS driver documentation.");
628   QSpinBox * spin_dump = new QSpinBox(this);
629   spin_dump->setMinimum(0);
630   spin_dump->setMaximum(1000000);
631   registerField("dump_yacs_state", spin_dump);
632   QLineEdit* edit_yacs_driver_options = new QLineEdit(this);
633   registerField("yacs_driver_options", edit_yacs_driver_options);
634   QGridLayout * specific_layout = new QGridLayout;
635   specific_layout->addWidget(label_dump, 0, 0);
636   specific_layout->addWidget(spin_dump, 0, 1);
637   specific_layout->addWidget(label_driver_options, 1, 0);
638   specific_layout->addWidget(edit_yacs_driver_options, 1, 1);
639   spec_param_box->setLayout(specific_layout);
640
641   QVBoxLayout * main_layout = new QVBoxLayout;
642   main_layout->addWidget(label);
643   main_layout->addWidget(files_param_box);
644   main_layout->addWidget(spec_param_box);
645
646   setLayout(main_layout);
647 };
648
649 BL::YACSSchemaPage::~YACSSchemaPage()
650 {}
651
652 bool
653 BL::YACSSchemaPage::validatePage()
654 {
655   bool return_value;
656   QString yacs_file = field("yacs_file").toString();
657   if (yacs_file != "")
658   {
659     return_value = true;
660   }
661   else
662   {
663     QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
664     return_value = false;
665   }
666   return return_value;
667 }
668
669 void
670 BL::YACSSchemaPage::choose_file()
671 {
672   QString yacs_file = QFileDialog::getOpenFileName(this,
673                                                    tr("Open YACS files"), "",
674                                                    tr("XML (*.xml);;All Files (*)"));
675   _yacs_file_text->setReadOnly(false);
676   _yacs_file_text->setText(yacs_file);
677   _yacs_file_text->setReadOnly(true);
678 }
679
680 void
681 BL::YACSSchemaPage::choose_env_file()
682 {
683   QString env_file = QFileDialog::getOpenFileName(this,
684                                                   tr("Open environnement file"), "",
685                                                   tr("sh (*.sh);;All Files (*)"));
686   _line_env_file->setReadOnly(false);
687   _line_env_file->setText(env_file);
688   _line_env_file->setReadOnly(true);
689 }
690
691 void
692 BL::YACSSchemaPage::choose_pre_command_file()
693 {
694   QString pre_command_file = QFileDialog::getOpenFileName(this,
695                                                     tr("Open script file"), "",
696                                                     tr("All Files (*)"));
697   _line_pre_command->setReadOnly(false);
698   _line_pre_command->setText(pre_command_file);
699   _line_pre_command->setReadOnly(true);
700 }
701
702 int 
703 BL::YACSSchemaPage::nextId() const
704 {
705   return BL::CreateJobWizard::Page_Resource;
706 }
707
708 BL::CommandMainPage::CommandMainPage(QWidget * parent)
709 : QWizardPage(parent)
710 {
711   setTitle("Define command job");
712   QLabel *label = new QLabel("Enter the command that will be executed into the resource");
713   label->setWordWrap(true);
714
715   // command
716   QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
717   connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
718   _line_command = new QLineEdit(this);
719   registerField("command", _line_command);
720   _line_command->setReadOnly(true);
721
722   QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
723   connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
724   _line_env_file = new QLineEdit(this);
725   registerField("env_command_file", _line_env_file);
726   _line_env_file->setReadOnly(true);
727
728   QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script"));
729   connect(command_pre_command_button, SIGNAL(clicked()),
730           this, SLOT(choose_pre_command_file()));
731   _line_pre_command = new QLineEdit(this);
732   registerField("pre_command_file", _line_pre_command);
733   _line_pre_command->setReadOnly(true);
734
735   QGridLayout *layout = new QGridLayout;
736   layout->addWidget(command_file_button, 0, 0);
737   layout->addWidget(_line_command, 0, 1);
738   layout->addWidget(command_env_file_button, 1, 0);
739   layout->addWidget(_line_env_file, 1, 1);
740   layout->addWidget(command_pre_command_button, 2, 0);
741   layout->addWidget(_line_pre_command, 2, 1);
742
743   QVBoxLayout * main_layout = new QVBoxLayout;
744   main_layout->addWidget(label);
745   main_layout->insertLayout(-1, layout);
746   setLayout(main_layout);
747 };
748
749 BL::CommandMainPage::~CommandMainPage()
750 {}
751
752 void
753 BL::CommandMainPage::choose_command_file()
754 {
755   QString command_file = QFileDialog::getOpenFileName(this,
756                                                       tr("Open command file"), "",
757                                                       tr("sh (*.sh);;All Files (*)"));
758   _line_command->setReadOnly(false);
759   _line_command->setText(command_file);
760   _line_command->setReadOnly(true);
761 }
762
763 void
764 BL::CommandMainPage::choose_env_file()
765 {
766   QString env_file = QFileDialog::getOpenFileName(this,
767                                                   tr("Open environnement file"), "",
768                                                   tr("sh (*.sh);;All Files (*)"));
769   _line_env_file->setReadOnly(false);
770   _line_env_file->setText(env_file);
771   _line_env_file->setReadOnly(true);
772 }
773
774 void
775 BL::CommandMainPage::choose_pre_command_file()
776 {
777   QString pre_command_file = QFileDialog::getOpenFileName(this,
778                                                     tr("Open script file"), "",
779                                                     tr("All Files (*)"));
780   _line_pre_command->setReadOnly(false);
781   _line_pre_command->setText(pre_command_file);
782   _line_pre_command->setReadOnly(true);
783 }
784
785 bool
786 BL::CommandMainPage::validatePage()
787 {
788   QString command = field("command").toString();
789   if (command == "")
790   {
791     QMessageBox::warning(NULL, "Command Error", "Please enter a command");
792     return false;
793   }
794
795   return true;
796 }
797
798 int 
799 BL::CommandMainPage::nextId() const
800 {
801   return BL::CreateJobWizard::Page_Resource;
802 }
803
804 BatchParametersPage::BatchParametersPage(QWidget * parent, SALOMEServices * salome_services)
805 : QWizardPage(parent),
806   ui(new Ui::ResourceRequirementsWizardPage),
807   _salome_services(salome_services),
808   resource_choosed()
809 {
810   ui->setupUi(this);
811
812   registerField("duration_hour", ui->spin_duration_hour);
813   registerField("duration_min", ui->spin_duration_min);
814   registerField("mem_value", ui->spin_memory);
815   registerField("proc_value", ui->spin_proc);
816   registerField("node_value", ui->spin_node);
817   registerField("exclusive", ui->check_exclusive);
818   registerField("default_time", ui->rb_default_time);
819   registerField("user_time", ui->rb_user_time);
820   registerField("default_mem", ui->rb_default_mem);
821   registerField("user_mem", ui->rb_user_mem);
822
823   ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "MB", MB);
824   ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "GB", GB);
825   setMemUnit(GB);
826
827   ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
828                                         "per node", Job::MEM_PER_NODE);
829   ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
830                                         "per core", Job::MEM_PER_CPU);
831
832   connect(ui->spin_duration_hour, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
833   connect(ui->spin_duration_min, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
834   connect(ui->spin_memory, SIGNAL(valueChanged(int)), this, SLOT(memChanged()));
835   connect(ui->combo_memory_unit, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
836   connect(ui->combo_memory_req_type, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
837 };
838
839 BatchParametersPage::~BatchParametersPage()
840 {
841   delete ui;
842 }
843
844 void
845 BatchParametersPage::initializePage()
846 {
847   string f_resource_choosed = field("resource_choosed").toString().toUtf8().constData();
848   if (f_resource_choosed != resource_choosed)
849   {
850     resource_choosed = f_resource_choosed;
851     // If choosed resource has a SLURM batch manager, activate option "memory per cpu"
852     ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
853     if (resource_descr.batch == "slurm")
854     {
855       ui->combo_memory_req_type->setEnabled(true);
856     }
857     else
858     {
859       ui->combo_memory_req_type->setEnabled(false);
860       setMemReqType(Job::MEM_PER_NODE);
861     }
862   }
863 }
864
865 BatchParametersPage::MemUnit
866 BatchParametersPage::getMemUnit() const
867 {
868   int idx = ui->combo_memory_unit->currentIndex();
869   return (MemUnit)(ui->combo_memory_unit->itemData(idx).toInt());
870 }
871
872 void
873 BatchParametersPage::setMemUnit(MemUnit mem_unit)
874 {
875   ui->combo_memory_unit->setCurrentIndex(ui->combo_memory_unit->findData(mem_unit));
876 }
877
878 Job::MemReqType
879 BatchParametersPage::getMemReqType() const
880 {
881   int idx = ui->combo_memory_req_type->currentIndex();
882   return (Job::MemReqType)(ui->combo_memory_req_type->itemData(idx).toInt());
883 }
884
885 void
886 BatchParametersPage::setMemReqType(Job::MemReqType mem_req_type)
887 {
888   ui->combo_memory_req_type->setCurrentIndex(ui->combo_memory_req_type->findData(mem_req_type));
889 }
890
891 void
892 BatchParametersPage::timeChanged()
893 {
894   if (ui->spin_duration_hour->value() == 0 && ui->spin_duration_min->value() == 0)
895     ui->rb_default_time->setChecked(true);
896   else
897     ui->rb_user_time->setChecked(true);
898 }
899
900 void
901 BatchParametersPage::memChanged()
902 {
903   ui->rb_user_mem->setChecked(true);
904 }
905
906 void
907 BatchParametersPage::cleanupPage()
908 {
909 }
910
911 int 
912 BatchParametersPage::nextId() const
913 {
914   return CreateJobWizard::Page_Files;
915 }
916
917 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
918 : QWizardPage(parent)
919 {
920   setTitle("Enter COORM Parameters");
921   resource_choosed = "";
922
923   _salome_services = salome_services;
924
925   QLabel *label = new QLabel("In this step you define the parameters for COORM");
926   label->setWordWrap(true);
927   QVBoxLayout * main_layout = new QVBoxLayout;
928   main_layout->addWidget(label);
929
930   // coorm_batch_directory
931   QLabel * label_directory = new QLabel("Remote work directory: ");
932   QLineEdit * line_directory = new QLineEdit(this);
933   registerField("coorm_batch_directory", line_directory);
934
935   // launcher_file
936   QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
937   connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
938   _launcher_file_text = new QLineEdit(this);
939   _launcher_file_text->setText("");
940   registerField("launcher_file", _launcher_file_text);
941   _launcher_file_text->setReadOnly(true);
942
943   // launcher_args
944   QLabel * launcher_args_label = new QLabel("Launcher args:");
945   QLineEdit * launcher_args_text = new QLineEdit(this);
946   registerField("launcher_args", launcher_args_text);
947
948   QGridLayout * layout = new QGridLayout;
949   layout->addWidget(label_directory, 0, 0);
950   layout->addWidget(line_directory, 0, 1);
951   layout->addWidget(launcher_file_button, 1, 0);
952   layout->addWidget(_launcher_file_text, 1, 1);
953   layout->addWidget(launcher_args_label, 2, 0);
954   layout->addWidget(launcher_args_text, 2, 1);
955
956   main_layout->insertLayout(-1, layout);
957
958   setLayout(main_layout);
959 };
960
961 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
962 {}
963
964 bool
965 BL::COORM_BatchParametersPage::validatePage()
966 {
967   QString coorm_batch_directory = field("coorm_batch_directory").toString();
968   if (coorm_batch_directory == "")
969   {
970     QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
971     return false;
972   }
973
974   QString launcher_file = field("launcher_file").toString();
975   if (launcher_file == "")
976   {
977     QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
978     return false;
979   }
980
981   return true;
982 }
983
984 int
985 BL::COORM_BatchParametersPage::nextId() const
986 {
987   return BL::CreateJobWizard::Page_Files;
988 }
989
990 void
991 BL::COORM_BatchParametersPage::choose_launcher_file()
992 {
993   QString launcher_file = QFileDialog::getOpenFileName(this,
994                                                    tr("Open launcher files"), "",
995                                                    tr("Py (*.py);;All Files (*)"));
996   _launcher_file_text->setReadOnly(false);
997   _launcher_file_text->setText(launcher_file);
998   _launcher_file_text->setReadOnly(true);
999 }
1000
1001 void BL::COORM_BatchParametersPage::cleanupPage()
1002 {}
1003
1004 void
1005 BL::COORM_BatchParametersPage::initializePage()
1006 {
1007   QString f_resource_choosed = field("resource_choosed").toString();
1008   if (f_resource_choosed != resource_choosed)
1009   {
1010     resource_choosed = f_resource_choosed;
1011     // If choosed resource has a working_directory set
1012     // Generates a default remote working directory
1013     BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1014     QString res_work_dir = resource_descr.working_directory.c_str();
1015     if (res_work_dir != "")
1016     {
1017       time_t rawtime;
1018       time(&rawtime);
1019       std::string launch_date = ctime(&rawtime);
1020       for (int i = 0; i < launch_date.size(); i++)
1021         if (launch_date[i] == '/' ||
1022             launch_date[i] == '-' ||
1023             launch_date[i] == ':' ||
1024             launch_date[i] == ' ')
1025           launch_date[i] = '_';
1026       launch_date.erase(--launch_date.end()); // Last caracter is a \n
1027       QString date = launch_date.c_str();
1028       setField("coorm_batch_directory", res_work_dir + "/" + date);
1029     }
1030   }
1031 }
1032
1033 FilesPage::FilesPage(CreateJobWizard * parent, SALOMEServices * salome_services)
1034 : QWizardPage(parent),
1035   ui(new Ui::FilesWizardPage)
1036 {
1037   ui->setupUi(this);
1038
1039   resource_choosed = "";
1040   _salome_services = salome_services;
1041
1042   connect(ui->add_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
1043   connect(ui->remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
1044   connect(ui->input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
1045   connect(ui->add_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
1046   connect(ui->remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
1047   connect(ui->output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
1048   connect(ui->button_choose_result_dir, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
1049
1050   registerField("batch_directory", ui->line_remote_working_dir);
1051   registerField("result_directory", ui->line_result_dir);
1052
1053   // Default result directory is home directory (if we found it)
1054   // First try -> HOME
1055 #ifdef WNT
1056   ui->line_result_dir->setText(getenv("HOME"));
1057 #else
1058   if (getenv("HOME"))
1059     ui->line_result_dir->setText(getenv("HOME"));
1060   else {
1061     // Second try -> getpwuid
1062     struct passwd * pass_struct = getpwuid(getuid());
1063     if (pass_struct)
1064       ui->line_result_dir->setText(pass_struct->pw_dir);
1065   }
1066 #endif
1067
1068   parent->setFilesList(ui->input_files_list, ui->output_files_list);
1069
1070   // Check for warning messages
1071   ui->label_warning_icon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(16, 16));
1072   connect(ui->line_remote_working_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
1073   connect(ui->line_result_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
1074 };
1075
1076 FilesPage::~FilesPage()
1077 {
1078   delete ui;
1079 }
1080
1081 void
1082 FilesPage::initializePage()
1083 {
1084   QString f_resource_choosed = field("resource_choosed").toString();
1085   if (f_resource_choosed != resource_choosed)
1086   {
1087     resource_choosed = f_resource_choosed;
1088     // If choosed resource has a working_directory set
1089     // Generates a default remote working directory
1090     BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1091     QString res_work_dir = resource_descr.working_directory.c_str();
1092     if (res_work_dir != "")
1093     {
1094       time_t rawtime;
1095       time(&rawtime);
1096       std::string launch_date = ctime(&rawtime);
1097       for (int i = 0; i < launch_date.size(); i++)
1098         if (launch_date[i] == '/' ||
1099             launch_date[i] == '-' ||
1100             launch_date[i] == ':' ||
1101             launch_date[i] == ' ')
1102           launch_date[i] = '_';
1103       launch_date.erase(--launch_date.end()); // Last caracter is a \n
1104       QString date = launch_date.c_str();
1105       setField("batch_directory", res_work_dir + "/" + date);
1106     }
1107   }
1108 }
1109
1110 bool
1111 FilesPage::isComplete() const
1112 {
1113   QString warn_msg;
1114   if (field("batch_directory").toString().isEmpty())
1115     warn_msg = "Remote working directory is mandatory.";
1116   if (field("result_directory").toString().isEmpty() && ui->output_files_list->count() != 0)
1117   {
1118     if (!warn_msg.isEmpty()) warn_msg += "\n";
1119     warn_msg += "Result directory is mandatory if there are output files.";
1120   }
1121
1122   ui->label_warning_text->setText(warn_msg);
1123   if (warn_msg.isEmpty())
1124   {
1125     ui->label_warning_icon->hide();
1126     return true;
1127   }
1128   else
1129   {
1130     ui->label_warning_icon->show();
1131     return false;
1132   }
1133 }
1134
1135 void
1136 FilesPage::choose_input_files()
1137 {
1138   // We need to be able to select both files and folders.
1139   // Standard QFileDialog cannot do it.
1140   QFileDialog w(this, tr("Select input files"),
1141               "", tr("All files and folders(*)")) ;
1142   w.setOption(QFileDialog::DontUseNativeDialog,true);
1143   QListView *l = w.findChild<QListView*>("listView");
1144   if (l)
1145   {
1146     l->setSelectionMode(QAbstractItemView::MultiSelection);
1147   }
1148   QTreeView *t = w.findChild<QTreeView*>();
1149   if (t)
1150   {
1151     t->setSelectionMode(QAbstractItemView::MultiSelection);
1152   }
1153   if(w.exec())
1154   {
1155     QStringList files = w.selectedFiles();
1156     for (int i = 0; i < files.size(); ++i)
1157     {
1158       if (ui->input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
1159         ui->input_files_list->addItem(files.at(i));
1160     }
1161   }
1162 }
1163
1164 void
1165 FilesPage::choose_local_directory()
1166 {
1167   QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
1168                                                  "",
1169                                                  QFileDialog::ShowDirsOnly
1170                                                  | QFileDialog::DontResolveSymlinks);
1171
1172   if (dir != "")
1173     ui->line_result_dir->setText(dir);
1174 }
1175
1176 void 
1177 FilesPage::remove_input_files()
1178 {
1179   QList<QListWidgetItem *> list = ui->input_files_list->selectedItems();
1180   for (int i = 0; i < list.size(); ++i)
1181   {
1182     int row = ui->input_files_list->row( list.at(i) );
1183     delete ui->input_files_list->takeItem(row);
1184   }
1185 }
1186
1187 void 
1188 FilesPage::input_itemSelectionChanged()
1189 {
1190   if (ui->input_files_list->selectedItems().size() > 0)
1191     ui->remove_input_files_button->setEnabled(true);
1192   else
1193     ui->remove_input_files_button->setEnabled(false);
1194 }
1195
1196 void
1197 FilesPage::add_output_file()
1198 {
1199   QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1200   new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1201   ui->output_files_list->addItem(new_item);
1202   emit completeChanged();
1203 }
1204
1205 void 
1206 FilesPage::remove_output_files()
1207 {
1208   QList<QListWidgetItem *> list = ui->output_files_list->selectedItems();
1209   for (int i = 0; i < list.size(); ++i)
1210   {
1211     int row = ui->output_files_list->row( list.at(i) );
1212     delete ui->output_files_list->takeItem(row);
1213   }
1214   emit completeChanged();
1215 }
1216
1217 void 
1218 FilesPage::output_itemSelectionChanged()
1219 {
1220   if (ui->output_files_list->selectedItems().size() > 0)
1221     ui->remove_output_files_button->setEnabled(true);
1222   else
1223     ui->remove_output_files_button->setEnabled(false);
1224 }
1225
1226 int 
1227 FilesPage::nextId() const
1228 {
1229   return BL::CreateJobWizard::Page_Advanced;
1230 }
1231
1232 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1233 : QWizardPage(parent)
1234 {
1235   setTitle("Job definition is finished");
1236   QCheckBox * check_box =  new QCheckBox("Start job after creation");
1237   registerField("start_job", check_box);
1238   QVBoxLayout * main_layout = new QVBoxLayout;
1239   main_layout->addWidget(check_box);
1240   setLayout(main_layout);
1241 };
1242
1243 BL::ConclusionPage::~ConclusionPage()
1244 {}
1245
1246 bool
1247 BL::ConclusionPage::validatePage()
1248 {
1249   return true;
1250 }
1251
1252 int 
1253 BL::ConclusionPage::nextId() const
1254 {
1255   return -1;
1256 }
1257
1258 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1259 : QWizardPage(parent)
1260 {
1261   _salome_services = salome_services;
1262   setTitle("Select a Resource");
1263
1264   QLabel * main_label = new QLabel("In this step you select the resource of your job");
1265   main_label->setWordWrap(true);
1266
1267   // input_Resource
1268   QGroupBox * resource_group_box = new QGroupBox("Resource List");
1269   _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1270   connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1271
1272   QVBoxLayout * resource_list_layout = new QVBoxLayout();
1273   resource_list_layout->addWidget(_resource_list);
1274   resource_group_box->setLayout(resource_list_layout);
1275
1276   QLabel * resource_label = new QLabel("Resource selected: ");
1277   _resource_choosed = new QLineEdit();
1278   _resource_choosed->setText("");
1279   _resource_choosed->setReadOnly(true);
1280   registerField("resource_choosed", _resource_choosed);
1281
1282   QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1283   QLineEdit * _bqLineEdit = new QLineEdit(this);
1284   registerField("batch_queue", _bqLineEdit);
1285
1286   QLabel * bpLabel = new QLabel("Batch Partition (could be optional):");
1287   QLineEdit * _bpLineEdit = new QLineEdit(this);
1288   registerField("batch_partition", _bpLineEdit);
1289
1290   _ll_label = new QLabel("LoadLeveler JobType:", this);
1291   _ll_value = new QLineEdit(this);
1292   registerField("ll_jobtype", _ll_value);
1293   _ll_label->hide();
1294   _ll_value->hide();
1295
1296   _main_layout = new QGridLayout;
1297   _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1298   _main_layout->addWidget(resource_label, 1, 0);
1299   _main_layout->addWidget(_resource_choosed, 1, 1);
1300   _main_layout->addWidget(bqLabel, 2, 0);
1301   _main_layout->addWidget(_bqLineEdit, 2, 1);
1302   _main_layout->addWidget(bpLabel, 3, 0);
1303   _main_layout->addWidget(_bpLineEdit, 3, 1);
1304   setLayout(_main_layout);
1305
1306 };
1307
1308 BL::ResourcePage::~ResourcePage()
1309 {}
1310
1311 void
1312 BL::ResourcePage::initializePage()
1313 {
1314   if (field("ll_jobtype").toString() != "")
1315   {
1316     _main_layout->addWidget(_ll_label, 3, 0);
1317     _main_layout->addWidget(_ll_value, 3, 1);
1318     _ll_label->show();
1319     _ll_value->show();
1320   }
1321
1322   // Initialize resource_choosed with first resource in resource list
1323   if (field("resource_choosed").toString() == "")
1324   {
1325     std::list<std::string> resource_list = _salome_services->getResourceList(true);
1326     std::list<std::string>::iterator it = resource_list.begin();
1327     if (it != resource_list.end())
1328     {
1329       QString first_resource((*it).c_str());
1330       setField("resource_choosed", first_resource);
1331     }
1332   }
1333 }
1334
1335 bool
1336 BL::ResourcePage::validatePage()
1337 {
1338   QString resource_choosed = field("resource_choosed").toString();
1339   if (resource_choosed == "")
1340   {
1341     QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1342     return false;
1343   }
1344
1345   BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1346   std::string batch = resource_descr.batch.c_str();
1347   if (batch == "ll")
1348   {
1349     QString ll_jobtype = field("ll_jobtype").toString();
1350     if (ll_jobtype == "")
1351     {
1352       QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1353       return false;
1354     }
1355   }
1356   return true;
1357 }
1358
1359 void 
1360 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1361 {
1362   _resource_choosed->setReadOnly(false);
1363   _resource_choosed->setText(item->text());
1364   _resource_choosed->setReadOnly(true);
1365
1366   //Specific parameters for LoadLeveler
1367   BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData());
1368   std::string batch = resource_descr.batch.c_str();
1369   if (batch == "ll")
1370   {
1371     _main_layout->addWidget(_ll_label, 3, 0);
1372     _main_layout->addWidget(_ll_value, 3, 1);
1373     _ll_label->show();
1374     _ll_value->show();
1375   }
1376   else
1377   {
1378     _main_layout->removeWidget(_ll_value);
1379     _main_layout->removeWidget(_ll_label);
1380     _ll_label->hide();
1381     _ll_value->hide();
1382   }
1383 }
1384
1385 int 
1386 BL::ResourcePage::nextId() const
1387 {
1388   BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData());
1389   std::string batch = resource_descr.batch.c_str();
1390   if (batch == "coorm")
1391   {
1392           return BL::CreateJobWizard::Page_COORM_BatchParameters;
1393   }
1394   else
1395   {
1396           return BL::CreateJobWizard::Page_BatchParameters;
1397   }
1398 }
1399
1400 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1401 : QWizardPage(parent)
1402 {
1403   setTitle("Define a Python script in SALOME job");
1404   QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1405   label->setWordWrap(true);
1406
1407   // PythonSalome
1408   QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1409   connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1410   _line_PythonSalome = new QLineEdit(this);
1411   registerField("PythonSalome", _line_PythonSalome);
1412   _line_PythonSalome->setReadOnly(true);
1413
1414   QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1415   connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1416   _line_env_file = new QLineEdit(this);
1417   registerField("env_PythonSalome_file", _line_env_file);
1418   _line_env_file->setReadOnly(true);
1419
1420   QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script"));
1421   connect(command_pre_command_button, SIGNAL(clicked()),
1422           this, SLOT(choose_pre_command_file()));
1423   _line_pre_command = new QLineEdit(this);
1424   registerField("pre_PythonSalome_file", _line_pre_command);
1425   _line_pre_command->setReadOnly(true);
1426
1427   QGridLayout *layout = new QGridLayout;
1428   layout->addWidget(PythonSalome_file_button, 0, 0);
1429   layout->addWidget(_line_PythonSalome, 0, 1);
1430   layout->addWidget(PythonSalome_env_file_button, 1, 0);
1431   layout->addWidget(_line_env_file, 1, 1);
1432   layout->addWidget(command_pre_command_button, 2, 0);
1433   layout->addWidget(_line_pre_command, 2, 1);
1434
1435   QVBoxLayout * main_layout = new QVBoxLayout;
1436   main_layout->addWidget(label);
1437   main_layout->insertLayout(-1, layout);
1438   setLayout(main_layout);
1439 };
1440
1441 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1442 {}
1443
1444 void
1445 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1446 {
1447   QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1448                                                       tr("Open Python script file"), "",
1449                                                       tr("py (*.py);;All Files (*)"));
1450   _line_PythonSalome->setReadOnly(false);
1451   _line_PythonSalome->setText(PythonSalome_file);
1452   _line_PythonSalome->setReadOnly(true);
1453 }
1454
1455 void
1456 BL::PythonSalomeMainPage::choose_env_file()
1457 {
1458   QString env_file = QFileDialog::getOpenFileName(this,
1459                                                       tr("Open environnement file"), "",
1460                                                       tr("sh (*.sh);;All Files (*)"));
1461   _line_env_file->setReadOnly(false);
1462   _line_env_file->setText(env_file);
1463   _line_env_file->setReadOnly(true);
1464 }
1465
1466 void
1467 BL::PythonSalomeMainPage::choose_pre_command_file()
1468 {
1469   QString pre_command_file = QFileDialog::getOpenFileName(this,
1470                                                     tr("Open script file"), "",
1471                                                     tr("All Files (*)"));
1472   _line_pre_command->setReadOnly(false);
1473   _line_pre_command->setText(pre_command_file);
1474   _line_pre_command->setReadOnly(true);
1475 }
1476
1477 bool
1478 BL::PythonSalomeMainPage::validatePage()
1479 {
1480   QString PythonSalome = field("PythonSalome").toString();
1481   if (PythonSalome == "")
1482   {
1483     QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1484     return false;
1485   }
1486
1487   return true;
1488 }
1489
1490 int 
1491 BL::PythonSalomeMainPage::nextId() const
1492 {
1493   return BL::CreateJobWizard::Page_Resource;
1494 }
1495
1496
1497
1498 AdvancedParametersPage::AdvancedParametersPage(CreateJobWizard * parent)
1499 : QWizardPage(parent),
1500   ui(new Ui::AdvancedParametersWizardPage)
1501 {
1502   ui->setupUi(this);
1503   registerField("wckey", ui->line_wckey);
1504   registerField("extra_params", ui->text_extra_params, "plainText", "textChanged()");
1505 };
1506
1507 AdvancedParametersPage::~AdvancedParametersPage()
1508 {
1509   delete ui;
1510 }
1511
1512 int
1513 AdvancedParametersPage::nextId() const
1514 {
1515   return BL::CreateJobWizard::Page_Conclusion;
1516 }