private ColorPicker BuildColorPicker(object data, BuildContext bc) { ColorPickerProperties properties = DataNodeWrapper.GetNodeAttributes(data).To <ColorPickerProperties>(); JSObject[] colorNodes = DataNodeWrapper.GetNodeChildren( DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.Colors)); int numColors = colorNodes.Length; ColorStyle[] colors = new ColorStyle[numColors]; for (int i = 0; i < numColors; i++) { ColorStyle color = new ColorStyle(); JSObject dict = DataNodeWrapper.GetNodeAttributes(colorNodes[i]); string title = DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.TITLE); color.Title = string.IsNullOrEmpty(title) ? DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.ALT) : title; color.Color = DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.COLOR); color.DisplayColor = DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.DISPLAYCOLOR); color.Style = DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.STYLE); colors[i] = color; } ColorPicker cp = new ColorPicker(Root, properties.Id, properties, colors); return(cp); }
private QAT BuildQATInternal(object data, QATBuildContext qbc) { if (CUIUtility.IsNullOrUndefined(data)) { throw new ArgumentNullException("No QAT element was present in the data"); } QAT = new QAT(DataNodeWrapper.GetAttribute(data, "Id"), DataNodeWrapper.GetNodeAttributes(data).To <QATProperties>()); // Handle the controls in the QAT // The XML structure looks like <QAT><Controls><Control></Control><Control></Control>... JSObject controlsParent = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.CONTROLS); JSObject[] controls = DataNodeWrapper.GetNodeChildren(controlsParent); for (int j = 0; j < controls.Length; j++) { if (!IsNodeTrimmed(controls[j])) { Control control = BuildControl(controls[j], qbc); QAT.AddChild(control.CreateComponentForDisplayMode("Small")); } } return(QAT); }
private GalleryButton BuildGalleryButton(object data, BuildContext bc, string strElmDims) { GalleryElementDimensions elmDims; // If elmDims is null, try to get the value from data if (string.IsNullOrEmpty(strElmDims)) { JSObject attrs = DataNodeWrapper.GetNodeAttributes(data); strElmDims = DataNodeWrapper.GetAttribute(attrs, DataNodeWrapper.ELEMENTDIMENSIONS); } // If elmDims is still null (no value defined in data), default to 32x32 if (string.IsNullOrEmpty(strElmDims)) { elmDims = GalleryElementDimensions.Size32by32; } else { elmDims = Gallery.ConvertStringToGalleryElementDimensions(strElmDims); } GalleryButtonProperties properties = DataNodeWrapper.GetNodeAttributes(data).To <GalleryButtonProperties>(); GalleryButton gb = new GalleryButton(Root, properties.Id, properties, elmDims); return(gb); }
internal void AttachAndBuildJewelFromData(object jewelData) { if (!_hasJewel) { return; } _elmJewelPlaceholder.Style.Display = "block"; JewelBuildContext jbc = new JewelBuildContext(); jbc.JewelId = DataNodeWrapper.GetAttribute(jewelData, "Id"); // Build Jewel JewelBuildOptions options = new JewelBuildOptions(); options.TrimmedIds = _builder.Options.TrimmedIds; JewelBuilder builder = new JewelBuilder(options, _elmJewelPlaceholder, _builder.BuildClient); builder.BuildJewelFromData(jewelData, jbc); this.Jewel = builder.Jewel; }
private string[] BuildUnitAbbreviations(JSObject[] children) { int l = children.Length; string[] abbreviations = new string[l]; for (int i = 0; i < l; i++) { abbreviations[i] = DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.VALUE); } return(abbreviations); }
private SPRibbon BuildRibbon(object data, RibbonBuildContext rbc) { JSObject ribbonElement = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.RIBBON); if (CUIUtility.IsNullOrUndefined(ribbonElement)) { throw new ArgumentNullException("No ribbon element was present in the data"); } Ribbon = new SPRibbon(DataNodeWrapper.GetAttribute(ribbonElement, "Id"), DataNodeWrapper.GetNodeAttributes(ribbonElement).To <RibbonProperties>()); //REVIEW(josefl) Should this be configurable? Ribbon.UseDataCookie = true; // Handle the Tabs // The XML structure that we are looking at is <Ribbon><Tabs><Tab/><Tab/>... JSObject[] tabChildren = DataNodeWrapper.GetNodeChildren( DataNodeWrapper.GetFirstChildNodeWithName(ribbonElement, DataNodeWrapper.TABS)); AddTabsToRibbon(tabChildren, "", rbc); // Handle the Contextual Tab Groups // The XML structure that we are looking at is <Ribbon><ContextualTabs><ContextualGroup>... object contextualTabs = DataNodeWrapper.GetFirstChildNodeWithName(ribbonElement, DataNodeWrapper.CONTEXTUALTABS); if (!CUIUtility.IsNullOrUndefined(contextualTabs)) { JSObject[] cgChildren = DataNodeWrapper.GetNodeChildren(contextualTabs); bool shownContextualGroupsSpecified = !CUIUtility.IsNullOrUndefined(RibbonBuildOptions.ShownContextualGroups); for (int j = 0; j < cgChildren.Length; j++) { if (shownContextualGroupsSpecified) { // Show the contextual group if it has been explicitly requested/ made available string cgId = DataNodeWrapper.GetAttribute(cgChildren[j], DataNodeWrapper.ID); if (!string.IsNullOrEmpty(cgId)) { if (!RibbonBuildOptions.ShownContextualGroups.ContainsKey(cgId) || CUIUtility.IsNullOrUndefined(RibbonBuildOptions.ShownContextualGroups[cgId])) { continue; } } } AddContextualGroup(cgChildren[j], rbc); } } return(Ribbon); }
private MenuSection BuildMenuSection(JSObject data, BuildContext bc) { string displayMode = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DISPLAYMODE); if (CUIUtility.IsNullOrUndefined(displayMode)) { displayMode = "Menu"; } string id = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID); string title = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE); string description = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DESCRIPTION); bool scrollable = Utility.IsTrue(DataNodeWrapper.GetAttribute(data, DataNodeWrapper.SCROLLABLE)); string maxheight = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.MAXHEIGHT); MenuSection ms = Root.CreateMenuSection(id, title, description, scrollable, maxheight, displayMode); JSObject[] menuSectionChildren = DataNodeWrapper.GetNodeChildren(data); JSObject msChild = menuSectionChildren[0]; string msChildName = DataNodeWrapper.GetNodeName(msChild); if (msChildName == DataNodeWrapper.CONTROLS) { // Get the <MenuSection><Controls> node's children JSObject[] individualControls = DataNodeWrapper.GetNodeChildren(msChild); int l = individualControls.Length; JSObject child = null; for (int i = 0; i < l; i++) { child = individualControls[i]; if (IsNodeTrimmed(child)) { continue; } Control control = BuildControl(child, bc); ms.AddChild(control.CreateComponentForDisplayMode(displayMode)); } } else if (msChildName == DataNodeWrapper.GALLERY) { Gallery gallery = BuildGallery(msChild, bc, true); ms.AddChild(gallery); } return(ms); }
private Tab BuildTab(object data, RibbonBuildContext rbc, string contextualGroupId) { Tab tab; string id = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID); string title = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE); string description = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DESCRIPTION); string command = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.COMMAND); string cssclass = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.CSSCLASS); if (string.IsNullOrEmpty(contextualGroupId)) { tab = Ribbon.CreateTab(id, title, description, command, cssclass); } else { tab = Ribbon.CreateContextualTab(id, title, description, command, contextualGroupId, cssclass); // Make sure that the tabs that are in the initially shown contextual groups are visible if (!CUIUtility.IsNullOrUndefined(RibbonBuildOptions.InitiallyVisibleContextualGroups) && RibbonBuildOptions.InitiallyVisibleContextualGroups.ContainsKey(contextualGroupId) && RibbonBuildOptions.InitiallyVisibleContextualGroups[contextualGroupId]) { tab.VisibleInternal = true; } } // If the Tab is being inited in a shallow way, then we set the callback so that // the builder will be called if the Tab is selected. // We set up the Tab to be delay initialized and give it its own copy of the build context JSObject[] children = DataNodeWrapper.GetNodeChildren(data); if (children.Length == 0) { tab.SetDelayedInitData(new DelayedInitHandler(DelayInitTab), data, rbc.Clone()); } else { FillTab(tab, data, rbc); } return(tab); }
/// <summary> /// The toolbar doesn't require scaling code -- it just builds with a static set of display modes, /// since it only supports one display mode per control type. /// </summary> private Component BuildToolbarControlComponent(object data, ToolbarBuildContext buildContext) { Control control = null; string name = DataNodeWrapper.GetNodeName(data); string displayMode = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DISPLAYMODE); switch (name) { case DataNodeWrapper.Button: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Small" : displayMode)); case DataNodeWrapper.CheckBox: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Small" : displayMode)); case DataNodeWrapper.ComboBox: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode("Medium")); case DataNodeWrapper.FlyoutAnchor: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Medium" : displayMode)); case DataNodeWrapper.Label: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Small" : displayMode)); case DataNodeWrapper.Separator: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode("Small")); case DataNodeWrapper.TextBox: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Medium" : displayMode)); case DataNodeWrapper.ToggleButton: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Small" : displayMode)); default: throw new InvalidOperationException("Invalid control type."); } }
private ComboBox BuildComboBox(object data, BuildContext bc) { ComboBoxProperties properties = DataNodeWrapper.GetNodeAttributes(data).To <ComboBoxProperties>(); JSObject[] children = DataNodeWrapper.GetNodeChildren(data); Menu menu = null; MenuLauncherControlProperties launcherProperties = DataNodeWrapper.GetNodeAttributes(data).To <MenuLauncherControlProperties>(); Dictionary <string, string> menuItems = null; if (!Utility.IsTrue(launcherProperties.PopulateDynamically)) { // Since PopulateDynamically is not true, we pass in "false" for LazyInit menu = BuildMenu(children[0], bc, false); // Parse XML subtree to build MenuItem list for auto-complete menuItems = new Dictionary <string, string>(); JSObject[] sections = DataNodeWrapper.GetNodeChildren(children[0]); int l = sections.Length; for (int i = 0; i < l; i++) { // Get children of the MenuSection node JSObject[] sectionChildren = DataNodeWrapper.GetNodeChildren(sections[i]); // Get children of the Controls node within the MenuSection // There should only be 1 Controls node within the MenuSection subtree JSObject[] items = DataNodeWrapper.GetNodeChildren(sectionChildren[0]); int m = items.Length; for (int j = 0; j < m; j++) { string labeltext = DataNodeWrapper.GetAttribute(items[j], DataNodeWrapper.LABELTEXT); string menuitemid = DataNodeWrapper.GetAttribute(items[j], DataNodeWrapper.MENUITEMID); menuItems[labeltext] = menuitemid; } } } ComboBox fscb = new ComboBox(Root, properties.Id, properties, menu); fscb.MenuItems = menuItems; return(fscb); }
private void LoadGroupTemplate(object data) { string id = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID); string className = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.CLASSNAME); // If the template is already loaded, then we don't load it again if (!CUIUtility.IsNullOrUndefined(GetTemplate(id))) { return; } if (string.IsNullOrEmpty(className)) { AddTemplate(new DeclarativeTemplate(data), id); } }
private ControlComponent CreateControlComponentFromData(object data, DeclarativeTemplateBuildContext bc) { string alias = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TEMPLATEALIAS); string displayMode = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DISPLAYMODE); ControlComponent comp = null; List <Control> control = bc.Controls.ContainsKey(alias) ? bc.Controls[alias] : null; // If there is more than one control that is using the same TemplateAlias and the template // slot is a ControlRef, then the slot remains empty so that the problem can be detected and resolved. if (!CUIUtility.IsNullOrUndefined(control) && control.Count > 1) { comp = control[0].CreateComponentForDisplayMode(displayMode); } return(comp); }
private Jewel BuildJewelInternal(object data, JewelBuildContext jbc) { if (CUIUtility.IsNullOrUndefined(data)) { throw new ArgumentNullException("No Jewel element was present in the data"); } Jewel = new Jewel(DataNodeWrapper.GetAttribute(data, "Id"), DataNodeWrapper.GetNodeAttributes(data).To <JewelProperties>()); // Handle the Jewel Menu Launcher control JewelMenuLauncher jml = BuildJewelMenuLauncher(data, jbc); Jewel.AddChild(jml.CreateComponentForDisplayMode("Default")); Jewel.JewelMenuLauncher = jml; return(Jewel); }
/// <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); }
private Gallery BuildGallery(object data, BuildContext bc, bool isInMenu) { JSObject attrs = DataNodeWrapper.GetNodeAttributes(data); GalleryProperties properties = DataNodeWrapper.GetNodeAttributes(data).To <GalleryProperties>(); Gallery gallery = Root.CreateGallery(properties.Id, DataNodeWrapper.GetAttribute(attrs, DataNodeWrapper.TITLE), DataNodeWrapper.GetAttribute(attrs, DataNodeWrapper.DESCRIPTION), properties); string displayMode = isInMenu ? "Menu" : "Default"; JSObject[] children = DataNodeWrapper.GetNodeChildren(data); int l = children.Length; for (int i = 0; i < l; i++) { JSObject child = children[i]; if (IsNodeTrimmed(child)) { continue; } // NOTE: currently, galleries can only host GalleryButton controls. // In the future, the gallery could support other control types, so those should be added here. Control control; switch (DataNodeWrapper.GetNodeName(child)) { case DataNodeWrapper.GalleryButton: control = BuildGalleryButton(child, bc, properties.ElementDimensions); break; default: control = BuildControl(child, bc); break; } gallery.AddChild(control.CreateComponentForDisplayMode(displayMode)); } return(gallery); }
private Layout CreateLayoutFromData(object data, Group group, DeclarativeTemplateBuildContext bc) { string title = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE); if (title == DataNodeWrapper.POPUP) { string layoutTitle = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.LAYOUTTITLE); group.PopupLayoutTitle = layoutTitle; return(null); } Layout layout = bc.Ribbon.CreateLayout(group.Id + "-" + title, title); layout.SetDelayedInitData(new DelayedInitHandler(this.DelayInitLayout), data, bc); // Comment out the SetDelayedInitData() line and uncomment this one to disable // on-demand construction of layouts. // FillLayout(data, layout, bc); return(layout); }
internal Menu BuildMenu(JSObject data, BuildContext bc, bool lazyInit) { JSObject attrs = DataNodeWrapper.GetNodeAttributes(data); string id = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID); string title = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE); string description = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DESCRIPTION); string maxwidth = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.MAXWIDTH); Menu menu = Root.CreateMenu(id, title, description, maxwidth); if (_bo.LazyMenuInit && lazyInit) { menu.SetDelayedInitData(new DelayedInitHandler(this.DelayInitMenu), data, bc); return(menu); } FillMenu(menu, data, bc); return(menu); }
public int Compare(JSObject node1, JSObject node2) { string sequence1 = DataNodeWrapper.GetAttribute(node1, DataNodeWrapper.SEQUENCE); string sequence2 = DataNodeWrapper.GetAttribute(node2, DataNodeWrapper.SEQUENCE); // If both nodes don't have Sequences, then they are equal if (string.IsNullOrEmpty(sequence2) && string.IsNullOrEmpty(sequence1)) { return(0); } // If the second node has no sequence number then it should always go last so we leave it. // node1 should be higher if (string.IsNullOrEmpty(sequence2)) { return(-1); // node1 should be higher } // If the second node does have a sequence number and // the first one does not then the second one should sort higher than the first. if (string.IsNullOrEmpty(sequence1)) { return(1); // node1 should be lower } // If we reach this point then it means that both nodes have sequence numbers // In this case we need to compare and move the smallest sequence number up. int seq1 = Int32.Parse(sequence1); int seq2 = Int32.Parse(sequence2); if (seq1 < seq2) { return(-1); // node1 should be higher } else if (seq1 > seq2) { return(1); // node2 should be higher } return(0); // They are equal. Presumably they stay in their same order }
private Unit[] BuildUnits(object data) { JSObject[] children = DataNodeWrapper.GetNodeChildren(data); int l = children.Length; Unit[] units = new Unit[l]; for (int i = 0; i < l; i++) { JSObject childData = children[i]; string name = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.NAME_CAPS); string minValue = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.MINIMUMVALUE); string maxValue = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.MAXIMUMVALUE); string decimalDigits = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.DECIMALDIGITS); string interval = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.INTERVAL); units[i] = Spinner.CreateUnit(name, BuildUnitAbbreviations(DataNodeWrapper.GetNodeChildren(childData)), Double.Parse(minValue), Double.Parse(maxValue), Int32.Parse(decimalDigits), Double.Parse(interval)); } return(units); }
private void AddTabsToRibbon(JSObject[] tabs, string contextualGroupId, RibbonBuildContext rbc) { bool shownTabsSpecified = !CUIUtility.IsNullOrUndefined(RibbonBuildOptions.ShownTabs); for (int j = 0; j < tabs.Length; j++) { if (shownTabsSpecified) { // Only construct the tabs/tabheaders that have been made available string tabId = DataNodeWrapper.GetAttribute(tabs[j], DataNodeWrapper.ID); if (!string.IsNullOrEmpty(tabId)) { if (!RibbonBuildOptions.ShownTabs.ContainsKey(tabId) || CUIUtility.IsNullOrUndefined(RibbonBuildOptions.ShownTabs[tabId])) { continue; } } } Tab tab = BuildTab(tabs[j], rbc, contextualGroupId); Ribbon.AddChild(tab); } }
private Group BuildGroup(object data, RibbonBuildContext rbc) { string templateName = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TEMPLATE); Template template = TemplateManager.Instance.GetTemplate(templateName); if (CUIUtility.IsNullOrUndefined(template)) { throw new ArgumentOutOfRangeException("A template with name: " + templateName + " could not be loaded."); } JSObject controlsData = null; JSObject[] dataChildren = DataNodeWrapper.GetNodeChildren(data); for (int i = 0; i < dataChildren.Length; i++) { if (DataNodeWrapper.GetNodeName(dataChildren[i]) == DataNodeWrapper.CONTROLS) { controlsData = dataChildren[i]; break; } } if (CUIUtility.IsNullOrUndefined(controlsData)) { throw new InvalidOperationException("No Controls node found in this Group tag."); } JSObject[] children = DataNodeWrapper.GetNodeChildren(controlsData); bool groupIsEmpty = true; Dictionary <string, List <Control> > controls = new Dictionary <string, List <Control> >(); int len = children.Length; for (int i = 0; i < len; i++) { // Don't build controls that have been trimmed if (IsNodeTrimmed(children[i])) { continue; } // The group has one or more controls in it groupIsEmpty = false; Control control = BuildControl(children[i], rbc); if (!controls.ContainsKey(control.TemplateAlias) || CUIUtility.IsNullOrUndefined(controls[control.TemplateAlias])) { controls[control.TemplateAlias] = new List <Control>(); } controls[control.TemplateAlias].Add(control); } if (RibbonBuildOptions.TrimEmptyGroups && groupIsEmpty) { return(null); } string id = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID); string title = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE); string description = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DESCRIPTION); string command = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.COMMAND); Group group = template.CreateGroup(Ribbon, id, DataNodeWrapper.GetNodeAttributes(data).To <GroupProperties>(), title, description, command, controls, null); return(group); }
private void FillTab(Tab tab, object data, RibbonBuildContext rbc) { JSObject groupsNode = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.GROUPS); JSObject[] groupChildren = DataNodeWrapper.GetNodeChildren(groupsNode); Dictionary <string, string> emptyTrimmedGroupIds = new Dictionary <string, string>(); for (int i = 0; i < groupChildren.Length; i++) { if (IsNodeTrimmed(groupChildren[i])) { continue; } Group group = BuildGroup(groupChildren[i], rbc); // If the build option TrimEmptyGroups is null, and the Group is empty // then null is returned by BuildGroup() if (!CUIUtility.IsNullOrUndefined(group)) { tab.AddChild(group); } else { // If the group has an Id, then we store it so that we can ignore any scaling // information that relates it it. If it does not have an id, then any scaling info // will not work anyways and it is an invalid node. Groups must have ids. string id = DataNodeWrapper.GetAttribute(groupChildren[i], DataNodeWrapper.ID); if (!string.IsNullOrEmpty(id)) { emptyTrimmedGroupIds[id] = id; } } } JSObject scaling = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.SCALING); JSObject[] children = DataNodeWrapper.GetNodeChildren(scaling); string _scaleWarningMessage = ""; bool _scaleWarning = false; for (int i = 0; i < children.Length; i++) { string name = DataNodeWrapper.GetNodeName(children[i]); string groupId = DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.GROUPID); if (name == DataNodeWrapper.MAXSIZE) { // Don't include the scale step if the group that it refers to has been trimmed if (IsIdTrimmed(groupId) || (emptyTrimmedGroupIds.ContainsKey(groupId) && !CUIUtility.IsNullOrUndefined(emptyTrimmedGroupIds[groupId]))) { continue; } tab.Scaling.SetGroupMaxSize(groupId, DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.SIZE)); } else if (name == DataNodeWrapper.SCALE) { // Don't include the scale step if the group that it refers to has been trimmed if (IsIdTrimmed(groupId) || (emptyTrimmedGroupIds.ContainsKey(groupId) && !CUIUtility.IsNullOrUndefined(emptyTrimmedGroupIds[groupId]))) { continue; } tab.Scaling.AddScalingStep(new ScalingStep(groupId, DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.SIZE), DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.POPUPSIZE), _scaleWarningMessage, _scaleWarning)); _scaleWarningMessage = ""; _scaleWarning = false; } else if (name == DataNodeWrapper.LOWSCALEWARNING) { _scaleWarningMessage = DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.MESSAGE); _scaleWarning = true; } else { throw new InvalidOperationException("Was expecting a node with name MaxSize or Scale."); } } // Start at the largest scale tab.ScaleMax(); }
/// <summary> /// As much as we'd like to fail gracefully in every corner case for this, /// we have to maintain a "garbage in garbage out policy" because this /// recursive set of routines is very performance sensitive since it /// will run on every single node in the CUI data. /// </summary> /// <param name="data"></param> /// <param name="extensions"></param> /// <returns></returns> protected static JSObject ApplyDataNodeExtensions(object data, Dictionary <string, List <JSObject> > extensions) { // If a data node does not have any attributes, then it cannot be extended if (CUIUtility.IsNullOrUndefined(DataNodeWrapper.GetNodeAttributes(data))) { return((JSObject)data); } string id = DataNodeWrapper.GetAttribute(data, "Id"); List <JSObject> replacementData = extensions.ContainsKey(id) ? extensions[id] : null; // Has this data node been overridden? if (!CUIUtility.IsNullOrUndefined(replacementData)) { JSObject winner = null; int winningSequence = Int32.MaxValue; // We now go through and find the correct replacement depending on sequence number. // We can only pick one replacement if there are multiple replacements. int l = replacementData.Count; for (int i = 0; i < l; i++) { JSObject replacementNode = replacementData[i]; // If there is an entry in the array but it is null, then // we remove this node from the final data by returning null. // Because this means that it was basically overriden with "nothing". // aka "removed". if (replacementNode == null) { return(null); } string sequence = DataNodeWrapper.GetAttribute(replacementNode, DataNodeWrapper.SEQUENCE); // If this extension does not have a sequence, then it has lowest precedence. // This means that it will only be the winner if there is no previous winner. if (string.IsNullOrEmpty(sequence)) { if (CUIUtility.IsNullOrUndefined(winner)) { winner = replacementNode; } continue; } // If this extension node has a lower sequence value than anything previously seen // then it becomes the new winner. "Lowest Sequence Wins". int seq = Int32.Parse(sequence); if (seq < winningSequence) { winner = replacementNode; winningSequence = seq; } } // Set the actual data node that we will be returning to the // node the winner that was determined by examining all the possible extensions. if (!CUIUtility.IsNullOrUndefined(winner)) { data = winner; } } JSObject[] children = DataNodeWrapper.GetNodeChildren(data); // If there is not a children node, then we create one so that we can add extensions if (CUIUtility.IsNullOrUndefined(children)) { children = new JSObject[1]; children[0] = new JSObject(); ((JSObject)data).SetField <JSObject[]>("children", children); } // Now we make a temporary list where we will put the data nodes and the // extension nodes and then sort them according to sequence before saving // them back into the children array in the data node. List <JSObject> combinedNodes = new List <JSObject>(); int m = children.Length; for (int i = 0; i < m; i++) { combinedNodes.Add(children[i]); } // Have any children been added to this node through this extension mechanism? string extKey = id + "._children"; List <JSObject> childrenReplacementData = extensions.ContainsKey(extKey) ? extensions[extKey] : null; // Add the extension nodes if there are any if (!CUIUtility.IsNullOrUndefined(childrenReplacementData)) { int n = childrenReplacementData.Count; for (int i = 0; i < n; i++) { combinedNodes.Add(childrenReplacementData[i]); } // Now do a sort over the combined list to get the final order combinedNodes.Sort(new CompareDataNodeOrder()); } // Now that we have the maximal set of child nodes from the data and the customizations, // we need to allow for extensibility on each one before we finally add them to the main // parent node. int ln = combinedNodes.Count; JSObject[] finalChildNodes = new JSObject[ln]; for (int i = 0; i < ln; i++) { // Recurse on this child node to get its customizations JSObject dataNode = ApplyDataNodeExtensions(combinedNodes[i], extensions); if (!CUIUtility.IsNullOrUndefined(dataNode)) { finalChildNodes[i] = dataNode; } } // Now insert this combined, sorted and extended list of children into the data node ((JSObject)data).SetField <JSObject[]>("children", finalChildNodes); return((JSObject)data); }
private void AddContextualGroup(JSObject data, RibbonBuildContext rbc) { ContextualColor color = ContextualColor.None; string contextualGroupId = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID); // If the contextual tab group has been normalized, then we build the tabs as regular tabs bool normalized = !CUIUtility.IsNullOrUndefined(RibbonBuildOptions.NormalizedContextualGroups) && RibbonBuildOptions.NormalizedContextualGroups.ContainsKey(contextualGroupId) && RibbonBuildOptions.NormalizedContextualGroups[contextualGroupId]; // If the contextual group has been normalized, it means that all of its tabs should // behave like regular tabs on this page so we do not need to create the contextual // group object in this case. if (!normalized) { switch (DataNodeWrapper.GetAttribute(data, DataNodeWrapper.COLOR)) { case DataNodeWrapper.DARKBLUE: color = ContextualColor.DarkBlue; break; case DataNodeWrapper.LIGHTBLUE: color = ContextualColor.LightBlue; break; case DataNodeWrapper.MAGENTA: color = ContextualColor.Magenta; break; case DataNodeWrapper.GREEN: color = ContextualColor.Green; break; case DataNodeWrapper.ORANGE: color = ContextualColor.Orange; break; case DataNodeWrapper.PURPLE: color = ContextualColor.Purple; break; case DataNodeWrapper.TEAL: color = ContextualColor.Teal; break; case DataNodeWrapper.YELLOW: color = ContextualColor.Yellow; break; default: color = ContextualColor.None; break; } Ribbon.AddContextualGroup(contextualGroupId, DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE), color, DataNodeWrapper.GetAttribute(data, DataNodeWrapper.COMMAND)); } JSObject[] tabChildren = DataNodeWrapper.GetNodeChildren(data); if (!normalized) { // This array will usually have one or two entries and at the very most three // So we are not using an iterator or caching tabChildren.Length etc. for (int i = 0; i < tabChildren.Length; i++) { // If the initially visible tabId is in a contextual group, then we make that contextual // group initially visible. string tabId = DataNodeWrapper.GetAttribute(tabChildren[i], DataNodeWrapper.ID); if (tabId == rbc.InitialTabId) { if (CUIUtility.IsNullOrUndefined(RibbonBuildOptions.InitiallyVisibleContextualGroups)) { RibbonBuildOptions.InitiallyVisibleContextualGroups = new Dictionary <string, bool>(); } RibbonBuildOptions.InitiallyVisibleContextualGroups[contextualGroupId] = true; break; } } } AddTabsToRibbon(tabChildren, normalized ? "" : contextualGroupId, rbc); }
protected bool IsNodeTrimmed(JSObject dataNode) { string id = DataNodeWrapper.GetAttribute(dataNode, DataNodeWrapper.ID); return(IsIdTrimmed(id)); }
internal Control BuildControl(object data, BuildContext bc) { Control control = null; string name = DataNodeWrapper.GetNodeName(data); switch (name) { case DataNodeWrapper.ToggleButton: control = BuildToggleButton(data, bc); break; case DataNodeWrapper.ComboBox: control = BuildComboBox(data, bc); break; case DataNodeWrapper.DropDown: control = BuildDropDown(data, bc); break; case DataNodeWrapper.Button: control = BuildButton(data, bc); break; case DataNodeWrapper.SplitButton: control = BuildSplitButton(data, bc); break; case DataNodeWrapper.FlyoutAnchor: control = BuildFlyoutAnchor(data, bc); break; case DataNodeWrapper.GalleryButton: control = BuildGalleryButton(data, bc, null); break; case DataNodeWrapper.InsertTable: control = BuildInsertTable(data, bc); break; case DataNodeWrapper.Label: control = BuildLabel(data, bc); break; case DataNodeWrapper.MRUSplitButton: control = BuildMRUSplitButton(data, bc); break; case DataNodeWrapper.Spinner: control = BuildSpinner(data, bc); break; case DataNodeWrapper.TextBox: control = BuildTextBox(data, bc); break; case DataNodeWrapper.ColorPicker: control = BuildColorPicker(data, bc); break; case DataNodeWrapper.CheckBox: control = BuildCheckBox(data, bc); break; case DataNodeWrapper.Separator: control = BuildSeparator(data, bc); break; default: JSObject attrs = DataNodeWrapper.GetNodeAttributes(data); string className = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.CLASSNAME); if (CUIUtility.IsNullOrUndefined(className)) { throw new InvalidOperationException("Unable to create Control with tagname: " + name); } break; } return(control); }
private int HandleOverflow(object data, DeclarativeTemplateBuildContext bc, Component parent, int sectionCounter) { string alias = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TEMPLATEALIAS); string name = DataNodeWrapper.GetNodeName(data); List <Control> rec = bc.Controls.ContainsKey(alias) ? bc.Controls[alias] : null; // No Controls need to be added to this overflowarea so we return without doing anything if (CUIUtility.IsNullOrUndefined(rec)) { return(sectionCounter); } bool dividerBefore = false; bool dividerAfter = false; SectionType sectionType = SectionType.OneRow; if (name == DataNodeWrapper.OVERFLOWSECTION) { dividerBefore = Utility.IsTrue(DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DIVIDERBEFORE)); dividerAfter = Utility.IsTrue(DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DIVIDERAFTER)); if (dividerBefore) { Section section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.Divider, SectionAlignment.Top); parent.AddChild(section); } string secType = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TYPE); switch (secType) { case DataNodeWrapper.ONEROW: sectionType = SectionType.OneRow; break; case DataNodeWrapper.TWOROW: sectionType = SectionType.TwoRow; break; case DataNodeWrapper.THREEROW: sectionType = SectionType.ThreeRow; break; default: throw new ArgumentOutOfRangeException("Invalid Section attribute \"Type\" found in XML: " + secType); } } string displayMode = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DISPLAYMODE); if (rec.Count > 1) { Section currentSection = null; for (int i = 0; i < rec.Count; i++) { Control control = rec[i]; if (name == DataNodeWrapper.OVERFLOWSECTION) { if (sectionType == SectionType.OneRow) { if (CUIUtility.IsNullOrUndefined(currentSection)) { currentSection = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.OneRow, SectionAlignment.Top); parent.AddChild(currentSection); } currentSection.GetRow(1).AddChild(control.CreateComponentForDisplayMode(displayMode)); } else if (sectionType == SectionType.ThreeRow) { // ThreeRow Sections if (CUIUtility.IsNullOrUndefined(currentSection)) { currentSection = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.ThreeRow, SectionAlignment.Top); parent.AddChild(currentSection); } currentSection.GetRow((i % 3) + 1).AddChild(control.CreateComponentForDisplayMode(displayMode)); // If we have just filled the third row of a section with a ControlComponent, then // we need to signal that we need to start a new section the next time through the loop if (i % 3 == 2) { currentSection = null; } } else { // Two Row Sections if (CUIUtility.IsNullOrUndefined(currentSection)) { currentSection = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.TwoRow, SectionAlignment.Top); parent.AddChild(currentSection); } currentSection.GetRow((i % 2) + 1).AddChild(control.CreateComponentForDisplayMode(displayMode)); // If we have just filled the third row of a section with a ControlComponent, then // we need to signal that we need to start a new section the next time through the loop if (i % 2 == 1) { currentSection = null; } } } else { // <OverflowArea> tag parent.AddChild(control.CreateComponentForDisplayMode(displayMode)); } } } else { Control control = rec[0]; if (name == DataNodeWrapper.OVERFLOWSECTION) { Section section; if (sectionType == SectionType.OneRow) { section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.OneRow, SectionAlignment.Top); section.GetRow(1).AddChild(control.CreateComponentForDisplayMode(displayMode)); } else if (sectionType == SectionType.ThreeRow) { // Three Row Section section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.ThreeRow, SectionAlignment.Top); section.GetRow(1).AddChild(control.CreateComponentForDisplayMode(displayMode)); } else { // Two Row Section section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.TwoRow, SectionAlignment.Top); section.GetRow(1).AddChild(control.CreateComponentForDisplayMode(displayMode)); } parent.AddChild(section); } else { // <OverflowArea> tag parent.AddChild(control.CreateComponentForDisplayMode(displayMode)); } } if (dividerAfter) { Section section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.Divider, SectionAlignment.Top); parent.AddChild(section); } return(sectionCounter); }
private Section CreateSectionFromData(object data, DeclarativeTemplateBuildContext bc, Layout layout, int sectionNumber) { SectionType type; string strType = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TYPE); string strAlignment = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ALIGNMENT); switch (strType) { case DataNodeWrapper.ONEROW: type = SectionType.OneRow; break; case DataNodeWrapper.TWOROW: type = SectionType.TwoRow; break; case DataNodeWrapper.THREEROW: type = SectionType.ThreeRow; break; case DataNodeWrapper.DIVIDER: type = SectionType.Divider; break; default: throw new ArgumentOutOfRangeException("Invalid Section attribute \"Type\" found in XML: " + strType); } SectionAlignment alignment = SectionAlignment.Top; if (strAlignment == "Middle") { alignment = SectionAlignment.Middle; } Section section = bc.Ribbon.CreateSection(layout.Id + "-" + sectionNumber, type, alignment); if (type != SectionType.Divider) { HandleRow(section.GetRow(1), DataNodeWrapper.GetNodeChildren(data)[0], bc); if (section.Type == SectionType.TwoRow || section.Type == SectionType.ThreeRow) { HandleRow(section.GetRow(2), DataNodeWrapper.GetNodeChildren(data)[1], bc); } if (section.Type == SectionType.ThreeRow) { HandleRow(section.GetRow(3), DataNodeWrapper.GetNodeChildren(data)[2], bc); } } return(section); }