Exemplo n.º 1
0
        private void FindSkinParts()
        {
            if (null == _thisType)
            {
                _thisType = GetType();
            }

            var parts = SkinParts.Keys;

            foreach (var id in parts)
            {
                object part = null;

                /**
                 * 1. If this is a mapper skin,
                 * */
                if (_isMapperSkin)
                {
                    part = Skin.GetChildComponent(id);
                    //if (null != part)
                    //    Debug.Log("Found mapper skin part: " + part);
                    //else
                    //    Debug.Log(Skin + " -> Couldn't find mapper skin part: " + id);
                }

                else
                {
                    if (CoreReflector.HasMember(Skin, id))
                    {
                        try
                        {
                            part = CoreReflector.GetValue(Skin, id);
                        }
                        catch (InvalidCastException /* ex*/)
                        {
                            Debug.LogError(string.Format("Cannot cast the skin part to InteractiveComponent. Skin: {0}; Part: {1}", Skin, id));
                        }
                    }

                    //else
                    //    Debug.LogWarning("Couldn't find member: " + id);
                }

                if (SkinParts[id]) // == true (required part)
                {
                    if (null == part)
                    {
                        throw new Exception("Required skin part not found: " + id);
                    }
                }

                if (null != part)
                {
                    /**
                     * Note: we've been having a hard-core bug here (20131216)!
                     * The system FREEZED when using Panel with children in designer
                     * For instance, a panel had a single button child as a content child (not tool or control bar child)
                     * This is also the source of bug whereever we add a child prior to adding itself to the display list (both designer and code)
                     * I think it might be related to styles and StyleProtoChain process (?)
                     * This shoould - of course - be fixed
                     * The problem with designer was in ComponentAdapter ("Produce" method):
                     * _component.AddEventListener(FrameworkEvent.PREINITIALIZE, InitializeHandler)
                     * During the PREINITILIZE, child components have not yet been created - so the skin wasn't created
                     * When I changed it to INITILIZE, it started to work properly:
                     * _component.AddEventListener(FrameworkEvent.INITIALIZE, InitializeHandler)                     *
                     * */

                    /*if (id == "ContentGroup")
                     *  Debug.LogWarning("ContentGroup: " + part);*/

                    //CoreReflector.SetValue(this, id, part);
                    MemberWrapper wrapper = new MemberWrapper(GetType(), id);
                    wrapper.SetValue(this, part);

                    // If the assigned part has already been instantiated, call partAdded() here,
                    // but only for static parts.

                    try
                    {
                        /* Note: this fails, because the wrapper wraps around the Skin's property, not the Panel's */
                        //var p = CoreReflector.GetValue(this, id);
                        wrapper = new MemberWrapper(GetType(), id);
                        var p = wrapper.GetValue(this);

                        // TODO: we should get the value silently here, because not to disturb the DoubleGroup.Modified flag
                        //Debug.Log("Just added: " + p);

                        // If the assigned part has already been instantiated, call partAdded() here,
                        // but only for static parts.
                        if (null != p && !(p is IFactory))
                        {
                            PartAdded(id, p);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        throw ex;
                    }
                }
            }
        }