/// <summary> /// Throws an exception if the block control's MaximumWidth property value is invalid /// </summary> /// <param name="blockControl"></param> public static void ThrowIfInvalidMaximumWidth(this IBlockControl blockControl) { if (blockControl.MaximumWidth < 4 || blockControl.MaximumWidth > 12) { throw new InvalidPropertyValueException("MaximumWidth must be set to a value between 4 and 12 and be divisible by 2"); } }
private void ProcessBlock(ContainerGlobals globals, XmlNode valueNode, IFieldControl fieldControl, string fullPropertyName) { int maxDepth = globals.MaxDepth; IBlockControl blockControl = fieldControl as IBlockControl; if (valueNode.Attributes["maxelements"] != null) { blockControl.MaxBlockCount = Convert.ToInt32(valueNode.Attributes["maxelements"].Value); } else { blockControl.MaxBlockCount = -1; } // At this point, we need to recurse and create the sub control for this block. // Step 1: Locate the proper struct in the document and construct it's full path. string structName = valueNode.Attributes["struct"].InnerText; XmlNode structNode = tagDefinition.SelectSingleNode("//struct[@name='" + structName + "']"); Controls.BlockContainer fieldControlContainer = new Controls.BlockContainer(); fieldControlContainer.Globals = new ContainerGlobals(globals, structNode, maxDepth); InitContainer(fieldControlContainer); fieldControlContainer.ContainerName = StringOps.CapitalizeWords(fieldControl.Title); fieldControlContainer.FooterText = "End of '" + fieldControlContainer.ContainerName + "' Block"; fieldControlContainer.BoundPropertyName = fullPropertyName; //fieldControlContainer.Block.BlockChanged += new BlockChangedHandler(); // add the IBlockControl fieldControlContainer.AddField(fieldControl); containers.Peek().AddFieldContainer(fieldControlContainer); // Step 3: Wire up the BlockChanged event for databinding. blockControl.Initialize(); }
/// <summary> /// Throws an exception if the block control's Width property value is invalid /// </summary> /// <param name="blockControl"></param> public static void ThrowIfInvalidWidth(this IBlockControl blockControl) { if (blockControl.Width < blockControl.MinimumWidth || blockControl.Width > blockControl.MaximumWidth) { throw new InvalidPropertyValueException(string.Format("Width must be set to a value between {0} and {1}", blockControl.MinimumWidth, blockControl.MaximumWidth)); } }
/// <summary> /// Gets the content area control in which this partial view is rendered /// </summary> /// <returns>The PropertyContentAreaControl in which this control is rendered, otherwise null</returns> public static PropertyContentAreaControl ContentAreaControl(this IBlockControl contentDataControl) { var ctrl = contentDataControl as Control; if (ctrl != null && ctrl.Parent != null && ctrl.Parent.BindingContainer != null) { return(ctrl.Parent.BindingContainer as PropertyContentAreaControl); } return(null); }
/// <summary> /// Gets the number of blocks or partial pages rendered inside a content area /// </summary> public static int NumberOfBlocks(this IBlockControl contentDataControl) { var contentAreaControl = contentDataControl.ContentAreaControl(); // Not rendered inside a content area if (contentAreaControl == null || contentAreaControl.PropertyData == null) { return(0); } var contentArea = contentAreaControl.PropertyData.Value as ContentArea; return(contentArea != null ? contentArea.Count : 0); }
/// <summary> /// Called when the control is changed. If the parent of this /// control is a Block control, then we update it with its new /// element field data /// </summary> protected void UpdateParent() { if (Parent != null) { try { IBlockControl parent = Parent.Parent.Parent as IBlockControl; if (parent.CurrentIndex != -1) { parent.UpdateFieldData(parent.CurrentIndex); } } catch { Debug.LogFile.WriteLine("Block element data update failed! {0} {1}", GetType().Name, ControlName); } } }
protected void SetBlockControl(IBlockControl block) { if (block != blockControl) { if (blockControl is Control) { Controls.Remove(blockControl as Control); } blockControl = block; Controls.Add(block as Control); OnBlockControlChanged(this, new EventArgs()); } }
/// <summary> /// Adds a CSS class to the parent content control /// </summary> /// <param name="contentDataControl"></param> /// <param name="cssClass"></param> /// <remarks>Equivalent of setting the ChildrenCssClass render setting for a Property control rendering a ContentArea, but only affects the block container for this particular block instance</remarks> public static void AddParentControlControlCssClass(this IBlockControl contentDataControl, string cssClass) { if (string.IsNullOrWhiteSpace(cssClass)) { return; } var control = contentDataControl as Control; if (control == null) { throw new NotSupportedException("The specified IContentDataControl was not a Control"); } var parent = control.Parent as ContentRenderer; if (parent == null) { return; } parent.CssClass = string.Join(" ", parent.CssClass, cssClass).Trim(); }
/// <summary> /// Gets common CSS classes for a block or partial page when rendered inside a content area /// </summary> /// <param name="contentDataControl"></param> /// <returns></returns> /// <remarks>The CSS class names and rules derive from the Bootstrap HTML framework</remarks> public static string GetBlockContainerCssClasses(this IBlockControl contentDataControl) { /* Block styling is based on a combination of a Bootstrap CSS class and a site styling CSS class. * The site styling CSS class name can be retrieved using the GetCssClassForTag method. * No site styling CSS class is needed for the default block size, ie 'span4' */ var blockTypeName = contentDataControl.CurrentData is PageData ? ((PageData)contentDataControl.CurrentData).PageTypeName.ToLower().Replace("proxy", string.Empty) // The 'proxy' suffix is added to type names at runtime : contentDataControl.CurrentData.GetType().Name.ToLower().Replace("proxy", string.Empty); var cssClasses = new List <string>(3) { "block", // Common for all blocks and partial page views blockTypeName, // For styling based on the block type string.Format("span{0}", contentDataControl.Width), // Sets a size CSS class based on Bootstrap contentDataControl.ContainerCssClass // Any CSS classes specified explicitly by the block control }; // Add additional styling CSS class if required switch (contentDataControl.Width) { case Global.ContentAreaWidths.HalfWidth: cssClasses.Add(GetCssClassForTag(Global.ContentAreaTags.HalfWidth)); break; case Global.ContentAreaWidths.TwoThirdsWidth: cssClasses.Add(GetCssClassForTag(Global.ContentAreaTags.TwoThirdsWidth)); break; case Global.ContentAreaWidths.FullWidth: cssClasses.Add(GetCssClassForTag(Global.ContentAreaTags.FullWidth)); break; } return(string.Join(" ", cssClasses).Trim()); }
public void DatabindChildrenToBlock(IBlock block, IFieldControlContainer container) { #region Old Method /*linkedBlock = block; * * if (block != null) * { * int index = -1; * IFieldControl[] childFields = GetChildFields(); * foreach (FieldControlBase field in childFields) * { * index++; * field.Enabled = true; * * try * { * // If the field is not a block, we will need to databind it. * if (!(field is IBlockControl)) * { * IField binding = (LocateFieldByName(linkedBlock, field.BoundPropertyName) as IField); * if (binding != null) * { * field.DataBind(binding); * Binding[] bindings = field.GetDataBindings(); * foreach (Binding bind in bindings) * { * bind.Parse += bind_Parse; * } * } * } * // If it is a block, we need to recurse on the block so that its children get databound. * else * { * IBlockCollection binding = LocateFieldByName(linkedBlock, field.BoundPropertyName) as IBlockCollection; * if (binding != null) * { * (field as IBlockControl).DataBindCollection(binding); * (field as IBlockControl).Initialize(); * } * else * field.Enabled = false; * } * } * catch (Exception ex) * { * Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "There was an error databinding to " + field.BoundPropertyName + ":" + ex.Message, ex); * //MessageBox.Show("There was an error binding \"" + field.BoundPropertyName + ":\" " + ex.Message); * } * } * } * else * { * foreach (FieldControlBase field in GetChildFields()) * field.Enabled = false; * }*/ #endregion #region New Method if (container is FieldContainerBase) { container = (container as FieldContainerBase).FieldPanel; } if (container == null) { return; } //(container as Control).Enabled = (block != null); if (block == null) { IFieldControl[] children = container.GetChildFields(); foreach (FieldControlBase field in children) { field.Enabled = false; } return; } Control control = container as Control; // This is a bug-fix. At some point along the line, databinding was attached to an FieldContainerBase... so to fix it, we relink to the FieldPanel property. if (container is FieldContainerBase) { control = (container as FieldContainerBase).FieldPanel; } for (int x = 0; x < control.Controls.Count; x++) { Control curControl = control.Controls[x]; curControl.Visible = true; // Determine whether or not the field is a FieldControlBase or not. FieldControlBase field = (curControl is FieldControlBase) ? curControl as FieldControlBase : null; #region the current control is a field if (field != null) { field.Enabled = true; #region If the field is not a block, we will need to databind it. if (!(field is IBlockControl)) { IField binding = (LocateFieldByName(block, field.BoundPropertyName) as IField); if (binding != null) { field.DataBind(binding); Binding[] bindings = field.GetDataBindings(); foreach (Binding bind in bindings) { bind.Parse += bind_Parse; } } else { field.Enabled = false; } } #endregion else // This shouldn't happen, EVER! { Interfaces.Output.Write(Interfaces.OutputTypes.Information, "DatabindChildrenToBlock came across an IBlockControl."); } } #endregion #region the current control is a block container. else if (curControl is Prometheus.Controls.BlockContainer) { Prometheus.Controls.BlockContainer blockContainer = curControl as Prometheus.Controls.BlockContainer; blockContainer.Enabled = true; IBlock nextBlock = null; BlockContainerPanel nextContainer = null; #region get the next container // We're getting all of the controls of type FieldContainerPanel, though there should only be one. /*Control[] fieldContainerPanels = GetChildControlsByType(blockContainer, typeof(BlockContainerPanel)); * if (fieldContainerPanels.Length > 0) * { * nextContainer = fieldContainerPanels[0] as BlockContainerPanel; * } * else * { * // This is a warning because the rest of the tag will work properly and execution can continue as normal. * Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "During databinding, the block \"" + blockContainer.BoundPropertyName + "\" did not have a field container panel!"); * continue; * }*/ if (blockContainer.FieldPanel != null) { nextContainer = blockContainer.FieldPanel; } #endregion #region get the next block /*Control[] blocks = GetChildControlsByType(blockContainer, typeof(IBlockControl)); * if (blocks.Length > 0) * { * IBlockControl blockControl = blocks[0] as IBlockControl; * blockControl.Container = nextContainer as IFieldControlContainer; * IBlockCollection binding = LocateFieldByName(block, (blockControl as IBoundPropertyCapable).BoundPropertyName) as IBlockCollection; * if (binding != null) * { * blockControl.DataBindCollection(binding); * blockControl.Initialize(); * } * } * else * { * Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "During databinding, the block \"" + blockContainer.BoundPropertyName + "\" did not have an IBlockControl!"); * continue; * }*/ if (blockContainer.Block != null) { IBlockControl blockControl = blockContainer.Block; if (blockContainer.FieldPanel == null) { blockControl.Container = blockContainer; } else { blockControl.Container = blockContainer.FieldPanel; } IBlockCollection binding = LocateFieldByName(block, (blockControl as IBoundPropertyCapable).BoundPropertyName) as IBlockCollection; if (binding != null) { blockControl.DataBindCollection(binding); blockControl.Initialize(); } if (blockControl.SelectedBlockIndex > -1) { nextBlock = blockControl.BlockCollection.GetBlock(blockControl.SelectedBlockIndex); } } #endregion if ((nextBlock != null) && (nextContainer != null)) { DatabindChildrenToBlock(nextBlock, nextContainer); } } else if (curControl is FieldContainerBase) { FieldContainerBase fieldContainer = curControl as FieldContainerBase; fieldContainer.Enabled = true; DatabindChildrenToBlock(block, fieldContainer.FieldPanel); } #endregion } #endregion }
private void LoadBlock(IDynamicContainer container) { this.tagDefinition = container.Globals.TagDefinition; //int depth = (int)buildDepth.Pop(); //buildDepth.Push(depth + 1); BlockContainerPanel panel = BuildStruct(container.Globals); panel.SuspendLayout(); panel.DepthDifference = container.Globals.DepthDifference; container.FieldPanel = panel; //container.Block.BlockChanged += new BlockChangedHandler(panel.DatabindChildrenToBlock); /*if (container.Block != null) * { * container.Block.BlockChanged += new BlockChangedHandler((panel as BlockContainerPanel).DatabindChildrenToBlock); * if (container.Block.SelectedBlockIndex > -1) * (panel as BlockContainerPanel).DatabindChildrenToBlock(container.Block.BlockCollection.GetBlock(container.Block.SelectedBlockIndex)); * else * { * if ((container.Parent != null) && (container.Parent.Block != null) && (container.Parent.Block.SelectedBlockIndex != null)) * ((tabArguments[tabControl.SelectedTabIndex].Container as IDynamicContainer).FieldPanel).DatabindChildrenToBlock(container.Parent.Block.BlockCollection.GetBlock(container.Parent.Block.SelectedBlockIndex)); * else * ((tabArguments[tabControl.SelectedTabIndex].Container as Control).Controls[0] as BlockContainerPanel).DatabindChildrenToBlock(tabArguments[tabControl.SelectedTabIndex].TagData, container); * } * } * else * { * //((tabArguments[tabControl.SelectedTabIndex].Container as Control).Controls[0] as BlockContainerPanel).DatabindChildrenToBlock(tabArguments[tabControl.SelectedTabIndex].TagData); * if ((container.Parent != null) && (container.Parent.Block != null) && (container.Parent.Block.SelectedBlockIndex != null)) * ((tabArguments[tabControl.SelectedTabIndex].Container as IDynamicContainer).FieldPanel).DatabindChildrenToBlock(container.Parent.Block.BlockCollection.GetBlock(container.Parent.Block.SelectedBlockIndex)); * else * ((tabArguments[tabControl.SelectedTabIndex].Container as Control).Controls[0] as BlockContainerPanel).DatabindChildrenToBlock(tabArguments[tabControl.SelectedTabIndex].TagData, container); * }*/ // Sets the active block to being the block's selection and performs databinding IBlockControl block = panel.GetParentBlock(); if ((block != null) && (block.BlockCollection != null)) { block.BlockChanged += new BlockChangedHandler(panel.DatabindChildrenToBlock); IBlock tempBlock = null; if (block.BlockCollection.BlockCount > 0) { if (block.SelectedBlockIndex > 0) { tempBlock = block.BlockCollection.GetBlock(block.SelectedBlockIndex); } else { block.SelectedBlockIndex = 0; tempBlock = block.BlockCollection.GetBlock(0); } } // if this is a region, we don't want the databinding to disable the controls. // Basically, it will always databind if it's not null, or if it is a block, rather than a region/section/whatever. if ((tempBlock != null) || (container is BlockContainer)) { panel.DatabindChildrenToBlock(tempBlock); } } else { panel.DatabindChildrenToBlock(tabArguments[tabControl.SelectedTabIndex].TagData, panel); } // Databind the block. if (panel != null) { panel.Visible = true; if (panel is BlockContainerPanel) { ConnectBlocks(panel as BlockContainerPanel); } } container.Globals.IsLoaded = true; panel.ResumeLayout(); }
public void ConnectBlockControl(IBlockControl control) { control.BlockCollectionChanged += new BlockCollectionChangedHandler(control_BlockCollectionChanged); UpdateComboBox(control.BlockValues); DataBindComboBox(); }