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