Exemplo n.º 1
0
        // NOTE: AppliedDeviceFiltersDialog also uses this test...
        internal static bool NewLabelIsLegal(
            ISite site,
            EditableTreeList filterList,
            String oldLabel,
            String newLabel,
            String errorDialogTitle
            )
        {
            Debug.Assert(site != null);

            if (newLabel.Length == 0)
            {
                GenericUI.ShowWarningMessage(
                    errorDialogTitle,
                    SR.GetString(SR.DeviceFilterEditorDialog_UnnamedFilter)
                    );
                return(false);
            }

            /* Removed for DCR 4240
             * if (!DesignerUtility.IsValidName(newLabel))
             * {
             *  GenericUI.ShowWarningMessage(
             *      errorDialogTitle,
             *      SR.GetString(SR.DeviceFilterEditorDialog_IllegalName, newLabel)
             *  );
             *  return false;
             * }
             */

            return(true);
        }
Exemplo n.º 2
0
        private bool FiltersAreValid()
        {
            #if DEBUG
            Debug.Assert(
                !Debug_DuplicateFiltersExist(_filterList.TvList.Nodes),
                "UI failed to prevent duplicate filters from being created."
                );
            #endif

            ArrayList filtersInErrorList = new ArrayList();
            foreach (DeviceFilterTreeNode filterNode in _filterList.TvList.Nodes)
            {
                DeviceFilterNode filter = filterNode.DeviceFilter;
                if (!FilterIsLegal(filter))
                {
                    filtersInErrorList.Add(filter.Name);
                }
            }
            if (filtersInErrorList.Count != 0)
            {
                GenericUI.ShowWarningMessage(
                    SR.GetString(SR.DeviceFilterEditorDialog_Title),
                    SR.GetString(
                        SR.DeviceFilterEditorDialog_InvalidFilter,
                        GenericUI.BuildCommaDelimitedList(
                            filtersInErrorList
                            )
                        )
                    );
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        private void ApplyChoiceToRuntimeControl_helper(
            PropertyDescriptor property,
            Object target,
            String prefix
            )
        {
            String propertyName = prefix + property.Name;
            String value        = ((IAttributeAccessor)_choice).GetAttribute(propertyName) as String;

            if (property.Converter is ExpandableObjectConverter)
            {
                PropertyDescriptorCollection properties =
                    TypeDescriptor.GetProperties(
                        property.PropertyType
                        );
                foreach (PropertyDescriptor embeddedProperty in properties)
                {
                    if (IsDeviceOverridable(embeddedProperty))
                    {
                        ApplyChoiceToRuntimeControl_helper(
                            embeddedProperty,
                            property.GetValue(target),
                            propertyName + "-"
                            );
                    }
                }
                return;
            }

            if (value != null)
            {
                try
                {
                    property.SetValue(
                        target,
                        property.Converter.ConvertFromString(value)
                        );
                }
                catch
                {
                    GenericUI.ShowWarningMessage(
                        SR.GetString(SR.PropertyOverridesDialog_Title),
                        SR.GetString(
                            SR.PropertyOverridesDialog_InvalidPropertyValue,
                            value,
                            propertyName
                            )
                        );
                }
            }
        }
        private bool ValidateAppliedFilters()
        {
            StringCollection duplicateChoices =
                DesignerUtility.GetDuplicateChoiceTreeNodes(
                    _appliedFiltersList.TvList.Nodes
                    );

            if (duplicateChoices.Count > 0)
            {
                GenericUI.ShowWarningMessage(
                    SR.GetString(SR.AppliedDeviceFiltersDialog_Title),
                    SR.GetString(SR.AppliedDeviceFiltersDialog_DuplicateChoices,
                                 GenericUI.BuildCommaDelimitedList(duplicateChoices))
                    );
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
        private bool SaveFilters()
        {
            Cursor oldCursor = null;

            try
            {
                oldCursor   = this.Cursor;
                this.Cursor = Cursors.WaitCursor;

                ArrayList oldFilters = _webConfig.ReadDeviceFilters();
                foreach (DeviceFilterNode filter in oldFilters)
                {
                    filter.Delete();
                }

                _webConfig.EnsureSystemWebSectionIsPresent();
                foreach (DeviceFilterTreeNode filter in _filterList.TvList.Nodes)
                {
                    filter.DeviceFilter.Save();
                }
                _webConfig.Save();
            }
            catch (FileNotFoundException)
            {
                this.Cursor = oldCursor;
                GenericUI.ShowWarningMessage(
                    SR.GetString(SR.DeviceFilterEditorDialog_Title),
                    SR.GetString(SR.DeviceFilterEditorDialog_WebConfigMissing)
                    );
                return(false);
            }
            catch (Exception e)
            {
                this.Cursor = oldCursor;
                GenericUI.ShowWarningMessage(
                    SR.GetString(SR.DeviceFilterEditorDialog_Title),
                    SR.GetString(SR.DeviceFilterEditorDialog_WebConfigParsingError, e.Message)
                    );
                Debug.Fail(e.ToString());
                return(false);
            }
            this.Cursor = oldCursor;
            return(true);
        }
        private void OnAfterLabelEdit(Object sender, NodeLabelEditEventArgs e)
        {
            // null still returned if label unmodified (verified 2310)
            if (e.Label == null)
            {
                return;
            }

            String oldLabel = e.Node.Text;
            String newLabel = e.Label;

            bool labelIsLegal = true;

            if (!DeviceFilterEditorDialog.NewLabelIsLegal(
                    _designer.UnderlyingControl.Site,
                    _appliedFiltersList,
                    oldLabel,
                    newLabel,
                    SR.GetString(SR.AppliedDeviceFiltersDialog_Title)
                    ))
            {
                labelIsLegal = false;
            }
            else if (IsDefaultFilter(newLabel))
            {
                GenericUI.ShowWarningMessage(
                    SR.GetString(SR.AppliedDeviceFiltersDialog_Title),
                    SR.GetString(SR.DeviceFilterEditorDialog_IllegalDefaultName)
                    );
                labelIsLegal = false;
            }

            if (!labelIsLegal)
            {
                e.CancelEdit = true;
                return;
            }

            ((ChoiceTreeNode)e.Node).Name = newLabel;
            EnsureDefaultFilterAvailableXorApplied();
            SetDirty(true);
            UpdateUI();
        }
Exemplo n.º 7
0
        private bool ValidateLoadedChoices()
        {
            StringCollection duplicateChoices =
                DesignerUtility.GetDuplicateChoiceTreeNodes(
                    _cbChoices.Items
                    );

            if (duplicateChoices.Count > 0)
            {
                if (!_ignoreSelectionChanged)
                {
                    GenericUI.ShowWarningMessage(
                        SR.GetString(SR.PropertyOverridesDialog_Title),
                        SR.GetString(SR.PropertyOverridesDialog_DuplicateChoices,
                                     GenericUI.BuildCommaDelimitedList(duplicateChoices))
                        );
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 8
0
        private void OnAfterLabelEdit(Object sender, NodeLabelEditEventArgs e)
        {
            // null still returned if label unmodified (verified 2310)
            if (e.Label == null)
            {
                return;
            }

            String oldLabel = e.Node.Text;
            String newLabel = e.Label;

            if (String.Compare(oldLabel, newLabel, StringComparison.OrdinalIgnoreCase) != 0 &&
                _filterList.LabelExists(newLabel))
            {
                // if the filter is duplicate
                GenericUI.ShowWarningMessage(
                    SR.GetString(SR.DeviceFilterEditorDialog_Title),
                    SR.GetString(SR.DeviceFilterEditorDialog_DuplicateName, newLabel)
                    );
            }
            else if (String.Compare(newLabel, _nameOfDefaultFilter, StringComparison.OrdinalIgnoreCase) == 0)
            {
                GenericUI.ShowWarningMessage(
                    SR.GetString(SR.DeviceFilterEditorDialog_Title),
                    SR.GetString(SR.DeviceFilterEditorDialog_IllegalDefaultName, newLabel)
                    );
            }
            else if (NewLabelIsLegal(_site, _filterList, oldLabel, newLabel,
                                     SR.GetString(SR.DeviceFilterEditorDialog_Title)
                                     ))
            {
                // if the filter name is legal
                ((DeviceFilterTreeNode)e.Node).DeviceFilter.Name = e.Label;
                return;
            }
            // if the filter name was duplicate or not legal
            e.CancelEdit = true;
        }
Exemplo n.º 9
0
        // NOTE: A FileLoadException is thrown if an error occurs while reading
        //       web.config.
        internal DeviceFilterEditorDialog(ISite site, WebConfigManager webConfig) : base(site)
        {
            InitializeComponent();

            _lblArgument.Text  = SR.GetString(SR.DeviceFilterEditorDialog_Argument);
            _glAttributes.Text = SR.GetString(SR.DeviceFilterEditorDialog_Attributes);
            _lblMethod.Text    = SR.GetString(SR.DeviceFilterEditorDialog_Method);
            _glType.Text       = SR.GetString(SR.DeviceFilterEditorDialog_TypeGl);
            _rbCompare.Text    = SR.GetString(SR.DeviceFilterEditorDialog_Equality);
            _lblCompare.Text   = SR.GetString(SR.DeviceFilterEditorDialog_Compare);
            _rbDelegate.Text   = SR.GetString(SR.DeviceFilterEditorDialog_Evaluator);
            _lblType.Text      = SR.GetString(SR.DeviceFilterEditorDialog_TypeTxt);
            _lblHeader.Text    = SR.GetString(SR.DeviceFilterEditorDialog_Header);
            this.Text          = SR.GetString(SR.DeviceFilterEditorDialog_Title);

            int tabOffset = 0;

            this._pnlMain.TabIndex       = tabOffset++;
            this._filterList.TabIndex    = tabOffset++;
            this._pnlRight.TabIndex      = tabOffset++;
            this._glType.TabIndex        = tabOffset++;
            this._rbCompare.TabIndex     = tabOffset++;
            this._rbDelegate.TabIndex    = tabOffset++;
            this._glAttributes.TabIndex  = tabOffset++;
            this._pnlCompare.TabIndex    = tabOffset++;
            this._pnlDelegate.TabIndex   = tabOffset++;
            this._lblCompare.TabIndex    = tabOffset++;
            this._cbCompare.TabIndex     = tabOffset++;
            this._lblType.TabIndex       = tabOffset++;
            this._txtType.TabIndex       = tabOffset++;
            this._lblArgument.TabIndex   = tabOffset++;
            this._txtArgument.TabIndex   = tabOffset++;
            this._lblMethod.TabIndex     = tabOffset++;
            this._txtMethod.TabIndex     = tabOffset++;
            this._dialogButtons.TabIndex = tabOffset++;

            _webConfig = webConfig;
            this._site = site;
            GenericUI.InitDialog(this, site);

            _filterList.LblTitle.Text = SR.GetString(SR.DeviceFilterEditorDialog_DeviceFilters);
            _filterList.BtnAdd.Text   = SR.GetString(SR.DeviceFilterEditorDialog_NewDeviceFilter);

            // Attempt to load Device Filters
            ArrayList filters = null;

            try
            {
                filters = _webConfig.ReadDeviceFilters();
            }
            catch (FileNotFoundException e)
            {
                GenericUI.ShowWarningMessage(
                    SR.GetString(SR.DeviceFilterEditorDialog_Title),
                    SR.GetString(SR.DeviceFilterEditorDialog_WebConfigMissingOnOpen)
                    );
                throw new FileLoadException(
                          SR.GetString(SR.WebConfig_FileLoadException, e)
                          );
            }
            catch (Exception e)
            {
                if (e.Message.Equals(SR.GetString(SR.DeviceFilterEditorDialog_DuplicateNames)))
                {
                    GenericUI.ShowWarningMessage(
                        SR.GetString(SR.DeviceFilterEditorDialog_Title),
                        SR.GetString(SR.DeviceFilterEditorDialog_DuplicateNames)
                        );
                }
                else
                {
                    GenericUI.ShowWarningMessage(
                        SR.GetString(SR.DeviceFilterEditorDialog_Title),
                        SR.GetString(
                            SR.DeviceFilterEditorDialog_WebConfigParsingError,
                            e.Message
                            )
                        );
                }
                throw new FileLoadException(
                          SR.GetString(SR.WebConfig_FileLoadException, e)
                          );
            }

            // Make sure web.config is checked out before we make changes.
            _webConfig.EnsureWebConfigCheckedOut();

            // Insert the Device Filters into the List UI
            foreach (DeviceFilterNode filter in filters)
            {
                DeviceFilterTreeNode node = new DeviceFilterTreeNode(filter);
                _filterList.TvList.Nodes.Add(node);
            }

            // Make sure all filters have a name...
            // NOTE: Do not combine with the above loop or GetUniqueLabel()
            //       will not necessarily be unique.  It could be done if
            //       we wrote another implementation of GetUniqueLabel()
            //       that compared against filters [ArrayList returned
            //       from ReadDeviceFilters()].
            foreach (DeviceFilterTreeNode node in _filterList.TvList.Nodes)
            {
                if (String.IsNullOrEmpty(node.Text))
                {
                    node.Text = _filterList.GetUniqueLabel(
                        SR.GetString(SR.DeviceFilterNode_DefaultFilterName)
                        );
                }
            }

            // Initialize the UI
            _rbCompare.Click                  += new EventHandler(OnClickCompareRadioButton);
            _rbDelegate.Click                 += new EventHandler(OnClickDelegateRadioButton);
            _cbCompare.TextChanged            += new EventHandler(OnTextChanged);
            _cbCompare.SelectedIndexChanged   += new EventHandler(OnTextChanged);
            _txtArgument.TextChanged          += new EventHandler(OnTextChanged);
            _txtType.TextChanged              += new EventHandler(OnTextChanged);
            _txtMethod.TextChanged            += new EventHandler(OnTextChanged);
            _filterList.TvList.AfterLabelEdit += new NodeLabelEditEventHandler(OnAfterLabelEdit);
            _filterList.TvList.AfterSelect    += new TreeViewEventHandler(OnFilterSelected);
            _filterList.BtnAdd.Click          += new EventHandler(OnClickAddButton);
            _filterList.BtnRemove.Click       += new EventHandler(OnClickRemoveButton);
            _filterList.TvList.SelectedNode    = null;

            LoadAvailableCapabilities();
            UpdateButtonsEnabling();

            _dialogButtons.CmdOK.Click     += new EventHandler(OnClickOK);
            _dialogButtons.CmdCancel.Click += new EventHandler(OnClickCancel);
        }
        private void OnApplyFilter(Object sender, EventArgs e)
        {
            DeviceFilterNode filter = (DeviceFilterNode)_cbAvailableFilters.SelectedItem;

            if (filter == null)
            {
                String name = _cbAvailableFilters.Text;
                Debug.Assert(
                    ((name != null) && (name.Length > 0)),
                    "Should not be trying to apply a filter with none selected. "
                    + "Missed a call to UpdateUI()?"
                    );

                // If the user typed the name of a filter which exists in their
                // web.config, we need to find the original rather than create
                // a new external filter.
                filter = FindAvailableFilter(name);
                if (filter == null)
                {
                    /* Removed for DCR 4240
                     * if (!DesignerUtility.IsValidName(name))
                     * {
                     *  GenericUI.ShowWarningMessage(
                     *      SR.GetString(SR.AppliedDeviceFiltersDialog_Title),
                     *      SR.GetString(
                     *          SR.AppliedDeviceFiltersDialog_InvalidFilterName,
                     *          _cbAvailableFilters.Text
                     *      )
                     *  );
                     *  return;
                     * }
                     */

                    filter = CreateExternalFilter(_cbAvailableFilters.Text);
                }
            }
            ChoiceTreeNode choice = new ChoiceTreeNode(
                filter,
                _designer
                );

            if (IsDefaultFilter(filter.Name))
            {
                if (DefaultFilterIsApplied)
                {
                    // Do not allow user to apply default filter if already
                    // been applied.
                    GenericUI.ShowWarningMessage(
                        SR.GetString(SR.AppliedDeviceFiltersDialog_Title),
                        SR.GetString(SR.AppliedDeviceFiltersDialog_DefaultFilterAlreadyApplied)
                        );
                }
                else
                {
                    // Add the default filter to the end of the list and
                    // remove it from list of available filters.
                    _appliedFiltersList.TvList.Nodes.Add(choice);
                    RemoveAvailableFilter(filter);
                }
            }
            else
            {
                // All other filters are added to the beginning
                _appliedFiltersList.TvList.Nodes.Insert(0, choice);
            }
            SetDirty(true);
            UpdateUI();
        }