Beispiel #1
0
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!(child is ControlComponent))
         throw new InvalidCastException("Only ControlComponents can be added to GroupPopupLayout.");
     if (Children.Count > 0)
         throw new ArgumentException("GroupPopupLayouts can only have one child");
 }
Beispiel #2
0
 /// <summary>
 /// Checks that the given child component is of the correct type to be under a Jewel root
 /// </summary>
 /// <param name="child">The child component in question</param>
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!typeof(ControlComponent).IsInstanceOfType(child))
         throw new InvalidOperationException("The child \"" + child.Id + "\" is not a ControlComponent");
     if (!typeof(JewelMenuLauncher).IsInstanceOfType(((ControlComponent)child).Control))
         throw new ArgumentException("Only children of type JewelMenuLauncher can be added to a Jewel");
 }
Beispiel #3
0
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!typeof(Strip).IsInstanceOfType(child) &&
         !typeof(ControlComponent).IsInstanceOfType(child))
     {
         throw new InvalidCastException("Only children of type Strip and ControlComponent" +
             " can be added to Row Components.");
     }
 }
 private Component DelayInitLayout(Component component,
                                   object data,
                                   object bc)
 {
     Layout layout = (Layout)component;
     DeclarativeTemplateBuildContext buildContext = (DeclarativeTemplateBuildContext)bc;
     FillLayout(data, layout, buildContext);
     layout.OnDelayedInitFinished(true);
     return layout;
 }
Beispiel #5
0
 internal CommandEventArgs(string id,
                           CommandType type,
                           Component source,
                           Dictionary<string, string> pars)
 {
     _id = id;
     _params = pars;
     _source = source;
     _type = type;
 }
Beispiel #6
0
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!typeof(ControlComponent).IsInstanceOfType(child))
         throw new ArgumentException("Only children of type Control can be added to Strips.");
 }
Beispiel #7
0
 protected override void EnsureCorrectChildType(Component child)
 {
     _control.EnsureCorrectChildType(child);
 }
Beispiel #8
0
 /// <summary>
 /// This is called by AddChild and AddChildAtIndex to ensure that the child is of a legal type. 
 /// We throw an Exception if the child is not a ContextMenuDock.
 /// </summary>
 /// <param name="child">The child whose type should be checked.</param>
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!typeof(ContextMenuDock).IsInstanceOfType(child))
         throw new ArgumentException("Only children of type ContextMenuDock can be added to a ContextMenuRoot");
 }
Beispiel #9
0
 // Override this to enforce child type restirctions
 /// <summary>
 /// This is called by AddChild and AddChildAtIndex to ensure that the child is of a legal type for this component type.  This should be overriden in each subclass of Component to ensure that the child is of the correct type.  This method should throw an exception if the child is not of the correct type.
 /// </summary>
 /// <param name="child">The child whose type should be checked to make sure that it is a valid child for this Component.</param>
 protected virtual void EnsureCorrectChildType(Component child)
 {
     return;
 }
Beispiel #10
0
 // This is the default behavior for MenuLaunchers
 // This can of course be overriden to change what types of child Components are allowed
 public override void EnsureCorrectChildType(Component child)
 {
     // allow both menus and tooltips            
     if ((!typeof(MenuType).IsInstanceOfType(child))
          && (!(typeof(ToolTip).IsInstanceOfType(child)))
         )
     {
         throw new ArgumentException("This Component can only have Menu and ToolTip Components as children.");
     }
 }
Beispiel #11
0
        protected override void EnsureCorrectChildType(Component child)
        {
            if (!typeof(MenuItem).IsInstanceOfType(child)
                && !typeof(Gallery).IsInstanceOfType(child)
#if !CUI_NORIBBON
                && !typeof(GroupPopup).IsInstanceOfType(child)
#endif
)
            {
                throw new ArgumentException("MenuSections can only have children of type MenuItem, Gallery or GroupPopup.");
            }
        }
Beispiel #12
0
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!(child is ControlComponent))
         throw new InvalidCastException("Only children of type Control can be added to Strips.");
 }
Beispiel #13
0
 /// <summary>
 /// Creates a Command
 /// </summary>
 /// <param name="commandId">id of the Command ("paste" etc)</param>
 /// <param name="type">type of the command</param>
 /// <param name="creator">the Component that created the Command</param>
 /// <param name="parameters">Dictionary of extra parameters that go along with this Command</param>
 /// <returns>the created Command</returns>
 internal CommandEventArgs CreateCommandEventArgs(string commandId,
                                                  CommandType type,
                                                  Component creator,
                                                  Dictionary<string, string> properties)
 {
     return new CommandEventArgs(commandId, type, creator, properties);
 }
        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;
        }
Beispiel #15
0
        private Component DelayInitTab(Component component,
                                       object data,
                                       object buildContext)
        {
            RibbonBuildContext rbc = (RibbonBuildContext)buildContext;
            Tab tab = (Tab)component;

            rbc.InitializedTab = (Tab)component;
            // If the data node does not have children, then it means that this tab
            // was shallowly fetched from the server.  In this case we need to run
            // a query to get the whole node with all of its controls from the server.
            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            if (children.Length == 0)
            {
                // TODO: implement this so that the asynchronous part works
                // Find out if we even need to fetch the tabs asynchronously
                // or if we can get away with just initializing them asynchronously
                DataQuery query = new DataQuery();
                query.TabQuery = true;
                query.Id = rbc.InitializedTab.Id;
                query.QueryType = DataQueryType.RibbonTab;
                query.Handler = new DataReturnedEventHandler(this.OnReturnTab);
                query.Data = rbc;
                DataSource.RunQuery(query);
                return null;
            }

            FillTab(tab, data, rbc);
            tab.OnDelayedInitFinished(true);
            // TODO(josefl): this should later be an idle task registration instead of a hard call
            Ribbon.Refresh();

            return tab;
        }
        private Strip CreateStripFromData(object data,
                                          DeclarativeTemplateBuildContext bc,
                                          Component parent,
                                          int rowComponentNumber)
        {
            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            Strip strip = bc.Ribbon.CreateStrip(parent.Id + "-" + rowComponentNumber);

            for (int i = 0; i < children.Length; i++)
            {
                string name = DataNodeWrapper.GetNodeName(children[i]);
                if (name == DataNodeWrapper.CONTROL)
                {
                    ControlComponent comp = CreateControlComponentFromData(children[i], bc);
                    if (!CUIUtility.IsNullOrUndefined(comp))
                        strip.AddChild(comp);
                }
                else
                {
                    HandleOverflow(children[i], bc, strip, i);
                }
            }

            // If there are no children in the strip then there is no reason to add it
            // If we ever support dynamically adding and removing components out of the ribbon
            // then this will need to be revisitited.
            if (strip.Children.Count == 0)
                return null;

            return strip;
        }
Beispiel #17
0
        protected override void EnsureCorrectChildType(Component child)
        {
            int count = Children.Count;
            if ((this.Type == SectionType.OneRow && count > 0) ||
                (this.Type == SectionType.TwoRow && count > 1) ||
                (this.Type == SectionType.ThreeRow && count > 2))
            {
                throw new InvalidOperationException("No more children can be added to a Section of this type.");
            }

            if (this.Type == SectionType.Divider)
                throw new InvalidOperationException("Cannot add child components to Divider Section types.");

            if (!typeof(Row).IsInstanceOfType(child))
                throw new InvalidCastException("Only children of type Row can be added to Section Components.");
        }
Beispiel #18
0
 public override void AddChildAtIndex(Component child, int index)
 {
     throw new InvalidOperationException("Cannot directly add and remove children from Section Components");
 }
Beispiel #19
0
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!typeof(Section).IsInstanceOfType(child))
         throw new InvalidOperationException("Only children of Section can be added to a Layout");
 }
Beispiel #20
0
 /// <summary>
 /// Checks that the given child component is of the correct type to be under a QAT root
 /// </summary>
 /// <param name="child">The child component in question</param>
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!typeof(ControlComponent).IsInstanceOfType(child))
         throw new InvalidCastException("Only children of type ControlComponent can be added to a QAT");
 }
Beispiel #21
0
 // Ensure that the child type and conditions is right for this child
 // Component to be added to this control's ControlComponent
 public virtual void EnsureCorrectChildType(Component child)
 {
     if (!(typeof(ToolTip).IsInstanceOfType(child)))
     {
         throw new InvalidOperationException("Child Components may not be added to this type of ControlComponent.");
     }
 }
Beispiel #22
0
 /// <summary>
 /// Called to clean up anything that this component needs to
 /// Usually releasing event handlers and cleaning up any circular references.
 /// </summary>
 public virtual void Dispose()
 {
     if (!CUIUtility.IsNullOrUndefined(_children))
     {
         foreach (Component c in _children)
             c.Dispose();
         _children = null;
     }
     _parent = null;
     _root = null;
     _delayedInitData = null;
     _delayedInitHandler = null;
     _delayedInitOptions = null;
     _elmDOM = null;
 }
Beispiel #23
0
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!typeof(Layout).IsInstanceOfType(child) && !typeof(GroupPopupLayout).IsInstanceOfType(child))
         throw new InvalidCastException("Only children of type Layout can be added to Groups");
     if (!CUIUtility.IsNullOrUndefined(GetChildByTitle(child.Title)))
     {
         throw new ArgumentNullException("A Layout with title " + child.Title +
                             " already exists in this Group.");
     }
 }
Beispiel #24
0
 /// <summary>
 /// Adds a child Component to this Component.  The Component will be added at the end of the list of children.
 /// </summary>
 /// <param name="child">The Component that should be added as a child to this Component.</param>
 /// <seealso cref="AddChildAtIndex"/>
 public virtual void AddChild(Component child)
 {
     // If the Root is in the process of initializing then we 
     // do not validate the children.
     // This is for performance reasons.
     // TODO(josefl): visit this
     // AddChildInternal(child, !Root.Initializing);
     AddChildInternal(child, true);
 }
Beispiel #25
0
        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.");
                }
            }
        }
Beispiel #26
0
 /// <summary>
 /// <see cref="AddChild"/>
 /// </summary>
 /// <param name="child"></param>
 /// <param name="validateChild"></param>
 internal void AddChildInternal(Component child, bool validateChild)
 {
     AddChildAtIndexInternal(child, -1, validateChild);
 }
Beispiel #27
0
 /// <summary>
 /// Adds a child Component at a specific index within the list of children of this Component.
 /// </summary>
 /// <param name="child">The child Component to be added.</param>
 /// <param name="index">The index in the list of child Components where this Component should be added.</param>
 /// <seealso cref="AddChild"/>
 public virtual void AddChildAtIndex(Component child, int index)
 {
     AddChildAtIndexInternal(child, index, true);
 }
Beispiel #28
0
        /// <summary>
        /// <see cref="AddChildAtIndex"/>
        /// <see cref="EnsureCorrectChildType"></see>
        /// </summary>
        /// <param name="child"></param>
        /// <param name="index"></param>
        /// <param name="validateChild">Whether the child type should be validated or not.  The reflective operations like Type.isInstanceOfObject() are slow so for performance reasons this can be turned off during Root initialization.  This parameter controls whether EnsureValidChild() is called or not.</param>
        internal void AddChildAtIndexInternal(Component child, int index, bool validateChild)
        {
            // Make sure that it is legal to add this kind of child
            // to this Component
            if (validateChild)
                EnsureCorrectChildType(child);

            // Make sure that this child doesn't already live somewhere else in the hierarchy
            if (!CUIUtility.IsNullOrUndefined(child.Parent))
            {
                throw new InvalidOperationException("This child cannot be added because it has already been added \n " +
                                       "to another Component in the hierarchy.  \n You must first call child.Parent.RemoveChild(child)");
            }

            if (index == -1)
                _children.Add(child);
            else
                _children.Insert(index, child);

            child.Parent = this;
            OnDirtyingChange();
        }
Beispiel #29
0
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!typeof(Group).IsInstanceOfType(child))
         throw new InvalidCastException("Only children of type Group can be added to Tab Components");
 }
Beispiel #30
0
 protected override void EnsureCorrectChildType(Component child)
 {
     if (!typeof(ControlComponent).IsInstanceOfType(child))
         throw new ArgumentException("Galleries can only have children controls of type GalleryButton");
     ControlComponent cc = (ControlComponent)child;
     if (!typeof(GalleryButton).IsInstanceOfType(cc.Control))
         throw new ArgumentException("Galleries can only have children of type GalleryButton");
 }