Permalink
Browse files

[new general-purpose list filtering]

per DevExpress sample [How to: Use Criteria Property
Editors](https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument113143)
  • Loading branch information...
jhorv authored and apobekiaris committed Sep 18, 2015
1 parent 4bf0f19 commit 17d50d9e871ab3a3b39bdec0852dc49662a3974c
@@ -0,0 +1,40 @@
+using DevExpress.ExpressApp;
+using DevExpress.ExpressApp.Actions;
+using DevExpress.ExpressApp.Editors;
+using DevExpress.Persistent.Base;
+
+namespace Xpand.ExpressApp.SystemModule.Filtering {
+ public class ApplyFilterCriteriaToListViewController : ViewController<ListView>{
+ private readonly SingleChoiceAction _filteringCriteria;
+
+ public ApplyFilterCriteriaToListViewController() {
+ _filteringCriteria = new SingleChoiceAction(this, "FilteringCriteria", PredefinedCategory.Filters);
+ _filteringCriteria.Execute += FilteringCriteria_Execute;
+ }
+
+ public SingleChoiceAction FilteringCriteria {
+ get { return _filteringCriteria; }
+ }
+
+ private void FilteringCriteria_Execute(object sender, SingleChoiceActionExecuteEventArgs e) {
+ var collectionSource = View.CollectionSource;
+ collectionSource.BeginUpdateCriteria();
+ collectionSource.Criteria.Clear();
+ collectionSource.Criteria[e.SelectedChoiceActionItem.Caption] = CriteriaEditorHelper.GetCriteriaOperator(e.SelectedChoiceActionItem.Data as string, View.ObjectTypeInfo.Type, ObjectSpace);
+ collectionSource.EndUpdateCriteria();
+ }
+
+ protected override void OnActivated() {
+ base.OnActivated();
+ _filteringCriteria.Items.Clear();
+ foreach (var criterion in ObjectSpace.GetObjects<FilteringCriteria>()) {
+ if (criterion.ObjectType.IsAssignableFrom(View.ObjectTypeInfo.Type)) {
+ _filteringCriteria.Items.Add(new ChoiceActionItem(criterion.Name, criterion.Criteria));
+ }
+ }
+
+ if (_filteringCriteria.Items.Count > 0)
+ _filteringCriteria.Items.Add(new ChoiceActionItem("All", null));
+ }
+ }
+}
@@ -0,0 +1,88 @@
+using System;
+using System.ComponentModel;
+using DevExpress.ExpressApp;
+using DevExpress.ExpressApp.DC;
+using DevExpress.ExpressApp.Editors;
+using DevExpress.ExpressApp.Model;
+using DevExpress.Persistent.Base;
+using DevExpress.Xpo;
+using Xpand.Xpo;
+
+namespace Xpand.ExpressApp.SystemModule.Filtering{
+ public interface IFilteringCriteria{
+ string Name { get; set; }
+ string ObjectTypeName { get; set; }
+ Type ObjectType { get; set; }
+ string Criteria { get; set; }
+ }
+
+ [ImageName("Action_Filter")]
+ public class FilteringCriteria : XpandCustomObject, IFilteringCriteria{
+ [Persistent("Criteria")] private string _criteria;
+
+ private string _name;
+ private Type _objectType;
+ private string _objectTypeName;
+
+ public FilteringCriteria(Session session)
+ : base(session){
+ }
+
+ [CriteriaOptions("ObjectType")]
+ [Size(SizeAttribute.Unlimited), ObjectValidatorIgnoreIssue(typeof (ObjectValidatorLargeNonDelayedMember))]
+ [ModelDefault("RowCount", "0")]
+ [VisibleInListView(true)]
+ [VisibleInDetailView(false)]
+ [EditorAlias(EditorAliases.PopupCriteriaPropertyEditor)]
+ [PersistentAlias("_criteria")]
+ [XafDisplayName("Criteria")]
+ public string CriteriaPopup{
+ get { return _criteria; }
+ set { SetPropertyValue("Criteria", ref _criteria, value); }
+ }
+
+ public string Name{
+ get { return _name; }
+ set { SetPropertyValue("Name", ref _name, value); }
+ }
+
+ [Browsable(false)]
+ public string ObjectTypeName{
+ get { return _objectTypeName; }
+ set{
+ var type = XafTypesInfo.Instance.FindTypeInfo(value) == null
+ ? null
+ : XafTypesInfo.Instance.FindTypeInfo(value).Type;
+ _objectType = type;
+ if (!IsLoading && value != _objectTypeName){
+ Criteria = string.Empty;
+ }
+ SetPropertyValue("ObjectTypeName", ref _objectTypeName, value);
+ }
+ }
+
+ [TypeConverter(typeof (LocalizedClassInfoTypeConverter))]
+ [ImmediatePostData, NonPersistent]
+ public Type ObjectType{
+ get { return _objectType; }
+ set{
+ if (_objectType != value){
+ _objectType = value;
+ ObjectTypeName = (value == null) ? null : value.FullName;
+ }
+ }
+ }
+
+ [CriteriaOptions("ObjectType")]
+ [Size(SizeAttribute.Unlimited), ObjectValidatorIgnoreIssue(typeof (ObjectValidatorLargeNonDelayedMember))]
+ [ModelDefault("RowCount", "0")]
+ [VisibleInListView(false)]
+ [VisibleInDetailView(true)]
+ [EditorAlias(EditorAliases.CriteriaPropertyEditor)]
+ [PersistentAlias("_criteria")]
+ public string Criteria{
+ get { return _criteria; }
+ set { SetPropertyValue("Criteria", ref _criteria, value); }
+ }
+ }
+}
@@ -119,9 +119,7 @@
<Compile Include="ListEditors\IXpandListEditor.cs" />
<Compile Include="Core\BaseDomainLogic.cs" />
<Compile Include="Model\ListView.cs" />
- <Compile Include="Model\UnboundColumn.cs">
- <SubType>Component</SubType>
- </Compile>
+ <Compile Include="Model\UnboundColumn.cs" />
<Compile Include="Model\ProccessViewShortcuts.cs" />
<Compile Include="NodeUpdaters\ModelMemberGeneratorUpdater.cs" />
<Compile Include="PropertyEditors\ComboBoxItemsBuilder.cs" />
@@ -153,27 +151,23 @@
<Compile Include="SystemModule\CloneMemberValueViewController.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="SystemModule\ListViewShowViewStrategyController.cs">
- <SubType>Component</SubType>
- </Compile>
- <Compile Include="SystemModule\NewObjectCreateGroupController.cs">
+ <Compile Include="SystemModule\Filtering\FilteringCriteria.cs" />
+ <Compile Include="SystemModule\Filtering\ApplyFilterCriteriaToListViewController.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="SystemModule\PositionInListViewController.cs">
+ <Compile Include="SystemModule\ListViewShowViewStrategyController.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="SystemModule\ProccessListViewSelectedItemController.cs">
+ <Compile Include="SystemModule\NewObjectCreateGroupController.cs">
<SubType>Component</SubType>
</Compile>
+ <Compile Include="SystemModule\PositionInListViewController.cs" />
+ <Compile Include="SystemModule\ProccessListViewSelectedItemController.cs" />
<Compile Include="SystemModule\ReloadObjectController.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="SystemModule\Search\DetailViewFullTextSearchController.cs">
- <SubType>Component</SubType>
- </Compile>
- <Compile Include="SystemModule\Search\FullTextContainsController.cs">
- <SubType>Component</SubType>
- </Compile>
+ <Compile Include="SystemModule\Search\DetailViewFullTextSearchController.cs" />
+ <Compile Include="SystemModule\Search\FullTextContainsController.cs" />
<Compile Include="SystemModule\UpdateFastManyToManyActionsController.cs">
<SubType>Component</SubType>
</Compile>
@@ -186,9 +180,7 @@
<Compile Include="SystemModule\AssignMasterDetailToNestedViewController.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="SystemModule\ToolTipsController.cs">
- <SubType>Component</SubType>
- </Compile>
+ <Compile Include="SystemModule\ToolTipsController.cs" />
<Compile Include="TranslatorProviders\GoogleTranslatorProvider.cs" />
<Compile Include="Updater.cs" />
<Compile Include="Editors\ActionButtonDetailItem.cs">
@@ -222,18 +214,14 @@
<Compile Include="SystemModule\PreventDataLoadingController.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="SystemModule\FilterByPropertyPathViewController.cs">
- <SubType>Component</SubType>
- </Compile>
+ <Compile Include="SystemModule\FilterByPropertyPathViewController.cs" />
<Compile Include="SystemModule\FKViolationViewController.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="SystemModule\HideToolBarController.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="SystemModule\HighlightFocusedLayoutItemDetailViewControllerBase.cs">
- <SubType>Component</SubType>
- </Compile>
+ <Compile Include="SystemModule\HighlightFocusedLayoutItemDetailViewControllerBase.cs" />
<Compile Include="SystemModule\ListViewController.cs">
<SubType>Component</SubType>
</Compile>
@@ -249,12 +237,8 @@
<Compile Include="SystemModule\Search\SearchFromListViewController.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="SystemModule\Search\SearchFromViewController.cs">
- <SubType>Component</SubType>
- </Compile>
- <Compile Include="SystemModule\TrackNewObjectSavedController.cs">
- <SubType>Component</SubType>
- </Compile>
+ <Compile Include="SystemModule\Search\SearchFromViewController.cs" />
+ <Compile Include="SystemModule\TrackNewObjectSavedController.cs" />
<Compile Include="SystemModule\XpandSystemModule.cs">
<SubType>Component</SubType>
</Compile>
@@ -266,9 +250,7 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="ViewFactory.cs" />
- <Compile Include="ViewShortCutProccesor.cs">
- <SubType>Component</SubType>
- </Compile>
+ <Compile Include="ViewShortCutProccesor.cs" />
<Compile Include="XpandDetailView.cs" />
<Compile Include="XpandListView.cs" />
</ItemGroup>
@@ -318,6 +300,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

0 comments on commit 17d50d9

Please sign in to comment.