2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "tfarmcontroller.h"
|
|
|
|
#include "application.h"
|
|
|
|
#include "dependedlist.h"
|
|
|
|
#include "submitpage.h"
|
|
|
|
|
|
|
|
#include "tw/message.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
DependedList::DependedList(TWidget *parent) : TWidget(parent) {
|
|
|
|
m_depList = new TTextList(this);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_add = new TButton(this, "Add");
|
|
|
|
tconnect<DependedList>(*(m_add), this, onAdd);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_remove = new TButton(this, "Remove");
|
|
|
|
tconnect<DependedList>(*(m_remove), this, onRemove);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedList::configureNotify(const TDimension &size) {
|
|
|
|
const int leftSize = size.lx / 3;
|
|
|
|
m_depList->setGeometry(0, 0, leftSize, size.ly - 1);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TDimension buttonSize(60, 15);
|
|
|
|
int x = leftSize + 30;
|
|
|
|
int y0 = size.ly - 10;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_add->setGeometry(x, y0 - buttonSize.ly, x + buttonSize.lx, y0);
|
|
|
|
y0 -= (buttonSize.ly + 10);
|
|
|
|
m_remove->setGeometry(x, y0 - buttonSize.ly, x + buttonSize.lx, y0);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedList::onRemove() {
|
|
|
|
if (!m_depList->getSelectedItem(0)) return;
|
|
|
|
|
|
|
|
int count = m_depList->getSelectedItemCount();
|
|
|
|
int i = 0;
|
|
|
|
for (; i < count; ++i) {
|
|
|
|
string id = m_depList->getSelectedItemId(i);
|
|
|
|
m_tasks.erase(m_tasks.find(id));
|
|
|
|
m_depList->removeItem(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_depList->invalidate();
|
|
|
|
|
|
|
|
SubmitPage *submitPage = dynamic_cast<SubmitPage *>(getParent());
|
|
|
|
if (submitPage) {
|
|
|
|
SubmitPageTask *task = submitPage->getTask();
|
|
|
|
if (task) task->setDependencies(m_tasks);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedList::clearAll() {
|
|
|
|
m_depList->clearAll();
|
|
|
|
m_tasks.erase(m_tasks.begin(), m_tasks.end());
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedList::onAdd() {
|
|
|
|
static DependedPopup *popup = 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!popup) {
|
|
|
|
popup = new DependedPopup(this);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
popup->setOkAction(
|
|
|
|
new TDependedPopupAction<DependedList>(this, &DependedList::AddItems));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!popup) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFarmController *controller = Application::instance()->getController();
|
|
|
|
vector<TaskShortInfo> tasks;
|
|
|
|
try {
|
|
|
|
controller->getTasks("", tasks);
|
|
|
|
} catch (TException &e) {
|
|
|
|
TMessage::error(toString(e.getMessage()));
|
|
|
|
return;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
popup->setList(tasks);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TDimension d = TMainshell::getMainshell()->getSize();
|
2016-03-19 06:57:51 +13:00
|
|
|
#ifdef WIN32
|
2016-06-15 18:43:10 +12:00
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
d.lx = GetDeviceCaps(hdc, HORZRES);
|
|
|
|
d.ly = GetDeviceCaps(hdc, VERTRES);
|
|
|
|
ReleaseDC(0, hdc);
|
2016-03-19 06:57:51 +13:00
|
|
|
#endif
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
d -= popup->getSize();
|
|
|
|
popup->popup(TPoint(d.lx / 2, d.ly / 2));
|
|
|
|
popup->setCaption("Tasks Submitted");
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedList::AddItems(const vector<string> &tasksId) {
|
|
|
|
TFarmController *controller = Application::instance()->getController();
|
|
|
|
vector<string>::const_iterator it = tasksId.begin();
|
|
|
|
for (; it != tasksId.end(); ++it)
|
|
|
|
if (m_tasks.end() == m_tasks.find(*it)) {
|
|
|
|
try {
|
|
|
|
string parentId, name;
|
|
|
|
TaskState status;
|
|
|
|
controller->queryTaskShortInfo(*it, parentId, name, status);
|
|
|
|
string label = "<" + *it + "> " + name;
|
|
|
|
m_depList->addItem(new TTextListItem(*it, label));
|
|
|
|
m_tasks.insert(make_pair(*it, label));
|
|
|
|
} catch (TException &e) {
|
|
|
|
TMessage::error(toString(e.getMessage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_depList->invalidate();
|
|
|
|
|
|
|
|
SubmitPage *submitPage = dynamic_cast<SubmitPage *>(getParent());
|
|
|
|
if (submitPage) {
|
|
|
|
SubmitPageTask *task = submitPage->getTask();
|
|
|
|
if (task) task->setDependencies(m_tasks);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedList::setList(const std::map<string, string> &tasks) {
|
|
|
|
m_depList->clearAll();
|
|
|
|
std::map<string, string>::const_iterator it = tasks.begin();
|
|
|
|
for (; it != tasks.end(); ++it)
|
|
|
|
m_depList->addItem(new TTextListItem((*it).first, (*it).second));
|
|
|
|
m_tasks = tasks;
|
|
|
|
invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
DependedPopup::DependedPopup(TWidget *parent)
|
2016-06-15 18:43:10 +12:00
|
|
|
: TModalPopup(parent, "DependedList"), m_okAction(0) {
|
|
|
|
m_submitList = new TTextList(this);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_ok = new TButton(this, "Ok");
|
|
|
|
tconnect<DependedPopup>(*(m_ok), this, onOk);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_cancel = new TButton(this, "Cancel");
|
|
|
|
tconnect<DependedPopup>(*(m_cancel), this, TPopup::close);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedPopup::configureNotify(const TDimension &size) {
|
|
|
|
const int bottomSize = 35;
|
|
|
|
m_submitList->setGeometry(0, bottomSize, size.lx - 1, size.ly - 1);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TDimension buttonSize(60, 15);
|
|
|
|
int x1 = 30;
|
|
|
|
int x2 = size.lx - x1;
|
|
|
|
int y0 = bottomSize - 10;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_ok->setGeometry(x1, y0 - buttonSize.ly, x1 + buttonSize.lx, y0);
|
|
|
|
m_cancel->setGeometry(x2 - buttonSize.lx, y0 - buttonSize.ly, x2, y0);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TDimension DependedPopup::getPreferredSize() const {
|
|
|
|
return TDimension(400, 300);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedPopup::onOk() {
|
|
|
|
assert(m_okAction);
|
|
|
|
vector<string> tasks;
|
|
|
|
if (m_submitList->getSelectedItem(0)) {
|
|
|
|
int count = m_submitList->getSelectedItemCount();
|
|
|
|
int i = 0;
|
|
|
|
for (; i < count; ++i) tasks.push_back(m_submitList->getSelectedItemId(i));
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
m_okAction->sendCommand(tasks);
|
|
|
|
close();
|
|
|
|
} catch (TException &e) {
|
|
|
|
TMessage::error(toString(e.getMessage()));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedPopup::setList(const vector<TaskShortInfo> &tasks) {
|
|
|
|
m_submitList->clearAll();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
vector<TaskShortInfo>::const_iterator it = tasks.begin();
|
|
|
|
for (; it != tasks.end(); ++it) {
|
|
|
|
string label = "<" + (*it).m_id + "> " + (*it).m_name;
|
|
|
|
m_submitList->addItem(new TTextListItem((*it).m_id, label));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DependedPopup::setOkAction(TGenericDependedPopupAction *action) {
|
|
|
|
m_okAction = action;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|