1.1 --- a/Server/FormEditObject.cs Tue Aug 16 12:59:32 2016 +0200
1.2 +++ b/Server/FormEditObject.cs Wed Aug 17 13:41:26 2016 +0200
1.3 @@ -35,7 +35,7 @@
1.4 /// <param name="e"></param>
1.5 private void FormEditAction_Load(object sender, EventArgs e)
1.6 {
1.7 - // Populate registered actions
1.8 + // Populate registered object types
1.9 IEnumerable < Type > types = Reflection.GetConcreteClassesDerivedFrom<T>();
1.10 foreach (Type type in types)
1.11 {
1.12 @@ -90,10 +90,10 @@
1.13 /// <summary>
1.14 /// Get properties values from our generated input fields
1.15 /// </summary>
1.16 - private void FetchPropertiesValue(T aAction)
1.17 + private void FetchPropertiesValue(T aObject)
1.18 {
1.19 int ctrlIndex = 0;
1.20 - foreach (PropertyInfo pi in aAction.GetType().GetProperties())
1.21 + foreach (PropertyInfo pi in aObject.GetType().GetProperties())
1.22 {
1.23 AttributeObjectProperty[] attributes =
1.24 ((AttributeObjectProperty[]) pi.GetCustomAttributes(typeof(AttributeObjectProperty), true));
1.25 @@ -109,7 +109,7 @@
1.26 continue;
1.27 }
1.28
1.29 - GetPropertyValueFromControl(iTableLayoutPanel.Controls[ctrlIndex+1], pi, aAction); //+1 otherwise we get the label
1.30 + GetPropertyValueFromControl(iTableLayoutPanel.Controls[ctrlIndex+1], pi, aObject); //+1 otherwise we get the label
1.31
1.32 ctrlIndex+=2; //Jump over the label too
1.33 }
1.34 @@ -118,13 +118,13 @@
1.35 /// <summary>
1.36 /// Extend this function to support reading new types of properties.
1.37 /// </summary>
1.38 - /// <param name="aAction"></param>
1.39 - private void GetPropertyValueFromControl(Control aControl, PropertyInfo aInfo, T aAction)
1.40 + /// <param name="aObject"></param>
1.41 + private void GetPropertyValueFromControl(Control aControl, PropertyInfo aInfo, T aObject)
1.42 {
1.43 if (aInfo.PropertyType == typeof(int))
1.44 {
1.45 NumericUpDown ctrl=(NumericUpDown)aControl;
1.46 - aInfo.SetValue(aAction,(int)ctrl.Value);
1.47 + aInfo.SetValue(aObject,(int)ctrl.Value);
1.48 }
1.49 else if (aInfo.PropertyType.IsEnum)
1.50 {
1.51 @@ -134,27 +134,30 @@
1.52 enumValue = Enum.Parse(aInfo.PropertyType,((ComboBox)aControl).SelectedItem.ToString());
1.53 //enumValue = ((ComboBox)aControl).SelectedValue;
1.54 // Set enum value
1.55 - aInfo.SetValue(aAction, enumValue);
1.56 + aInfo.SetValue(aObject, enumValue);
1.57 }
1.58 else if (aInfo.PropertyType == typeof(bool))
1.59 {
1.60 CheckBox ctrl = (CheckBox)aControl;
1.61 - aInfo.SetValue(aAction, ctrl.Checked);
1.62 + aInfo.SetValue(aObject, ctrl.Checked);
1.63 }
1.64 else if (aInfo.PropertyType == typeof(string))
1.65 {
1.66 TextBox ctrl = (TextBox)aControl;
1.67 - aInfo.SetValue(aAction, ctrl.Text);
1.68 + aInfo.SetValue(aObject, ctrl.Text);
1.69 }
1.70 //TODO: add support for other types here
1.71 }
1.72
1.73 +
1.74 /// <summary>
1.75 - ///
1.76 + /// Create a control for the given property.
1.77 /// </summary>
1.78 /// <param name="aInfo"></param>
1.79 - /// <param name="action"></param>
1.80 - private Control CreateControlForProperty(PropertyInfo aInfo, AttributeObjectProperty aAttribute, T aAction)
1.81 + /// <param name="aAttribute"></param>
1.82 + /// <param name="aObject"></param>
1.83 + /// <returns></returns>
1.84 + private Control CreateControlForProperty(PropertyInfo aInfo, AttributeObjectProperty aAttribute, T aObject)
1.85 {
1.86 if (aInfo.PropertyType == typeof(int))
1.87 {
1.88 @@ -164,7 +167,7 @@
1.89 ctrl.Minimum = Int32.Parse(aAttribute.Minimum);
1.90 ctrl.Maximum = Int32.Parse(aAttribute.Maximum);
1.91 ctrl.Increment = Int32.Parse(aAttribute.Increment);
1.92 - ctrl.Value = (int)aInfo.GetValue(aAction);
1.93 + ctrl.Value = (int)aInfo.GetValue(aObject);
1.94 return ctrl;
1.95 }
1.96 else if (aInfo.PropertyType.IsEnum)
1.97 @@ -194,7 +197,7 @@
1.98
1.99 // Instantiate our enum
1.100 object enumValue = Activator.CreateInstance(aInfo.PropertyType);
1.101 - enumValue = aInfo.GetValue(aAction);
1.102 + enumValue = aInfo.GetValue(aObject);
1.103 //Set the current item
1.104 ctrl.SelectedItem = enumValue.ToString();
1.105
1.106 @@ -205,14 +208,14 @@
1.107 CheckBox ctrl = new CheckBox();
1.108 ctrl.AutoSize = true;
1.109 ctrl.Text = aAttribute.Description;
1.110 - ctrl.Checked = (bool)aInfo.GetValue(aAction);
1.111 + ctrl.Checked = (bool)aInfo.GetValue(aObject);
1.112 return ctrl;
1.113 }
1.114 else if (aInfo.PropertyType == typeof(string))
1.115 {
1.116 TextBox ctrl = new TextBox();
1.117 ctrl.AutoSize = true;
1.118 - ctrl.Text = (string)aInfo.GetValue(aAction);
1.119 + ctrl.Text = (string)aInfo.GetValue(aObject);
1.120 return ctrl;
1.121 }
1.122 //TODO: add support for other control type here
1.123 @@ -253,7 +256,7 @@
1.124 /// Fields must be specified by rows from the left.
1.125 /// </summary>
1.126 /// <param name="aLayout"></param>
1.127 - private void UpdateTableLayoutPanel(T aAction)
1.128 + private void UpdateTableLayoutPanel(T aObject)
1.129 {
1.130 toolTip.RemoveAll();
1.131 //Debug.Print("UpdateTableLayoutPanel")
1.132 @@ -269,17 +272,17 @@
1.133 iTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
1.134
1.135
1.136 - if (aAction == null)
1.137 + if (aObject == null)
1.138 {
1.139 //Just drop it
1.140 return;
1.141 }
1.142
1.143 - //IEnumerable<PropertyInfo> properties = aAction.GetType().GetProperties().Where(
1.144 + //IEnumerable<PropertyInfo> properties = aObject.GetType().GetProperties().Where(
1.145 // prop => Attribute.IsDefined(prop, typeof(AttributeObjectProperty)));
1.146
1.147
1.148 - foreach (PropertyInfo pi in aAction.GetType().GetProperties())
1.149 + foreach (PropertyInfo pi in aObject.GetType().GetProperties())
1.150 {
1.151 AttributeObjectProperty[] attributes = ((AttributeObjectProperty[])pi.GetCustomAttributes(typeof(AttributeObjectProperty), true));
1.152 if (attributes.Length != 1)
1.153 @@ -291,7 +294,7 @@
1.154
1.155 //Before anything we need to check if that kind of property is supported by our UI
1.156 //Create the editor
1.157 - Control ctrl = CreateControlForProperty(pi, attribute, aAction);
1.158 + Control ctrl = CreateControlForProperty(pi, attribute, aObject);
1.159 if (ctrl == null)
1.160 {
1.161 //Property type not supported