Builds an IPanelInfo that has the information required to link the IPanel built by the Panel Builder to the IBusinessObject with a certain layout (as defined by the LayoutManager (Currently Only the GridLayoutManager can be used).
The IPanel Built by the PanelBuilder has all the controls required for a IBusinessObject to be viewed and edited in. The Controls to be used are defind in the UIFormTab or the UIForm depending on whether the BuildPanelForForm(IUIForm) or BuildPanelForTab method is used.

The PanelBuilder can create a panel for any environment based on the implementation of IControlFactory that is passed through in the constructor.

Once the panel has been constructed, you will need to assign the instance of the business object. See IPanelInfo for these options. Once editing is completed, you will need to persist the changes. First call ApplyChangesToBusinessObject on the IPanelInfo object, and then carry out persistence on the BusinessObject.
コード例 #1
0
        public void TestChangeControlValues_DoesNotChangeBusinessObjectValues()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            MyBO myBO = new MyBO();
            myBO.TestProp = START_VALUE_1;
            myBO.SetPropertyValue(TEST_PROP_2, START_VALUE_2);

            Habanero.Faces.Base.PanelBuilder factory = new Habanero.Faces.Base.PanelBuilder(GetControlFactory());
            IPanelInfo panelInfo = factory.BuildPanelForForm(myBO.ClassDef.UIDefCol["default"].UIForm);
            panelInfo.BusinessObject = myBO;
            //---------------Execute Test ----------------------
            ChangeValuesInControls(panelInfo);
            //---------------Test Result -----------------------

            Assert.AreEqual(START_VALUE_1, myBO.GetPropertyValue(TEST_PROP_1));
            Assert.AreEqual(START_VALUE_2, myBO.GetPropertyValue(TEST_PROP_2));

        }
コード例 #2
0
 public void Test_UpdateErrorProviderError_WhenBOInvalid_ShouldNotChangeMessageAsAlreadyUpdatedForWin()
 {
     //---------------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.AreNotEqual("", SurnameControlMapper.GetErrorMessage());
     //---------------Execute Test ----------------------
     panelInfo.UpdateErrorProvidersErrorMessages();
     //---------------Test Result -----------------------
     Assert.AreNotEqual("", SurnameControlMapper.GetErrorMessage());
 }
コード例 #3
0
        public void Test_BuildPanelForTab_tabNull()
        {
            //---------------Set up test pack-------------------
            PanelBuilder panelBuilder = new PanelBuilder(this.GetControlFactory());

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                panelBuilder.BuildPanelForTab(null);
                Assert.Fail("expected ArgumentNullException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("Value cannot be null", ex.Message);
                StringAssert.Contains("formTab", ex.ParamName);
            }
        }
コード例 #4
0
        public void Test_BuildPanelForTab_Parameter_SetAlignment_NumericUpDown()
        {
            //---------------Set up test pack-------------------
            Sample.SampleUserInterfaceMapper interfaceMapper = GetSampleUserInterfaceMapper();
            UIFormTab singleFieldTab = interfaceMapper.GetFormTabOneFieldsWithNumericUpDown();

            Habanero.Faces.Base.PanelBuilder panelBuilder = CreatePanelBuilder();
            //---------------Assert Precondition----------------
            Assert.AreEqual("right", ((UIFormField)singleFieldTab[0][0]).Alignment);

            //---------------Execute Test ----------------------
            IPanel panel = panelBuilder.BuildPanelForTab(singleFieldTab).Panel;

            //---------------Test Result -----------------------

            Assert.IsInstanceOf(typeof(INumericUpDown), panel.Controls[1]);
            INumericUpDown control = (INumericUpDown)panel.Controls[1];

            Assert.AreEqual(HorizontalAlignment.Right, control.TextAlign);
        }
コード例 #5
0
        public void TestChangeControlValues_DoesNotChangeBusinessObjectValues()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            MyBO myBO = new MyBO();

            myBO.TestProp = START_VALUE_1;
            myBO.SetPropertyValue(TEST_PROP_2, START_VALUE_2);

            Habanero.Faces.Base.PanelBuilder factory = new Habanero.Faces.Base.PanelBuilder(GetControlFactory());
            IPanelInfo panelInfo = factory.BuildPanelForForm(myBO.ClassDef.UIDefCol["default"].UIForm);

            panelInfo.BusinessObject = myBO;
            //---------------Execute Test ----------------------
            ChangeValuesInControls(panelInfo);
            //---------------Test Result -----------------------

            Assert.AreEqual(START_VALUE_1, myBO.GetPropertyValue(TEST_PROP_1));
            Assert.AreEqual(START_VALUE_2, myBO.GetPropertyValue(TEST_PROP_2));
        }
コード例 #6
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());
        }
コード例 #7
0
        public void Test_BuildPanelForTab_Parameter_SetNumericUpDownAlignment()
        {
            //---------------Set up test pack-------------------
            Sample.SampleUserInterfaceMapper interfaceMapper = GetSampleUserInterfaceMapper();
            UIFormTab singleFieldTab = interfaceMapper.GetFormTabOneFieldsWithAlignment_NumericUpDown();

            Habanero.Faces.Base.PanelBuilder panelBuilder = CreatePanelBuilder();
            //---------------Assert Precondition----------------
            Assert.AreEqual("left", ((UIFormField)singleFieldTab[0][0]).Alignment);
            Assert.AreEqual("right", ((UIFormField)singleFieldTab[0][1]).Alignment);
            Assert.AreEqual("center", ((UIFormField)singleFieldTab[0][2]).Alignment);
            Assert.AreEqual("centre", ((UIFormField)singleFieldTab[0][3]).Alignment);
            //---------------Execute Test ----------------------
            IPanel panel = panelBuilder.BuildPanelForTab(singleFieldTab).Panel;

            //---------------Test Result -----------------------

            Assert.IsInstanceOf(typeof(INumericUpDown), panel.Controls[1]);
            INumericUpDown control1 = (INumericUpDown)panel.Controls[1];

            Assert.AreEqual(HorizontalAlignment.Left, control1.TextAlign);

            Assert.IsInstanceOf(typeof(INumericUpDown), panel.Controls[Habanero.Faces.Base.PanelBuilder.CONTROLS_PER_COLUMN + 1]);
            INumericUpDown control2 = (INumericUpDown)panel.Controls[Habanero.Faces.Base.PanelBuilder.CONTROLS_PER_COLUMN + 1];

            Assert.AreEqual(HorizontalAlignment.Right, control2.TextAlign);

            Assert.IsInstanceOf(typeof(INumericUpDown), panel.Controls[Habanero.Faces.Base.PanelBuilder.CONTROLS_PER_COLUMN * 2 + 1]);
            INumericUpDown control3 = (INumericUpDown)panel.Controls[Habanero.Faces.Base.PanelBuilder.CONTROLS_PER_COLUMN * 2 + 1];

            Assert.AreEqual(HorizontalAlignment.Center, control3.TextAlign);

            Assert.IsInstanceOf(typeof(INumericUpDown), panel.Controls[Habanero.Faces.Base.PanelBuilder.CONTROLS_PER_COLUMN * 3 + 1]);
            INumericUpDown control4 = (INumericUpDown)panel.Controls[Habanero.Faces.Base.PanelBuilder.CONTROLS_PER_COLUMN * 3 + 1];

            Assert.AreEqual(HorizontalAlignment.Center, control4.TextAlign);
        }
コード例 #8
0
        /// <summary>
        /// Constructs the <see cref="DefaultBOEditorFormVWG"/> class  with 
        /// the specified <see cref="BusinessObject"/>, uiDefName and <see cref="IControlFactory"/>. 
        /// </summary>
        /// <param name="bo">The business object to represent</param>
        /// <param name="uiDefName">The name of the ui def to use.</param>
        /// <param name="controlFactory">The <see cref="IControlFactory"/> to use for creating the Editor form controls</param>
        public DefaultBOEditorFormVWG(BusinessObject bo, string uiDefName, IControlFactory controlFactory)
        {
            _bo = bo;
            _controlFactory = controlFactory;
            _uiDefName = uiDefName;
            GroupControlCreator = _controlFactory.CreateTabControl;
            BOMapper mapper = new BOMapper(bo);

            IUIForm def;
            if (_uiDefName.Length > 0)
            {
                IUIDef uiMapper = mapper.GetUIDef(_uiDefName);
                if (uiMapper == null)
                {
                    throw new NullReferenceException("An error occurred while " +
                                                     "attempting to load an object editing form.  A possible " +
                                                     "cause is that the class definitions do not have a " +
                                                     "'form' section for the class, under the 'ui' " +
                                                     "with the name '" + _uiDefName + "'.");
                }
                def = uiMapper.UIForm;
            }
            else
            {
                IUIDef uiMapper = mapper.GetUIDef();
                if (uiMapper == null)
                {
                    throw new NullReferenceException("An error occurred while " +
                                                     "attempting to load an object editing form.  A possible " +
                                                     "cause is that the class definitions do not have a " +
                                                     "'form' section for the class.");
                }
                def = uiMapper.UIForm;
            }
            if (def == null)
            {
                throw new NullReferenceException("An error occurred while " +
                                                 "attempting to load an object editing form.  A possible " +
                                                 "cause is that the class definitions do not have a " +
                                                 "'form' section for the class.");
            }

            PanelBuilder panelBuilder = new PanelBuilder(_controlFactory);
            //_panelInfo = panelBuilder.BuildPanelForForm(_bo.ClassDef.UIDefCol["default"].UIForm);
            //_panelInfo = panelBuilder.BuildPanelForForm(_bo.ClassDef.UIDefCol[uiDefName].UIForm);
            _panelInfo = panelBuilder.BuildPanelForForm(def);

            _panelInfo.BusinessObject = _bo;
            _boPanel = _panelInfo.Panel;
            _buttons = _controlFactory.CreateButtonGroupControl();
            // These buttons used to be "&Cancel" and "&OK", but they are missing the "&" in win, so I took them out for VWG
            //  Soriya had originally removed them from Win in revision 2854, but I'm not sure of the reason other than 
            //  externally, when fetching the button from the button control, it would be fetched using the text only.
            //  I would prefer to have the "&" in the control, but it may break existing code that uses the buttons on this form.
            //  Also, it seems that VWG does not do anything with the "&"
            _buttons.AddButton("Cancel", CancelButtonHandler);
            IButton okbutton = _buttons.AddButton("OK", OKButtonHandler);
            okbutton.TabStop = false;
            //okbutton.TabIndex = 3;
            //okbutton.TabStop = true;
            //cancelButton.TabIndex = 4;
            //cancelButton.TabStop = true;

            okbutton.NotifyDefault(true);
            this.AcceptButton = (ButtonVWG)okbutton;
            this.Load += delegate { FocusOnFirstControl(); };
            this.Closing += OnClosing;

            this.Text = def.Title;
            SetupFormSize(def);
            MinimizeBox = false;
            MaximizeBox = false;
            //this.ControlBox = false;
            this.StartPosition = FormStartPosition.CenterScreen;

            CreateLayout();
            OnResize(new EventArgs());
        }
コード例 #9
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());
 }
コード例 #10
0
        public void Test_UIFormTab()
        {
            //--------------- Set up test pack ------------------
            IClassDef classDef = Sample.CreateClassDefWithTwoPropsOneInteger();
            PanelBuilder panelBuilder = new PanelBuilder(GetControlFactory());
            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            IPanelInfo panelInfo = panelBuilder.BuildPanelForTab((UIFormTab) classDef.UIDefCol["default"].UIForm[0]);

            //--------------- Test Result -----------------------
            Assert.IsNotNull(panelInfo.UIFormTab);
            Assert.AreEqual(panelInfo.UIFormTab.Name, panelInfo.PanelTabText);
        }
コード例 #11
0
        public void TestClearErrorProviders()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = Sample.CreateClassDefWithTwoPropsOneCompulsory();
            PanelBuilder panelBuilder = new PanelBuilder(GetControlFactory());
            IPanelInfo panelInfo = panelBuilder.BuildPanelForTab((UIFormTab) classDef.UIDefCol["default"].UIForm[0]);
            Sample businessObject = new Sample();

            panelInfo.BusinessObject = businessObject;

            //businessObject.SetPropertyValue("SampleText2", "sdlkfj");
            PanelInfo.FieldInfo fieldInfo = panelInfo.FieldInfos["SampleText2"];
            panelInfo.ApplyChangesToBusinessObject();
            IErrorProvider errorProvider = fieldInfo.ControlMapper.ErrorProvider;

            //---------------Assert Precondition----------------
            Assert.IsTrue(errorProvider.GetError(fieldInfo.InputControl).Length > 0);
            //---------------Execute Test ----------------------
            panelInfo.ClearErrorProviders();
            //---------------Test Result -----------------------
            Assert.IsFalse(errorProvider.GetError(fieldInfo.InputControl).Length > 0);
        }
コード例 #12
0
 public void TestControlsVisible()
 {
     //---------------Set up test pack-------------------
     IClassDef classDef = Sample.CreateClassDefWithTwoPropsOneInteger();
     PanelBuilder panelBuilder = new PanelBuilder(GetControlFactory());
     IPanelInfo panelInfo = panelBuilder.BuildPanelForTab((UIFormTab) classDef.UIDefCol["default"].UIForm[0]);
     panelInfo.BusinessObject = new Sample();
     //---------------Assert Precondition----------------
     Assert.IsTrue(panelInfo.FieldInfos[0].InputControl.Visible);
     Assert.IsTrue(panelInfo.FieldInfos[1].InputControl.Visible);
     //---------------Execute Test ----------------------
     panelInfo.ControlsVisible = false;
     //---------------Test Result -----------------------
     Assert.IsFalse(panelInfo.FieldInfos[0].InputControl.Visible);
     Assert.IsFalse(panelInfo.FieldInfos[1].InputControl.Visible);
 }
コード例 #13
0
        /// <summary>
        /// Constructs the <see cref="DefaultBOEditorFormWin"/> class  with 
        /// the specified businessObject, uiDefName and post edit action. 
        /// </summary>
        /// <param name="bo">The business object to represent</param>
        /// <param name="uiDefName">The name of the ui def to use.</param>
        /// <param name="controlFactory">The <see cref="IControlFactory"/> to use for creating the Editor form controls</param>
        /// <param name="creator">The Creator used to Create the Group Control.</param>
        public DefaultBOEditorFormWin(BusinessObject bo, string uiDefName, IControlFactory controlFactory, GroupControlCreator creator)
        {
            _bo = bo;
            _controlFactory = controlFactory;
            GroupControlCreator = creator;
            _uiDefName = uiDefName;

            BOMapper mapper = new BOMapper(bo);

            IUIForm def;
            if (_uiDefName.Length > 0)
            {
                IUIDef uiMapper = mapper.GetUIDef(_uiDefName);
                if (uiMapper == null)
                {
                    throw new NullReferenceException("An error occurred while " +
                                                     "attempting to load an object editing form.  A possible " +
                                                     "cause is that the class definitions do not have a " +
                                                     "'form' section for the class, under the 'ui' " +
                                                     "with the name '" + _uiDefName + "'.");
                }
                def = uiMapper.UIForm;
            }
            else
            {
                IUIDef uiMapper = mapper.GetUIDef();
                if (uiMapper == null)
                {
                    throw new NullReferenceException("An error occurred while " +
                                                     "attempting to load an object editing form.  A possible " +
                                                     "cause is that the class definitions do not have a " +
                                                     "'form' section for the class.");
                }
                def = uiMapper.UIForm;
            }
            if (def == null)
            {
                throw new NullReferenceException("An error occurred while " +
                                                 "attempting to load an object editing form.  A possible " +
                                                 "cause is that the class definitions do not have a " +
                                                 "'form' section for the class.");
            }

            PanelBuilder panelBuilder = new PanelBuilder(_controlFactory);
            //_panelInfo = panelBuilder.BuildPanelForForm(_bo.ClassDef.UIDefCol["default"].UIForm);
            //_panelInfo = panelBuilder.BuildPanelForForm(_bo.ClassDef.UIDefCol[uiDefName].UIForm, this.GroupControlCreator);
            _panelInfo = panelBuilder.BuildPanelForForm(def, this.GroupControlCreator);

            _panelInfo.BusinessObject = _bo;
            _boPanel = _panelInfo.Panel;

            _buttons = _controlFactory.CreateButtonGroupControl();
            _buttons.AddButton("Cancel", CancelButtonHandler);
            IButton okbutton = _buttons.AddButton("OK", OkButtonHandler);

            okbutton.NotifyDefault(true);
            this.AcceptButton = (ButtonWin) okbutton;
            this.Load += delegate { FocusOnFirstControl(); };
            this.FormClosing += OnFormClosing;

            this.Text = def.Title;
            SetupFormSize(def);
            MinimizeBox = false;
            MaximizeBox = false;
            //this.ControlBox = false;
            this.StartPosition = FormStartPosition.CenterScreen;

            CreateLayout();
            OnResize(new EventArgs());
        }
コード例 #14
0
 internal static IPanelInfo CreatePanelInfo
     (IControlFactory controlFactory, IClassDef classDef, string uiDefName, IBOEditorControl iboEditorControl)
 {
     IUIForm uiForm = GetUiForm(classDef, uiDefName);
     PanelBuilder panelBuilder = new PanelBuilder(controlFactory);
     IPanelInfo panelInfo = panelBuilder.BuildPanelForForm(uiForm);
     BorderLayoutManager layoutManager = controlFactory.CreateBorderLayoutManager(iboEditorControl);
     layoutManager.AddControl(panelInfo.Panel, BorderLayoutManager.Position.Centre);
     return panelInfo;
 }