/// <summary>
        /// Edits the value of the specified object.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that can be used to gain
        /// additional context information.</param>
        /// <param name="provider">An <see cref="IServiceProvider"/> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var baseTypeAttribute = GetBaseTypeAttribute(context);
            var constraint =
                    new TypeBuildNodeConstraint(
                        baseTypeAttribute.BaseType,
                        baseTypeAttribute.ConfigurationType,
                        baseTypeAttribute.TypeSelectorIncludes);

            var model = new TypeBrowserViewModel(constraint, provider);
            var window =
                new TypeBrowser(model, (IAssemblyDiscoveryService)provider.GetService(typeof(IAssemblyDiscoveryService)));

            var service = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf));
            if (service != null)
            {
                service.ShowDialog(window);
            }
            else
            {
                window.ShowDialog();
            }

            if (window.DialogResult.HasValue && window.DialogResult.Value)
            {
                return window.SelectedType != null ? window.SelectedType.AssemblyQualifiedName : null;
            }

            return value;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Edits the value of the specified object.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that can be used to gain
        /// additional context information.</param>
        /// <param name="provider">An <see cref="IServiceProvider"/> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var baseTypeAttribute = GetBaseTypeAttribute(context);
            var constraint        =
                new TypeBuildNodeConstraint(
                    baseTypeAttribute.BaseType,
                    baseTypeAttribute.ConfigurationType,
                    baseTypeAttribute.TypeSelectorIncludes);

            var model  = new TypeBrowserViewModel(constraint, provider);
            var window =
                new TypeBrowser(model, (IAssemblyDiscoveryService)provider.GetService(typeof(IAssemblyDiscoveryService)));

            var service = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf));

            if (service != null)
            {
                service.ShowDialog(window);
            }
            else
            {
                window.ShowDialog();
            }

            if (window.DialogResult.HasValue && window.DialogResult.Value)
            {
                return(window.SelectedType != null ? window.SelectedType.AssemblyQualifiedName : null);
            }

            return(value);
        }
Ejemplo n.º 3
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.Browser = ((Microsoft.Practices.EnterpriseLibrary.Configuration.Design.ComponentModel.Editors.TypeBrowser)(target));
     return;
     case 2:
     this.AddFromGac = ((System.Windows.Controls.Button)(target));
     
     #line 22 "..\..\..\..\..\ComponentModel\Editors\TypeBrowser\TypeBrowser.xaml"
     this.AddFromGac.Click += new System.Windows.RoutedEventHandler(this.AddFromGac_Click);
     
     #line default
     #line hidden
     return;
     case 3:
     this.AddFromFile = ((System.Windows.Controls.Button)(target));
     
     #line 33 "..\..\..\..\..\ComponentModel\Editors\TypeBrowser\TypeBrowser.xaml"
     this.AddFromFile.Click += new System.Windows.RoutedEventHandler(this.AddFromFile_Click);
     
     #line default
     #line hidden
     return;
     case 4:
     this.Cancel = ((System.Windows.Controls.Button)(target));
     return;
     case 5:
     this.Ok = ((System.Windows.Controls.Button)(target));
     
     #line 54 "..\..\..\..\..\ComponentModel\Editors\TypeBrowser\TypeBrowser.xaml"
     this.Ok.Click += new System.Windows.RoutedEventHandler(this.Ok_Click);
     
     #line default
     #line hidden
     return;
     case 6:
     this.TypeName = ((System.Windows.Controls.TextBox)(target));
     return;
     case 7:
     this.TypesTree = ((System.Windows.Controls.TreeView)(target));
     return;
     }
     this._contentLoaded = true;
 }
        /// <summary>
        /// Retrieves and returns the selected type from the user.
        /// </summary>
        /// <param name="selectedType">The type to select in the type selection dialog.</param>
        /// <param name="baseType">The base type (class or interface) from which the constrained type should derive.</param>
        /// <param name="selectorIncludes">Indicates the types that can be browsed.</param>
        /// <param name="configurationType">The base type from which a type specified by the 
        /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationElementTypeAttribute"/>
        /// bound to the constrained type should derive, or <see langword="null"/> if no such constraint is necessary.
        /// </param>
        /// <returns>
        /// The selected <see cref="Type"/> or <see langword="null"/> if not type is selected.
        /// </returns>
        protected virtual Type GetSelectedType(Type selectedType, Type baseType, TypeSelectorIncludes selectorIncludes, Type configurationType)
        {
            var viewModel = new TypeBrowserViewModel(new TypeBuildNodeConstraint(baseType, configurationType, selectorIncludes), this);
            var selector = new TypeBrowser(viewModel, this.discoveryService);

            Nullable<bool> result = false;
            if (this.UIService != null)
            {
                result = UIService.ShowDialog(selector);
            }
            else
            {
                result = selector.ShowDialog();
            }

            if (result.HasValue && result.Value)
            {
                return selector.SelectedType;
            }
            return null;
        }