2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiDataBindingContext.h
20 * @brief This is the header file for the %DataBindingContext class.
22 * This header file contains the declarations of the %DataBindingContext class.
25 #ifndef _FUI_DATA_BINDING_CONTEXT_H_
26 #define _FUI_DATA_BINDING_CONTEXT_H_
28 #include <FBaseTypes.h>
29 #include <FBaseObject.h>
30 #include <FUiDataBindingTypes.h>
31 #include <FUiIDataBindingListener.h>
32 #include <FUiIDataBindingDataValidator.h>
33 #include <FUiIDataBindingDataTransformer.h>
35 namespace Tizen { namespace Base
40 namespace Tizen { namespace Ui
44 class _DataBindingContextImpl;
47 * @class DataBindingContext
48 * @brief This class represents a data binding context and the application's data source.
52 * The %DataBindingContext class represents the data binding context.
54 * The following example demonstrates how to use the %DataBindingContext class.
57 // Sample code for DataBindingSample.h
61 class DataBindingSample
62 : public Tizen::Ui::Controls::Form
63 , public Tizen::Ui::IActionEventListener
66 virtual bool Initialize(void);
67 virtual result OnInitializing(void);
68 virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
71 static const int ID_BUTTON_UNBIND = 402;
72 static const int ID_BUTTON_UPDATE_BINDING = 403;
73 static const int ID_BUTTON_BIND = 404;
75 Tizen::Base::Integer __bindIntegerToButtonText;
76 Tizen::Ui::Controls::Button* __pUnbindButton;
77 Tizen::Ui::Controls::Button* __pUpdateBindingButton;
78 Tizen::Ui::Controls::Button* __pTargetButton;
79 Tizen::Ui::Controls::Button* __pBindButton;
86 // Sample code for DataBindingSample.cpp
87 #include "DataBindingSample.h"
89 using namespace Tizen::App;
90 using namespace Tizen::Graphics;
91 using namespace Tizen::Ui;
92 using namespace Tizen::Ui::Controls;
95 DataBindingSample::Initialize(void)
97 Construct(FORM_STYLE_NORMAL| FORM_STYLE_PORTRAIT_INDICATOR| FORM_STYLE_HEADER| FORM_STYLE_FOOTER);
102 DataBindingSample::OnInitializing(void)
104 result r = E_SUCCESS;
106 Header* pHeader = GetHeader();
107 pHeader->SetTitleText(L"DataBinding");
110 rect = GetClientAreaBounds();
112 __pUpdateBindingButton = new (std::nothrow) Button();
113 __pUpdateBindingButton->Construct(Rectangle(10, rect.height / 6, rect.width - 20, rect.height / 6), L"BindingTarget");
114 __pUpdateBindingButton->SetName("Target");
115 AddControl(__pUpdateBindingButton);
117 __pTargetButton = new (std::nothrow) Button();
118 __pTargetButton->Construct(Rectangle(10, (rect.height / 3) + 10 , (rect.width - 20), rect.height / 6), L"Update Binding");
119 __pTargetButton->SetActionId(ID_BUTTON_UPDATE_BINDING);
120 __pTargetButton->AddActionEventListener(*this);
121 AddControl(__pTargetButton);
123 __pUnbindButton = new (std::nothrow) Button();
124 __pUnbindButton->Construct(Rectangle(10, (rect.height * 2 / 3), (rect.width / 2) - 10, rect.height / 6), L"Unbind");
125 __pUnbindButton->SetActionId(ID_BUTTON_UNBIND);
126 __pUnbindButton->AddActionEventListener(*this);
127 AddControl(__pUnbindButton);
129 __pBindButton = new (std::nothrow) Button();
130 __pBindButton->Construct(Rectangle((rect.width / 2) + 10 , (rect.height * 2 / 3), (rect.width / 2) - 20 , rect.height / 6), L"Bind");
131 __pBindButton->SetActionId(ID_BUTTON_BIND);
132 __pBindButton->AddActionEventListener(*this);
133 AddControl(__pBindButton);
135 DataBindingContext* pContext = GetDataBindingContextN();
136 r = pContext->Bind(L"bindingcount", L"Target", L"text", __bindIntegerToButtonText, DATA_BINDING_DATA_TYPE_INTEGER, DATA_BINDING_FLOW_ONE_WAY, DATA_BINDING_TRIGGER_EXPLICIT, null, null, null);
143 DataBindingSample::OnActionPerformed(const Control& source, int actionId)
145 DataBindingContext* pContext = GetDataBindingContextN();
146 result r = E_SUCCESS;
149 case ID_BUTTON_UNBIND:
151 pContext->Unbind(L"bindingcount");
156 pContext->Bind(L"bindingcount", L"Target", L"text", __bindIntegerToButtonText, DATA_BINDING_DATA_TYPE_INTEGER, DATA_BINDING_FLOW_ONE_WAY, DATA_BINDING_TRIGGER_EXPLICIT, null, null, null);
159 case ID_BUTTON_UPDATE_BINDING:
161 r = pContext->UpdateBinding(L"bindingcount", DATA_BINDING_DESTINATION_TYPE_TARGET);
164 __bindIntegerToButtonText = __bindIntegerToButtonText.ToInt() + 1;
177 class _OSP_EXPORT_ DataBindingContext
178 : public Tizen::Base::Object
182 * This is the destructor for this class.
186 virtual ~DataBindingContext(void);
190 * Gets the owner of this data binding context.
194 * @return The context owner
196 Control* GetContextOwner(void) const;
199 * Binds the specified control's property and data source.
203 * @return An error code
204 * @param[in] bindingId The binding ID
205 * @param[in] controlName The name of target property owner
206 * @param[in] propertyName The target property name
207 * @param[in] dataSource The data binding source
208 * @param[in] sourceType The data type of the @c dataSource
209 * @param[in] flow The data flow type
210 * @param[in] trigger The data binding trigger type
211 * @param[in] pListener The data binding listener
212 * @param[in] pValidator The data validator
213 * @param[in] pTransformer The data transformer
214 * @exception E_SUCCESS The method is successful.
215 * @exception E_SYSTEM A system error has occurred.
216 * @exception E_INVALID_ARG 1. sourceType is not of a supported type.
217 2. flow is not of a supported type.
218 3. trigger is not of a supported type.
219 * @exception E_OBJ_NOT_FOUND 1. The control named controlName does not exist.
220 2. The parameter "propertyName" is not found in control properties.
221 * @exception E_UNSUPPORTED_FORMAT The given transformer does not supported changing source type to target type.
222 * @exception E_UNSUPPORTED_OPERATION In this system, binding with the given trigger and flow is not supported.
223 * @remarks The propertyName parameter is defined in "UI Builder Guide". @n
224 * There is no duplication check for each binding ID. @n
225 * Please use a unique binding ID for each binding setting.
227 result Bind(const Tizen::Base::String& bindingId, const Tizen::Base::String& controlName, const Tizen::Base::String& propertyName, Tizen::Base::Object& dataSource, DataBindingDataType sourceType, DataBindingFlow flow, DataBindingTrigger trigger, const IDataBindingListener* pListener, const IDataBindingDataValidator* pValidator, const IDataBindingDataTransformer* pTransformer = null);
230 * Sets the binding listener for the specified data binding.
234 * @return An error code
235 * @param[in] bindingId The binding ID
236 * @param[in] pListener The data binding listener
237 * @exception E_SUCCESS The method is successful.
238 * @exception E_SYSTEM A system error has occurred.
239 * @exception E_OBJ_NOT_FOUND The given binding ID is not registered.
240 * @exception E_INVALID_ARG The given listener is not valid.
241 * @remarks If you give pListener parameter as 'null', the existing dataBindingEventListener will be removed.
243 result SetDataBindingEventListener(const Tizen::Base::String& bindingId, IDataBindingListener* pListener);
246 * Unbinds all bindings that exist in this context.
250 * @return An error code
251 * @exception E_SUCCESS The method is successful.
252 * @exception E_SYSTEM A system error has occurred.
254 result UnbindAll(void);
257 * Unbinds a binding that exists in this context.
261 * @return An error code
262 * @param[in] bindingId The binding ID
263 * @exception E_SUCCESS The method is successful.
264 * @exception E_SYSTEM A system error has occurred.
265 * @exception E_OBJ_NOT_FOUND The given binding ID is not registered.
267 result Unbind(const Tizen::Base::String& bindingId);
270 * Updates all 'explicit' data bindings.
274 * @return An error code
275 * @param[in] destType The destination type
276 * @exception E_SUCCESS The method is successful.
277 * @exception E_SYSTEM A system error has occurred.
278 * @exception E_INVALID_ARG The specified @c destType is not of a supported type.
280 * - If you have set a data binding listener, @n
281 * this method is returned after that listener is called.
282 * - The behavior of this method is dependent on the system default locale setting.
283 * @see IDataBindingListener
285 result UpdateAllBindings(DataBindingDestinationType destType);
288 * Updates the specified data binding.
292 * @param[in] bindingId The binding ID
293 * @param[in] destType The destination type
294 * @exception E_SUCCESS The method is successful.
295 * @exception E_SYSTEM A system error has occurred.
296 * @exception E_OBJ_NOT_FOUND The given binding ID is not registered.
297 * @exception E_INVALID_OPERATION The given binding's trigger is not 'explicit' type.
298 * @exception E_INVALID_ARG The specified @c destType is not supported in binding ID.
300 * - If you have set a data binding listener, @n
301 * this method is returned after that listener is called.
302 * - The behavior of this method is dependent on the system default locale setting.
303 * @see IDataBindingListener
305 result UpdateBinding(const Tizen::Base::String& bindingId, DataBindingDestinationType destType);
309 // This default constructor is intentionally declared as private so that only the platform can create an instance.
311 DataBindingContext(void);
314 // This destructor is intentionally declared as private so that only the platform can delete an instance.
316 DataBindingContext(const Control& contextOwner);
319 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
321 DataBindingContext(const DataBindingContext& rhs);
324 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
326 DataBindingContext& operator =(const DataBindingContext& rhs);
329 _DataBindingContextImpl* __pDataBindingContextImpl;
331 friend class _DataBindingContextImpl;
333 }; // DataBindingContext
336 #endif // _FUI_DATA_BINDING_CONTEXT_H_