예제 #1
0
            internal void RenderView(MXViewPerspective viewPerspective, object model)
            {
                IMXView view = GetOrCreateView(viewPerspective);

                if (view == null)
                {
                    // No view perspective found for model
                    throw new ArgumentException("No View Perspective found for: " + viewPerspective.ToString(), "viewPerspective");
                }
                view.SetModel(model);
                view.Render();
            }
            /*
             * public MXViewPerspective GetViewPerspectiveForViewType(Type viewType)
             * {
             *  return _typeMap.First(keyValuePair => keyValuePair.Value == viewType).Key;
             * }
             */


            internal void RenderView <TViewModel>(MXShowViewRequest <TViewModel> showViewRequest)
            {
                IMXView view = CreateView(showViewRequest.ViewPerspective);

                if (view == null)
                {
                    // No view perspective found for model
                    throw new ArgumentException("No View Perspective found for: " + showViewRequest.ViewPerspective.ToString(), "viewPerspective");
                }

                view.SetModel(showViewRequest.ViewModel);
                view.Render();
            }
예제 #3
0
        /// <summary>
        /// Renders the view described by the perspective.
        /// </summary>
        /// <param name="modelType">The type of the view's model.</param>
        /// <param name="perspective">The perspective describing the view.</param>
        /// <param name="model">The model for the view.</param>
        public IMXView RenderViewFromPerspective(Type modelType, string perspective, object model)
        {
            IMXView view = Views.GetOrCreateView(modelType, perspective);

            if (view == null)
            {
                // No view perspective found for model
                throw new ArgumentException("No View found for: " + perspective, "perspective");
            }
            view.SetModel(model);
            view.Render();

            return(view);
        }
예제 #4
0
        /// <summary>
        /// Executes the rendering logic for the view of the specified <see cref="IMXController"/> instance before painting it on the screen.
        /// </summary>
        /// <param name="controller">The controller to output.</param>
        /// <param name="perspective">The perspective that is mapped to the view that will be rendered.</param>
        /// <param name="navigatedUri">A <see cref="String"/> that represents the uri used to navigate to the controller.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="controller"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">Thrown when there is no view mapped to the <paramref name="perspective"/>.</exception>
        public void OutputController(IMXController controller, string perspective, string navigatedUri)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            var     ilayer = controller as iLayer;
            IMXView view   = Views.GetView(controller.ModelType, perspective);

            if (view == null)
            {
                if (ilayer != null)
                {
                    view        = ilayer.GetView();
                    ilayer.View = view;
                }
                else
                {
                    var viewType = Views.GetViewType(controller.ModelType, perspective);
                    if (viewType == null)
                    {
                        object model = controller.GetModel();
                        if (model != null && Device.Reflector.HasAttribute(model.GetType(), typeof(ViewAttribute), false))
                        {
                            view = ReflectiveUIBuilder.GenerateView(model);
                        }
                        else
                        {
                            throw new InvalidOperationException("There is no view or view type mapped to the given perspective.");
                        }
                    }
                    else
                    {
                        view = (IMXView)Activator.CreateInstance(viewType);
                    }
                }
            }

            view.SetModel(controller.GetModel());

            var entry = view as IHistoryEntry;

            if (entry != null)
            {
                entry.OutputPane = PaneManager.Instance.GetPreferredPaneForView(view);
            }

            view.Render();

            {
                var handler = ViewOutputting;
                if (handler != null)
                {
                    var args = new ViewOutputCancelEventArgs(controller, view);
                    handler(this, args);

                    if (args.Cancel)
                    {
                        return;
                    }
                }
            }

            var tabs = view as ITabView;

            if (tabs != null)
            {
                PaneManager.Instance.Tabs = tabs;
            }

            PaneManager.Instance.NavigatedURIs[view] = navigatedUri;
            OnOutputView(view);

            { // Handler scope
                var handler = ViewOutputted;
                if (handler != null)
                {
                    handler(this, new ViewOutputEventArgs(controller, view));
                }
            }

            StopBlockingUserInput();
        }
예제 #5
0
        /*
         * public static IMXController NavigateFromButton(string url, Dictionary<string, string> parameters, UIBarButtonItem button)
         * {
         *  //_stashButton = button;
         * a
         *  return Navigate(url, parameters);
         * }
         */

        void LoadViewForController(IMXView fromView, IMXController controller, string viewPerspective)
        {
            HideLoading();

            // get the view, create it if it has yet been created
            IMXView view = Views.GetOrCreateView(controller.ModelType, viewPerspective);

            if (view == null)
            {
                Debug.WriteLine("View not found for perspective!" + viewPerspective.ToString());
                throw new ArgumentException("View creation failed for perspective!" + viewPerspective.ToString());
            }

            // asign the view it's model and render the contents of the view
            view.SetModel(controller.GetModel());

            // pull the type from the view
            ViewNavigationContext navigationContext = MXTouchNavigation.GetViewNavigationContext(view);
            UIViewController      viewController    = view as UIViewController;

            if (navigationContext == ViewNavigationContext.InContext)
            {
                view.Render();

                // it's just an in-context view, just slap it on top of the view that navigated it here!
                UIViewController parentViewController = fromView as UIViewController;
                parentViewController.NavigationController.PushViewController(viewController, true);
            }
            else
            {
                // if the view is one of the views in the group
                MXTouchViewGroup     viewGroup     = null;
                MXTouchViewGroupItem viewGroupItem = null;

                foreach (MXTouchViewGroup vg in ViewGroups)
                {
                    var viewType = view.GetType();
                    // Check the type itself and its interfaces
                    viewGroupItem = vg.Items.Find(item => item.ViewType == viewType || viewType.GetInterface(item.ViewType.ToString()) != null);

                    if (viewGroupItem != null)
                    {
                        viewGroup = vg;
                        break;
                    }
                }

                if (viewGroup != null)
                {
                    // activate the group!
                    _touchNavigation.PushToViewGroup(viewGroup, viewGroupItem, viewController);
                }
                else
                {
                    view.Render();

                    switch (navigationContext)
                    {
                    case ViewNavigationContext.Master:
                        _touchNavigation.PushToMaster(viewController);
                        break;

                    case ViewNavigationContext.Detail:
                        _touchNavigation.PushToDetail(viewController);
                        break;

                    case ViewNavigationContext.Modal:
                        _touchNavigation.PushToModel(viewController);
                        break;
                    }
                }
            }

            // handle initial view display if not already handled
            ShowView();
        }