Quantcast
Channel: eXpandFramework RSS
Viewing all articles
Browse latest Browse all 861

New ways to customize the New Action's items list in XAF v16.2.5 - YOUR FEEDBACK IS NEEDED!!!

$
0
0
Changing the way how the New Action's items list is populated is quite an often task. The default behavior when the current types and all its descendants are added may be inappropriate in large XAF applications with a complex business objects inheritance hierarchy.



That is why we have decided to provide more built-in modes of populating this list. The available modes are listed in the DevExpress.ExpressApp.SystemModule.NewObjectActionItemListMode enumeration.

Value Description
Default The current type and all of its descendant types are added.
ExcludeBaseType All descendants of the current type are added. The current type itself is excluded.
LastDescendantsOnly Only the last types in the inheritance hierarchy of the current type are added.


You can change the mode globally using the NewObjectViewController.DefaultNewObjectActionItemListMode static field, or individually for each View using the NewObjectViewController.NewObjectActionItemListMode property.

using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; using DevExpress.Persistent.BaseImpl;
// ...
public class CustomizeNewActionItemsListController : ObjectViewController<ObjectView, Task> {
protected override void OnActivated() {
base.OnActivated();
NewObjectViewController controller = Frame.GetController<NewObjectViewController>();
controller.NewObjectActionItemListMode = NewObjectActionItemListMode.LastDescendantsOnly;
}
}

The NewObjectActionItemListMode value is ignored in case when there are no descendants of the current business object type. In the ExcludeBaseType and LastDescendantsOnly modes, the New Action may become inactive if it is impossible to instantiate any of the descendants (e.g., due to the Security System restrictions).

If none of the default modes meets your requirements, handle the NewObjectViewController.CollectDescendantTypes and NewObjectViewController.CollectCreatableItemTypes events and populate the list manually.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.Persistent.BaseImpl;
// ...

public class CustomizeNewActionItemsListController : ObjectViewController<ObjectView, Task> {
protected override void OnActivated() {
base.OnActivated();
NewObjectViewController controller = Frame.GetController<NewObjectViewController>();
controller.CollectCreatableItemTypes += HideHCategoryViewController_CollectCreatableItemTypes;
controller.CollectDescendantTypes += HideHCategoryViewController_CollectDescendantTypes;
controller.UpdateNewObjectAction();
}
private void HideHCategoryViewController_CollectDescendantTypes(object sender, CollectTypesEventArgs e) {
CustomizeList(e.Types);
}
private void HideHCategoryViewController_CollectCreatableItemTypes(object sender, CollectTypesEventArgs e) {
CustomizeList(e.Types);
}
private void CustomizeList(ICollection<Type> types) {
List<Type> unusableTypes = new List<Type>();
foreach (Type item in types) {
if (item == typeof(Task)) {
unusableTypes.Add(item);
}
}
foreach (Type item in unusableTypes) {
types.Remove(item);
}
}
}


To try the demonstrated functionality, update to XAF version 16.2.5. Also, we will be happy to receive your feedback in comments to this post. Possibly, we have missed a certain popular scenario which can be added to the list of built-in modes.

Viewing all articles
Browse latest Browse all 861

Trending Articles