/// <summary> /// Gets the property with the given relative binding path /// </summary> /// <param name="context">the context to extend</param> /// <param name="pathExpression">the binding path</param> /// <param name="absolutePath">true if the generated path should be absolute; false otherwise</param> /// <returns>the property value</returns> public static TValue getPropertyFor <TModel, TValue>(this sap.ui.model.Context <TModel> context, Expression <Func <TModel, TValue> > pathExpression, bool absolutePath = true) { string pref = absolutePath ? "/" : ""; string sPropertyName = $"{pref}{ExpressionEvaluator.GetPath(pathExpression)}"; return(context.getProperty <TValue>(sPropertyName)); }
/// <summary> /// Factory function for the notification items /// </summary> /// <param name="sId">sId The id for the item</param> /// <param name="oBindingContext">The binding context for the item</param> /// <returns>The new notification list item</returns> public sap.ui.core.Element _createNotification(string sId, sap.ui.model.Context oBindingContext) { Notification oBindingObject = oBindingContext.getObject <Notification>(); sap.m.NotificationListItem oNotificationItem = new sap.m.NotificationListItem(new sap.m.NotificationListItem.Settings() { title = oBindingObject.title, description = oBindingObject.description, priority = oBindingObject.priority, close = ([email protected] oEvent, object oData) => { var source = oEvent.getSource <sap.m.NotificationListItem>(); string sBindingPath = source.getCustomData()[0].getValue <string>(); string sIndex = sBindingPath.Split('/').Last(); List <Notification> aItems = source.getModelFor <AlertsModel>("alerts").getPropertyFor(p => p.alerts.notifications).ToList(); aItems.RemoveRange(Script.ParseInt(sIndex), 1); source.getModelFor <AlertsModel>("alerts").setPropertyFor(p => p.alerts.notifications, aItems.ToArray()); source.getModel <sap.ui.model.json.JSONModel>("alerts").updateBindings(true); sap.m.MessageToast.show("Notification has been deleted."); }, datetime = oBindingObject.date, authorPicture = oBindingObject.icon, press = ([email protected] oEvent, object oData) => { }, customData = new sap.ui.core.CustomData[] { new sap.ui.core.CustomData(new sap.ui.core.CustomData.Settings() { key = "path", value = oBindingContext.getPath() }) } }); return(oNotificationItem); }
public sap.ui.core.Element productListFactory(string sId, sap.ui.model.Context oContext) { sap.ui.core.Element oUIControl = null; // Decide based on the data which fragment to show if (oContext.getProperty <int>("UnitsInStock") == 0 && oContext.getProperty <bool>("Discontinued")) { // The item is discontinued, so use a StandardListItem if (this._oProductSimple == null) { this._oProductSimple = (sap.ui.core.Control)sap.ui.xmlfragment(sId, "sap.ui.demo.db.view.ProductSimple", this); } oUIControl = _oProductSimple.clone(); } else { // The item is available, so we will create an ObjectListItem if (this._oProductExtended == null) { this._oProductExtended = (sap.ui.core.Control)sap.ui.xmlfragment(sId, "sap.ui.demo.db.view.ProductExtended", this); } oUIControl = this._oProductExtended.clone(); // The item is temporarily out of stock, so we will add a status if (oContext.getProperty <int>("UnitsInStock") < 1) { oUIControl.As <sap.m.ObjectListItem>().addAttribute(new sap.m.ObjectAttribute(new sap.m.ObjectAttribute.Settings() { text = new [email protected]() { path = "i18n>outOfStock" } })); } } return(oUIControl); }
public sap.ui.core.Element _createError(string sId, sap.ui.model.Context oBindingContext) { Error oBindingObject = oBindingContext.getObject <Error>(); sap.m.Link oLink = new sap.m.Link(new sap.m.Link.Settings() { text = "More Details", press = ([email protected] oEvent, object oData) => { sap.m.MessageToast.show("More Details was pressed"); } }); sap.m.MessagePopoverItem oMessageItem = new sap.m.MessagePopoverItem(new sap.m.MessagePopoverItem.Settings() { title = oBindingObject.title, subtitle = oBindingObject.subTitle, description = oBindingObject.description, counter = oBindingObject.counter, link = oLink }); return(oMessageItem); }
/// <summary> /// Implement in inheriting classes /// </summary> /// <param name="model">the model to extend</param> /// <param name="pathExpression">the path to where to read the attribute value</param> /// <param name="oContext">the context with which the path should be resolved</param> /// <param name="absolutePath">true if the generated path should be absolute; false otherwise</param> /// <returns>Returns the value for the property with the given sPropertyName</returns> public static TValue getPropertyFor <TModel, TValue>(this sap.ui.model.json.JSONModel <TModel> model, Expression <Func <TModel, TValue> > pathExpression, sap.ui.model.Context oContext, bool absolutePath = true) { return(getPropertyForInternal(model, pathExpression, oContext, absolutePath)); }
private static TValue getOriginalPropertyForInternal <TModel, TValue>(this sap.ui.model.Model <TModel> model, Expression <Func <TModel, TValue> > pathExpression, sap.ui.model.Context oContext, bool absolutePath = true) { string pref = absolutePath ? "/" : ""; string sPropertyName = $"{pref}{ExpressionEvaluator.GetPath(pathExpression)}"; return(model.getOriginalProperty <TValue>(sPropertyName, oContext)); }
/// <summary> /// Sets a new value for the given property <code>sPropertyName</code> in the model. If the model value changed all interested parties are informed. /// </summary> /// <param name="model">the model to extend</param> /// <param name="pathExpression">path of the property to set</param> /// <param name="value">value to set the property to</param> /// <param name="oContext">the context which will be used to set the property</param> /// <param name="absolutePath">true if the generated path should be absolute; false otherwise</param> /// <returns>true if the value was set correctly and false if errors occurred like the entry was not found.</returns> public static bool setPropertyFor <TModel, TValue>(this sap.ui.model.Model <TModel> model, Expression <Func <TModel, TValue> > pathExpression, TValue value, sap.ui.model.Context oContext, bool absolutePath = true) { return(setPropertyForInternal(model, pathExpression, value, oContext, absolutePath)); }
private static bool setPropertyForInternal <TModel, TValue>(this sap.ui.model.Model <TModel> model, Expression <Func <TModel, TValue> > pathExpression, TValue value, sap.ui.model.Context oContext, bool bAsyncUpdate, bool absolutePath = true) { string pref = absolutePath ? "/" : ""; string sPropertyName = $"{pref}{ExpressionEvaluator.GetPath(pathExpression)}"; return(model.setProperty(sPropertyName, value, oContext, bAsyncUpdate)); }