Exemplo n.º 1
0
        internal IControlHabanero ConfigureInputControl(UIFormField formField, out IControlMapper controlMapper)
        {
            IControlHabanero inputControl = ControlFactory.CreateControl
                                                (formField.ControlTypeName, formField.ControlAssemblyName);

            controlMapper = ControlMapper.Create
                                (formField.MapperTypeName, formField.MapperAssembly, inputControl, formField.PropertyName,
                                !formField.Editable, ControlFactory);
            controlMapper.ClassDef = GetClassDef(formField);
            SetInputControlAlignment(formField, inputControl);
            SetInputControlNumLines(formField, inputControl);

            controlMapper.SetPropertyAttributes(formField.Parameters);

            AddDecimalPlacesToNumericUpDown(formField, inputControl);

            AddComboBoxItems(formField, inputControl);

            AddEmailFunctionalityToTextBox(formField, inputControl);

            AddMultiLineTextbox(formField, inputControl);

            if (formField.KeepValuePrivate)
            {
                ITextBox tBox = inputControl as ITextBox;
                if (tBox != null)
                {
                    tBox.PasswordChar = '*';
                }
            }

            SetToolTip(formField, inputControl);
            return(inputControl);
        }
Exemplo n.º 2
0
 public static bool IsForProperty(this IControlMapper controlMapper, string propName)
 {
     if (controlMapper == null)
     {
         return(false);
     }
     return(controlMapper.PropertyName == propName);
 }
Exemplo n.º 3
0
        public void Test_UpdateErrorProviderError_WhenBOValid_ShouldClearErrorMessage()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDefWithUIDef();
            ContactPersonTestBO person       = ContactPersonTestBO.CreateUnsavedContactPerson("", "");
            PanelBuilder        panelBuilder = new PanelBuilder(GetControlFactory());
            IPanelInfo          panelInfo    = panelBuilder.BuildPanelForTab((UIFormTab)person.ClassDef.UIDefCol["default"].UIForm[0]);

            panelInfo.BusinessObject = person;
            IControlMapper SurnameControlMapper = panelInfo.FieldInfos["Surname"].ControlMapper;

            panelInfo.UpdateErrorProvidersErrorMessages();
            //---------------Assert Precondition----------------
            Assert.AreNotEqual("", SurnameControlMapper.GetErrorMessage());
            //---------------Execute Test ----------------------
            person.Surname = "SomeValue";
            panelInfo.UpdateErrorProvidersErrorMessages();
            //---------------Test Result -----------------------
            Assert.AreEqual("", SurnameControlMapper.GetErrorMessage());
        }
Exemplo n.º 4
0
        public void Test_UpdateErrorProviderError_WhenBOInvalid_ShouldSetErrorMessage()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDefWithUIDef();
            ContactPersonTestBO person = ContactPersonTestBO.CreateUnsavedContactPerson("", "");

            Habanero.Faces.Base.PanelBuilder panelBuilder = new Habanero.Faces.Base.PanelBuilder(GetControlFactory());
            IPanelInfo panelInfo = panelBuilder.BuildPanelForTab((UIFormTab)person.ClassDef.UIDefCol["default"].UIForm[0]);

            person.Surname           = TestUtil.GetRandomString();
            panelInfo.BusinessObject = person;
            IControlMapper SurnameControlMapper = panelInfo.FieldInfos["Surname"].ControlMapper;

            person.Surname = "";
            //---------------Assert Precondition----------------
            Assert.IsFalse(person.Status.IsValid());
            Assert.AreEqual("", SurnameControlMapper.GetErrorMessage());
            //---------------Execute Test ----------------------
            panelInfo.UpdateErrorProvidersErrorMessages();
            //---------------Test Result -----------------------
            Assert.AreNotEqual("", SurnameControlMapper.GetErrorMessage());
        }
Exemplo n.º 5
0
        internal IControlHabanero ConfigureInputControl(UIFormField formField, out IControlMapper controlMapper)
        {
            IControlHabanero inputControl = ControlFactory.CreateControl
                (formField.ControlTypeName, formField.ControlAssemblyName);
            controlMapper = ControlMapper.Create
                (formField.MapperTypeName, formField.MapperAssembly, inputControl, formField.PropertyName,
                 !formField.Editable, ControlFactory);
            controlMapper.ClassDef = GetClassDef(formField);
            SetInputControlAlignment(formField, inputControl);
            SetInputControlNumLines(formField, inputControl);
            
            controlMapper.SetPropertyAttributes(formField.Parameters);

            AddDecimalPlacesToNumericUpDown(formField, inputControl);

            AddComboBoxItems(formField, inputControl);

            AddEmailFunctionalityToTextBox(formField, inputControl);

            AddMultiLineTextbox(formField, inputControl);

            if (formField.KeepValuePrivate)
            {
                ITextBox tBox = inputControl as ITextBox;
                if(tBox != null)
                {
                    tBox.PasswordChar = '*';
                }
            }

            SetToolTip(formField, inputControl);
            return inputControl;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a new control mapper of a specified type.  If no 'mapperTypeName'
        /// has been specified, an appropriate mapper for standard controls will
        /// be assigned, depending on the type of control.
        /// </summary>
        /// <param name="mapperTypeName">The class name of the mapper type
        /// (e.g. ComboBoxMapper).  The current namespace of this
        /// ControlMapper class will then be prefixed to the name.</param>
        /// <param name="mapperAssembly">The assembly where the mapper is
        /// located</param>
        /// <param name="ctl">The control to be mapped</param>
        /// <param name="propertyName">The property name</param>
        /// <param name="isReadOnly">Whether the control is read-only</param>
        /// <returns>Returns a new object which is a subclass of ControlMapper</returns>
        /// <exception cref="UnknownTypeNameException">An exception is
        /// thrown if the mapperTypeName does not provide a type that is
        /// a subclass of the ControlMapper class.</exception>
        /// <param name="controlFactory">The control factory</param>
        public static IControlMapper Create
            (string mapperTypeName, string mapperAssembly, IControlHabanero ctl,
            string propertyName, bool isReadOnly,
            IControlFactory controlFactory)
        {
            if (string.IsNullOrEmpty(mapperTypeName))
            {
                mapperTypeName = "TextBoxMapper";
            }

            if (mapperTypeName == "TextBoxMapper" && !(ctl is ITextBox))
            {
                if (ctl is IComboBox)
                {
                    mapperTypeName = "LookupComboBoxMapper";
                }
                else if (ctl is ICheckBox)
                {
                    mapperTypeName = "CheckBoxMapper";
                }
                else if (ctl is IDateTimePicker)
                {
                    mapperTypeName = "DateTimePickerMapper";
                }
                else if (ctl is INumericUpDown)
                {
                    mapperTypeName = "NumericUpDownIntegerMapper";
                }
                else if (ctl is IExtendedComboBox)
                {
                    mapperTypeName = "ExtendedComboBoxMapper";
                }
                else if (ctl is IExtendedTextBox)
                {
                    mapperTypeName = "ExtendedTextBox";
                }
                else
                {
                    throw new InvalidXmlDefinitionException
                              (String.Format
                                  ("No suitable 'mapperType' has been provided in the class "
                                  + "definitions for the form control '{0}'.  Either add the "
                                  + "'mapperType' attribute or check that spelling and "
                                  + "capitalisation are correct.",
                                  ctl.Name));
                }
            }

            Type mapperType;

            if (String.IsNullOrEmpty(mapperAssembly))
            {
                string nspace = typeof(ControlMapper).Namespace;
                mapperType = Type.GetType(nspace + "." + mapperTypeName);
            }
            else
            {
                mapperType = TypeLoader.LoadType(mapperAssembly, mapperTypeName);
            }

            IControlMapper controlMapper = Create(mapperType, ctl, propertyName, isReadOnly, controlFactory);

            return(controlMapper);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a panel with the controls and dimensions as prescribed
        /// </summary>
        /// <param name="uiFormTab">The UIFormTab object</param>
        /// <returns>Returns the object containing the new panel</returns>
        private IPanelFactoryInfo CreateOnePanel(IUIFormTab uiFormTab)
        {
            if (uiFormTab.UIFormGrid != null)
            {
                return(CreatePanelWithGrid(uiFormTab.UIFormGrid));
            }
            IPanel            panel   = _controlFactory.CreatePanel(_controlFactory);
            IToolTip          toolTip = _controlFactory.CreateToolTip();
            GridLayoutManager manager = new GridLayoutManager(panel, _controlFactory);
            int rowCount = 0;
            int colCount = 0;

            colCount += uiFormTab.Count;
            foreach (UIFormColumn uiFormColumn in uiFormTab)
            {
                if (uiFormColumn.Count > rowCount)
                {
                    rowCount = uiFormColumn.Count;
                }
            }
            const int intNoOfLayoutGridColumnsPerPanel = 3;

            manager.SetGridSize(rowCount, colCount * intNoOfLayoutGridColumnsPerPanel);
            for (int col = 0; col < colCount; col++)
            {
                //Fixing the labels column widths
                manager.FixColumnBasedOnContents(col * intNoOfLayoutGridColumnsPerPanel);
            }

            ControlMapperCollection controlMappers = new ControlMapperCollection();

            controlMappers.BusinessObject = _currentBusinessObject;
            ITextBox temptb = _controlFactory.CreateTextBox();

            for (int row = 0; row < rowCount; row++)
            {
                manager.FixRow(row, temptb.Height);
            }
            manager.FixAllRowsBasedOnContents();
            GridLayoutManager.ControlInfo[,] controls =
                new GridLayoutManager.ControlInfo[rowCount, colCount *intNoOfLayoutGridColumnsPerPanel];
            int currentColumn = 0;

            foreach (UIFormColumn uiFormColumn in uiFormTab)
            {
                int currentRow = 0;
                foreach (UIFormField field in uiFormColumn)
                {
                    bool     isCompulsory;
                    ClassDef classDef = _currentBusinessObject.ClassDef;
                    PropDef  propDef  = (PropDef)field.GetPropDefIfExists(classDef);
                    if (propDef != null)
                    {
                        isCompulsory = propDef.Compulsory;
                    }
                    else
                    {
                        isCompulsory = false;
                    }
                    string labelCaption = field.GetLabel(classDef);
                    //                    BOPropCol boPropCol = _currentBusinessObject.Props;
                    //                    if (boPropCol.Contains(field.PropertyName))
                    //                    {
                    //                        IBOProp boProp = boPropCol[field.PropertyName];
                    //                        if (!boProp.HasDisplayName())
                    //                        {
                    //                            boProp.DisplayName = labelCaption;
                    //                        }
                    //                    }

                    IControlHabanero ctl          = CreateControl(field, _controlFactory);
                    bool             editable     = CheckIfEditable(field, ctl);
                    ILabel           labelControl = _controlFactory.CreateLabel(labelCaption, isCompulsory && editable);
                    controls[currentRow, currentColumn + 0] = new GridLayoutManager.ControlInfo(labelControl);

                    if (ctl is ITextBox && propDef != null)
                    {
                        if (propDef.PropertyType == typeof(bool))
                        {
                            ctl = _controlFactory.CreateCheckBox();
                        }
                        else if (propDef.PropertyType == typeof(string) && propDef.KeepValuePrivate)
                        {
                            ctl = _controlFactory.CreatePasswordTextBox();
                        }
                        else if (field.GetParameterValue("numLines") != null)
                        {
                            int numLines;
                            try
                            {
                                numLines = Convert.ToInt32(field.GetParameterValue("numLines"));
                            }
                            catch (Exception)
                            {
                                throw new InvalidXmlDefinitionException
                                          ("An error " + "occurred while reading the 'numLines' parameter "
                                          + "from the class definitions.  The 'value' "
                                          + "attribute must be a valid integer.");
                            }
                            if (numLines > 1)
                            {
                                ctl = _controlFactory.CreateTextBoxMultiLine(numLines);
                            }
                        }
                    }


                    if (ctl is ITextBox)
                    {
                        if (field.GetParameterValue("isEmail") != null)
                        {
                            string isEmailValue = (string)field.GetParameterValue("isEmail");
                            if (isEmailValue != "true" && isEmailValue != "false")
                            {
                                throw new InvalidXmlDefinitionException
                                          ("An error " + "occurred while reading the 'isEmail' parameter "
                                          + "from the class definitions.  The 'value' "
                                          + "attribute must hold either 'true' or 'false'.");
                            }

                            //bool isEmail = Convert.ToBoolean(isEmailValue);
                            //if (isEmail)
                            //{
                            //    ITextBox tb = (ITextBox) ctl;
                            //    tb.DoubleClick += _emailTextBoxDoubleClickedHandler;
                            //}
                        }
                    }
                    //if (ctl is IDateTimePicker)
                    //{
                    //    IDateTimePicker editor = (IDateTimePicker) ctl;
                    //    editor.Enter += DateTimePickerEnterHandler;
                    //}
                    //if (ctl is INumericUpDown)
                    //{
                    //    INumericUpDown upDown = (INumericUpDown) ctl;
                    //    upDown.Enter += UpDownEnterHandler;
                    //}



                    CheckGeneralParameters(field, ctl);

                    IControlMapper ctlMapper =
                        ControlMapper.Create
                            (field.MapperTypeName, field.MapperAssembly, ctl, field.PropertyName, !editable,
                            _controlFactory);
                    if (ctlMapper is ControlMapper)
                    {
                        ControlMapper controlMapper = (ControlMapper)ctlMapper;
                        controlMapper.SetPropertyAttributes(field.Parameters);
                    }
                    controlMappers.Add(ctlMapper);
                    ctlMapper.BusinessObject = _currentBusinessObject;

                    int colSpan = 1;
                    if (field.GetParameterValue("colSpan") != null)
                    {
                        try
                        {
                            colSpan = Convert.ToInt32(field.GetParameterValue("colSpan"));
                        }
                        catch (Exception)
                        {
                            throw new InvalidXmlDefinitionException
                                      ("An error " + "occurred while reading the 'colSpan' parameter "
                                      + "from the class definitions.  The 'value' " + "attribute must be a valid integer.");
                        }
                    }
                    colSpan = (colSpan - 1) * intNoOfLayoutGridColumnsPerPanel + 1; // must span label columns too

                    int rowSpan = 1;
                    if (field.GetParameterValue("rowSpan") != null)
                    {
                        try
                        {
                            rowSpan = Convert.ToInt32(field.GetParameterValue("rowSpan"));
                        }
                        catch (Exception)
                        {
                            throw new InvalidXmlDefinitionException
                                      ("An error " + "occurred while reading the 'rowSpan' parameter "
                                      + "from the class definitions.  The 'value' " + "attribute must be a valid integer.");
                        }
                    }
                    if (rowSpan == 1)
                    {
                        manager.FixRow(currentRow, ctl.Height);
                    }
                    controls[currentRow, currentColumn + 1] = new GridLayoutManager.ControlInfo(ctl, rowSpan, colSpan);
                    currentRow++;
                    string toolTipText = field.GetToolTipText(classDef);
                    if (!String.IsNullOrEmpty(toolTipText))
                    {
                        toolTip.SetToolTip(labelControl, toolTipText);
                        toolTip.SetToolTip(ctl, toolTipText);
                    }
                    //Hack brett trying to fix prob with dynamic properties
                    ctl.Width = 100;
                }

                currentColumn += 3;
            }
            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < colCount * intNoOfLayoutGridColumnsPerPanel; j++)
                {
                    if (controls[i, j] == null)
                    {
                        manager.AddControl(null);
                    }
                    else
                    {
                        manager.AddControl(controls[i, j]);
                        controls[i, j].Control.TabIndex = rowCount * j + i;
                    }
                }
            }
            for (int col = 0; col < colCount; col++)
            {
                if (uiFormTab[col].Width > -1)
                {
                    //Fix width of the control column e.g. textbox or combobox.
                    manager.FixColumn(col * intNoOfLayoutGridColumnsPerPanel + 1, uiFormTab[col].Width - manager.GetFixedColumnWidth(col * intNoOfLayoutGridColumnsPerPanel));
                }
                manager.FixColumn(col * intNoOfLayoutGridColumnsPerPanel + 2, 15);
            }

            panel.Height = manager.GetFixedHeightIncludingGaps();
            panel.Width  = manager.GetFixedWidthIncludingGaps();
            IPanelFactoryInfo panelFactoryInfo = new PanelFactoryInfo(panel, controlMappers, _uiDefName, _firstControl);

            panelFactoryInfo.MinimumPanelHeight = panel.Height;
            panelFactoryInfo.MinumumPanelWidth  = panel.Width;
            panelFactoryInfo.ToolTip            = toolTip;
            panelFactoryInfo.PanelTabText       = uiFormTab.Name;
            panelFactoryInfo.UIForm             = _uiForm;
            panelFactoryInfo.UiFormTab          = uiFormTab;
            return(panelFactoryInfo);
        }
Exemplo n.º 8
0
 internal static Control GetControl(this IControlMapper controlMapper)
 {
     return(controlMapper.Control == null ? null : controlMapper.Control.GetControl());
 }
 private IControlMapper AddMapper(IControlMapper mapper)
 {
     return(this.ControlMappers.Add(mapper));
 }
Exemplo n.º 10
0
 ///<summary>
 /// Constructs a Field info.
 ///</summary>
 ///<param name="propertyName">The property that this field info is for</param>
 ///<param name="labelControl">The label that this field info is wrapping</param>
 ///<param name="controlMapper">The control mapper that this field info is mapping</param>
 public FieldInfo(string propertyName, IControlHabanero labelControl, IControlMapper controlMapper)
 {
     PropertyName   = propertyName;
     LabelControl   = labelControl;
     _controlMapper = controlMapper;
 }