FixColumn() public method

Fixes the width of a column to a specified size
public FixColumn ( int columnNumber, int columnWidth ) : void
columnNumber int The column in question
columnWidth int The width to fix the column at
return void
Beispiel #1
0
        private GridLayoutManager SetupLayoutManager(UIFormTab formTab, IPanel panel)
        {
            GridLayoutManager layoutManager = new GridLayoutManager(panel, ControlFactory);
            int maxRowsInColumns            = formTab.GetMaxRowsInColumns();

            int colCount = formTab.Count * CONTROLS_PER_COLUMN;

            layoutManager.SetGridSize(maxRowsInColumns, colCount);
            layoutManager.FixColumnBasedOnContents(0);
            for (int i = 0; i < colCount; i += CONTROLS_PER_COLUMN)
            {
                layoutManager.FixColumnBasedOnContents(i + LABEL_CONTROL_COLUMN_NO);
                layoutManager.FixColumn(i + ERROR_PROVIDER_COLUMN_NO, ERROR_PROVIDER_WIDTH);
            }
            ITextBox sampleTextBoxForHeight = ControlFactory.CreateTextBox();

            for (int row = 0; row < maxRowsInColumns; row++)
            {
                layoutManager.FixRow(row, sampleTextBoxForHeight.Height);
            }
            return(layoutManager);
        }
Beispiel #2
0
        private static void SetupInputControlColumnWidth(IPanelInfo panelInfo, IUIFormTab formTab)
        {
            GridLayoutManager layoutManager = panelInfo.LayoutManager;
            int formColCount = 0;

            foreach (UIFormColumn formColumn in formTab)
            {
                if (formColumn.Width < 0)
                {
                    continue;
                }
                int gridCol                  = formColCount * CONTROLS_PER_COLUMN;
                int labelColumnWidth         = layoutManager.GetFixedColumnWidth(gridCol + LABEL_CONTROL_COLUMN_NO);
                int errorProviderColumnWidth = layoutManager.GetFixedColumnWidth(gridCol + ERROR_PROVIDER_COLUMN_NO);
                int totalGap                 = (CONTROLS_PER_COLUMN - 1) * layoutManager.HorizontalGapSize;
                if (formTab.Count == 1)
                {
                    totalGap += 2 * layoutManager.BorderSize; // add extra border for single column
                }
                else if (formColCount == formTab.Count - 1)
                {
                    totalGap += layoutManager.BorderSize + layoutManager.HorizontalGapSize; // last column in multi-column
                }
                else if (formColCount > 0 && formTab.Count > 0)
                {
                    totalGap += layoutManager.HorizontalGapSize; //2 More gaps for internal column in multi-column
                }
                else if (formColCount == 0 && formTab.Count > 0)
                {
                    totalGap += layoutManager.BorderSize;
                }

                layoutManager.FixColumn
                    (gridCol + INPUT_CONTROL_COLUMN_NO,
                    formColumn.Width - labelColumnWidth - errorProviderColumnWidth - totalGap);
                formColCount++;
            }
        }
 private GridLayoutManager SetupLayoutManager(UIFormTab formTab, IPanel panel)
 {
     GridLayoutManager layoutManager = new GridLayoutManager(panel, ControlFactory);
     int maxRowsInColumns = formTab.GetMaxRowsInColumns();
     
     int colCount = formTab.Count * CONTROLS_PER_COLUMN;
     layoutManager.SetGridSize(maxRowsInColumns, colCount);
     layoutManager.FixColumnBasedOnContents(0);
     for (int i = 0; i < colCount; i += CONTROLS_PER_COLUMN)
     {
         layoutManager.FixColumnBasedOnContents(i + LABEL_CONTROL_COLUMN_NO);
         layoutManager.FixColumn(i + ERROR_PROVIDER_COLUMN_NO, ERROR_PROVIDER_WIDTH);
     }
     ITextBox sampleTextBoxForHeight = ControlFactory.CreateTextBox();
     for (int row = 0; row < maxRowsInColumns; row++)
     {
         layoutManager.FixRow(row, sampleTextBoxForHeight.Height);
     }
     return layoutManager;
 }
Beispiel #4
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);
        }
        /// <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;
        }