Wt examples  3.3.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
TreeViewDragDrop Class Reference

Main application class. More...

Inheritance diagram for TreeViewDragDrop:
Inheritance graph
[legend]

Public Member Functions

 TreeViewDragDrop (const WEnvironment &env)
 Constructor. More...
 
virtual ~TreeViewDragDrop ()
 
- Public Member Functions inherited from Wt::WApplication
 WApplication (const WEnvironment &environment)
 
 ~WApplication ()
 
const WEnvironmentenvironment () const
 
WContainerWidgetroot () const
 
WWidgetfindWidget (const std::string &name)
 
void setTitle (const WString &title)
 
const WStringtitle () const
 
const WStringcloseMessage () const
 
WLocalizedStringslocalizedStrings ()
 
void setLocalizedStrings (WLocalizedStrings *stringResolver)
 
WMessageResourceBundlemessageResourceBundle ()
 
void setLocale (const WLocale &locale)
 
const WLocalelocale () const
 
virtual void refresh ()
 
void bindWidget (WWidget *widget, const std::string &domId)
 
std::string docRoot () const
 
std::string sessionId () const
 
void changeSessionId ()
 
void processEvents ()
 
void setAjaxMethod (AjaxMethod method)
 
AjaxMethod ajaxMethod () const
 
virtual void initialize ()
 
virtual void finalize ()
 
void setTwoPhaseRenderingThreshold (int size)
 
void setCookie (const std::string &name, const std::string &value, int maxAge, const std::string &domain="", const std::string &path="", bool secure=false)
 
void removeCookie (const std::string &name, const std::string &domain="", const std::string &path="")
 
void addMetaLink (const std::string &href, const std::string &rel, const std::string &media, const std::string &hreflang, const std::string &type, const std::string &sizes, bool disabled)
 
void removeMetaLink (const std::string &href)
 
void addMetaHeader (const std::string &name, const WString &content, const std::string &lang="")
 
void addMetaHeader (MetaHeaderType type, const std::string &name, const WString &content, const std::string &lang="")
 
void removeMetaHeader (MetaHeaderType type, const std::string &name="")
 
WLogEntry log (const std::string &type) const
 
void setLoadingIndicator (WLoadingIndicator *indicator)
 
WLoadingIndicatorloadingIndicator () const
 
void quit ()
 
bool isQuited () const
 
bool hasQuit () const
 
::int64_t maximumRequestSize () const
 
Signal< ::int64_t > & requestTooLarge ()
 
void setConfirmCloseMessage (const WString &message)
 
void deferRendering ()
 
void resumeRendering ()
 
boost::function< void()> bind (const F &f)
 
std::string encodeUntrustedUrl (const std::string &url) const
 
void pushExposedConstraint (WWidget *w)
 
WCssStyleSheetstyleSheet ()
 
void useStyleSheet (const WLink &link, const std::string &media="all")
 
void useStyleSheet (const WLink &link, const std::string &condition, const std::string &media)
 
void useStyleSheet (const WCssStyleSheet &styleSheet, const std::string &condition="")
 
void setTheme (const WTheme *theme)
 
const WThemetheme () const
 
void setCssTheme (const std::string &name)
 
void setLayoutDirection (LayoutDirection direction)
 
LayoutDirection layoutDirection () const
 
void setBodyClass (const std::string &styleClass)
 
std::string bodyClass () const
 
void setHtmlClass (const std::string &styleClass)
 
std::string htmlClass () const
 
std::string url (const std::string &internalPath=std::string()) const
 
virtual std::string makeAbsoluteUrl (const std::string &url) const
 
std::string resolveRelativeUrl (const std::string &url) const
 
std::string bookmarkUrl () const
 
std::string bookmarkUrl (const std::string &internalPath) const
 
void setInternalPath (const std::string &path, bool emitChange=false)
 
void setInternalPathDefaultValid (bool valid)
 
bool internalPathDefaultValid () const
 
void setInternalPathValid (bool valid)
 
bool internalPathValid () const
 
std::string internalPath () const
 
std::string internalPathNextPart (const std::string &path) const
 
std::string internalSubPath (const std::string &path) const
 
bool internalPathMatches (const std::string &path) const
 
Signal< std::string > & internalPathChanged ()
 
Signal< std::string > & internalPathInvalid ()
 
void redirect (const std::string &url)
 
void enableUpdates (bool enabled=true)
 
bool updatesEnabled () const
 
void triggerUpdate ()
 
UpdateLock getUpdateLock ()
 
void attachThread (bool attach=true)
 
void doJavaScript (const std::string &javascript, bool afterLoaded=true)
 
void addAutoJavaScript (const std::string &javascript)
 
void declareJavaScriptFunction (const std::string &name, const std::string &function)
 
bool require (const std::string &url, const std::string &symbol=std::string())
 
bool requireJQuery (const std::string &url)
 
bool customJQuery () const
 
void setJavaScriptClass (const std::string &className)
 
std::string javaScriptClass ()
 
EventSignal< WKeyEvent > & globalKeyWentDown ()
 
EventSignal< WKeyEvent > & globalKeyPressed ()
 
EventSignal< WKeyEvent > & globalKeyWentUp ()
 
EventSignalglobalEnterPressed ()
 
EventSignalglobalEscapePressed ()
 

Private Member Functions

void createUI ()
 Setup the user interface. More...
 
WTextcreateTitle (const WString &title)
 Creates a title widget. More...
 
WTreeViewfolderView ()
 Creates the folder WTreeView. More...
 
WTableViewfileView ()
 Creates the file table view (a WTableView) More...
 
void editFile (const WModelIndex &item)
 Edit a particular row. More...
 
WWidgetpieChart ()
 Creates the chart. More...
 
WWidgetaboutDisplay ()
 Creates the hints text. More...
 
void folderChanged ()
 Change the filter on the file view when the selected folder changes. More...
 
void showPopup (const WModelIndex &item, const WMouseEvent &event)
 Show a popup for a folder item. More...
 
void popupAction ()
 Process the result of the popup menu. More...
 
void dialogDone ()
 Process the result of the message box. More...
 
void populateFiles ()
 Populate the files model. More...
 
void convertToDate (WStandardItem *item)
 Convert a string to a date. More...
 
void populateFolders ()
 Populate the folders model. More...
 
WStandardItemcreateFolderItem (const WString &location, const std::string &folderId=std::string())
 Create a folder item. More...
 

Private Attributes

WStandardItemModelfolderModel_
 The folder model (used by folderView_) More...
 
WStandardItemModelfileModel_
 The file model (used by fileView_) More...
 
WSortFilterProxyModelfileFilterModel_
 The sort filter proxy model that adapts fileModel_. More...
 
std::map< std::string, WStringfolderNameMap_
 Maps folder id's to folder descriptions. More...
 
WTreeViewfolderView_
 The folder view. More...
 
WTableViewfileView_
 The file view. More...
 
WPopupMenupopup_
 Popup menu on the folder view. More...
 
WMessageBoxpopupActionBox_
 Message box to confirm the poup menu action. More...
 

Additional Inherited Members

- Public Types inherited from Wt::WApplication
enum  AjaxMethod
 
typedef Wt::ApplicationCreator ApplicationCreator
 
typedef boost::function
< WApplication *(const
WEnvironment &)> 
ApplicationCreator
 
- Static Public Member Functions inherited from Wt::WApplication
static WApplicationinstance ()
 
static std::string resourcesUrl ()
 
static std::string relativeResourcesUrl ()
 
static std::string appRoot ()
 
static bool readConfigurationProperty (const std::string &name, std::string &value)
 
- Public Attributes inherited from Wt::WApplication
 XMLHttpRequest
 
 DynamicScriptTag
 
- Protected Member Functions inherited from Wt::WApplication
virtual void notify (const WEvent &e)
 
virtual bool isExposed (WWidget *w) const
 
virtual void enableAjax ()
 
virtual void unload ()
 

Detailed Description

Main application class.

Definition at line 237 of file TreeViewDragDrop.C.

Constructor & Destructor Documentation

TreeViewDragDrop::TreeViewDragDrop ( const WEnvironment env)
inline

Constructor.

Definition at line 242 of file TreeViewDragDrop.C.

243  : WApplication(env),
244  popup_(0),
245  popupActionBox_(0)
246  {
247  setCssTheme("polished");
248 
249  /*
250  * Create the data models.
251  */
252  folderModel_ = new WStandardItemModel(0, 1, this);
253  populateFolders();
254 
255  fileModel_ = new FileModel(this);
256  populateFiles();
257 
258  /*
259  The header items are also endered using an ItemDelegate, and thus
260  support other data, e.g.:
261 
262  fileModel_->setHeaderFlags(0, Horizontal, HeaderIsUserCheckable);
263  fileModel_->setHeaderData(0, Horizontal,
264  std::string("icons/file.gif"),
265  Wt::DecorationRole);
266  */
272 
273  /*
274  * Setup the user interface.
275  */
276  createUI();
277  }
virtual TreeViewDragDrop::~TreeViewDragDrop ( )
inlinevirtual

Definition at line 279 of file TreeViewDragDrop.C.

279  {
280  delete popup_;
281  delete popupActionBox_;
282  }

Member Function Documentation

WWidget* TreeViewDragDrop::aboutDisplay ( )
inlineprivate

Creates the hints text.

Definition at line 457 of file TreeViewDragDrop.C.

457  {
458  WText *result = new WText(WString::tr("about-text"));
459  result->setStyleClass("about");
460  return result;
461  }
void TreeViewDragDrop::convertToDate ( WStandardItem item)
inlineprivate

Convert a string to a date.

Definition at line 587 of file TreeViewDragDrop.C.

587  {
588  WDate d = WDate::fromString(item->text(), FileModel::dateEditFormat);
589  item->setData(boost::any(d), DisplayRole);
590  }
WStandardItem* TreeViewDragDrop::createFolderItem ( const WString location,
const std::string &  folderId = std::string() 
)
inlineprivate

Create a folder item.

Configures flags for drag and drop support.

Definition at line 624 of file TreeViewDragDrop.C.

626  {
627  WStandardItem *result = new WStandardItem(location);
628 
629  if (!folderId.empty()) {
630  result->setData(boost::any(folderId));
631  result->setFlags(result->flags() | ItemIsDropEnabled);
632  folderNameMap_[folderId] = location;
633  } else
634  result->setFlags(result->flags().clear(ItemIsSelectable));
635 
636  result->setIcon("icons/folder.gif");
637 
638  return result;
639  }
WText* TreeViewDragDrop::createTitle ( const WString title)
inlineprivate

Creates a title widget.

Definition at line 347 of file TreeViewDragDrop.C.

347  {
348  WText *result = new WText(title);
349  result->setInline(false);
350  result->setStyleClass("title");
351 
352  return result;
353  }
void TreeViewDragDrop::createUI ( )
inlineprivate

Setup the user interface.

Definition at line 311 of file TreeViewDragDrop.C.

311  {
312  WContainerWidget *w = root();
313  w->setStyleClass("maindiv");
314 
315  /*
316  * The main layout is a 3x2 grid layout.
317  */
318  WGridLayout *layout = new WGridLayout();
319  layout->addWidget(createTitle("Folders"), 0, 0);
320  layout->addWidget(createTitle("Files"), 0, 1);
321  layout->addWidget(folderView(), 1, 0);
322  layout->setColumnResizable(0);
323 
324  // select the first folder
326 
327  WVBoxLayout *vbox = new WVBoxLayout();
328  vbox->addWidget(fileView(), 1);
329  vbox->addWidget(pieChart(), 1);
330  vbox->setResizable(0);
331 
332  layout->addLayout(vbox, 1, 1);
333 
334  layout->addWidget(aboutDisplay(), 2, 0, 1, 2);
335 
336  /*
337  * Let row 1 and column 1 take the excess space.
338  */
339  layout->setRowStretch(1, 1);
340  layout->setColumnStretch(1, 1);
341 
342  w->setLayout(layout);
343  }
void TreeViewDragDrop::dialogDone ( )
inlineprivate

Process the result of the message box.

Definition at line 548 of file TreeViewDragDrop.C.

548  {
549  delete popupActionBox_;
550  popupActionBox_ = 0;
551  }
void TreeViewDragDrop::editFile ( const WModelIndex item)
inlineprivate

Edit a particular row.

Definition at line 422 of file TreeViewDragDrop.C.

422  {
423  new FileEditDialog(fileView_->model(), item);
424  }
WTableView* TreeViewDragDrop::fileView ( )
inlineprivate

Creates the file table view (a WTableView)

Definition at line 386 of file TreeViewDragDrop.C.

386  {
387  WTableView *tableView = new WTableView();
388 
389  tableView->setAlternatingRowColors(true);
390 
391  tableView->setModel(fileFilterModel_);
392  tableView->setSelectionMode(ExtendedSelection);
393  tableView->setDragEnabled(true);
394 
395  tableView->setColumnWidth(0, 100);
396  tableView->setColumnWidth(1, 150);
397  tableView->setColumnWidth(2, 100);
398  tableView->setColumnWidth(3, 60);
399  tableView->setColumnWidth(4, 100);
400  tableView->setColumnWidth(5, 100);
401 
402  WItemDelegate *delegate = new WItemDelegate(this);
404  tableView->setItemDelegateForColumn(4, delegate);
405  tableView->setItemDelegateForColumn(5, delegate);
406 
407  tableView->setColumnAlignment(3, AlignRight);
408  tableView->setColumnAlignment(4, AlignRight);
409  tableView->setColumnAlignment(5, AlignRight);
410 
411  tableView->sortByColumn(1, AscendingOrder);
412 
413  tableView->doubleClicked().connect(this, &TreeViewDragDrop::editFile);
414 
415  fileView_ = tableView;
416 
417  return tableView;
418  }
void TreeViewDragDrop::folderChanged ( )
inlineprivate

Change the filter on the file view when the selected folder changes.

Definition at line 466 of file TreeViewDragDrop.C.

466  {
467  if (folderView_->selectedIndexes().empty())
468  return;
469 
470  WModelIndex selected = *folderView_->selectedIndexes().begin();
471  boost::any d = selected.data(UserRole);
472  if (!d.empty()) {
473  std::string folder = boost::any_cast<std::string>(d);
474 
475  // For simplicity, we assume here that the folder-id does not
476  // contain special regexp characters, otherwise these need to be
477  // escaped -- or use the \Q \E qutoing escape regular expression
478  // syntax (and escape \E)
480  }
481  }
WTreeView* TreeViewDragDrop::folderView ( )
inlineprivate

Creates the folder WTreeView.

Definition at line 357 of file TreeViewDragDrop.C.

357  {
358  WTreeView *treeView = new FolderView();
359 
360  /*
361  * To support right-click, we need to disable the built-in browser
362  * context menu.
363  *
364  * Note that disabling the context menu and catching the
365  * right-click does not work reliably on all browsers.
366  */
367  treeView->setAttributeValue
368  ("oncontextmenu",
369  "event.cancelBubble = true; event.returnValue = false; return false;");
370  treeView->setModel(folderModel_);
371  treeView->resize(200, WLength::Auto);
372  treeView->setSelectionMode(SingleSelection);
373  treeView->expandToDepth(1);
374  treeView->selectionChanged()
376 
377  treeView->mouseWentUp().connect(this, &TreeViewDragDrop::showPopup);
378 
379  folderView_ = treeView;
380 
381  return treeView;
382  }
WWidget* TreeViewDragDrop::pieChart ( )
inlineprivate

Creates the chart.

Definition at line 428 of file TreeViewDragDrop.C.

428  {
429  using namespace Chart;
430 
431  WPieChart *chart = new WPieChart();
432  // chart->setPreferredMethod(WPaintedWidget::PngImage);
433  chart->setModel(fileFilterModel_);
434  chart->setTitle("File sizes");
435 
436  chart->setLabelsColumn(1); // Name
437  chart->setDataColumn(3); // Size
438 
439  chart->setPerspectiveEnabled(true, 0.2);
440  chart->setDisplayLabels(Outside | TextLabel);
441 
442  if (!WApplication::instance()->environment().ajax()) {
443  chart->resize(500, 200);
444  chart->setMargin(WLength::Auto, Left | Right);
446  w->addWidget(chart);
447  w->setStyleClass("about");
448  return w;
449  } else {
450  chart->setStyleClass("about");
451  return chart;
452  }
453  }
void TreeViewDragDrop::populateFiles ( )
inlineprivate

Populate the files model.

Data (and headers) is read from the CSV file data/files.csv. We add icons to the first column, resolve the folder id to the actual folder name, and configure item flags, and parse date values.

Definition at line 560 of file TreeViewDragDrop.C.

560  {
562 
563  std::ifstream f((appRoot() + "data/files.csv").c_str());
564 
565  if (!f)
566  throw std::runtime_error("Could not read: data/files.csv");
567 
569 
570  for (int i = 0; i < fileModel_->rowCount(); ++i) {
571  WStandardItem *item = fileModel_->item(i, 0);
572  item->setFlags(item->flags() | ItemIsDragEnabled);
573  item->setIcon("icons/file.gif");
574 
575  std::string folderId = item->text().toUTF8();
576 
577  item->setData(boost::any(folderId), UserRole);
578  item->setText(folderNameMap_[folderId]);
579 
580  convertToDate(fileModel_->item(i, 4));
581  convertToDate(fileModel_->item(i, 5));
582  }
583  }
void TreeViewDragDrop::populateFolders ( )
inlineprivate

Populate the folders model.

Definition at line 594 of file TreeViewDragDrop.C.

594  {
595  WStandardItem *level1, *level2;
596 
597  folderModel_->appendRow(level1 = createFolderItem("San Fransisco"));
598  level1->appendRow(level2 = createFolderItem("Investors", "sf-investors"));
599  level1->appendRow(level2 = createFolderItem("Fellows", "sf-fellows"));
600 
601  folderModel_->appendRow(level1 = createFolderItem("Sophia Antipolis"));
602  level1->appendRow(level2 = createFolderItem("R&D", "sa-r_d"));
603  level1->appendRow(level2 = createFolderItem("Services", "sa-services"));
604  level1->appendRow(level2 = createFolderItem("Support", "sa-support"));
605  level1->appendRow(level2 = createFolderItem("Billing", "sa-billing"));
606 
607  folderModel_->appendRow(level1 = createFolderItem("New York"));
608  level1->appendRow(level2 = createFolderItem("Marketing", "ny-marketing"));
609  level1->appendRow(level2 = createFolderItem("Sales", "ny-sales"));
610  level1->appendRow(level2 = createFolderItem("Advisors", "ny-advisors"));
611 
613  (WString::fromUTF8("Frankfürt")));
614  level1->appendRow(level2 = createFolderItem("Sales", "frank-sales"));
615 
616  folderModel_->setHeaderData(0, Horizontal,
617  boost::any(std::string("SandBox")));
618  }
void TreeViewDragDrop::popupAction ( )
inlineprivate

Process the result of the popup menu.

Definition at line 527 of file TreeViewDragDrop.C.

527  {
528  if (popup_->result()) {
529  /*
530  * You could also bind extra data to an item using setData() and
531  * check here for the action asked. For now, we just use the text.
532  */
533  WString text = popup_->result()->text();
534  popup_->hide();
535 
536  popupActionBox_ = new WMessageBox("Sorry.","Action '" + text
537  + "' is not implemented.", NoIcon, Ok);
539  .connect(this, &TreeViewDragDrop::dialogDone);
541  } else {
542  popup_->hide();
543  }
544  }
void TreeViewDragDrop::showPopup ( const WModelIndex item,
const WMouseEvent event 
)
inlineprivate

Show a popup for a folder item.

Definition at line 485 of file TreeViewDragDrop.C.

485  {
486  if (event.button() == WMouseEvent::RightButton) {
487  // Select the item, it was not yet selected.
488  if (!folderView_->isSelected(item))
489  folderView_->select(item);
490 
491  if (!popup_) {
492  popup_ = new WPopupMenu();
493  popup_->addItem("icons/folder_new.gif", "Create a New Folder");
494  popup_->addItem("Rename this Folder")->setCheckable(true);
495  popup_->addItem("Delete this Folder");
496  popup_->addSeparator();
497  popup_->addItem("Folder Details");
498  popup_->addSeparator();
499  popup_->addItem("Application Inventory");
500  popup_->addItem("Hardware Inventory");
501  popup_->addSeparator();
502 
503  WPopupMenu *subMenu = new WPopupMenu();
504  subMenu->addItem("Sub Item 1");
505  subMenu->addItem("Sub Item 2");
506  popup_->addMenu("File Deployments", subMenu);
507 
508  /*
509  * This is one method of executing a popup, which does not block a
510  * thread for a reentrant event loop, and thus scales.
511  *
512  * Alternatively you could call WPopupMenu::exec(), which returns
513  * the result, but while waiting for it, blocks the thread.
514  */
516  }
517 
518  if (popup_->isHidden())
519  popup_->popup(event);
520  else
521  popup_->hide();
522  }
523  }

Member Data Documentation

WSortFilterProxyModel* TreeViewDragDrop::fileFilterModel_
private

The sort filter proxy model that adapts fileModel_.

Definition at line 292 of file TreeViewDragDrop.C.

WStandardItemModel* TreeViewDragDrop::fileModel_
private

The file model (used by fileView_)

Definition at line 289 of file TreeViewDragDrop.C.

WTableView* TreeViewDragDrop::fileView_
private

The file view.

Definition at line 301 of file TreeViewDragDrop.C.

WStandardItemModel* TreeViewDragDrop::folderModel_
private

The folder model (used by folderView_)

Definition at line 286 of file TreeViewDragDrop.C.

std::map<std::string, WString> TreeViewDragDrop::folderNameMap_
private

Maps folder id's to folder descriptions.

Definition at line 295 of file TreeViewDragDrop.C.

WTreeView* TreeViewDragDrop::folderView_
private

The folder view.

Definition at line 298 of file TreeViewDragDrop.C.

WPopupMenu* TreeViewDragDrop::popup_
private

Popup menu on the folder view.

Definition at line 304 of file TreeViewDragDrop.C.

WMessageBox* TreeViewDragDrop::popupActionBox_
private

Message box to confirm the poup menu action.

Definition at line 307 of file TreeViewDragDrop.C.


The documentation for this class was generated from the following file:

Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1