/// <summary> /// A constructor as before, but with a UIDefName specified /// </summary> public PanelFactory(BusinessObject bo, string uiDefName, IControlFactory controlFactory) { _uiDefName = uiDefName; _controlFactory = controlFactory; BOMapper mapper = new BOMapper(bo); IUIDef uiDef = mapper.GetUIDef(uiDefName); if (uiDef == null) { string errMessage = "Cannot create a panel factory for '" + bo.ClassDef.ClassName + "' since the classdefs do not contain a uiDef '" + uiDefName + "'"; throw new HabaneroDeveloperException ("There is a serious application error please contact your system administrator" + Environment.NewLine + errMessage, errMessage); } _uiForm = uiDef.GetUIFormProperties(); if (_uiForm == null) { string errMsg = "Cannot create a panel factory for '" + bo.ClassDef.ClassName + "' since the classdefs do not contain a form def for uidef '" + uiDefName + "'"; throw new HabaneroDeveloperException ("There is a serious application error please contact your system administrator" + Environment.NewLine + errMsg, errMsg); } InitialiseFactory(bo); }
/// <summary> /// Gets a list of the property values to display to the user /// </summary> /// <param name="businessObject">The business object whose /// properties are to be displayed</param> /// <returns>Returns an array of values</returns> protected object[] GetValues(IBusinessObject businessObject) { if (businessObject == null) { throw new ArgumentNullException("businessObject"); } object[] values = new object[_uiGridProperties.Count + 1]; values[0] = businessObject.ID.ObjectID; int i = 1; BOMapper mapper = new BOMapper(businessObject); foreach (UIGridColumn gridProperty in _uiGridProperties) { object val = mapper.GetPropertyValueToDisplay(gridProperty.PropertyName); values[i++] = val ?? DBNull.Value; } return(values); }
// ReSharper disable InconsistentNaming public void Test_SetDisplayPropertyValue_ShouldSetPropValue() { //---------------Set up test pack------------------- const string propName = "TestProp"; ClassDef.ClassDefs.Clear(); var myBOClassDef = MyBO.LoadClassDefWithRelationship(); MyRelatedBo.LoadClassDef(); var myBO = (MyBO) myBOClassDef.CreateNewBusinessObject(); var boMapper = new BOMapper(myBO); var initialPropValue = RandomValueGen.GetRandomString(); myBO.SetPropertyValue(propName, initialPropValue); //---------------Assert Precondition---------------- Assert.AreEqual(initialPropValue, myBO.GetPropertyValue(propName)); //---------------Execute Test ---------------------- var expectedPropValue = RandomValueGen.GetRandomString(); boMapper.SetDisplayPropertyValue(propName, expectedPropValue); //---------------Test Result ----------------------- Assert.AreEqual(expectedPropValue, myBO.GetPropertyValue(propName)); }
public void TestAddRowCreatesBusinessObjectThroughCollection() { SetupTestData(); //---------------Set up test pack------------------- BusinessObjectCollection<MyBO> boCollection = new BusinessObjectCollection<MyBO>(); MyBO bo = new MyBO(); bo.SetPropertyValue("TestProp", "bo1prop1"); bo.SetPropertyValue("TestProp2", "s1"); bo.Save(); boCollection.Add(bo); MyBO bo2 = new MyBO(); bo2.SetPropertyValue("TestProp", "bo2prop1"); bo2.SetPropertyValue("TestProp2", "s2"); bo2.Save(); boCollection.Add(bo2); _dataSetProvider = new EditableDataSetProvider(boCollection); BOMapper mapper = new BOMapper(boCollection.ClassDef.CreateNewBusinessObject()); itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); //--------------Assert PreConditions---------------- Assert.AreEqual(2, boCollection.Count); Assert.AreEqual(0, boCollection.CreatedBusinessObjects.Count, "Should be no created items to start"); //---------------Execute Test ---------------------- itsTable.Rows.Add(new object[] {null, "bo3prop1", "bo3prop2"}); //---------------Test Result ----------------------- Assert.AreEqual (1, boCollection.CreatedBusinessObjects.Count, "Adding a row to the table should use the collection to create the object"); //Assert.AreEqual(2, boCollection.Count, "Adding a row to the table should not add a bo to the main collection"); Assert.AreEqual(3, boCollection.Count, "Adding a row to the table should add a bo to the main collection"); }
/// <summary> /// This is a bit of a hack_ was used on a specific project some time ago. /// This is not generally supported throughout Habanero so has been isolated here. /// </summary> /// <param name="propertyName"></param> /// <returns></returns> private object GetAlternateRelationshipValue(string propertyName) { string relationshipName = propertyName.Substring(0, propertyName.IndexOf(".")); propertyName = propertyName.Remove(0, propertyName.IndexOf(".") + 1); string[] parts = relationshipName.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); List <string> relNames = new List <string>(parts); IBusinessObject relatedBo = this._businessObject; IBusinessObject oldBo = relatedBo; int i = 0; do { relatedBo = oldBo.Relationships.GetRelatedObject(relNames[i++]); } while (relatedBo == null && i < relNames.Count); if (relatedBo == null) { return(null); //throw new HabaneroApplicationException("Unable to retrieve property " + propertyName + " from a business object of type " + this._businessObject.GetType().Name); } BOMapper relatedBoMapper = new BOMapper(relatedBo); return(relatedBoMapper.GetPropertyValueToDisplay(propertyName)); }
public void Test_GetPropertyValue_WithDot_IncorrectRelationshipName() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); _itsClassDef = MyBO.LoadClassDefWithRelationship(); _itsRelatedClassDef = MyRelatedBo.LoadClassDef(); MyBO bo1 = (MyBO) _itsClassDef.CreateNewBusinessObject(); BOMapper mapper = new BOMapper(bo1); //---------------Execute Test ---------------------- try { mapper.GetPropertyValueToDisplay("MyIncorrectRelationship.MyRelatedTestProp"); Assert.Fail("Expected to throw an RelationshipNotFoundException"); } //---------------Test Result ----------------------- catch (RelationshipNotFoundException ex) { StringAssert.Contains("The relationship 'MyIncorrectRelationship' on 'MyBO' cannot be found", ex.Message); } }
public void Test_GetPropertyValueToDisplay_SimpleLookup() { ClassDef.ClassDefs.Clear(); _itsClassDef = MyBO.LoadClassDefWithSimpleIntegerLookup(); MyBO bo1 = (MyBO)_itsClassDef.CreateNewBusinessObject(); bo1.SetPropertyValue("TestProp2", "Text"); BOMapper mapper = new BOMapper(bo1); Assert.AreEqual("Text", mapper.GetPropertyValueToDisplay("TestProp2")); }
public void Test_GetPropertyValue_WithDot() { ClassDef.ClassDefs.Clear(); _itsClassDef = MyBO.LoadClassDefWithRelationship(); _itsRelatedClassDef = MyRelatedBo.LoadClassDef(); //MyBO bo1 = (MyBO)itsClassDef.CreateNewBusinessObject(connection); MyBO bo1 = (MyBO)_itsClassDef.CreateNewBusinessObject(); MyRelatedBo relatedBo = (MyRelatedBo)_itsRelatedClassDef.CreateNewBusinessObject(); Guid myRelatedBoGuid = relatedBo.ID.GetAsGuid(); bo1.SetPropertyValue("RelatedID", myRelatedBoGuid); relatedBo.SetPropertyValue("MyRelatedTestProp", "MyValue"); BOMapper mapper = new BOMapper(bo1); Assert.AreEqual("MyValue", mapper.GetPropertyValueToDisplay("MyRelationship.MyRelatedTestProp")); }
public void Test_SetDisplayPropertyValue_WhenLookupList_ShouldSetUnderlyingValue() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); const string propertyName = "TestProp2"; const string expectedLookupDisplayValue = "s1"; Guid expectedLookupValue; StringUtilities.GuidTryParse("{E6E8DC44-59EA-4e24-8D53-4A43DC2F25E7}", out expectedLookupValue); _itsClassDef = MyBO.LoadClassDefWithLookup(); MyBO bo1 = (MyBO)_itsClassDef.CreateNewBusinessObject(); BOMapper boMapper = new BOMapper(bo1); //---------------Assert Precondition---------------- Assert.IsNullOrEmpty(bo1.TestProp2); //---------------Execute Test ---------------------- boMapper.SetDisplayPropertyValue(propertyName, expectedLookupDisplayValue); //---------------Test Result ----------------------- Assert.AreEqual(expectedLookupValue, bo1.GetPropertyValue(propertyName)); Assert.AreEqual(expectedLookupDisplayValue, bo1.GetPropertyValueToDisplay(propertyName)); }
public void Test_SetPropertyDisplayValue_WithIntString_ShouldBeAbleGetString() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); MyBO.LoadDefaultClassDef(); var testBo = new MyBO(); var boMapper = new BOMapper(testBo); const string propName = "TestProp"; boMapper.SetDisplayPropertyValue(propName, "7"); //---------------Assert Precondition---------------- Assert.AreEqual("7", boMapper.GetPropertyValueToDisplay(propName).ToString()); //---------------Execute Test ---------------------- boMapper.SetDisplayPropertyValue(propName, "3"); //---------------Test Result ----------------------- Assert.AreEqual("3", boMapper.GetPropertyValueToDisplay(propName).ToString()); Assert.AreEqual("3", testBo.TestProp); }
///// <summary> ///// Gets or sets whether the user is able to right-click to ///// add additional items to the drop-down list ///// </summary> //public override bool RightClickEnabled //{ // get { return base.RightClickEnabled && _allowRightClick; } // set // { // _allowRightClick = value; // base.RightClickEnabled = value; // } //} /// <summary> /// Sets up the list of items to display and calls SetLookupList() /// to populate the ComboBox with this list /// </summary> private void SetupLookupList() { if (_businessObject == null) { Dictionary<string, string> emptyList = new Dictionary<string, string>(); LookupList = emptyList; return; } BOMapper mapper = new BOMapper(_businessObject); Dictionary<string, string> col = mapper.GetLookupList(PropertyName); //if (!_isRightClickInitialised) //{ // //SetupRightClickBehaviour(); // if (_attributes != null && !_attributes.Contains("rightClickEnabled") && // GlobalUIRegistry.UISettings != null && // GlobalUIRegistry.UISettings.PermitComboBoxRightClick != null) // { // ClassDef lookupClassDef = mapper.GetLookupListClassDef(_propertyName); // if (lookupClassDef != null) // { // Type boType = lookupClassDef.ClassType; // if (GlobalUIRegistry.UISettings.PermitComboBoxRightClick(boType, this)) // { // RightClickEnabled = _allowRightClick; // } // } // } // else // { // RightClickEnabled = _allowRightClick; // } // _isRightClickInitialised = true; //} CustomiseLookupList(col); LookupList = col; var boPropertyValue = GetPropertyValue(); if (col.Count > 0 && boPropertyValue != null) { SetLookupListValueFromBO(boPropertyValue); } }
/// <summary> /// Sets the property value to that provided. If the property value /// is invalid, the error provider will be given the reason why the /// value is invalid. /// </summary> protected virtual void SetPropertyValue(object value) { if (_businessObject == null) return; var boMapper = new BOMapper(_businessObject); try { boMapper.SetDisplayPropertyValue(PropertyName, value); } catch (InvalidPropertyValueException ex) { SetError(ex.Message); return; } catch (HabaneroIncorrectTypeException ex) { SetError(ex.Message); return; } UpdateErrorProviderErrorMessage(); }
/// <summary> /// Handles the event of a row being added /// </summary> /// <param name="e">Attached arguments regarding the event</param> private void RowAdded(DataRowChangeEventArgs e) { try { _isBeingAdded = true; BusinessObject newBo; try { DeregisterForBOEvents(); newBo = (BusinessObject) _collection.CreateBusinessObject(); } finally { RegisterForBOEvents(); } if (ObjectInitialiser != null) { try { DeregisterForBOEvents(); ObjectInitialiser.InitialiseObject(newBo); } finally { RegisterForBOEvents(); } } DataRow row = e.Row; try { DeregisterForBOEvents(); // set all the values in the grid to the bo's current prop values (defaults) // make sure the part entered to create the row is not changed. row[IDColumnName] = newBo.ID.ObjectID; foreach (UIGridColumn uiProperty in _uiGridProperties) { //If no value was typed into the grid then use the default value for the property if one exists. if (DBNull.Value.Equals(row[uiProperty.PropertyName])) { var boMapper = new BOMapper(newBo); var propertyValueToDisplay = boMapper.GetPropertyValueToDisplay(uiProperty.PropertyName); if (propertyValueToDisplay != null) { _table.Columns[uiProperty.PropertyName].ReadOnly = false; row[uiProperty.PropertyName] = propertyValueToDisplay; } } else { ApplyRowCellValueToBOProperty(row, uiProperty, newBo); } } } finally { RegisterForBOEvents(); } string message; if (newBo.Status.IsValid(out message)) { newBo.Save(); row.AcceptChanges(); } row.RowError = message; if (newBo.Status.IsNew) { _addedRows.Add(row, newBo); } if (newBo.ID.ObjectID == Guid.Empty) { throw new HabaneroDeveloperException ("Serious error The objectID is Empty", "Serious error The objectID is Empty"); } _isBeingAdded = false; } catch (Exception ex) { _isBeingAdded = false; if (e.Row != null) { e.Row.RowError = ex.Message; } throw; } }
public override void SetValue(object component, object value) { IBusinessObject bo = GetBusinessObject(component); BOMapper boMapper = new BOMapper(bo); boMapper.SetDisplayPropertyValue(PropertyName, value); }
public void TestAddRow_ThenAddBO_UpdatesTable() { BusinessObjectCollection<MyBO> col = null; IDataSetProvider dataSetProvider = GetDataSetProviderWithCollection(ref col); BOMapper mapper = new BOMapper(col.ClassDef.CreateNewBusinessObject()); DataTable table = dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); MyBO boNew = new MyBO(); boNew.SetPropertyValue("TestProp", "bo3prop1"); boNew.SetPropertyValue("TestProp2", "s2"); //---------------Assert Precondition---------------- Assert.AreEqual(4, table.Rows.Count); Assert.AreEqual(4, col.Count); Assert.AreEqual(4, col.CreatedBusinessObjects.Count); //---------------Execute Test ---------------------- table.Rows.Add(new object[] { null, "bo3prop1", "bo3prop2" }); col.Add(boNew); //---------------Test Result ----------------------- Assert.AreEqual(6, col.Count); Assert.AreEqual(6, col.CreatedBusinessObjects.Count); Assert.AreEqual(6, table.Rows.Count); }
public void Test_EditDataTable_ToDBNull_EditsBo() { //---------------Set up test pack------------------- BusinessObjectCollection<MyBO> col = null; IDataSetProvider dataSetProvider = GetDataSetProviderWithCollection(ref col); BOMapper mapper = new BOMapper(col.ClassDef.CreateNewBusinessObject()); DataTable table = dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); MyBO bo1 = col[0]; // const string updatedvalue = "UpdatedValue"; const string columnName = "TestProp"; object origionalPropValue = bo1.GetPropertyValue(columnName); //---------------Assert Precondition---------------- Assert.IsTrue(dataSetProvider is EditableDataSetProvider); Assert.AreEqual(4, table.Rows.Count); Assert.AreEqual(bo1.ID.AsString_CurrentValue(), table.Rows[0][_dataTableIdColumnName]); Assert.AreEqual(origionalPropValue, table.Rows[0][columnName]); //---------------Execute Test ---------------------- table.Rows[0][columnName] = DBNull.Value; //---------------Test Result ----------------------- Assert.AreEqual(bo1.ID.AsString_CurrentValue(), table.Rows[0][_dataTableIdColumnName]); Assert.AreEqual(DBNull.Value, table.Rows[0][columnName]); Assert.AreEqual(null, bo1.GetPropertyValue(columnName)); }
public void TestDuplicateColumnNames() { //---------------Set up test pack------------------- SetupTestData(); BOMapper mapper = new BOMapper(_collection.ClassDef.CreateNewBusinessObject()); //---------------Execute Test ---------------------- try { itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef("duplicateColumns").UIGrid); Assert.Fail("Expected to throw an DuplicateNameException"); } //---------------Test Result ----------------------- catch (DuplicateNameException ex) { StringAssert.Contains("Only one column per property can be specified", ex.Message); } }
public void TestAddRowP_RowValueDBNull_BOProp_DateTime_NUll_ShouldNotRaiseException_FIXBUG() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); SetupTestData(); BusinessObjectCollection<MyBO> boCollection = new BusinessObjectCollection<MyBO>(); _dataSetProvider = new EditableDataSetProvider(boCollection); BOMapper mapper = new BOMapper(boCollection.ClassDef.CreateNewBusinessObject()); itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); //--------------Assert PreConditions---------------- Assert.AreEqual(0, boCollection.Count); Assert.AreEqual(0, boCollection.PersistedBusinessObjects.Count, "Should be no created items to start"); // Assert.AreEqual(0, boCollection.CreatedBusinessObjects.Count, "Should be no created items to start"); //---------------Execute Test ---------------------- itsTable.Rows.Add(new object[] { DBNull.Value, DBNull.Value, DBNull.Value }); //---------------Test Result ----------------------- Assert.AreEqual (1, boCollection.PersistedBusinessObjects.Count, "Adding a row to the table should use the collection to create the object"); // Assert.AreEqual // (1, boCollection.CreatedBusinessObjects.Count, // "Adding a row to the table should use the collection to create the object"); Assert.AreEqual(1, boCollection.Count, "Adding a row to the table should add a bo to the main collection"); }
public void TestAddRowP_RowValueDBNull_VirtualProp_NUll_ShouldNotRaiseException_FIXBUG() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); ClassDef.ClassDefs.Clear(); IClassDef classDef = MyBO.LoadClassDefWithUIAllDataTypes(); classDef.UIDefCol["default"].UIGrid.Add(new UIGridColumn("VirtualProp", "-TestProp-", typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable())); BusinessObjectCollection<MyBO> boCollection = new BusinessObjectCollection<MyBO>(); _dataSetProvider = new EditableDataSetProvider(boCollection); BOMapper mapper = new BOMapper(boCollection.ClassDef.CreateNewBusinessObject()); itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); //--------------Assert PreConditions---------------- Assert.AreEqual(0, boCollection.Count); Assert.AreEqual(0, boCollection.PersistedBusinessObjects.Count, "Should be no created items to start"); // Assert.AreEqual(0, boCollection.CreatedBusinessObjects.Count, "Should be no created items to start"); //---------------Execute Test ---------------------- itsTable.Rows.Add(new object[] { DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value }); //---------------Test Result ----------------------- Assert.IsFalse(itsTable.Rows[0].HasErrors); //Behaviour has been changed to persist the business object Assert.AreEqual (1, boCollection.PersistedBusinessObjects.Count, "Adding a row to the table should use the collection to create the object"); // Assert.AreEqual // (1, boCollection.CreatedBusinessObjects.Count, // "Adding a row to the table should use the collection to create the object"); Assert.AreEqual(1, boCollection.Count, "Adding a row to the table should add a bo to the main collection"); }
public void Test_GetPropertyValueToDisplay_WhenVirtualPropertyValue() { ClassDef.ClassDefs.Clear(); _itsClassDef = MyBO.LoadDefaultClassDef(); MyBO bo1 = (MyBO)_itsClassDef.CreateNewBusinessObject(); BOMapper mapper = new BOMapper(bo1); Assert.AreEqual("MyNameIsMyBo", mapper.GetPropertyValueToDisplay("-MyName-")); }
/// <summary> /// Returns the property value of the business object being mapped /// </summary> /// <returns>Returns the property value in appropriate object form</returns> protected virtual object GetPropertyValue() { if (_businessObject != null) { var boMapper = new BOMapper(_businessObject); return boMapper.GetPropertyValueToDisplay(PropertyName); } return null; }
public void TestGetLookupListDoesntExist() { ClassDef.ClassDefs.Clear(); _itsClassDef = MyBO.LoadClassDefWithNoLookup(); MyBO bo = new MyBO(); BOMapper mapper = new BOMapper(bo); Assert.AreEqual(0, mapper.GetLookupList("TestProp").Count); }
private IClassDef GetLookupTypeClassDef(out Type classType) { BOMapper mapper = new BOMapper(BusinessObject); IClassDef lookupTypeClassDef = mapper.GetLookupListClassDef(PropertyName); classType = lookupTypeClassDef.ClassType; return lookupTypeClassDef; }
/// <summary> /// Handles the event of a row being added /// </summary> /// <param name="e">Attached arguments regarding the event</param> private void RowAdded(DataRowChangeEventArgs e) { try { _isBeingAdded = true; BusinessObject newBo; try { DeregisterForBOEvents(); newBo = (BusinessObject)_collection.CreateBusinessObject(); } finally { RegisterForBOEvents(); } if (ObjectInitialiser != null) { try { DeregisterForBOEvents(); ObjectInitialiser.InitialiseObject(newBo); } finally { RegisterForBOEvents(); } } DataRow row = e.Row; try { DeregisterForBOEvents(); // set all the values in the grid to the bo's current prop values (defaults) // make sure the part entered to create the row is not changed. row[IDColumnName] = newBo.ID.ObjectID; foreach (UIGridColumn uiProperty in _uiGridProperties) { //If no value was typed into the grid then use the default value for the property if one exists. if (DBNull.Value.Equals(row[uiProperty.PropertyName])) { var boMapper = new BOMapper(newBo); var propertyValueToDisplay = boMapper.GetPropertyValueToDisplay(uiProperty.PropertyName); if (propertyValueToDisplay != null) { _table.Columns[uiProperty.PropertyName].ReadOnly = false; row[uiProperty.PropertyName] = propertyValueToDisplay; } } else { ApplyRowCellValueToBOProperty(row, uiProperty, newBo); } } } finally { RegisterForBOEvents(); } string message; if (newBo.Status.IsValid(out message)) { newBo.Save(); row.AcceptChanges(); } row.RowError = message; if (newBo.Status.IsNew) { _addedRows.Add(row, newBo); } if (newBo.ID.ObjectID == Guid.Empty) { throw new HabaneroDeveloperException ("Serious error The objectID is Empty", "Serious error The objectID is Empty"); } _isBeingAdded = false; } catch (Exception ex) { _isBeingAdded = false; if (e.Row != null) { e.Row.RowError = ex.Message; } throw; } }
/// <summary> /// Gets a list of the property values to display to the user /// </summary> /// <param name="businessObject">The business object whose /// properties are to be displayed</param> /// <returns>Returns an array of values</returns> protected object[] GetValues(IBusinessObject businessObject) { if (businessObject == null) throw new ArgumentNullException("businessObject"); object[] values = new object[_uiGridProperties.Count + 1]; values[0] = businessObject.ID.ObjectID; int i = 1; BOMapper mapper = new BOMapper(businessObject); foreach (UIGridColumn gridProperty in _uiGridProperties) { object val = mapper.GetPropertyValueToDisplay(gridProperty.PropertyName); values[i++] = val ?? DBNull.Value; } return values; }
public override object GetValue(object component) { IBusinessObject bo = GetBusinessObject(component); BOMapper boMapper = new BOMapper(bo); return boMapper.GetPropertyValueToDisplay(PropertyName); }
/// <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()); }
/// <summary> /// This is a bit of a hack_ was used on a specific project some time ago. /// This is not generally supported throughout Habanero so has been isolated here. /// </summary> /// <param name="propertyName"></param> /// <returns></returns> private object GetAlternateRelationshipValue(string propertyName) { string relationshipName = propertyName.Substring(0, propertyName.IndexOf(".")); propertyName = propertyName.Remove(0, propertyName.IndexOf(".") + 1); string[] parts = relationshipName.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); List<string> relNames = new List<string>(parts); IBusinessObject relatedBo = this._businessObject; IBusinessObject oldBo = relatedBo; int i = 0; do { relatedBo = oldBo.Relationships.GetRelatedObject(relNames[i++]); } while (relatedBo == null && i < relNames.Count); if (relatedBo == null) { return null; //throw new HabaneroApplicationException("Unable to retrieve property " + propertyName + " from a business object of type " + this._businessObject.GetType().Name); } BOMapper relatedBoMapper = new BOMapper(relatedBo); return relatedBoMapper.GetPropertyValueToDisplay(propertyName); }
/// <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()); }