fw4spl
src/fwGui/dialog/SelectorDialog.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwGui/dialog/SelectorDialog.hpp"
8 
9 #include <fwServices/registry/ActiveWorkers.hpp>
10 
11 namespace fwGui
12 {
13 namespace dialog
14 {
15 
16 //-----------------------------------------------------------------------------
17 
18 std::string SelectorDialog::showSelectorDialog(const std::string& title, const std::string& message,
19  std::vector< std::string > _selections)
20 {
21  ::fwGui::dialog::SelectorDialog selector(title, message, _selections);
22  return selector.show();
23 }
24 
25 //-----------------------------------------------------------------------------
26 
27 SelectorDialog::SelectorDialog(const std::string& title, const std::string& message,
28  std::vector< std::string > _selections)
29 {
30  create();
32  {
33  m_implementation->setTitle(title);
34  m_implementation->setMessage( message );
35  m_implementation->setSelections( _selections );
36  }).wait();
37 }
38 
39 //-----------------------------------------------------------------------------
40 
42 {
43  create();
44 }
45 
46 //------------------------------------------------------------------------------
47 
49 {
50  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >([&]
51  {
52  ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(ISelectorDialog::REGISTRY_KEY);
53  m_implementation = ::fwGui::dialog::ISelectorDialog::dynamicCast(guiObj);
54  })).wait();
55 }
56 
57 //-----------------------------------------------------------------------------
58 
59 void SelectorDialog::setTitle(std::string title)
60 {
61  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >( [&]
62  {
63  m_implementation->setTitle(title);
64  })).wait();
65 }
66 
67 //-----------------------------------------------------------------------------
68 
69 std::string SelectorDialog::show()
70 {
71  std::function< std::string() > f = std::bind(&ISelectorDialog::show, m_implementation);
72  std::shared_future< std::string > future =
73  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask< std::string >(f);
74  future.wait();
75  return future.get();
76 }
77 
78 //-----------------------------------------------------------------------------
79 
80 void SelectorDialog::setSelections(std::vector< std::string > _selections)
81 {
82  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >([&]
83  {
84  m_implementation->setSelections( _selections );
85  })).wait();
86 }
87 
88 //-----------------------------------------------------------------------------
89 
90 void SelectorDialog::setMessage(const std::string& msg)
91 {
92  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >([&]
93  {
94  m_implementation->setMessage( msg );
95  })).wait();
96 }
97 
98 //------------------------------------------------------------------------------
99 
100 void SelectorDialog::addCustomButton(const std::string& label, std::function<void()> clickedFn)
101 {
102 
103  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >([&]
104  {
105  m_implementation->addCustomButton( label, clickedFn );
106  })).wait();
107 }
108 
109 //-----------------------------------------------------------------------------
110 
111 } //namespace dialog
112 } //namespace fwGui
virtual FWGUI_API void setSelections(std::vector< std::string > _selections) override
Set the string list that can be chosen by the selector.
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
virtual FWGUI_API std::string show()=0
Show the selector and return the selection.
The namespace fwGui contains the base interface for IHM services.
Definition: SJobBar.hpp:23
static FWGUI_API const FactoryRegistryKeyType REGISTRY_KEY
this unique key should be used for all factory for specific Selector(qt,wx,...)
FWGUI_API void setTitle(std::string title) override
Sets the selector title.
SelectorDialog allows the choice of an element among several (_selections) Use the Delegate design pa...
FWGUI_API SelectorDialog()
will instanciate the concrete implementation
FWGUI_API std::string show() override
Show the selector and return the selection.
virtual FWGUI_API void addCustomButton(const std::string &label, std::function< void()> clickedFn) override
Add a custom button to this dialog.
FWGUI_API void create()
Called by the constructor in the GUI thread.
static FWGUI_API std::string showSelectorDialog(const std::string &title, const std::string &message, std::vector< std::string > _selections)
static FWSERVICES_API::fwThread::Worker::sptr getDefaultWorker()
Get the default registered worker.