private void SetToolTip(UIFormField formField, IControlHabanero control) { string toolTipText = formField.GetToolTipText(); IToolTip toolTip = ControlFactory.CreateToolTip(); if (!String.IsNullOrEmpty(toolTipText)) { toolTip.SetToolTip(control, toolTipText); } }
/// <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); }