Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / UI / MobileControls / Design / SelectionListDesigner.cs / 1305376 / SelectionListDesigner.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.Design.MobileControls { using System; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Data; using System.Diagnostics; using System.Web.UI.MobileControls; using System.Web.UI.Design.MobileControls.Adapters; using DataBinding = System.Web.UI.DataBinding; [ System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode) ] [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] internal class SelectionListDesigner : MobileControlDesigner, IListDesigner, IDataSourceProvider { private SelectionList _selectionList; private DesignerVerbCollection _designerVerbs; private DataTable _dummyDataTable; private DataTable _designTimeDataTable; private const String _dataSourcePropertyName = "DataSource"; private const String _dataMemberPropertyName = "DataMember"; private const String _dataTextFieldPropertyName = "DataTextField"; private const String _dataValueFieldPropertyName = "DataValueField"; private static readonly Attribute[] _emptyAttrs = new Attribute[0]; ////// public String DataValueField { get { return _selectionList.DataValueField; } set { _selectionList.DataValueField = value; } } ////// public String DataTextField { get { return _selectionList.DataTextField; } set { _selectionList.DataTextField = value; } } public String DataMember { get { return _selectionList.DataMember; } set { _selectionList.DataMember = value; OnDataSourceChanged(); } } public MobileListItemCollection Items { get { return _selectionList.Items; } } ////// ////// Gets or sets the data source property. /// ////// ////// A string indicating the data source for the designer's control. /// ////// public String DataSource { get { DataBinding binding = DataBindings[_dataSourcePropertyName]; if (binding != null) { return binding.Expression; } return String.Empty; } set { if ((value == null) || (value.Length == 0)) { DataBindings.Remove(_dataSourcePropertyName); } else { DataBinding binding = DataBindings[_dataSourcePropertyName]; if (binding == null) { binding = new DataBinding(_dataSourcePropertyName, typeof(IEnumerable), value); } else { binding.Expression = value; } DataBindings.Add(binding); } OnDataSourceChanged(); OnBindingsCollectionChanged(_dataSourcePropertyName); } } ////// Designer implementation of a DataSource property that operates on the /// DataSource property in the control's binding collection. /// ////// ////// The designer's collection of verbs. /// ////// public override DesignerVerbCollection Verbs { get { if (null == _designerVerbs) { _designerVerbs = base.Verbs; _designerVerbs.Add(new DesignerVerb(SR.GetString(SR.PropertyBuilderVerb), new EventHandler(this.OnPropertyBuilder))); } return _designerVerbs; } } ////// An array of type ///containing the verbs available to the /// designer. /// /// /// /// The minimum rows of sample data the data source data should contain. /// /// /// Whether the data source being returned is a dummy data source. /// ////// Gets sample data matching the schema of the selected data source. /// ////// /// protected IEnumerable GetDesignTimeDataSource( int minimumRows, out bool dummyDataSource) { IEnumerable selectedDataSource = GetResolvedSelectedDataSource(); return GetDesignTimeDataSource( selectedDataSource, minimumRows, out dummyDataSource); } ////// An IEnumerable containing a live data source for use at /// design time. /// ////// /// /// The selected data source to be used as a reference for the shape of the data. /// /// /// The minimum rows of sample data the data source data should contain. /// /// /// Whether the data source being returned is a dummy data source. /// ////// Gets sample data matching the schema of the selected data source. /// ////// /// protected IEnumerable GetDesignTimeDataSource( IEnumerable selectedDataSource, int minimumRows, out bool dummyDataSource) { DataTable dataTable = _designTimeDataTable; dummyDataSource = false; // use the datatable corresponding to the selected datasource if possible if (dataTable == null) { if (selectedDataSource != null) { _designTimeDataTable = DesignTimeData.CreateSampleDataTable(selectedDataSource); dataTable = _designTimeDataTable; } if (dataTable == null) { // fallback on a dummy datasource if we can't create a sample datatable if (_dummyDataTable == null) { _dummyDataTable = DesignTimeData.CreateDummyDataTable(); } dataTable = _dummyDataTable; dummyDataSource = true; } } IEnumerable liveDataSource = DesignTimeData.GetDesignTimeDataSource(dataTable, minimumRows); return liveDataSource; } ////// An IEnumerable containing /// a live data source for use at design time. /// ////// ////// Gets the HTML to be used for the design-time representation /// of the control. /// ////// protected override String GetDesignTimeNormalHtml() { const int numberOfStaticItems = 5; IEnumerable selectedDataSource = null; String oldDataTextField = null, oldDataValueField = null; bool dummyDataSource = false; DesignerTextWriter htmlWriter = new DesignerTextWriter(true); MobileListItemCollection items = _selectionList.Items; Debug.Assert(items != null, "Items is null in LisControl"); if (items.Count > 0) { _selectionList.Adapter.Render(htmlWriter); } else { MobileListItem[] oldItems = items.GetAll(); int sampleRows = numberOfStaticItems; // try designtime databinding. selectedDataSource = GetResolvedSelectedDataSource(); IEnumerable designTimeDataSource = GetDesignTimeDataSource( selectedDataSource, sampleRows, out dummyDataSource); // If dummy datasource is applied, change the data fields so that // dummy source will be rendered. if (dummyDataSource) { oldDataTextField = _selectionList.DataTextField; oldDataValueField = _selectionList.DataValueField; _selectionList.DataTextField = "Column0"; _selectionList.DataValueField = "Column1"; } try { _selectionList.DataSource = designTimeDataSource; _selectionList.DataBind(); _selectionList.Adapter.Render(htmlWriter); } finally { _selectionList.DataSource = null; _selectionList.Items.SetAll(oldItems); if (dummyDataSource) { _selectionList.DataTextField = oldDataTextField; _selectionList.DataValueField = oldDataValueField; } } } return htmlWriter.ToString(); } public IEnumerable GetResolvedSelectedDataSource() { IEnumerable selectedDataSource = null; DataBinding binding = DataBindings["DataSource"]; if (binding != null) { selectedDataSource = DesignTimeData.GetSelectedDataSource( _selectionList, binding.Expression, DataMember); } return selectedDataSource; } ////// The design-time HTML. /// ////// ////// Gets the selected data source component from the component's container. /// ////// ////// An IEnumerable with the /// selected data source, or ///if a data source is not found, or if a data /// source with the same name does not exist. /// public Object GetSelectedDataSource() { Object selectedDataSource = null; DataBinding binding = DataBindings[_dataSourcePropertyName]; if (binding != null) { selectedDataSource = DesignTimeData.GetSelectedDataSource(_selectionList, binding.Expression); } return selectedDataSource; } /// /// /// /// The control element being designed. /// ////// Initializes the designer. /// ////// ////// This is called by the designer host to establish the component being /// designed. /// ///public override void Initialize(IComponent component) { Debug.Assert(component is System.Web.UI.MobileControls.SelectionList, "SelectionListDesigner.Initialize - Invalid SelectionList Control"); _selectionList = (SelectionList) component; base.Initialize(component); } /// /// /// /// The page to begin with. /// protected internal void InvokePropertyBuilder(int initialPage) { IComponentChangeService changeService = null; bool result = false; changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService)); if (changeService != null) { try { changeService.OnComponentChanging(_selectionList, null); } catch (CheckoutException ex) { if (ex == CheckoutException.Canceled) { return; } throw; } } try { SelectionListComponentEditor compEditor = new SelectionListComponentEditor(initialPage); result = compEditor.EditComponent(_selectionList); } finally { if (changeService != null) { changeService.OnComponentChanged(_selectionList, null, null, null); if (IMobileWebFormServices != null) { IMobileWebFormServices.ClearUndoStack(); } } } } ////// Invokes the property builder beginning with the specified page. /// ////// /// /// The source of the event. /// /// /// The/// Represents the method that will handle the component change event. /// ///that provides data about the event. /// public override void OnComponentChanged(Object sender, ComponentChangedEventArgs e) { if (e.Member != null) { if (e.Member.Name.Equals(_dataSourcePropertyName) || e.Member.Name.Equals(_dataMemberPropertyName)) { OnDataSourceChanged(); } } base.OnComponentChanged(sender, e); } /// /// /// public void OnDataSourceChanged() { _designTimeDataTable = null; } ////// Raises the DataSourceChanged event. /// ////// /// /// The source of the event. /// /// /// An EventArgs object that provides data about the event. /// protected void OnPropertyBuilder(Object sender, EventArgs e) { InvokePropertyBuilder(0); } ////// Represents the method that will handle the property builder event. /// ////// /// /// The set of properties to filter. /// ////// Filter the properties to replace the runtime DataSource property /// descriptor with the designer's. /// ///protected override void PreFilterProperties(IDictionary properties) { base.PreFilterProperties(properties); Type designerType = this.GetType(); DesignerAdapterUtil.AddAttributesToPropertiesOfDifferentType( designerType, typeof(String), properties, _dataSourcePropertyName, new TypeConverterAttribute(typeof(DataSourceConverter))); DesignerAdapterUtil.AddAttributesToProperty( designerType, properties, _dataMemberPropertyName, _emptyAttrs); DesignerAdapterUtil.AddAttributesToProperty( designerType, properties, _dataTextFieldPropertyName, _emptyAttrs); DesignerAdapterUtil.AddAttributesToProperty( designerType, properties, _dataValueFieldPropertyName, _emptyAttrs); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.Design.MobileControls { using System; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Data; using System.Diagnostics; using System.Web.UI.MobileControls; using System.Web.UI.Design.MobileControls.Adapters; using DataBinding = System.Web.UI.DataBinding; [ System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode) ] [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] internal class SelectionListDesigner : MobileControlDesigner, IListDesigner, IDataSourceProvider { private SelectionList _selectionList; private DesignerVerbCollection _designerVerbs; private DataTable _dummyDataTable; private DataTable _designTimeDataTable; private const String _dataSourcePropertyName = "DataSource"; private const String _dataMemberPropertyName = "DataMember"; private const String _dataTextFieldPropertyName = "DataTextField"; private const String _dataValueFieldPropertyName = "DataValueField"; private static readonly Attribute[] _emptyAttrs = new Attribute[0]; ////// public String DataValueField { get { return _selectionList.DataValueField; } set { _selectionList.DataValueField = value; } } ////// public String DataTextField { get { return _selectionList.DataTextField; } set { _selectionList.DataTextField = value; } } public String DataMember { get { return _selectionList.DataMember; } set { _selectionList.DataMember = value; OnDataSourceChanged(); } } public MobileListItemCollection Items { get { return _selectionList.Items; } } ////// ////// Gets or sets the data source property. /// ////// ////// A string indicating the data source for the designer's control. /// ////// public String DataSource { get { DataBinding binding = DataBindings[_dataSourcePropertyName]; if (binding != null) { return binding.Expression; } return String.Empty; } set { if ((value == null) || (value.Length == 0)) { DataBindings.Remove(_dataSourcePropertyName); } else { DataBinding binding = DataBindings[_dataSourcePropertyName]; if (binding == null) { binding = new DataBinding(_dataSourcePropertyName, typeof(IEnumerable), value); } else { binding.Expression = value; } DataBindings.Add(binding); } OnDataSourceChanged(); OnBindingsCollectionChanged(_dataSourcePropertyName); } } ////// Designer implementation of a DataSource property that operates on the /// DataSource property in the control's binding collection. /// ////// ////// The designer's collection of verbs. /// ////// public override DesignerVerbCollection Verbs { get { if (null == _designerVerbs) { _designerVerbs = base.Verbs; _designerVerbs.Add(new DesignerVerb(SR.GetString(SR.PropertyBuilderVerb), new EventHandler(this.OnPropertyBuilder))); } return _designerVerbs; } } ////// An array of type ///containing the verbs available to the /// designer. /// /// /// /// The minimum rows of sample data the data source data should contain. /// /// /// Whether the data source being returned is a dummy data source. /// ////// Gets sample data matching the schema of the selected data source. /// ////// /// protected IEnumerable GetDesignTimeDataSource( int minimumRows, out bool dummyDataSource) { IEnumerable selectedDataSource = GetResolvedSelectedDataSource(); return GetDesignTimeDataSource( selectedDataSource, minimumRows, out dummyDataSource); } ////// An IEnumerable containing a live data source for use at /// design time. /// ////// /// /// The selected data source to be used as a reference for the shape of the data. /// /// /// The minimum rows of sample data the data source data should contain. /// /// /// Whether the data source being returned is a dummy data source. /// ////// Gets sample data matching the schema of the selected data source. /// ////// /// protected IEnumerable GetDesignTimeDataSource( IEnumerable selectedDataSource, int minimumRows, out bool dummyDataSource) { DataTable dataTable = _designTimeDataTable; dummyDataSource = false; // use the datatable corresponding to the selected datasource if possible if (dataTable == null) { if (selectedDataSource != null) { _designTimeDataTable = DesignTimeData.CreateSampleDataTable(selectedDataSource); dataTable = _designTimeDataTable; } if (dataTable == null) { // fallback on a dummy datasource if we can't create a sample datatable if (_dummyDataTable == null) { _dummyDataTable = DesignTimeData.CreateDummyDataTable(); } dataTable = _dummyDataTable; dummyDataSource = true; } } IEnumerable liveDataSource = DesignTimeData.GetDesignTimeDataSource(dataTable, minimumRows); return liveDataSource; } ////// An IEnumerable containing /// a live data source for use at design time. /// ////// ////// Gets the HTML to be used for the design-time representation /// of the control. /// ////// protected override String GetDesignTimeNormalHtml() { const int numberOfStaticItems = 5; IEnumerable selectedDataSource = null; String oldDataTextField = null, oldDataValueField = null; bool dummyDataSource = false; DesignerTextWriter htmlWriter = new DesignerTextWriter(true); MobileListItemCollection items = _selectionList.Items; Debug.Assert(items != null, "Items is null in LisControl"); if (items.Count > 0) { _selectionList.Adapter.Render(htmlWriter); } else { MobileListItem[] oldItems = items.GetAll(); int sampleRows = numberOfStaticItems; // try designtime databinding. selectedDataSource = GetResolvedSelectedDataSource(); IEnumerable designTimeDataSource = GetDesignTimeDataSource( selectedDataSource, sampleRows, out dummyDataSource); // If dummy datasource is applied, change the data fields so that // dummy source will be rendered. if (dummyDataSource) { oldDataTextField = _selectionList.DataTextField; oldDataValueField = _selectionList.DataValueField; _selectionList.DataTextField = "Column0"; _selectionList.DataValueField = "Column1"; } try { _selectionList.DataSource = designTimeDataSource; _selectionList.DataBind(); _selectionList.Adapter.Render(htmlWriter); } finally { _selectionList.DataSource = null; _selectionList.Items.SetAll(oldItems); if (dummyDataSource) { _selectionList.DataTextField = oldDataTextField; _selectionList.DataValueField = oldDataValueField; } } } return htmlWriter.ToString(); } public IEnumerable GetResolvedSelectedDataSource() { IEnumerable selectedDataSource = null; DataBinding binding = DataBindings["DataSource"]; if (binding != null) { selectedDataSource = DesignTimeData.GetSelectedDataSource( _selectionList, binding.Expression, DataMember); } return selectedDataSource; } ////// The design-time HTML. /// ////// ////// Gets the selected data source component from the component's container. /// ////// ////// An IEnumerable with the /// selected data source, or ///if a data source is not found, or if a data /// source with the same name does not exist. /// public Object GetSelectedDataSource() { Object selectedDataSource = null; DataBinding binding = DataBindings[_dataSourcePropertyName]; if (binding != null) { selectedDataSource = DesignTimeData.GetSelectedDataSource(_selectionList, binding.Expression); } return selectedDataSource; } /// /// /// /// The control element being designed. /// ////// Initializes the designer. /// ////// ////// This is called by the designer host to establish the component being /// designed. /// ///public override void Initialize(IComponent component) { Debug.Assert(component is System.Web.UI.MobileControls.SelectionList, "SelectionListDesigner.Initialize - Invalid SelectionList Control"); _selectionList = (SelectionList) component; base.Initialize(component); } /// /// /// /// The page to begin with. /// protected internal void InvokePropertyBuilder(int initialPage) { IComponentChangeService changeService = null; bool result = false; changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService)); if (changeService != null) { try { changeService.OnComponentChanging(_selectionList, null); } catch (CheckoutException ex) { if (ex == CheckoutException.Canceled) { return; } throw; } } try { SelectionListComponentEditor compEditor = new SelectionListComponentEditor(initialPage); result = compEditor.EditComponent(_selectionList); } finally { if (changeService != null) { changeService.OnComponentChanged(_selectionList, null, null, null); if (IMobileWebFormServices != null) { IMobileWebFormServices.ClearUndoStack(); } } } } ////// Invokes the property builder beginning with the specified page. /// ////// /// /// The source of the event. /// /// /// The/// Represents the method that will handle the component change event. /// ///that provides data about the event. /// public override void OnComponentChanged(Object sender, ComponentChangedEventArgs e) { if (e.Member != null) { if (e.Member.Name.Equals(_dataSourcePropertyName) || e.Member.Name.Equals(_dataMemberPropertyName)) { OnDataSourceChanged(); } } base.OnComponentChanged(sender, e); } /// /// /// public void OnDataSourceChanged() { _designTimeDataTable = null; } ////// Raises the DataSourceChanged event. /// ////// /// /// The source of the event. /// /// /// An EventArgs object that provides data about the event. /// protected void OnPropertyBuilder(Object sender, EventArgs e) { InvokePropertyBuilder(0); } ////// Represents the method that will handle the property builder event. /// ////// /// /// The set of properties to filter. /// ////// Filter the properties to replace the runtime DataSource property /// descriptor with the designer's. /// ///protected override void PreFilterProperties(IDictionary properties) { base.PreFilterProperties(properties); Type designerType = this.GetType(); DesignerAdapterUtil.AddAttributesToPropertiesOfDifferentType( designerType, typeof(String), properties, _dataSourcePropertyName, new TypeConverterAttribute(typeof(DataSourceConverter))); DesignerAdapterUtil.AddAttributesToProperty( designerType, properties, _dataMemberPropertyName, _emptyAttrs); DesignerAdapterUtil.AddAttributesToProperty( designerType, properties, _dataTextFieldPropertyName, _emptyAttrs); DesignerAdapterUtil.AddAttributesToProperty( designerType, properties, _dataValueFieldPropertyName, _emptyAttrs); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- MouseButtonEventArgs.cs
- MetadataExporter.cs
- QilXmlReader.cs
- WebPartTransformerCollection.cs
- GeneralTransform3DTo2D.cs
- MappingSource.cs
- IPGlobalProperties.cs
- ToolStripSeparator.cs
- GlobalId.cs
- VerticalAlignConverter.cs
- IconConverter.cs
- PeerInvitationResponse.cs
- _DisconnectOverlappedAsyncResult.cs
- OrthographicCamera.cs
- SqlGatherConsumedAliases.cs
- indexingfiltermarshaler.cs
- StorageScalarPropertyMapping.cs
- METAHEADER.cs
- ThemeDirectoryCompiler.cs
- DetailsViewDeleteEventArgs.cs
- SystemUnicastIPAddressInformation.cs
- ProviderCollection.cs
- ButtonStandardAdapter.cs
- ContentElement.cs
- SymbolType.cs
- CharacterHit.cs
- AutomationEvent.cs
- PrintingPermission.cs
- X509Extension.cs
- TypedElement.cs
- DateTimeHelper.cs
- Matrix.cs
- PageParser.cs
- WebPartManagerInternals.cs
- XamlSerializerUtil.cs
- DesignerSerializerAttribute.cs
- WebServiceClientProxyGenerator.cs
- RemoteTokenFactory.cs
- MenuItemBinding.cs
- MailMessage.cs
- Parser.cs
- TreeViewItem.cs
- SiteMapDataSourceView.cs
- ToolStripItemEventArgs.cs
- CodeDirectiveCollection.cs
- ModelUIElement3D.cs
- DataTableReader.cs
- ECDiffieHellman.cs
- CodeIdentifiers.cs
- HostDesigntimeLicenseContext.cs
- HttpDigestClientCredential.cs
- DocumentCollection.cs
- PanelDesigner.cs
- FormatConvertedBitmap.cs
- Schedule.cs
- SendParametersContent.cs
- ConfigXmlWhitespace.cs
- KoreanLunisolarCalendar.cs
- ControlIdConverter.cs
- DemultiplexingDispatchMessageFormatter.cs
- Color.cs
- TabItem.cs
- SendMessageRecord.cs
- ValidatorCompatibilityHelper.cs
- FormsAuthenticationModule.cs
- TextBoxRenderer.cs
- DependencyPropertyHelper.cs
- SmiEventStream.cs
- SoapAttributeAttribute.cs
- EdmFunction.cs
- SessionStateUtil.cs
- WebPartChrome.cs
- SharedPersonalizationStateInfo.cs
- WsdlImporter.cs
- _Connection.cs
- ProfileEventArgs.cs
- PartitionedStream.cs
- CompositeDataBoundControl.cs
- DefaultValidator.cs
- ProfileGroupSettingsCollection.cs
- DecoderBestFitFallback.cs
- RealProxy.cs
- DBSqlParser.cs
- Model3DGroup.cs
- ActivityExecutor.cs
- MessageQueueCriteria.cs
- CommandValueSerializer.cs
- ListItem.cs
- AlternateViewCollection.cs
- AssemblyHelper.cs
- SmiMetaData.cs
- NavigationPropertySingletonExpression.cs
- XmlSchemaObjectCollection.cs
- FontUnitConverter.cs
- activationcontext.cs
- CmsUtils.cs
- SecUtil.cs
- TypeUnloadedException.cs
- LicenseException.cs
- TypefaceMetricsCache.cs