internal ButtonDock CreateButtonDock(object data, ToolbarBuildContext buildContext) { ButtonDockProperties properties = DataNodeWrapper.GetNodeAttributes(data).To <ButtonDockProperties>(); ButtonDock dock = new ButtonDock(Root, properties.Id, properties); return(dock); }
protected override void EnsureCorrectChildType(Component child) { if (!typeof(ButtonDock).IsInstanceOfType(child)) { throw new ArgumentOutOfRangeException("Only children of type ButtonDock can be added to a Toolbar"); } ButtonDock dock = (ButtonDock)child; if (dock.Alignment == DataNodeWrapper.CENTERALIGN) { foreach (ButtonDock current in Children) { if (current.Alignment == DataNodeWrapper.CENTERALIGN) { throw new InvalidOperationException("Can't add a centered buttondock because one is already present."); } } } }
/// <summary> /// Constructs a toolbar from its JSON data. /// </summary> private Toolbar BuildToolbarFromData(object data, ToolbarBuildContext context) { JSObject toolbarElement = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.TOOLBAR); if (CUIUtility.IsNullOrUndefined(toolbarElement)) { throw new ArgumentNullException("No toolbar element was present in the data"); } bool hasJewel = !CUIUtility.IsNullOrUndefined(DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.JEWEL)); Toolbar = new Toolbar( DataNodeWrapper.GetAttribute(toolbarElement, DataNodeWrapper.ID), DataNodeWrapper.GetNodeAttributes(toolbarElement).To <ToolbarProperties>(), this, hasJewel); Toolbar.ClientID = Options.ClientID; Toolbar.UseDataCookie = true; Toolbar.RefreshInternal(); // We need to refresh before we can attach the jewel. if (hasJewel) { Toolbar.AttachAndBuildJewelFromData(data); } // Build the ButtonDocks (the Docks will build their subcontrols). JSObject docks = DataNodeWrapper.GetFirstChildNodeWithName(toolbarElement, DataNodeWrapper.BUTTONDOCKS); JSObject[] dockChildren = DataNodeWrapper.GetNodeChildren(docks); for (int i = 0; i < dockChildren.Length; i++) { ButtonDock dock = BuildButtonDock(dockChildren[i], context); Toolbar.AddChild(dock); } return(Toolbar); }
/// <summary> /// Build up a ButtonDock based on the JSON object provided. /// </summary> private ButtonDock BuildButtonDock(object data, ToolbarBuildContext buildContext) { ButtonDock dock = Toolbar.CreateButtonDock(data, buildContext); JSObject controlsNode = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.CONTROLS); JSObject[] controls = DataNodeWrapper.GetNodeChildren(controlsNode); for (int i = 0; i < controls.Length; i++) { // Don't build trimmed controls if (IsNodeTrimmed(controls[i])) { continue; } Component currentDisplayComponent = BuildToolbarControlComponent(controls[i], buildContext); dock.AddChild(currentDisplayComponent); } return(dock); }
internal ButtonDock CreateButtonDock(object data, ToolbarBuildContext buildContext) { ButtonDockProperties properties = DataNodeWrapper.GetNodeAttributes(data).To<ButtonDockProperties>(); ButtonDock dock = new ButtonDock(Root, properties.Id, properties); return dock; }