Created a PCF control, working fine in harnes tool. After integrating to D365 , updateview()not being called. Once I click the developertool then it is working. If am not opening developer tool OR REsize the browser window, then updateview is not being called even though data changed.
Onresetclick am calling notifychanged event , though it is not triggering the updateview
private onResetClick = (newValue: boolean, props: ToggleProps): void => {
if (newValue) {
//isReset true -> clicked set button, action to grey out toggle and change button name to set
if (!this.changeProps.isControlDisabledInForm) {
this._isChanged = true;
this.isReset = this.changeProps.isReset = newValue;
this.changeProps.buttonProperties.checkbox.disabled = true;
this.changeProps.buttonProperties.checkbox.checked = false;
this._selectedOptionID = null;
// this.theNotifyChanged();
}
} else {
if (!this.changeProps.isControlDisabledInForm) {
this._isChanged = true;
this.changeProps.buttonProperties.checkbox.disabled = false;
this.isReset = this.changeProps.isReset = newValue;
this._selectedOptionID
= this.changeProps.optionsetValues.nokey;
// this.theNotifyChanged();
}
}
if (this.theNotifyChanged) {
this.theNotifyChanged();
}
};
/**
* Called when any value in the property bag has changed. This includes field values, data-sets, global values such as container height and width, offline status, control metadata values such as label, visible, etc.
* #param context The entire property bag availabel to control via Context Object; It contains values as set up by the customizer mapped to names defined in the manifest, as well as utility functions
*/
public updateView(context: ComponentFramework.Context<IInputs>): void {
this._context = context;
this.changeProps.isControlDisabledInForm = context.mode.isControlDisabled;
this.changeProps.isVisible = context.mode.isVisible;
this._checkboxID = context.parameters.OptionSetAttribute.attributes?.LogicalName ?? uuidv4();
let selBoolean: boolean = false;
if (!this._isChanged) {
this._selectedOptionID = context.parameters.OptionSetAttribute.raw;
// this.SetButtonProperties(selBoolean);
}
else {
//if (this.changeProps.isReset) {
// // this.changeProps.buttonProperties.checkbox.disabled = true;
// // this.changeProps.buttonProperties.checkbox.checked = false;
//}
//else {
// // this.changeProps.buttonProperties.checkbox.disabled = false;
//}
selBoolean = this.isReset as boolean;//this.changeProps.buttonProperties.checkbox.checked;
}
if (this.optionSetArray) {
for (var i = 0; i < this.optionSetArray.length; i++) {
if (this.optionSetArray[i].Value == this._selectedOptionID) {
this.SelectedOptionSetLabel = this.optionSetArray[i].Label;
}
if (this.optionSetArray[i]?.Label.toUpperCase() === "YES") { //TODO : this needs to be generic not fixed with yes
this.changeProps.optionsetValues.yeskey = this.optionSetArray[i].Value;
} else {
this.changeProps.optionsetValues.nokey = this.optionSetArray[i].Value;
}
}
}
if (!this._isChanged) {
if (this.SelectedOptionSetLabel != null && this.SelectedOptionSetLabel != undefined) {
this.changeProps.buttonProperties.checkbox.checked = this.SelectedOptionSetLabel?.toUpperCase() === "YES" ? true as boolean : false as boolean;//TODO : this needs to be generic not fixed with yes
selBoolean = this.changeProps.isReset = this.isReset = true;
} else {
selBoolean = false;
this.changeProps.isReset = this.isReset = false;
}
}
this._messageContent = selBoolean ? this.changeProps.labels.trueLabel : this.changeProps.labels.falseLabel;
this.changeProps.buttonProperties = {
resetButton: { innerHTML: selBoolean ? "Reset" : "Set" },// when there is a value stored in attribute we need to show Reset
messageContent: this._messageContent,
checkbox: {
disabled: this.changeProps.isControlDisabledInForm ? true : (this.isReset ? false : true),
checked: this.changeProps.buttonProperties.checkbox.checked, checkboxID: this._checkboxID
}
};
console.log("inside ts");
ReactDOM.render(
React.createElement(ToggleButton, this.changeProps
), this.container);
}
Though the context got changed , scope goes to getOutput() method to check if there is any change in output then only PCF view get rerender. In my case, i didnot change the output value in getoutput() method so it was not working.
Here "_selectedOptionID" value should be changed then it started working.
public getOutputs(): IOutputs {
return {
OptionSetAttribute: this._selectedOptionID as number
};
}
Related
I am creating a list of scanned items. Whenever an item is scanned it checks if it already exists and if it does it increases the quantity, otherwise it will be added as a new item in the list.
When an item is added in the list the change is reflected correctly, however, when only the quantity is changed the value is not visually updated.
if(PurchaseUnloadData.scannedItems.Where(x => x.ItemID == item.ItemID).Count() > 0)
{
PurchaseUnloadData.scannedItems.FirstOrDefault(x => x.ItemID == item.ItemID).Quantity = PurchaseUnloadData.scannedItems.FirstOrDefault(x => x.ItemID == item.ItemID).Quantity + 1;
}
else
{
item.Quantity = 1;
PurchaseUnloadData.scannedItems.Add(item);
}
MessagingCenter.Send<ViewPurchaseUnloadingCart>(this, "ItemsChanged");
In addition when i scan an item twice, meaning the quantity gets to 2, if i add a new row the quantity value is updated! If there isn't a new row it just updates the data behind but not the list.
public class PurchaseUnloadingCartViewModel : ObservableObject
{
private NavigationCategoryData _category;
private PurchaseUnloadData.ScannedItemInfo _selectedItem;
public PurchaseUnloadingCartViewModel()
: base(listenCultureChanges: true)
{
LoadData();
ExportToExcelCommand = new Command(async () => await ExportDataToExcelAsync());
MessagingCenter.Subscribe<ViewPurchaseUnloadingCart>(this, "ItemsChanged", (sender) =>
{
LoadData();
});
}
public ObservableCollection<PurchaseUnloadData.ScannedItemInfo> Items { get; } = new ObservableCollection<PurchaseUnloadData.ScannedItemInfo>();
public NavigationCategoryData Category
{
get { return _category; }
set { SetProperty(ref _category, value); }
}
public PurchaseUnloadData.ScannedItemInfo SelectedItem
{
get { return _selectedItem; }
set
{
if (SetProperty(ref _selectedItem, value) && value != null)
{
Int64 itemID = Convert.ToInt64(value.ItemID);
Application.Current.MainPage.Navigation.PushAsync(new AddScannedItem("EDIT", itemID));
SetProperty(ref _selectedItem, null);
}
}
}
protected override void OnCultureChanged(CultureInfo culture)
{
LoadData();
}
private void LoadData()
{
Category = null;
Items.Clear();
int i = 0;
while (i < PurchaseUnloadData.scannedItems.Count)
{
Items.Add(PurchaseUnloadData.scannedItems[i]);
i++;
}
}
}
Implement INotifyPropertyChanged. Credits to Jason
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/how-to-implement-the-inotifypropertychanged-interface?view=netframeworkdesktop-4.8
I am now on a project regarding controlling devices by using silverlight and web service(asmx page). The project flows like below:
pressing the button on the silverlight UI, it will send out a package by using socket to the middlewire. Then middlewire will accept the package and deconstructe it and return back another package to silverlight UI. I am using below code to load the button state, which will trigger database query:
private ButtonStateModel _buttonStateModel = new ButtonStateModel() { BtnOneImage = "Skins/images/flag/QU.png", BtnOneVisible = Visibility.Visible, BtnTwoVisible = Visibility.Collapsed };
public ButtonStateModel ButtonStateModel
{
get
{
ButtonStateModel btnState = null;
dataService.GetPR(BusEquipmentPermission.Control.RtuID, BusEquipmentPermission.Control.DevID, (result) =>
{
if (result != null && result.Count > 0)
{
var flag = result[0].PRFlag;
if (flag == 1)
{
btnState = new ButtonStateModel()
{
BtnOneImage = "Skins/images/flag/OP.png",
BtnOneVisible = Visibility.Visible,
BtnTwoImage = "Skins/images/flag/OFF.png",
BtnTwoVisible = Visibility.Visible
};
}
else if (flag == 2)
{
btnState = new ButtonStateModel()
{
BtnOneImage = "Skins/images/flag/OFF.png",
BtnOneVisible = Visibility.Visible,
BtnTwoImage = "Skins/images/flag/OR.png",
BtnTwoVisible = Visibility.Visible
};
}
}
});
return btnState;
}
set
{
if (value == _buttonStateModel)
{
return;
}
_buttonStateModel = value;
RaisePropertyChanged("ButtonStateModel");
}
}
Now the problem is, whenever I load the silverlight app, the button on the UI can't load its state correctly. I know the reason is because that the GetPR function is from webservice(asmx), it's very oddly that I can't do sync operation by using AutoResetEvent in silverlight generated client code:
public void GetPR(string rtuID, string devID, Action<List<BusControlPR>> action)
{
ServiceSoapClient proxy = new ServiceSoapClient();
proxy.GetPRAsync(rtuID, devID);
proxy.GetPRCompleted += (sender, args) =>
{
//I cannt do Sync Operation Here by using AutoResetEvent.
if (action != null)
action(args.Result.ToList());
};
}
I am using webservice (asmx page) instead of WCF ria service.
Above problem is what i meet, Anyone can give me some light?
The "GetPR" method is still running asynchronously, so the "ButtonStateModel" getter will return null immediately (the "completed" action will then have no effect). And, you do not want to use any kind of blocking inside your getters, as that will block the UI. Instead, you should put the "GetPR" in the initialization, and use the to set the "ButtonStateModel" property to the appropriate value:
public class TheViewModel
{
public ButtonStateModel ButtonStateModel
{
get
{
return _buttonStateModel;
}
set
{
if (value == _buttonStateModel)
{
return;
}
_buttonStateModel = value;
RaisePropertyChanged("ButtonStateModel");
}
}
public TheViewModel()
{
Initialize();
}
private void Initialize()
{
dataService.GetPR(BusEquipmentPermission.Control.RtuID, BusEquipmentPermission.Control.DevID, (result) =>
{
ButtonStateModel btnState = null;
if (result != null && result.Count > 0)
{
var flag = result[0].PRFlag;
if (flag == 1)
{
btnState = new ButtonStateModel()
{
BtnOneImage = "Skins/images/flag/OP.png",
BtnOneVisible = Visibility.Visible,
BtnTwoImage = "Skins/images/flag/OFF.png",
BtnTwoVisible = Visibility.Visible
};
}
else if (flag == 2)
{
btnState = new ButtonStateModel()
{
BtnOneImage = "Skins/images/flag/OFF.png",
BtnOneVisible = Visibility.Visible,
BtnTwoImage = "Skins/images/flag/OR.png",
BtnTwoVisible = Visibility.Visible
};
}
}
ButtonStateModel = btnState;
});
}
}
Is there a way to always have the selected items in a Sitecore Treelist sorted alphabetically?
No, but you could look in to creating your own 'sorted treelist'. Someone asked a different question earlier today but it has basically the same answer:
Sitecore Tree list datasource - VersionExist
Sitecore lets you create custom field types. They can be based on existing ones, but with some added tweaks.
As mentioned in the answers to the other question, here are 2 articles which are good places to start:
Creating a Composite Custom Field
Apply Dynamic TreeList Source Parameters with the Sitecore ASP.NET CMS
Here's my implementation, which although long, is mostly copy-and-pasted from the decompiled Treelist code. I've highlighted which bits which are new in the Value property and the Add method:
namespace CustomFieldTypes
{
public class Treelist : Sitecore.Shell.Applications.ContentEditor.TreeList
{
public override string Value
{
get
{
// ---------- New code here -----------
var ids = base.Value.Split('|');
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var items = ids.Select(id => db.GetItem(id)).Where(item => item != null);
var orderedItems = items.OrderBy(item => item.Name);
var orderedIds = orderedItems.Select(item => item.ID.ToString());
return String.Join("|", orderedIds);
// ---------------------------------------
}
set
{
base.Value = value;
}
}
protected void Add()
{
if (this.Disabled)
return;
string viewStateString = this.GetViewStateString("ID");
TreeviewEx treeviewEx = this.FindControl(viewStateString + "_all") as TreeviewEx;
Assert.IsNotNull((object) treeviewEx, typeof (DataTreeview));
Listbox listbox = this.FindControl(viewStateString + "_selected") as Listbox;
Assert.IsNotNull((object) listbox, typeof (Listbox));
Item selectionItem = treeviewEx.GetSelectionItem();
if (selectionItem == null)
{
SheerResponse.Alert("Select an item in the Content Tree.", new string[0]);
}
else
{
if (this.HasExcludeTemplateForSelection(selectionItem))
return;
if (this.IsDeniedMultipleSelection(selectionItem, listbox))
{
SheerResponse.Alert("You cannot select the same item twice.", new string[0]);
}
else
{
if (!this.HasIncludeTemplateForSelection(selectionItem))
return;
SheerResponse.Eval("scForm.browser.getControl('" + viewStateString + "_selected').selectedIndex=-1");
ListItem listItem = new ListItem();
listItem.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("L");
// ----- New Code Here -----------------------
bool listItemAdded = false;
for (int i = 0; i < listbox.Controls.Count; i++ )
{
ListItem control = (ListItem)listbox.Controls[i];
if (control == null)
return;
if (String.Compare(GetHeaderValue(selectionItem), control.Header) < 0)
{
listbox.Controls.AddAt(i, listItem);
listItemAdded = true;
break;
}
}
if (!listItemAdded)
{
Sitecore.Context.ClientPage.AddControl((System.Web.UI.Control)listbox, (System.Web.UI.Control)listItem);
}
// ------------------------------------------
listItem.Header = this.GetHeaderValue(selectionItem);
listItem.Value = listItem.ID + (object) "|" + (string) (object) selectionItem.ID.ToString();
SheerResponse.Refresh((Sitecore.Web.UI.HtmlControls.Control) listbox);
SetModified();
}
}
}
protected static void SetModified()
{
Sitecore.Context.ClientPage.Modified = true;
}
private bool HasIncludeTemplateForSelection(Item item)
{
Assert.ArgumentNotNull((object)item, "item");
if (this.IncludeTemplatesForSelection.Length == 0)
return true;
else
return HasItemTemplate(item, this.IncludeTemplatesForSelection);
}
private bool HasExcludeTemplateForSelection(Item item)
{
if (item == null)
return true;
else
return HasItemTemplate(item, this.ExcludeTemplatesForSelection);
}
private bool IsDeniedMultipleSelection(Item item, Listbox listbox)
{
Assert.ArgumentNotNull((object)listbox, "listbox");
if (item == null)
return true;
if (this.AllowMultipleSelection)
return false;
foreach (Sitecore.Web.UI.HtmlControls.Control control in listbox.Controls)
{
string[] strArray = control.Value.Split(new char[1]
{
'|'
});
if (strArray.Length >= 2 && strArray[1] == item.ID.ToString())
return true;
}
return false;
}
private static bool HasItemTemplate(Item item, string templateList)
{
Assert.ArgumentNotNull((object)templateList, "templateList");
if (item == null || templateList.Length == 0)
return false;
string[] strArray = templateList.Split(new char[1]
{
','
});
ArrayList arrayList = new ArrayList(strArray.Length);
for (int index = 0; index < strArray.Length; ++index)
arrayList.Add((object)strArray[index].Trim().ToLowerInvariant());
return arrayList.Contains((object)item.TemplateName.Trim().ToLowerInvariant());
}
}
}
When this is compiled and in your application you need to go to /sitecore/system/Field types/List Types/Treelist in the core database. In there, you need to fill in the Assembly and Class fields, and clear out the Control fields.
You could create a custom field and sort the items in the selected list using generics, then save the guids back to the field. I covered this in a recent blog post. There isn't that much coding involved.
The way I understand how eclipse validation framework works:
generate an object with a factory
set a value for an attribute in this object
check validation
For example:
public class ValidateNameTest {
public static void main(String[] args) {
ExtlibraryPackageImpl.init();
ExtlibraryFactory factory = ExtlibraryFactory.eINSTANCE;
Writer writer = factory.createWriter();
// comment next line for false result in console
writer.setName("test");
writer.setFirstName("test");
writer.setLastName("test");
boolean isNull = (writer.getName() == null) ? true : false;
System.out.println("writer name is null : " + isNull);
boolean result = validateObject(writer);
System.err.println("result = " + result);
boolean result2 = validateObject2(writer);
System.err.println("result2 = " + result2);
boolean result3 = validateObject3(writer);
System.err.println("result3 = " + result3);
boolean result4 = validateObject5(writer);
System.out.println("result4 = " + result4);
}
public static boolean validateObject(Writer writer) {
ExtlibraryValidator validator = ExtlibraryValidator.INSTANCE;
if (!validator.validateWriter_hasValidName(writer, null, null)) {
return false;
}
return true;
}
public static boolean validateObject2(EObject eObject) {
EValidator validator = EValidator.Registry.INSTANCE
.getEValidator(eObject.eClass().getEPackage());
if (validator != null) {
if (!validator.validate(eObject, null, null)) {
return false;
}
}
return true;
}
public static boolean validateObject3(EObject eObject) {
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
return diagnostic.getSeverity() == Diagnostic.OK;
}
public static boolean validateObject5(EObject eObject)
{
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
if (diagnostic.getSeverity() == Diagnostic.ERROR || diagnostic.getSeverity() == Diagnostic.WARNING)
{
System.err.println(diagnostic.getMessage());
for (Diagnostic childDiagnostic : diagnostic.getChildren())
{
switch (childDiagnostic.getSeverity())
{
case Diagnostic.ERROR:
case Diagnostic.WARNING:
System.err.println("\t" + childDiagnostic.getMessage());
}
}
return false;
}
return true;
}
}
But I want to check if a value is valid for the model before I call the setter for the attribute. Is this possible with Eclipse EMF validation framework? Can somebody give an example please?
I know of one common use case where this is possible: Data binding between model and UI controls.
When you establish the EMF data binding between your model and the user interface, you can validate user input as follows. Create an update strategy (target to model) and override the method validateBeforeSet(Object). Here is an example:
EMFDataBindingContext ctx = new EMFDataBindingContext();
ISWTObservableValue notesObservableValue = prop.observe(swtTextViewer);
IEMFValueProperty notesValueProperty = EMFProperties.value(ModelPackage.Literals.THING__NOTES);
UpdateValueStrategy targetToModel = new UpdateValueStrategy() {
#Override
public IStatus validateBeforeSet(Object value) {
if ("".equals(value)) {
MessageDialog.openError(Display.getCurrent()
.getActiveShell(), "Error",
"You should supply a description");
return ValidationStatus
.error("You should supply a description");
}
return super.validateBeforeSet(value);
}
};
ctx.bindValue(notesObservableValue,
notesValueProperty.observe(thing), targetToModel,
new UpdateValueStrategy());
I'm creating a program that uses SharePoint Web Services to query and show a Sharepoint list to the user. I can only show one column at a time, so I need to find a 'default column' or 'display column' to show. I know 'Title' is commonly used in many of the content types but I want this to be robust with any type of custom content type or list so I would like to find some way of querying the list to discover this field.
For example: I'm using SharePoint Manager 2010 here and looking at a Link Library (That doesn't have a Title field) but somehow it knows that the list item is called 'http://google.com'. How is it inferring this?
(source: adamburkepile.com)
Looks like DisplayName has quite a bit of logic behind it. Here is the code I got using Reflector:
public string DisplayName
{
get
{
if (!this.IsNew)
{
if ((!this.ParentList.AllowContentTypes && (this.ParentList.BaseType == SPBaseType.DocumentLibrary)) || (this.ParentList.AllowContentTypes && (this.ContentTypeId.IsNonDiscussionFolder || this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Document))))
{
string str = (string) this.GetValue("BaseName", false);
if (!string.IsNullOrEmpty(str))
{
return SPHttpUtility.HtmlDecode(str);
}
}
SPField fieldByInternalName = this.Fields.GetFieldByInternalName("Title", false);
if (fieldByInternalName != null)
{
string fieldValueAsText = fieldByInternalName.GetFieldValueAsText(this.GetValue(fieldByInternalName, -1, false));
if (!string.IsNullOrEmpty(fieldValueAsText))
{
return fieldValueAsText;
}
}
if (this.ParentList.AllowContentTypes)
{
if (this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Link))
{
SPFieldUrlValue value2 = new SPFieldUrlValue((string) this.GetValue("URL", false));
if (!string.IsNullOrEmpty(value2.Description))
{
return value2.Description;
}
if (!string.IsNullOrEmpty(value2.Url))
{
return value2.Url;
}
}
if (this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Message))
{
Guid discussionTitleLookup = SPBuiltInFieldId.DiscussionTitleLookup;
SPField fld = this.Fields[discussionTitleLookup];
string str3 = fld.GetFieldValueAsText(this.GetValue(fld, -1, false));
if (!string.IsNullOrEmpty(str3))
{
return str3;
}
}
}
if (this.ParentList.BaseType != SPBaseType.Survey)
{
using (IEnumerator enumerator = this.Fields.GetEnumerator())
{
SPField field3;
string str5;
while (enumerator.MoveNext())
{
field3 = (SPField) enumerator.Current;
if (field3.GetFieldBoolValue("TitleField"))
{
goto Label_00C6;
}
}
goto Label_016F;
Label_00BB:
if (!(field3 is SPFieldMultiLineText))
{
return str5;
}
goto Label_00ED;
Label_00C6:
str5 = field3.GetFieldValueAsText(this.GetValue(field3, -1, false));
if (string.IsNullOrEmpty(str5))
{
goto Label_016F;
}
goto Label_00BB;
Label_00ED:
if (str5.Length <= 0xff)
{
return str5;
}
return str5.Substring(0, 0xff);
}
}
SPContext context2 = SPContext.Current;
if ((context2 == null) || (context2.FormContext.FormMode != SPControlMode.Edit))
{
return SPResource.GetString("ViewResponseTitle", new object[] { this.ID.ToString("N0", this.Web.Locale) });
}
return SPResource.GetString("ToolBarMenuRespondToSurvey", new object[0]);
}
SPContext current = SPContext.Current;
if (this.ParentList.BaseType != SPBaseType.Survey)
{
if ((current != null) && current.FormContext.IsNonDiscussionFolder)
{
return SPResource.GetString("ButtonTextNewFolder", new object[0]);
}
return SPResource.GetString("NewFormTitleNewItem", new object[0]);
}
return SPResource.GetString("ToolBarMenuRespondToSurvey", new object[0]);
Label_016F:
return SPResource.GetString("NoTitle", new object[0]);
}
}