///	<summary>
        ///	Called by the tool pane to apply property changes to the selected Web Part.
        ///	</summary>
        public override bool ApplyChanges()
        {
            try
            {
                EnsureChildControls();
                // apply property values here
                ListMarquee wp = this.WebPartToEdit as ListMarquee;

                wp.ListWebUrl   = this.WebUrlTextBox.Text;
                wp.ListName     = this.AvailableListsDropDownList.SelectedValue;
                wp.ListViewName = this.AvailableViewsDropDownList.SelectedValue;
                return(true);
            }
            catch (Exception ex) { logger.LogError(ex); }
            return(false);
        }
        ///	<summary>
        ///	Called by the tool pane to apply property changes to the selected Web Part.
        ///	</summary>
        public override bool ApplyChanges()
        {
            try
            {
                EnsureChildControls();
                // apply property values here
                ListMarquee wp = this.WebPartToEdit as ListMarquee;

                wp.TitleFieldName   = this.TitleFieldNameTextBox.Text;
                wp.BodyFieldName    = this.BodyFieldNameTextBox.Text;
                wp.MarqueeDelay     = int.Parse(this.MarqueeSpeedTextBox.Text);
                wp.MarqueeAmount    = int.Parse(this.MarqueeStepSizeTextBox.Text);
                wp.MarqueeDirection = (MarqueeDirections)Enum.Parse(typeof(MarqueeDirections), this.MarqueeDirectionListBox.SelectedValue, true);
                wp.LinkTarget       = (LinkTargets)Enum.Parse(typeof(LinkTargets), this.MarqueeLinkTargetListBox.SelectedValue, true);
                return(true);
            }
            catch (Exception ex) { logger.LogError(ex); }
            return(false);
        }
        void LoadViews()
        {
            try
            {
                ListMarquee wp = this.WebPartToEdit as ListMarquee;

                EnsureChildControls();
                AvailableViewsDropDownList.Items.Clear();

                SPWeb web;
                if (WebUrlTextBox.Text.Trim() == string.Empty)
                {
                    web = Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context);
                }
                else
                {
                    SPSite st = new SPSite(new Uri(Page.Request.Url, WebUrlTextBox.Text, true).ToString());
                    st.CatchAccessDeniedException = false;
                    web = st.OpenWeb();
                }

                WebUrlTextBox.Text            = web.Url;
                web.Lists.ListsForCurrentUser = true;
                SPList list = web.Lists[this.AvailableListsDropDownList.SelectedValue];

                foreach (SPView vi in list.Views)
                {
                    if (vi.Title.Trim() != string.Empty)
                    {
                        AvailableViewsDropDownList.Items.Add(vi.Title);
                    }

                    if (wp.ListViewName == vi.Title)
                    {
                        AvailableViewsDropDownList.SelectedIndex = AvailableViewsDropDownList.Items.Count - 1;
                    }
                }
            }
            catch (Exception ex) { logger.LogError(ex); }
        }
        /// <summary>
        /// Load lists from the selected web into the available lists list.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoadListButton_Click(object sender, EventArgs e)
        {
            try
            {
                ListMarquee wp = this.WebPartToEdit as ListMarquee;

                EnsureChildControls();
                AvailableListsDropDownList.Items.Clear();

                SPWeb web;
                if (WebUrlTextBox.Text.Trim() == string.Empty)
                {
                    web = Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context);
                }
                else
                {
                    SPSite st = new SPSite(new Uri(Page.Request.Url, WebUrlTextBox.Text, true).ToString());
                    st.CatchAccessDeniedException = false;
                    web = st.OpenWeb();
                }

                WebUrlTextBox.Text            = web.Url;
                web.Lists.ListsForCurrentUser = true;
                foreach (SPList list in web.Lists)
                {
                    AvailableListsDropDownList.Items.Add(list.Title);

                    if (wp.ListName == list.Title)
                    {
                        AvailableListsDropDownList.SelectedIndex = AvailableListsDropDownList.Items.Count - 1;
                    }
                }

                LoadViews();
            }
            catch (Exception ex) { logger.LogError(ex); }
        }
        /// <summary>
        /// Loads the values fro mth eweb part.
        /// Use force=true to force replace of view state values.
        /// </summary>
        /// <param name="force">Override values</param>
        void LoadWebPartProperties(bool force)
        {
            this.EnsureChildControls();

            if (force || ViewState["ListConnectionToolPartLoaded" + this.WebPartToEdit.UniqueID] == null || (bool)ViewState["ListConnectionToolPartLoaded" + this.WebPartToEdit.UniqueID] != true)
            {
                ViewState["ListConnectionToolPartLoaded" + this.WebPartToEdit.UniqueID] = true;

                ListMarquee wp = this.WebPartToEdit as ListMarquee;

                if (force || this.WebUrlTextBox.Text == string.Empty)
                {
                    if (wp.ListWebUrl.Trim() == string.Empty)
                    {
                        WebUrlTextBox.Text = Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context).Url;
                    }
                    else
                    {
                        WebUrlTextBox.Text = wp.ListWebUrl;
                    }
                    LoadListButton_Click(null, null);
                }
            }
        }
        /// <summary>
        /// Loads the values from the web part.
        /// Use force=true to force replace of view state values.
        /// </summary>
        /// <param name="force">Override values</param>
        void LoadWebPartProperties(bool force)
        {
            this.EnsureChildControls();

            if (force || ViewState["MarqueeToolPartLoaded" + this.WebPartToEdit.UniqueID] == null || (bool)ViewState["MarqueeToolPartLoaded" + this.WebPartToEdit.UniqueID] != true)
            {
                ViewState["MarqueeToolPartLoaded" + this.WebPartToEdit.UniqueID] = true;

                ListMarquee wp = this.WebPartToEdit as ListMarquee;

                if (force || this.TitleFieldNameTextBox.Text == string.Empty)
                {
                    this.TitleFieldNameTextBox.Text = wp.TitleFieldName;
                }
                if (force || this.BodyFieldNameTextBox.Text == string.Empty)
                {
                    this.BodyFieldNameTextBox.Text = wp.BodyFieldName;
                }
                if (force || this.MarqueeSpeedTextBox.Text == string.Empty)
                {
                    this.MarqueeSpeedTextBox.Text = wp.MarqueeDelay.ToString();
                }
                if (force || this.MarqueeStepSizeTextBox.Text == string.Empty)
                {
                    this.MarqueeStepSizeTextBox.Text = wp.MarqueeAmount.ToString();
                }
                if (force || this.MarqueeDirectionListBox.Items.Count == 0)
                {
                    LoadMarqueeDirectionListBox(wp.MarqueeDirection);
                }
                if (force || this.MarqueeLinkTargetListBox.Items.Count == 0)
                {
                    LoadMarqueeLinkTargetListBox(wp.LinkTarget);
                }
            }
        }