/// <summary> /// declare the control /// </summary> public override void GenerateDeclaration(TFormWriter writer, TControlDef ctrl) { string hostedControlName = TYml2Xml.GetAttribute(ctrl.xmlNode, "HostedControl"); TControlDef hostedCtrl = FCodeStorage.FindOrCreateControl(hostedControlName, ctrl.controlName); IControlGenerator ctrlGenerator = writer.FindControlGenerator(hostedCtrl); // add control itself if ((hostedCtrl != null) && (ctrlGenerator != null)) { ctrlGenerator.GenerateDeclaration(writer, hostedCtrl); } string localControlType = ControlType; if (ctrl.controlType.Length > 0) { localControlType = ctrl.controlType; } writer.Template.AddToCodelet("CONTROLDECLARATION", "private " + localControlType + " " + ctrl.controlName + ";" + Environment.NewLine); writer.Template.AddToCodelet("CONTROLCREATION", "this." + ctrl.controlName + " = new " + localControlType + "(" + TYml2Xml.GetAttribute(ctrl.xmlNode, "HostedControl") + ");" + Environment.NewLine); }
/// <summary> /// get the controls that belong to the toolstrip /// </summary> public override void ProcessChildren(TFormWriter writer, TControlDef container) { // add all the children // TODO add Container elements in statusbar if (container.controlName.StartsWith("stb")) { return; } List <XmlNode> childrenlist; if (TYml2Xml.GetChild(container.xmlNode, "Controls") != null) { // this is for generated toolbar, eg. for the PrintPreviewControl StringCollection childrenNames = TYml2Xml.GetElements(container.xmlNode, "Controls"); childrenlist = new List <XmlNode>(); foreach (string name in childrenNames) { childrenlist.Add(container.xmlNode.OwnerDocument.CreateElement(name)); } } else { // usually, the toolbar buttons are direct children of the toolbar control childrenlist = TYml2Xml.GetChildren(container.xmlNode, true); } //Console.WriteLine("Container: " + container.controlName); foreach (XmlNode child in childrenlist) { // Console.WriteLine("Child: " + child.Name); /* Get unique name if we need it * at the moment we need it only for menu separators */ String UniqueChildName = child.Name; TControlDef ControlDefChild = container.FCodeStorage.GetControl(child.Name); if (ControlDefChild == null) { UniqueChildName = TYml2Xml.GetAttribute(child, "UniqueName"); ControlDefChild = container.FCodeStorage.GetControl(UniqueChildName); } container.Children.Add(ControlDefChild); if (ControlDefChild != null) { IControlGenerator ctrlGenerator = writer.FindControlGenerator(ControlDefChild); // add control itself if (ctrlGenerator != null) { ctrlGenerator.GenerateControl(writer, ControlDefChild); } } } }
/// <summary>add GeneratedReadSetControls</summary> public override void ApplyDerivedFunctionality(TFormWriter writer, TControlDef ctrl) { ReportControls.GenerateReadSetControls(writer, ctrl.xmlNode, writer.Template, "CHECKBOX"); // we are not doing it the same way as in RadioGroupComplexReportGenerator. // difference here: we will always store the value of the dependant controls, even when the checkbox is not ticked foreach (TControlDef childCtrl in ctrl.Children) { childCtrl.SetAttribute("DependsOnRadioButton", ""); IControlGenerator ctrlGenerator = writer.FindControlGenerator(childCtrl); ctrlGenerator.ApplyDerivedFunctionality(writer, childCtrl); childCtrl.SetAttribute("DependsOnRadioButton", "true"); } }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { // first create the hosted control string hostedControlName = TYml2Xml.GetAttribute(ctrl.xmlNode, "HostedControl"); TControlDef hostedCtrl = FCodeStorage.FindOrCreateControl(hostedControlName, ctrl.controlName); IControlGenerator ctrlGenerator = writer.FindControlGenerator(hostedCtrl); // add control itself if ((hostedCtrl != null) && (ctrlGenerator != null)) { ctrlGenerator.SetControlProperties(writer, hostedCtrl); } return(base.SetControlProperties(writer, ctrl)); }
/// <summary> /// insert the buttons for the form, eg. submit button, cancel button, etc /// </summary> /// <param name="ACtrl"></param> /// <param name="ATemplate"></param> /// <param name="AItemsPlaceholder"></param> /// <param name="AWriter"></param> public static void InsertButtons(TControlDef ACtrl, ProcessTemplate ATemplate, string AItemsPlaceholder, TFormWriter AWriter) { StringCollection children = TYml2Xml.GetElements(ACtrl.xmlNode, "Buttons"); foreach (string child in children) { TControlDef childCtrl = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName); IControlGenerator ctrlGen = AWriter.FindControlGenerator(childCtrl); ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(AWriter, childCtrl); ProcessTemplate snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION"); LayoutCellInForm(childCtrl, -1, ctrlSnippet, snippetCellDefinition); ATemplate.InsertSnippet(AItemsPlaceholder, ctrlSnippet, ","); } }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { ProcessTemplate snippetRowDefinition = writer.FTemplate.GetSnippet(FControlDefinitionSnippetName); ((TExtJsFormsWriter)writer).AddResourceString(snippetRowDefinition, "LABEL", ctrl, ctrl.Label); StringCollection Controls = FindContainedControls(writer, ctrl.xmlNode); snippetRowDefinition.AddToCodelet("ITEMS", ""); if (Controls.Count > 0) { // used for radiogroupbox foreach (string ChildControlName in Controls) { TControlDef childCtrl = FCodeStorage.FindOrCreateControl(ChildControlName, ctrl.controlName); IControlGenerator ctrlGen = writer.FindControlGenerator(childCtrl); ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(writer, childCtrl); ctrlSnippet.SetCodelet("COLUMNWIDTH", ""); ctrlSnippet.SetCodelet("ITEMNAME", ctrl.controlName); ctrlSnippet.SetCodelet("ITEMID", childCtrl.controlName); if (ctrl.GetAttribute("hideLabel") == "true") { ctrlSnippet.SetCodelet("HIDELABEL", "true"); } else if (ChildControlName == Controls[0]) { ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "LABEL", ctrl, ctrl.Label); } snippetRowDefinition.InsertSnippet("ITEMS", ctrlSnippet, ","); } } else { // used for GroupBox, and Composite TExtJsFormsWriter.InsertControl(ctrl, snippetRowDefinition, "ITEMS", "HiddenValues", writer); TExtJsFormsWriter.InsertControl(ctrl, snippetRowDefinition, "ITEMS", "Controls", writer); } return(snippetRowDefinition); }
/// <summary> /// process the children /// </summary> public override void ProcessChildren(TFormWriter writer, TControlDef container) { // usually, the toolbar buttons are direct children of the toolbar control List <XmlNode> childrenlist = TYml2Xml.GetChildren(container.xmlNode, true); foreach (XmlNode childNode in childrenlist) { /* Get unique name if we need it * at the moment we need it only for menu separators */ String UniqueChildName = childNode.Name; TControlDef childCtrl = container.FCodeStorage.GetControl(childNode.Name); if (childCtrl == null) { UniqueChildName = TYml2Xml.GetAttribute(childNode, "UniqueName"); childCtrl = container.FCodeStorage.GetControl(UniqueChildName); } container.Children.Add(childCtrl); IControlGenerator ctrlGenerator = writer.FindControlGenerator(childCtrl); ctrlGenerator.GenerateControl(writer, childCtrl); } }
/// <summary> /// main function for creating a control /// </summary> /// <param name="ACtrl"></param> /// <param name="ATemplate"></param> /// <param name="AItemsPlaceholder"></param> /// <param name="ANodeName"></param> /// <param name="AWriter"></param> public static void InsertControl(TControlDef ACtrl, ProcessTemplate ATemplate, string AItemsPlaceholder, string ANodeName, TFormWriter AWriter) { XmlNode controlsNode = TXMLParser.GetChild(ACtrl.xmlNode, ANodeName); List <XmlNode> childNodes = TYml2Xml.GetChildren(controlsNode, true); if ((childNodes.Count > 0) && childNodes[0].Name.StartsWith("Row")) { foreach (XmlNode row in TYml2Xml.GetChildren(controlsNode, true)) { ProcessTemplate snippetRowDefinition = AWriter.FTemplate.GetSnippet("ROWDEFINITION"); StringCollection children = TYml2Xml.GetElements(controlsNode, row.Name); foreach (string child in children) { TControlDef childCtrl = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName); IControlGenerator ctrlGen = AWriter.FindControlGenerator(childCtrl); ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(AWriter, childCtrl); ProcessTemplate snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION"); LayoutCellInForm(childCtrl, children.Count, ctrlSnippet, snippetCellDefinition); if ((children.Count == 1) && ctrlGen is RadioGroupSimpleGenerator) { // do not use the ROWDEFINITION, but insert control directly // this helps with aligning the label for the group radio buttons snippetRowDefinition.InsertSnippet("ITEMS", ctrlSnippet, ","); } else { snippetCellDefinition.InsertSnippet("ITEM", ctrlSnippet); snippetRowDefinition.InsertSnippet("ITEMS", snippetCellDefinition, ","); } } ATemplate.InsertSnippet(AItemsPlaceholder, snippetRowDefinition, ","); } } else { foreach (XmlNode childNode in childNodes) { string child = TYml2Xml.GetElementName(childNode); TControlDef childCtrl = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName); if ((ANodeName != "HiddenValues") && (childCtrl.controlTypePrefix == "hid")) { // somehow, hidden values get into the controls list as well. we don't want them there continue; } IControlGenerator ctrlGen = AWriter.FindControlGenerator(childCtrl); if (ctrlGen is FieldSetGenerator) { InsertControl(AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName), ATemplate, AItemsPlaceholder, ANodeName, AWriter); } else { ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(AWriter, childCtrl); ProcessTemplate snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION"); LayoutCellInForm(childCtrl, -1, ctrlSnippet, snippetCellDefinition); ATemplate.InsertSnippet(AItemsPlaceholder, ctrlSnippet, ","); } } } }
/// <summary> /// create the code /// </summary> /// <param name="writer"></param> /// <param name="ctrl"></param> public void InsertControl(TFormWriter writer, TControlDef ctrl) { IControlGenerator ctrlGenerator = writer.FindControlGenerator(ctrl); string controlName = ctrl.controlName; if (FOrientation == eOrientation.TableLayout) { if (FCurrentRow != ctrl.rowNumber) { FCurrentColumn = 0; FCurrentRow = ctrl.rowNumber; } } /* this does not work yet; creates endless loop/recursion * if (ctrl.HasAttribute("LabelUnit")) * { * // we need another label after the control * LabelGenerator lblGenerator = new LabelGenerator(); * string lblName = lblGenerator.CalculateName(controlName) + "Unit"; * TControlDef unitLabel = writer.CodeStorage.FindOrCreateControl(lblName, controlName); * unitLabel.Label = ctrl.GetAttribute("LabelUnit"); * * TableLayoutPanelGenerator TlpGenerator = new TableLayoutPanelGenerator(); * ctrl.SetAttribute("ControlsOrientation", "horizontal"); * TlpGenerator.SetOrientation(ctrl); * StringCollection childControls = new StringCollection(); * childControls.Add(controlName); * childControls.Add(lblName); * string subTlpControlName = TlpGenerator.CreateLayout(writer, FTlpName, childControls); * * TlpGenerator.CreateCode(writer, ctrl); * TlpGenerator.CreateCode(writer, unitLabel); * * if (FOrientation == eOrientation.Vertical) * { * AddControl(writer, FTlpName, subTlpControlName, 1, FCurrentRow); * } * else * { * AddControl(writer, FTlpName, subTlpControlName, FCurrentColumn * 2 + 1, 0); * } * } * else */ if (ctrl.HasAttribute("GenerateWithOtherControls")) { // add the checkbox/radiobutton first if (FOrientation == eOrientation.Vertical) { AddControl(ctrl, 0, FCurrentRow); } else if (FOrientation == eOrientation.Horizontal) { AddControl(ctrl, FCurrentColumn * 2, 0); } else if (FOrientation == eOrientation.TableLayout) { AddControl(ctrl, FCurrentColumn, FCurrentRow); } StringCollection childControls = TYml2Xml.GetElements(TXMLParser.GetChild(ctrl.xmlNode, "Controls")); if (childControls.Count > 1) { // we need another tablelayout to arrange all the controls PanelLayoutGenerator TlpGenerator = new PanelLayoutGenerator(); TlpGenerator.SetOrientation(ctrl); Int32 NewHeight = -1; Int32 NewWidth = -1; if (ctrl.HasAttribute("Height")) { NewHeight = Convert.ToInt32(ctrl.GetAttribute("Height")); ctrl.ClearAttribute("Height"); } if (ctrl.HasAttribute("Width")) { NewWidth = Convert.ToInt32(ctrl.GetAttribute("Width")); ctrl.ClearAttribute("Width"); } TControlDef subTlpControl = TlpGenerator.CreateNewPanel(writer, ctrl); TlpGenerator.CreateLayout(writer, ctrl, subTlpControl, NewWidth, NewHeight); foreach (string ChildControlName in childControls) { TControlDef ChildControl = ctrl.FCodeStorage.GetControl(ChildControlName); TlpGenerator.InsertControl(writer, ChildControl); } TlpGenerator.WriteTableLayout(writer, subTlpControl); if (FOrientation == eOrientation.Vertical) { AddControl(subTlpControl, 1, FCurrentRow); } else if (FOrientation == eOrientation.Horizontal) { AddControl(subTlpControl, FCurrentColumn * 2 + 1, 0); } else if (FOrientation == eOrientation.TableLayout) { AddControl(subTlpControl, FCurrentColumn + 1, FCurrentRow); } } else if (childControls.Count == 1) { // we don't need to add another table layout for just one other control TControlDef ChildCtrl = ctrl.FCodeStorage.GetControl(childControls[0]); IControlGenerator ChildGenerator = writer.FindControlGenerator(ChildCtrl); ChildGenerator.GenerateControl(writer, ChildCtrl); if (FOrientation == eOrientation.Vertical) { AddControl(ChildCtrl, 1, FCurrentRow); } else if (FOrientation == eOrientation.Horizontal) { AddControl(ChildCtrl, FCurrentColumn * 2 + 1, 0); } else if (FOrientation == eOrientation.TableLayout) { AddControl(ChildCtrl, FCurrentColumn + 1, FCurrentRow); } } } else if (ctrl.controlName.StartsWith("pnlEmpty")) { // don't do anything here! } else if (ctrlGenerator.GenerateLabel(ctrl)) { // add label LabelGenerator lblGenerator = new LabelGenerator(); string lblName = lblGenerator.CalculateName(controlName); TControlDef newLabel = writer.CodeStorage.FindOrCreateControl(lblName, ctrl.controlName); newLabel.Label = ctrl.Label; if (ctrl.HasAttribute("LabelWidth")) { newLabel.SetAttribute("Width", ctrl.GetAttribute("LabelWidth")); } if (ctrl.HasAttribute("LabelUnit")) { // alternative implementation above does not work: add another label control after the input control newLabel.Label = newLabel.Label + " (in " + ctrl.GetAttribute("LabelUnit") + ")"; } lblGenerator.GenerateDeclaration(writer, newLabel); lblGenerator.RightAlign = true; lblGenerator.SetControlProperties(writer, newLabel); AddControl(newLabel, FCurrentColumn * 2, FCurrentRow); AddControl(ctrl, FCurrentColumn * 2 + 1, FCurrentRow); } else { AddControl(ctrl, FCurrentColumn * 2, FCurrentRow); } if (FOrientation == eOrientation.Vertical) { FCurrentRow++; FCurrentColumn = 0; } else if (FOrientation == eOrientation.Horizontal) { FCurrentColumn++; } else if (FOrientation == eOrientation.TableLayout) { FCurrentColumn += ctrl.colSpan; } }
/// <summary>add GeneratedReadSetControls, and all dependent controls</summary> public override void ApplyDerivedFunctionality(TFormWriter writer, TControlDef control) { string paramName = ReportControls.GetParameterName(control.xmlNode); if (paramName == null) { return; } StringCollection Controls = TYml2Xml.GetElements(TXMLParser.GetChild(control.xmlNode, "Controls")); foreach (string controlName in Controls) { TControlDef rbtCtrl = writer.CodeStorage.GetControl(controlName); string rbtValue = rbtCtrl.Label; rbtValue = StringHelper.UpperCamelCase(rbtValue.Replace("'", "").Replace(" ", "_"), false, false); if (rbtCtrl.HasAttribute("ParameterValue")) { rbtValue = rbtCtrl.GetAttribute("ParameterValue"); } string rbtName = "rbt" + controlName.Substring(3); if (controlName.StartsWith("layoutPanel")) { // the table layouts of sub controls for each radio button need to be skipped continue; } ProcessTemplate RadioButtonReadControlsSnippet = writer.Template.GetSnippet("RADIOBUTTONREADCONTROLS"); RadioButtonReadControlsSnippet.SetCodelet("RBTNAME", rbtName); RadioButtonReadControlsSnippet.SetCodelet("PARAMNAME", paramName); RadioButtonReadControlsSnippet.SetCodelet("RBTVALUE", rbtValue); RadioButtonReadControlsSnippet.SetCodelet("READCONTROLS", ""); XmlNode childControls = TXMLParser.GetChild(rbtCtrl.xmlNode, "Controls"); // only assign variables that make sense if (childControls != null) { StringCollection childControlNames = TYml2Xml.GetElements(childControls); foreach (string childName in childControlNames) { if (childName.StartsWith("layoutPanel")) { continue; } TControlDef childCtrl = writer.CodeStorage.GetControl(childName); IControlGenerator generator = writer.FindControlGenerator(childCtrl); // make sure we ignore Button etc if (generator.GetType().ToString().EndsWith("ReportGenerator")) { childCtrl.SetAttribute("DependsOnRadioButton", ""); ReportControls.GenerateReadSetControls(writer, childCtrl.xmlNode, RadioButtonReadControlsSnippet, generator.TemplateSnippetName); childCtrl.SetAttribute("DependsOnRadioButton", "true"); } } } writer.Template.InsertSnippet("READCONTROLS", RadioButtonReadControlsSnippet); ProcessTemplate RadioButtonSetControlsSnippet = writer.Template.GetSnippet("RADIOBUTTONSETCONTROLS"); RadioButtonSetControlsSnippet.SetCodelet("RBTNAME", rbtName); RadioButtonSetControlsSnippet.SetCodelet("PARAMNAME", paramName); RadioButtonSetControlsSnippet.SetCodelet("RBTVALUE", rbtValue); // only assign variables that make sense if (childControls != null) { StringCollection childControlNames = TYml2Xml.GetElements(childControls); foreach (string childName in childControlNames) { if (childName.StartsWith("layoutPanel")) { continue; } TControlDef childCtrl = writer.CodeStorage.GetControl(childName); IControlGenerator generator = writer.FindControlGenerator(childCtrl); // make sure we ignore Button etc if (generator.GetType().ToString().EndsWith("ReportGenerator")) { childCtrl.SetAttribute("DependsOnRadioButton", ""); ReportControls.GenerateReadSetControls(writer, childCtrl.xmlNode, RadioButtonSetControlsSnippet, generator.TemplateSnippetName); childCtrl.SetAttribute("DependsOnRadioButton", "true"); } } } writer.Template.InsertSnippet("SETCONTROLS", RadioButtonSetControlsSnippet); } }