public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.ApsimXFile        = model as Simulations;
            this.ExplorerPresenter = explorerPresenter;
            this.View = view as IModelDetailsWrapperView;

            if (model != null)
            {
                ViewNameAttribute      viewName      = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;

                View.ModelTypeText = model.GetType().ToString().Substring("Models.".Length);
                DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute;
                if (descAtt != null)
                {
                    View.ModelDescriptionText = descAtt.ToString();
                }
                else
                {
                    View.ModelDescriptionText = "";
                }
                // Set CLEM specific colours for title
                if (View.ModelTypeText.Contains(".Resources."))
                {
                    View.ModelTypeTextColour = "996633";
                }
                else if (View.ModelTypeText.Contains("Activities."))
                {
                    View.ModelTypeTextColour = "009999";
                }

                HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute;
                View.ModelHelpURL = "";
                if (helpAtt != null)
                {
                    View.ModelHelpURL = helpAtt.ToString();
                }

                if (viewName != null && presenterName != null)
                {
                    ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString());
                }
            }
        }
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.ApsimXFile        = model as Simulations;
            this.explorerPresenter = explorerPresenter;
            this.view = view as IModelDetailsWrapperView;

            if (model != null)
            {
                ViewNameAttribute      viewName      = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;

                this.view.ModelTypeText = model.GetType().ToString().Substring("Models.".Length);
                DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute;
                if (descAtt != null)
                {
                    this.view.ModelDescriptionText = descAtt.ToString();
                }
                else
                {
                    this.view.ModelDescriptionText = "";
                }
                // Set CLEM specific colours for title
                if (this.view.ModelTypeText.Contains(".Resources."))
                {
                    this.view.ModelTypeTextColour = "996633";
                }
                else if (this.view.ModelTypeText.Contains(".Activities.LabourRequirement"))
                {
                    this.view.ModelTypeTextColour = "cc33cc";
                }
                else if (this.view.ModelTypeText.Contains(".Activities."))
                {
                    this.view.ModelTypeTextColour = "009999";
                }
                else if (this.view.ModelTypeText.Contains(".Groupings."))
                {
                    this.view.ModelTypeTextColour = "cc33cc";
                }
                else if (this.view.ModelTypeText.Contains(".File"))
                {
                    this.view.ModelTypeTextColour = "008000";
                }
                else if (this.view.ModelTypeText.Contains(".Market"))
                {
                    this.view.ModelTypeTextColour = "1785FF";
                }

                HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute;
                this.view.ModelHelpURL = "";
                if (helpAtt != null)
                {
                    this.view.ModelHelpURL = helpAtt.ToString();
                }

                var vs = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false);
                if (vs.Count() > 0)
                {
                    VersionAttribute verAtt = vs.ToList <Attribute>().Cast <VersionAttribute>().OrderBy(a => a.ToString()).Last() as VersionAttribute;
                    if (verAtt != null)
                    {
                        string v = "Version ";
                        v += verAtt.ToString();
                        this.view.ModelVersionText = v;
                    }
                    else
                    {
                        this.view.ModelVersionText = "";
                    }
                }

                if (viewName != null && presenterName != null)
                {
                    // if model CLEMModel
                    if (model.GetType().IsSubclassOf(typeof(CLEMModel)) | model is ZoneCLEM | model is Market | model is RandomNumberGenerator)
                    {
                        // all CLEMModels will handle this presenter
                        ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter");
                    }
                    else if (typeof(ICLEMPresenter).IsAssignableFrom(Assembly.GetExecutingAssembly().GetType(presenterName.ToString())))
                    {
                        // apply this if the presenter has ICLEMPresenter interface and is ready to create presenters
                        ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter");
                    }
                    else
                    {
                        ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString());
                    }
                }
            }
        }
Esempio n. 3
0
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.ApsimXFile        = model as Simulations;
            this.ExplorerPresenter = explorerPresenter;
            this.View = view as IModelDetailsWrapperView;

            if (model != null)
            {
                ViewNameAttribute      viewName      = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;

                View.ModelTypeText = model.GetType().ToString().Substring("Models.".Length);
                DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute;
                if (descAtt != null)
                {
                    View.ModelDescriptionText = descAtt.ToString();
                }
                else
                {
                    View.ModelDescriptionText = "";
                }
                // Set CLEM specific colours for title
                if (View.ModelTypeText.Contains(".Resources."))
                {
                    View.ModelTypeTextColour = "996633";
                }
                else if (View.ModelTypeText.Contains(".Activities.LabourRequirement"))
                {
                    View.ModelTypeTextColour = "cc33cc";
                }
                else if (View.ModelTypeText.Contains(".Activities."))
                {
                    View.ModelTypeTextColour = "009999";
                }
                else if (View.ModelTypeText.Contains(".Groupings."))
                {
                    View.ModelTypeTextColour = "cc33cc";
                }
                else if (View.ModelTypeText.Contains(".File"))
                {
                    View.ModelTypeTextColour = "008000";
                }

                HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute;
                View.ModelHelpURL = "";
                if (helpAtt != null)
                {
                    View.ModelHelpURL = helpAtt.ToString();
                }

                var vs = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false);
                if (vs.Count() > 0)
                {
                    VersionAttribute verAtt = vs.ToList <Attribute>().Last() as VersionAttribute;
                    if (verAtt != null)
                    {
                        string v = "Version ";
                        v += verAtt.ToString();
                        View.ModelVersionText = v;
                    }
                    else
                    {
                        View.ModelVersionText = "";
                    }
                }

                if (viewName != null && presenterName != null)
                {
                    // if model CLEMModel
                    if (model.GetType().IsSubclassOf(typeof(CLEMModel)) || model is ZoneCLEM)
                    {
                        ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter");
                    }
                    else
                    {
                        ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString());
                    }
                }
            }
        }