コード例 #1
0
        /// <summary>
        /// Applies the settings of this attribute to the given configuration entry.
        /// </summary>
        /// <param name="Entry"></param>
        public void ApplyToConfigurationEntry(ConfigurationEntry Entry) {
            Entry.Text = Text;
            Entry.SubText = SubText;
            Entry.SortKey = SortKey;
            Entry.GroupKey = GroupKey;
            Entry.ReadOnly = ReadOnly;
            Entry.Minimum = Minimum;
            Entry.Maximum = Maximum;
            Entry.ControlType = ControlType;

            if (!String.IsNullOrEmpty(Validator)) {
                String[] validators = Validator.Split(',');
                foreach (String v in validators) {
                    String validator = v.Trim();
                    if (String.IsNullOrEmpty(validator))
                        continue;

                    if (AvailableValidators.ContainsKey(validator))
                        Entry.ValidateValue += new ConfigurationEntry.ValidateEvent(AvailableValidators[validator]);
                    else
                            throw new ArgumentException(String.Format("Unknown validator: {0}", validator), "Validator");
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Add a new <see cref="ConfigurationEntry"/> to the set.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public ConfigurationEntry Add(ConfigurationEntry key) {
     Data.Add(key);
     return key;
 }
コード例 #3
0
        void config_ValidateValue(ConfigurationEntry Sender, ref object Value, out bool Valid) {
            Valid = true;
            if (ValidateValue == null)
                return;

            try {
                Valid = (bool)DirectInvoker.InvokeDirect(ValidateValue, SelectedRecord, new object[] { Value });
            } catch {
                Valid = false;
            }
        }
コード例 #4
0
        /// <summary>
        /// Generic validator for directories. Checks if a directory exists.
        /// </summary>
        /// <param name="Sender">The configuration entry for which the given <paramref name="Value"/> should be validated.</param>
        /// <param name="Value">The value to validate.</param>
        /// <param name="Valid">True if the value is valid or has been converted into a valid value, otherwise false.</param>
        public static void ValidateDirectoryExists(ConfigurationEntry Sender, ref object Value, out bool Valid) {
            Valid = false;
            if (Value == null)
                return;

            String val = Value.ToString();

            // Accept empty strings
            if (String.IsNullOrEmpty(val)) {
                Valid = true;
                return;
            }

            Valid = Directory.Exists(val);
        }
コード例 #5
0
        /// <summary>
        /// Generic validator for Double values. Includes constraint checking by respecting <see cref="Minimum"/> and <see cref="Maximum"/> values.
        /// </summary>
        /// <param name="Sender">The configuration entry for which the given <paramref name="Value"/> should be validated.</param>
        /// <param name="Value">The value to validate.</param>
        /// <param name="Valid">True if the value is valid or has been converted into a valid value, otherwise false.</param>
        public static void ValidateDoubleValue(ConfigurationEntry Sender, ref object Value, out bool Valid) {
            Valid = false;

            // Value conversion
            Double temp_value = 0.0;
            if (Value is Double) {
                Valid = true;
                temp_value = (Double)Value;
            } else if (Value != null && Double.TryParse(Value.ToString(), out temp_value)) {
                Valid = true;
            }

            // Constraint checking
            Double min = ToDouble(Sender.Minimum, Double.MinValue);
            Double max = ToDouble(Sender.Maximum, Double.MaxValue);
            if (Valid)
                Valid = temp_value >= min && temp_value <= max;

            // Transformation
            if (Valid)
                Value = temp_value;
        }
コード例 #6
0
        FileSystemBrowser AddFileSystemBrowserToRow(ConfigurationEntry Entry, Int32 Row, Boolean IsDirectoryBrowser) {
            FileSystemBrowser control = new FileSystemBrowser();
            ApplyBasicControlSettings(control, Entry, 1, Row);

            // Layout
            control.Anchor = AnchorStyles.Left | AnchorStyles.Right;

            // Content
            control.IsDirectoryBrowser = IsDirectoryBrowser;
            control.Value = Entry.ValueAsString;
            control.ValueChanged += new EventHandler(control_ValueChanged);

            return control;
        }
コード例 #7
0
        bool SetEditor(ConfigurationEntry Sender, IWin32Window Owner) {
            HasManyEditForm.SelectRecords(Owner, "Play around", this, "Set");

            // Nothing else to save, the has-many-set has been saved by the edit form.
            return false;
        }
コード例 #8
0
        string entry_FormatValue(ConfigurationEntry Sender, object Value) {
            String value_as_string = (Value == null ? "" : Value.ToString());

            if (BoundObject == null)
                return value_as_string;

            String method_name = Sender.Name + "FormatValue";

            Type t = GetDirectType(BoundObject);
            MethodInfo method = t.GetMethod(method_name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            if (method == null)
                return value_as_string;

            return (string)method.Invoke(BoundObject, new object[] { Sender, Value });
        }
コード例 #9
0
        void ApplyBasicControlSettings(Control Control, ConfigurationEntry Entry, Int32 Column, Int32 Row) {
            if (Entry != null) {
                Control.Tag = Entry;
                Control.Enabled = !Entry.ReadOnly;
                Control.Leave += new EventHandler(control_Leave);
            }

            Table.Controls.Add(Control);
            Table.SetCellPosition(Control, new TableLayoutPanelCellPosition(Column, Row));
        }
コード例 #10
0
        bool entry_Editor(ConfigurationEntry Sender, IWin32Window Owner) {
            if (BoundObject == null)
                return false;

            String method_name = Sender.Name + "Editor";

            Type t = GetDirectType(BoundObject);
            MethodInfo method = t.GetMethod(method_name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

            if (method == null)
                return false;

            return (bool)DirectInvoker.InvokeDirect(method, BoundObject, new object[] { Sender, Owner });
        }
コード例 #11
0
        void entry_QueryPossibleValues(ConfigurationEntry Sender, out object[] PossibleValues) {
            PossibleValues = null;
            if (BoundObject == null)
                return;

            String property_name = Sender.Name + "PossibleValues";

            Type t = GetDirectType(BoundObject);
            PropertyInfo prop = t.GetProperty(property_name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            if (prop == null)
                return;

            PossibleValues = (object[])prop.GetValue(BoundObject, null);
        }
コード例 #12
0
        protected ConfigurationEntry AddByPropertyWithAttribute(Object BoundObject, PropertyInfo Property) {
            Object[] attrs = Property.GetCustomAttributes(typeof(ConfigurationAttribute), true);
            if (attrs.Length <= 0)
                return null;

            ConfigurationAttribute attr = (ConfigurationAttribute)attrs[0];

            ConfigurationEntry entry = new ConfigurationEntry();

            entry.Name = Property.Name;
            attr.ApplyToConfigurationEntry(entry);

            if (BoundObject == null)
                entry.Value = null;
            else
                entry.Value = Property.GetValue(BoundObject, null);

            entry.PropertyChanged += new PropertyChangedEventHandler(entry_PropertyChanged);
            entry.QueryPossibleValues += new ConfigurationEntry.QueryPossibleValuesEvent(entry_QueryPossibleValues);
            entry.Editor += new ConfigurationEntry.EditorHandler(entry_Editor);
            entry.FormatValue += new ConfigurationEntry.FormatValueHandler(entry_FormatValue);

            if (entry.SortKey == 0)
                entry.SortKey = Data.Count;

            Add(entry);

            return entry;
        }
コード例 #13
0
 /// <summary>
 /// Remove a <see cref="ConfigurationEntry"/> from the set.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool Remove(ConfigurationEntry key) {
     return Data.Remove(key);
 }
コード例 #14
0
 /// <summary>
 /// Check if a <see cref="ConfigurationEntry"/> has already been added to the set.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool Contains(ConfigurationEntry key) {
     return Data.Contains(key);
 }
コード例 #15
0
        Button AddButtonToRow(ConfigurationEntry Entry, Int32 Row) {
            Button btn = new Button();
            ApplyBasicControlSettings(btn, Entry, 1, Row);
            
            // Layout
            btn.BackColor = SystemColors.ButtonFace;

            // Content
            btn.Text = "Ändern";
            btn.Click += new EventHandler(btn_Click);

            return btn;
        }
コード例 #16
0
        TextBox AddTextBoxToRow(ConfigurationEntry Entry, Int32 Row) {
            TextBox control = new TextBox();
            ApplyBasicControlSettings(control, Entry, 1, Row);
            
            // Layout
            control.Anchor = AnchorStyles.Right | AnchorStyles.Left;

            // Content
            control.Text = Entry.ValueAsString;
            control.TextChanged += new EventHandler(control_ValueChanged);

            return control;
        }
コード例 #17
0
        LabelSlider AddLabelSliderToRow(ConfigurationEntry Entry, Int32 Row) {
            LabelSlider sld = new LabelSlider();
            ApplyBasicControlSettings(sld, Entry, 1, Row);

            // Layout
            sld.Anchor = AnchorStyles.Right | AnchorStyles.Left;

            // Content
            sld.FormatValue += new LabelSlider.FormatValueEvent(sld_FormatValue);
            sld.Minimum = ConfigurationEntry.ToInt32(Entry.Minimum, 0);
            sld.Maximum = ConfigurationEntry.ToInt32(Entry.Maximum, 10);
            sld.SmallChange = 1;
            sld.LargeChange = Convert.ToInt32(Math.Round((Convert.ToDouble(sld.Maximum - sld.Minimum)) / 10.0));
            sld.Value = ConfigurationEntry.ToInt32(Entry.Value, sld.Minimum);
            sld.ValueChanged += new EventHandler(control_ValueChanged);

            return sld;
        }
コード例 #18
0
        TextBox AddMultilineBoxToRow(ConfigurationEntry Entry, Int32 Row) {
            TextBox control = AddTextBoxToRow(Entry, Row);

            control.Multiline = true;
            control.Height = control.Height * 3;
            control.ScrollBars = ScrollBars.Vertical;
            control.WordWrap = true;

            return control;
        }
コード例 #19
0
        Boolean ValidateValueOfControl(Control Control, ConfigurationEntry Entry, ref Object Value) {
            Boolean result = Entry.IsValueValid(ref Value);
            
            if (result) {
                Control.BackColor = SystemColors.Window;

                if (AutoSave) {
                    Saving = true;
                    Entry.Value = Value;
                    Saving = false;
                }
            } else {
                Control.BackColor = Color.Red;
            }

            return result;
        }
コード例 #20
0
        ComboBox AddComboBoxToRow(ConfigurationEntry Entry, Int32 Row) {
            ComboBox cbx = new ComboBox();
            ApplyBasicControlSettings(cbx, Entry, 1, Row);
            
            // Layout
            cbx.Anchor = AnchorStyles.Right | AnchorStyles.Left;

            // Content
            cbx.DropDownStyle = ComboBoxStyle.DropDownList;
            object[] values = Entry.GetPossibleValues();
            if (values != null && values.Length > 0)
                cbx.Items.AddRange(values);
            if (Entry.Value != null)
                cbx.SelectedIndex = cbx.Items.IndexOf(Entry.Value);
            cbx.SelectedIndexChanged += new EventHandler(control_ValueChanged);

            return cbx;
        }
コード例 #21
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="Text">Label text naming a property in a very short manner.</param>
 /// <param name="SortKey">Using this the order of all configurable properties is determined.</param>
 /// <param name="GroupKey">Configurable properties are grouped using this.</param>
 /// <param name="ControlType">Defines the GUI control that should be used when editing a property.</param>
 public ConfigurationAttribute(String Text, Int32 SortKey, Object GroupKey, ConfigurationEntry.ControlTypes ControlType) {
     this.Text = Text;
     this.SortKey = SortKey;
     this.GroupKey = GroupKey;
     this.ControlType = ControlType;
 }
コード例 #22
0
        LinkLabel AddLinkLabelToRow(ConfigurationEntry Entry, Int32 Row) {
            LinkLabel control = new LinkLabel();
            ApplyBasicControlSettings(control, Entry, 1, Row);

            // Layout
            control.AutoSize = true;
            control.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
            control.TextAlign = ContentAlignment.TopLeft;
            control.Margin = new Padding(
                control.Margin.Left,
                control.Margin.Top + (int)control.Font.Size,
                control.Margin.Right,
                control.Margin.Bottom);
            control.AutoEllipsis = true;

            // Content
            var default_text = "<Bitte auswählen>";
            control.Text = Entry.GetValueAsString(Entry.Value, default_text);
            if (String.IsNullOrEmpty(control.Text)) // Empty strings hide the label and the user will not
                control.Text = default_text;        // be able to click on it anymore -- catch that here.
            control.LinkClicked += new LinkLabelLinkClickedEventHandler(linklabel_LinkClicked);

            return control;
        }
コード例 #23
0
        /// <summary>
        /// Generic validator for Int32 values. Includes constraint checking by respecting <see cref="Minimum"/> and <see cref="Maximum"/> values.
        /// </summary>
        /// <param name="Sender">The configuration entry for which the given <paramref name="Value"/> should be validated.</param>
        /// <param name="Value">The value to validate.</param>
        /// <param name="Valid">True if the value is valid or has been converted into a valid value, otherwise false.</param>
        public static void ValidateInt32Value(ConfigurationEntry Sender, ref object Value, out bool Valid) {
            Valid = false;

            // Value conversion
            Int32 temp_value = 0;
            if (Value is Int32) {
                Valid = true;
                temp_value = (Int32)Value;
            } else if (Value != null && Int32.TryParse(Value.ToString(), out temp_value)) {
                Valid = true;
            }

            // Constraint checking
            Int32 min = ToInt32(Sender.Minimum, Int32.MinValue);
            Int32 max = ToInt32(Sender.Maximum, Int32.MaxValue);
            if (Valid)
                Valid = temp_value >= min && temp_value <= max;

            // Transformation
            if (Valid)
                Value = temp_value;
        }
コード例 #24
0
        CheckBox AddCheckBoxToRow(ConfigurationEntry Entry, Int32 Row) {
            CheckBox cb = new CheckBox();
            ApplyBasicControlSettings(cb, Entry, 1, Row);
            
            // Layout
            cb.Anchor = AnchorStyles.Right | AnchorStyles.Left;

            // Content
            cb.Text = Entry.Text;
            cb.Checked = (Entry.Value == null ? false : Entry.Value is Boolean ? (Boolean)Entry.Value : Boolean.Parse(Entry.Value.ToString()));
            cb.CheckedChanged += new EventHandler(control_ValueChanged);

            return cb;
        }
コード例 #25
0
        /// <summary>
        /// Generic validator for Boolean values.
        /// </summary>
        /// <param name="Sender">The configuration entry for which the given <paramref name="Value"/> should be validated.</param>
        /// <param name="Value">The value to validate.</param>
        /// <param name="Valid">True if the value is valid or has been converted into a valid value, otherwise false.</param>
        public static void ValidateBooleanValue(ConfigurationEntry Sender, ref object Value, out bool Valid) {
            Valid = false;

            if (Value == null || (Value is String && (String)Value == "")) {
                Value = false;
                Valid = true;
                return;
            }

            Boolean bool_value;
            if (Boolean.TryParse(Value.ToString(), out bool_value)) {
                Value = bool_value;
                Valid = true;
                return;
            }
        }
コード例 #26
0
        Label AddLabelToRow(ConfigurationEntry Entry, Int32 Row) {
            Label lbl = new Label();
            ApplyBasicControlSettings(lbl, Entry, 1, Row);

            // Layout
            lbl.AutoSize = true;
            lbl.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
            lbl.TextAlign = ContentAlignment.TopLeft;
            lbl.Margin = new Padding(
                lbl.Margin.Left,
                lbl.Margin.Top + (int)lbl.Font.Size,
                lbl.Margin.Right,
                lbl.Margin.Bottom);
            lbl.AutoEllipsis = true;
            
            // Content
            lbl.Text = Entry.ValueAsString;

            return lbl;
        }
コード例 #27
0
        /// <summary>
        /// Creates a new <see cref="Common.Configuration.ConfigurationEntry"/> according to the collection and
        /// assigns it to the matrix.
        /// </summary>
        protected virtual void CreateAndAssignConfiguration() {
            var config = new ConfigurationEntry();

            config.Value = Collection.CollectionDictionaryWithValues;
            config.PropertyChanged += new PropertyChangedEventHandler(config_PropertyChanged);
            config.ValidateValue += new ConfigurationEntry.ValidateEvent(config_ValidateValue);
            config.FormatValue += new ConfigurationEntry.FormatValueHandler(config_FormatValue);

            Matrix.ConfigEntry = config;
        }
コード例 #28
0
        Label AddSubTextLabelToRow(ConfigurationEntry Entry, Int32 Row) {
            Label lbl = new Label();
            ApplyBasicControlSettings(lbl, Entry, 1, Row);

            // Layout
            lbl.AutoSize = true;
            lbl.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
            lbl.TextAlign = ContentAlignment.TopLeft;
            lbl.ForeColor = SystemColors.GrayText;
            lbl.Margin = new Padding(lbl.Margin.Left, 0, lbl.Margin.Right,
                9);

            // Content
            lbl.Text = Entry.SubText;

            return lbl;
        }
コード例 #29
0
        string config_FormatValue(ConfigurationEntry Sender, object Value) {
            if (Value is IEditableDbRecord) {
                // Column and row headers ...
                return (Value as IEditableDbRecord).Name;
            } else {
                string result;
                try {
                    result = (string)DirectInvoker.InvokeDirect(FormatValue, SelectedRecord, new object[] { Value });
                } catch {
                    result = (Value == null ? "" : Value.ToString());
                }

                return result;
            }
        }
コード例 #30
0
 /// <summary>
 /// Add a new <see cref="ConfigurationEntry"/> to the set.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public ConfigurationEntry Add(ConfigurationEntry key, object value) {
     key.Value = value;
     Data.Add(key);
     return key;
 }