Example #1
0
        public override void Setup(CollectionSourceBase collectionSource, XafApplication application)
        {
            base.Setup(collectionSource, application);
            AutoLoad = false;
            IObjectSpace objectSpace = collectionSource.ObjectSpace;

            objectSpace.Reloaded += new EventHandler(this.ObjectSpace_Reloaded);
            ITypeInfo objectTypeInfo = collectionSource.ObjectTypeInfo;
            var       customSetting  = ObjectTypeInfo.FindAttribute <CategorySettingAttribute>();

            Setting = customSetting;
            Type memberType = null;

            if (customSetting == null)
            {
                IMemberInfo info2 = objectTypeInfo.FindMember("Category");
                if (info2 == null)
                {
                    throw new InvalidOperationException(string.Format("The {0} type does not declare the public {1} property.", objectTypeInfo.FullName, "Category"));
                }
                memberType = info2.MemberType;
            }
            else
            {
                memberType           = customSetting.CategoryType;
                CategoryPropertyName = Setting.PropertyName;
            }

            this.categoriesListViewId = application.FindListViewId(memberType);
            if (string.IsNullOrEmpty(this.categoriesListViewId))
            {
                throw new InvalidOperationException(string.Format("Cannot find ListView for the Category property type {0} in the Application Model. Make sure the property is of the business object type registered in the application.", memberType.FullName));
            }
            if ((base.Model != null) && (this.categoriesListViewId == base.Model.Id))
            {
                throw new InvalidOperationException(string.Format("The default category ListView ({0}) is the same as the container ListView. To avoid recursion, provide different EditorType settings for it.", this.categoriesListViewId));
            }
            this.categoriesDataSource    = application.CreateCollectionSource(objectSpace, memberType, this.categoriesListViewId);
            this.criteriaPropertyName    = "Category." + objectSpace.GetKeyPropertyName(memberType);
            this.typeDescriptionProvider = new CategorizedListEditorTypeDescriptionProvider(objectTypeInfo.Type);
            this.typeDescriptionProvider.AddProvider();
        }
Example #2
0
 public override void Dispose()
 {
     try
     {
         this.UnsubscribeFromTreeList();
         if (this.typeDescriptionProvider != null)
         {
             this.typeDescriptionProvider.RemoveProvider();
             this.typeDescriptionProvider = null;
         }
         if (this.layoutManager != null)
         {
             this.layoutManager.Dispose();
             this.layoutManager = null;
         }
         if (this.categoriesListView != null)
         {
             this.categoriesListView.SelectionChanged -= new EventHandler(this.categoriesListView_SelectionChanged);
             this.categoriesListView.Dispose();
             this.categoriesListView = null;
         }
         if (this.categoriesDataSource != null)
         {
             this.categoriesDataSource.Dispose();
             this.categoriesDataSource = null;
         }
         if (this.ItemsDataSource != null)
         {
             this.ItemsDataSource.ObjectSpace.Reloaded -= new EventHandler(this.ObjectSpace_Reloaded);
         }
         this.updateCriteriaLocker.LockedChanged -= new EventHandler <LockedChangedEventArgs>(this.updateCriteriaLocker_LockedChanged);
     }
     finally
     {
         base.Dispose();
     }
 }