Example #1
0
        protected override object CreateSpecificView(ViewModel mdl, ControlKind kind)
        {
            IView view = (IView)base.CreateSpecificView(mdl, kind);

            view.SetModel(mdl);
            return(view);
        }
Example #2
0
 public Key(TypeRef vmd,
            Toolkit tk,
            ControlKind ck)
 {
     this.vmd = vmd.ExportGuid;
     this.tk  = tk;
     this.ck  = ck != null ? ck.ExportGuid : Guid.Empty;
 }
Example #3
0
        void LauncherPage_Init(object sender, EventArgs e)
        {
            var mdl = ZetboxContextManagerModule.ViewModelFactory
                      .CreateViewModel <WorkspaceViewModel.Factory>().Invoke(ZetboxContextManagerModule.ZetboxContext, null);
            ControlKind launcher = Zetbox.NamedObjects.Gui.ControlKinds.Zetbox_App_GUI_LauncherKind.Find(ZetboxContextManagerModule.ZetboxContext);

            ZetboxContextManagerModule.ViewModelFactory.CreateSpecificView(mdl, launcher, ctrlMainContent);
        }
Example #4
0
 public OpenDataObjectCommand(IViewModelDependencies appCtx, Func <IZetboxContext> ctxFactory,
                              IZetboxContext dataCtx, ViewModel parent, ControlKind reqWorkspaceKind, ControlKind reqEditorKind
                              )
     : base(appCtx, dataCtx, parent, CommonCommandsResources.OpenDataObjectCommand_Name, CommonCommandsResources.OpenDataObjectCommand_Tooltip)
 {
     this.ctxFactory = ctxFactory;
     this._requestedWorkspaceKind = reqWorkspaceKind;
     this._requestedEditorKind    = reqEditorKind;
 }
Example #5
0
        public static void ToString(ControlKind kind, MethodReturnEventArgs<string> e)
        {
            if (kind == null)
            {
                e.Result = "(null)";
                return;
            }

            e.Result = kind.Name;
        }
Example #6
0
 public ColumnDisplayModel(string header, string name, ControlKind kind, ControlKind gridPreviewKind, ColumnType type, WidthHint requestedWidth, int? requestedWidthAbsolute)
 {
     this.Header = header;
     this.Name = name;
     this.ControlKind = kind;
     this.GridPreEditKind = gridPreviewKind ?? kind;
     this.Type = type;
     this.RequestedWidth = requestedWidth;
     this.RequestedWidthAbsolute = requestedWidthAbsolute;
 }
Example #7
0
 public ColumnDisplayModel(string header, string name, ControlKind kind, ControlKind gridPreviewKind, ColumnType type, WidthHint requestedWidth, int?requestedWidthAbsolute)
 {
     this.Header                 = header;
     this.Name                   = name;
     this.ControlKind            = kind;
     this.GridPreEditKind        = gridPreviewKind ?? kind;
     this.Type                   = type;
     this.RequestedWidth         = requestedWidth;
     this.RequestedWidthAbsolute = requestedWidthAbsolute;
 }
Example #8
0
        public static void ToString(ControlKind kind, MethodReturnEventArgs <string> e)
        {
            if (kind == null)
            {
                e.Result = "(null)";
                return;
            }

            e.Result = kind.Name;
        }
Example #9
0
        private void RemoveWindowViewModel(WindowViewModel windowViewModel, ControlKind controlKind)
        {
            var views = _windowViews[windowViewModel];

            views.Remove(controlKind);
            if (views.Count == 0)
            {
                _windowViews.Remove(windowViewModel);
            }
        }
Example #10
0
 public ReadOnlyCollection <ViewDescriptor> GetDescriptors(ControlKind c)
 {
     if (_vdCache.ContainsKey(c.ExportGuid))
     {
         return(_vdCache[c.ExportGuid]);
     }
     else
     {
         return(EmptyList);
     }
 }
Example #11
0
 public void ShowModel(ViewModel mdl, ControlKind kind, bool activate)
 {
     if (kind == null)
     {
         ShowModel(mdl, activate);
     }
     else
     {
         ShowInView(mdl, CreateSpecificView(mdl, kind), activate, false);
     }
 }
Example #12
0
        public static List <ControlKind> AndParents(this ControlKind ck)
        {
            var result = new List <ControlKind>();

            result.Add(ck);
            var parent = ck.Parent;

            while (parent != null)
            {
                result.Add(parent);
                parent = parent.Parent;
            }
            return(result);
        }
        private static DataTemplate SelectTemplate(ViewModel mdl, ControlKind controlKind, IFrozenContext frozenCtx)
        {
            var tr = GetTypeRef(mdl, frozenCtx);
            if (tr == null) return null;

            ViewModelDescriptor pmd = tr.GetViewModelDescriptor();
            if (pmd == null)
            {
                Logging.Log.ErrorFormat("No matching ViewModelDescriptor found for {0}", mdl.GetType());
                return null;
            }

            return CreateTemplate(pmd.GetViewDescriptor(Toolkit.WPF, controlKind));
        }
Example #14
0
        public static DialogCreator AddString(this DialogCreator c, string label, ControlKind requestedKind)
        {
            if (c == null)
            {
                throw new ArgumentNullException("c");
            }

            var mdl  = new ClassValueModel <string>(label, "", false, false);
            var vmdl = c.ViewModelFactory.CreateViewModel <ClassValueViewModel <string> .Factory>().Invoke(c.DataContext, null, mdl);

            vmdl.RequestedKind = requestedKind;
            c.ValueModels.Add(vmdl);
            return(c);
        }
Example #15
0
        private void InstallRemovalHandler(WindowViewModel windowViewModel, ControlKind controlKind)
        {
            PropertyChangedEventHandler handler = null;

            handler = (object sender, PropertyChangedEventArgs e) =>
            {
                if (e.PropertyName == "Show" && !windowViewModel.Show)
                {
                    RemoveWindowViewModel(windowViewModel, controlKind);
                    windowViewModel.PropertyChanged -= handler;
                }
            };

            windowViewModel.PropertyChanged += handler;
        }
Example #16
0
        /// <summary>
        /// Creates a specific View for the given ViewModel.
        /// </summary>
        /// <param name="mdl">the model to be viewed</param>
        /// <param name="kind">the kind of view to create</param>
        /// <returns>the configured view</returns>
        protected virtual object CreateSpecificView(ViewModel mdl, ControlKind kind)
        {
            if (mdl == null)
            {
                throw new ArgumentNullException("mdl");
            }
            if (kind == null)
            {
                throw new ArgumentNullException("kind");
            }

            ViewModelDescriptor pmd = mdl.GetType().ToRef(FrozenContext)
                                      .GetViewModelDescriptor();

            var vDesc = pmd.GetViewDescriptor(Toolkit, kind);

            return(CreateSpecificView(mdl, vDesc));
        }
Example #17
0
        public void Show(string[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            if (args.Contains("-installperfcounter"))
            {
                if (perfCounter != null)
                {
                    perfCounter.Install();
                }
            }
            else if (args.Contains("-uninstallperfcounter"))
            {
                if (perfCounter != null)
                {
                    perfCounter.Install();
                }
            }
            else if (args.Length > 0)
            {
                var appGuid = new Guid(args[0]);
                LaunchApplication(appGuid);
            }
            else if (cfg.Client.Application != null && cfg.Client.Application != Guid.Empty)
            {
                LaunchApplication(cfg.Client.Application.Value);
            }
            else
            {
                var         ws       = mdlFactory.CreateViewModel <WorkspaceViewModel.Factory>().Invoke(ctxFactory(ClientIsolationLevel.MergeServerData), null);
                ControlKind launcher = Zetbox.NamedObjects.Gui.ControlKinds.Zetbox_App_GUI_LauncherKind.Find(frozenCtx);
                mdlFactory.ShowModel(ws, launcher, true);
            }


            //var ctxDebugger = mdlFactory.CreateViewModel<ZetboxDebuggerAsViewModel.Factory>().Invoke(ctxFactory());
            //mdlFactory.ShowModel(ctxDebugger, true);

            //var cacheDebugger = mdlFactory.CreateViewModel<CacheDebuggerViewModel.Factory>().Invoke(ctxFactory());
            //mdlFactory.ShowModel(cacheDebugger, true);
        }
Example #18
0
        private static DataTemplate SelectTemplate(ViewModel mdl, ControlKind controlKind, IFrozenContext frozenCtx)
        {
            var tr = GetTypeRef(mdl, frozenCtx);

            if (tr == null)
            {
                return(null);
            }

            ViewModelDescriptor pmd = tr.GetViewModelDescriptor();

            if (pmd == null)
            {
                Logging.Log.ErrorFormat("No matching ViewModelDescriptor found for {0}", mdl.GetType());
                return(null);
            }

            return(CreateTemplate(pmd.GetViewDescriptor(Toolkit.WPF, controlKind)));
        }
Example #19
0
 internal static ConvertedControlKind ConvertToLocalType(this ControlKind source)
 {
     return(source.Convert <ControlKind, ConvertedControlKind>());
 }
Example #20
0
        //// Steps for resolving a ViewModel to View
        //// 1. Find all ViewModel requested Views matching the ControlKind
        //// 2. Find all Views supporting the ViewModel matching the ControlKind
        //// 3. Find all Views supporting the ViewModel without ControlKind
        /// <summary>
        /// Look up the ViewDescriptor for this presentable model and ControlKind
        /// </summary>
        /// <param name="self"></param>
        /// <param name="tk"></param>
        /// <param name="requestedControlKind"></param>
        /// <returns></returns>
        public static ViewDescriptor GetViewDescriptor(
            this ViewModelDescriptor self,
            Toolkit tk,
            ControlKind requestedControlKind)
        {
            // Checks
            if (self == null) throw new ArgumentNullException("self");

            #region Cache Management
            PrimeCaches(tk, self.ReadOnlyContext);

            var key = new ViewDescriptorCache.Key(self.ViewModelTypeRef, tk, requestedControlKind);
            if (_viewDescriptorCache.ContainsKey(key)) return _viewDescriptorCache[key];
            #endregion

            // If the ViewModel has a more specific DefaultKind respect its choice
            if (self.DefaultEditorKind != null
                && requestedControlKind != null
                && self.DefaultEditorKind.AndParents().Select(i => i.ExportGuid).Contains(requestedControlKind.ExportGuid))
            {
                if (requestedControlKind != self.DefaultEditorKind)
                {
                    Logging.Log.DebugFormat("Using more specific default kind: {0} -> {1}", requestedControlKind.Name, self.DefaultEditorKind.Name);
                }
                requestedControlKind = self.DefaultEditorKind;
            }
            else
            {
                requestedControlKind = self.SecondaryControlKinds
                    .FirstOrDefault(
                        sck => sck.AndParents()
                                .Select(i => i.ExportGuid)
                                .Contains(requestedControlKind.ExportGuid)
                    ) ?? requestedControlKind;
            }

            ViewDescriptor result = null;

            ICollection<ViewDescriptor> candidates;
            if (requestedControlKind != null)
            {
                candidates = _viewCaches[tk].GetDescriptors(requestedControlKind);
            }
            else
            {
                candidates = _viewCaches[tk].GetDescriptors();
            }

            if (candidates.Count == 0)
            {
                // Try parent
                var type = Type.GetType(self.ViewModelTypeRef);
                var parent = type != null && type.BaseType != null ? type.BaseType.GetViewModelDescriptor(self.ReadOnlyContext) : null;
                if (parent != null)
                {
                    result = GetViewDescriptor(parent, tk, requestedControlKind);
                }
                else
                {
                    Logging.Log.WarnFormat("Couldn't find View for '{1}' matching ControlKind: '{0}'", requestedControlKind, self.ViewModelTypeRef);
                }
            }
            else if (candidates.Count == 1)
            {
                result = candidates.First();
            }
            else
            {
                var allTypes = GetAllTypes(self);
                // As allTypes is sorted from most specific to least specific, so first or default is perfect.
                var match = allTypes.SelectMany(vmType => candidates.Where(candidate =>
                {
                    var viewType = Type.GetType(candidate.ControlTypeRef, throwOnError: false);
                    if (viewType == null) return false;
                    var supportedViewModels = viewType.GetInterfaces()
                        .Where(ifType => ifType.IsGenericType && ifType.GetGenericTypeDefinition() == typeof(IHasViewModel<>))
                        .Select(ifType => ifType.GetGenericArguments().Single());

                    return supportedViewModels.Contains(vmType);
                })).FirstOrDefault();

                // Log a warning if nothing found
                if (match == null)
                {
                    Logging.Log.WarnFormat("Couldn't find View for '{1}' matching ControlKind: '{0}'", requestedControlKind, self.ViewModelTypeRef);
                }
                result = match;
            }

            _viewDescriptorCache[key] = result;
            return result;
        }
Example #21
0
        public static DateRangeFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource valueSource, ControlKind requestedKind, bool setYearDefault, bool setQuaterDefault, bool setMonthDefault)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }

            var mdl = new DateRangeFilterModel();

            mdl.Label         = label;
            mdl.ValueSource   = valueSource;
            mdl.ViewModelType = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_DateRangeFilterViewModel.Find(frozenCtx);
            mdl.RequestedKind = requestedKind;

            var fromMdl = new DateTimeValueModel(FilterModelsResources.From, "", true, false, DateTimeStyles.Date);
            var toMdl   = new DateTimeValueModel(FilterModelsResources.To, "", true, false, DateTimeStyles.Date);

            mdl.FilterArguments.Add(new FilterArgumentConfig(
                                        fromMdl,
                                        /*cfg.ArgumentViewModel ?? */ ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDateTimePropertyViewModel.Find(frozenCtx)));
            mdl.FilterArguments.Add(new FilterArgumentConfig(
                                        toMdl,
                                        /*cfg.ArgumentViewModel ?? */ ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDateTimePropertyViewModel.Find(frozenCtx)));

            if (setYearDefault)
            {
                // Defaults to this month
                fromMdl.Value = DateTime.Today.FirstYearDay();
                toMdl.Value   = DateTime.Today.LastYearDay();
            }
            else if (setQuaterDefault)
            {
                // Defaults to this month
                fromMdl.Value = DateTime.Today.FirstQuaterDay();
                toMdl.Value   = DateTime.Today.LastQuaterDay();
            }
            else if (setMonthDefault)
            {
                // Defaults to this month
                fromMdl.Value = DateTime.Today.FirstMonthDay();
                toMdl.Value   = DateTime.Today.LastMonthDay();
            }

            return(mdl);
        }
Example #22
0
 public static RangeFilterModel Create(IFrozenContext frozenCtx, string label, string predicate, Type type, ControlKind requestedKind, ControlKind requestedArgumentKind)
 {
     return(Create(frozenCtx, label, FilterValueSource.FromExpression(predicate), type, requestedKind, requestedArgumentKind));
 }
Example #23
0
        public static SingleValueFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource predicate, Type propType, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }
            if (propType == null)
            {
                throw new ArgumentNullException("propType");
            }

            var fmdl = new SingleValueFilterModel()
            {
                Label                  = label,
                ValueSource            = predicate,
                Operator               = FilterOperators.Equals,
                ViewModelType          = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_SingleValueFilterViewModel.Find(frozenCtx),
                RequestedKind          = requestedKind,
                RefreshOnFilterChanged = false,
            };

            ViewModelDescriptor vDesc = null;
            BaseValueModel      mdl   = null;

            if (propType == typeof(decimal))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDecimalPropertyViewModel.Find(frozenCtx);
                mdl   = new DecimalValueModel(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(int))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Int32_.Find(frozenCtx);
                mdl   = new NullableStructValueModel <int>(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(double))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Double_.Find(frozenCtx);
                mdl   = new NullableStructValueModel <double>(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(bool))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableBoolPropertyViewModel.Find(frozenCtx);
                fmdl.RefreshOnFilterChanged = true;
                if (requestedArgumentKind == null)
                {
                    requestedArgumentKind = NamedObjects.Gui.ControlKinds.Zetbox_App_GUI_DropdownBoolKind.Find(frozenCtx);
                }
                mdl = new BoolValueModel(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(string))
            {
                vDesc         = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_ClassValueViewModel_1_System_String_.Find(frozenCtx);
                mdl           = new ClassValueModel <string>(label, "", true, false, requestedArgumentKind);
                fmdl.Operator = FilterOperators.Contains;
            }
            else
            {
                throw new NotSupportedException(string.Format("Singlevalue filters of Type {0} are not supported yet", propType.Name));
            }

            fmdl.FilterArguments.Add(new FilterArgumentConfig(mdl, vDesc));
            return(fmdl);
        }
Example #24
0
        public static SingleValueFilterModel Create(IFrozenContext frozenCtx, string label, IEnumerable <Property> props, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            var predicate = FilterValueSource.FromProperty(props);
            var last      = props.Last();

            if (last is DecimalProperty)
            {
                return(Create(frozenCtx, label, predicate, typeof(decimal), requestedKind, requestedArgumentKind));
            }
            else if (last is IntProperty)
            {
                return(Create(frozenCtx, label, predicate, typeof(int), requestedKind, requestedArgumentKind));
            }
            else if (last is DoubleProperty)
            {
                return(Create(frozenCtx, label, predicate, typeof(double), requestedKind, requestedArgumentKind));
            }
            else if (last is StringProperty)
            {
                return(Create(frozenCtx, label, predicate, typeof(string), requestedKind, requestedArgumentKind));
            }
            else if (last is BoolProperty)
            {
                return(Create(frozenCtx, label, predicate, typeof(bool), requestedKind, requestedArgumentKind));
            }
            else if (last is EnumerationProperty)
            {
                return(Create(frozenCtx, label, predicate, ((EnumerationProperty)last).Enumeration.ExportGuid, requestedKind, requestedArgumentKind));
            }
            else if (last is ObjectReferenceProperty)
            {
                return(Create(frozenCtx, label, predicate, ((ObjectReferenceProperty)last).GetReferencedObjectClass(), requestedKind, requestedArgumentKind));
            }
            else if (last is CompoundObjectProperty)
            {
                return(Create(frozenCtx, label, predicate, ((CompoundObjectProperty)last).CompoundObjectDefinition, requestedKind, requestedArgumentKind));
            }
            else
            {
                throw new NotSupportedException(string.Format("Singlevalue filters of Property Type {0} are not supported yet", last.GetType().Name));
            }
        }
Example #25
0
 public ColumnDisplayModel(string header, string name, ControlKind kind, ControlKind gridPreviewKind)
     : this(header, name, kind, gridPreviewKind, ColumnType.PropertyModel, WidthHint.Default, null)
 {
 }
Example #26
0
 /// <summary>
 /// Creates a ColumnDisplayModel for a view model property or path to a property
 /// </summary>
 /// <param name="header">Label for the list header</param>
 /// <param name="kind">The requested editor kind or null if default should be used</param>
 /// <param name="vmPropPath">Path to the viewmodels property</param>
 /// <returns>a ready configurated ColumnDisplayModel</returns>
 public static ColumnDisplayModel Create(string header, ControlKind kind, string vmPropPath)
 {
     return Create(header, kind, null, WidthHint.Default, null, vmPropPath);
 }
Example #27
0
        public static DialogCreator AddString(this DialogCreator c, string label, ControlKind requestedKind)
        {
            if (c == null) throw new ArgumentNullException("c");

            var mdl = new ClassValueModel<string>(label, "", false, false);
            var vmdl = c.ViewModelFactory.CreateViewModel<ClassValueViewModel<string>.Factory>().Invoke(c.DataContext, null, mdl);
            vmdl.RequestedKind = requestedKind;
            c.ValueModels.Add(vmdl);
            return c;
        }
Example #28
0
 public ControlKindViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, ControlKind obj)
     : base(dependencies, dataCtx, parent, obj)
 {
     Kind = obj;
 }
Example #29
0
 /// <summary>
 /// Creates a ColumnDisplayModel for a view model property or path to a property
 /// </summary>
 /// <param name="header">Label for the list header</param>
 /// <param name="kind">The requested editor kind or null if default should be used</param>
 /// <param name="gridPreviewKind">The requested preview kind or null if default should be used</param>
 /// <param name="requestedWidth">Requested list column width</param>
 /// <param name="requestedWidthAbsolute">Requested list column width in absolute toolkit units</param>
 /// <param name="vmPropPath">Path to the viewmodels property</param>
 /// <returns>a ready configurated ColumnDisplayModel</returns>
 public static ColumnDisplayModel Create(string header, ControlKind kind, ControlKind gridPreviewKind, WidthHint requestedWidth, int? requestedWidthAbsolute, string vmPropPath)
 {
     return new ColumnDisplayModel()
     {
         Header = header,
         Path = vmPropPath,
         Type = ColumnDisplayModel.ColumnType.ViewModelProperty,
         RequestedWidth = requestedWidth,
         RequestedWidthAbsolute = requestedWidthAbsolute,
         ControlKind = kind,
         GridPreEditKind = gridPreviewKind ?? kind,
     };
 }
Example #30
0
 /// <summary>
 /// Creates a ColumnDisplayModel for a view model property or path to a property
 /// </summary>
 /// <param name="header">Label for the list header</param>
 /// <param name="kind">The requested editor kind or null if default should be used</param>
 /// <param name="requestedWidthAbsolute">Requested list column width in absolute toolkit units</param>
 /// <param name="vmPropPath">Path to the viewmodels property</param>
 /// <returns>a ready configurated ColumnDisplayModel</returns>
 public static ColumnDisplayModel Create(string header, ControlKind kind, int? requestedWidthAbsolute, string vmPropPath)
 {
     return Create(header, kind, null, WidthHint.Default, requestedWidthAbsolute, vmPropPath);
 }
Example #31
0
 /// <summary>
 /// Creates a ColumnDisplayModel for a view model property or path to a property
 /// </summary>
 /// <param name="header">Label for the list header</param>
 /// <param name="kind">The requested editor kind or null if default should be used</param>
 /// <param name="requestedWidth">Requested list column width</param>
 /// <param name="vmPropPath">Path to the viewmodels property</param>
 /// <returns>a ready configurated ColumnDisplayModel</returns>
 public static ColumnDisplayModel Create(string header, ControlKind kind, WidthHint requestedWidth, string vmPropPath)
 {
     return Create(header, kind, null, requestedWidth, null, vmPropPath);
 }
Example #32
0
        //// Steps for resolving a ViewModel to View
        //// 1. Find all ViewModel requested Views matching the ControlKind
        //// 2. Find all Views supporting the ViewModel matching the ControlKind
        //// 3. Find all Views supporting the ViewModel without ControlKind
        /// <summary>
        /// Look up the ViewDescriptor for this presentable model and ControlKind
        /// </summary>
        /// <param name="self"></param>
        /// <param name="tk"></param>
        /// <param name="requestedControlKind"></param>
        /// <returns></returns>
        public static ViewDescriptor GetViewDescriptor(
            this ViewModelDescriptor self,
            Toolkit tk,
            ControlKind requestedControlKind)
        {
            // Checks
            if (self == null) throw new ArgumentNullException("self");

            #region Cache Management
            PrimeCaches(tk, self.ReadOnlyContext);

            var key = new ViewDescriptorCache.Key(self.ViewModelRef, tk, requestedControlKind);
            if (_viewDescriptorCache.ContainsKey(key)) return _viewDescriptorCache[key];
            #endregion

            // If the ViewModel has a more specific DefaultKind respect its choice
            if (self.DefaultEditorKind != null
                && requestedControlKind != null
                && self.DefaultEditorKind.AndParents().Select(i => i.ExportGuid).Contains(requestedControlKind.ExportGuid))
            {
                if (requestedControlKind != self.DefaultEditorKind)
                {
                    Logging.Log.DebugFormat("Using more specific default kind: {0} -> {1}", requestedControlKind.Name, self.DefaultEditorKind.Name);
                }
                requestedControlKind = self.DefaultEditorKind;
            }
            else
            {
                requestedControlKind = self.SecondaryControlKinds
                    .FirstOrDefault(
                        sck => sck.AndParents()
                                .Select(i => i.ExportGuid)
                                .Contains(requestedControlKind.ExportGuid)
                    ) ?? requestedControlKind;
            }

            ViewDescriptor result = null;

            ICollection<ViewDescriptor> candidates;
            if (requestedControlKind != null)
            {
                candidates = _viewCaches[tk].GetDescriptors(requestedControlKind);
            }
            else
            {
                candidates = _viewCaches[tk].GetDescriptors();
            }

            if (candidates.Count == 0)
            {
                // Try parent
                var parent =  self.ViewModelRef.Parent != null ? self.ViewModelRef.Parent.GetViewModelDescriptor() : null;
                if (parent != null)
                {
                    result = GetViewDescriptor(parent, tk, requestedControlKind);
                }
                else
                {
                    Logging.Log.WarnFormat("Couldn't find ViewDescriptor for '{1}' matching ControlKind: '{0}'", requestedControlKind, self.ViewModelRef);
                }
            }
            else if (candidates.Count == 1)
            {
                result = candidates.First();
            }
            else
            {
                var allTypes = GetAllTypes(self);
                // As allTypes is sorted from most specific to least specific first or default is perfect.
                var match = allTypes.SelectMany(t => candidates.Where(c => c.SupportedViewModels.Contains(t))).FirstOrDefault();

                // Try the most common
                if (match == null)
                {
                    match = allTypes.SelectMany(t => candidates.Where(c => c.SupportedViewModels.Count == 0)).FirstOrDefault();
                }

                // Log a warning if nothing found
                if (match == null)
                {
                    Logging.Log.WarnFormat("Couldn't find ViewDescriptor for '{1}' matching ControlKind: '{0}'", requestedControlKind, self.GetType().FullName);
                }
                result = match;
            }

            _viewDescriptorCache[key] = result;
            return result;
        }
Example #33
0
 public ColumnDisplayModel(string header, string name, ControlKind kind, ColumnType type)
     : this(header, name, kind, null, type, WidthHint.Default, null)
 {
 }
Example #34
0
 public ReadOnlyCollection<ViewDescriptor> GetDescriptors(ControlKind c)
 {
     if (_vdCache.ContainsKey(c.ExportGuid))
     {
         return _vdCache[c.ExportGuid];
     }
     else
     {
         return EmptyList;
     }
 }
Example #35
0
 protected override object CreateSpecificView(ViewModel mdl, ControlKind kind)
 {
     IView view = (IView)base.CreateSpecificView(mdl, kind);
     view.SetModel(mdl);
     return view;
 }
Example #36
0
        public static SingleValueFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource predicate, CompoundObject cpObj, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }

            var fmdl = new SingleCompoundValueFilterModel()
            {
                Label                    = label,
                ValueSource              = predicate,
                Operator                 = FilterOperators.Equals,
                ViewModelType            = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_SingleValueFilterViewModel.Find(frozenCtx),
                RequestedKind            = requestedKind,
                RefreshOnFilterChanged   = true,
                CompoundObjectDefinition = cpObj,
            };

            fmdl.FilterArguments.Add(new FilterArgumentConfig(
                                         new CompoundObjectValueModel(label, "", true, false, requestedArgumentKind, cpObj),
                                         cpObj.DefaultPropertyViewModelDescriptor ?? ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_CompoundObjectPropertyViewModel.Find(frozenCtx)));
            return(fmdl);
        }
Example #37
0
 public ColumnDisplayModel(string header, string name, ControlKind kind, int requestedWidthAbsoulte)
     : this(header, name, kind, null, ColumnType.PropertyModel, WidthHint.Default, requestedWidthAbsoulte)
 {
 }
Example #38
0
 public static SingleValueFilterModel Create(IFrozenContext frozenCtx, string label, Property prop, ControlKind requestedKind, ControlKind requestedArgumentKind)
 {
     return(Create(frozenCtx, label, new[] { prop }, requestedKind, requestedArgumentKind));
 }
Example #39
0
 public ColumnDisplayModel(string header, string name, ControlKind kind, WidthHint requestedWidth)
     : this(header, name, kind, null, ColumnType.PropertyModel, requestedWidth, null)
 {
 }
Example #40
0
        public static YearValueFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource valueSource, bool setDefault, ControlKind requestedKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }

            var valMdl = new NullableStructValueModel <int>(label, "", true, false);
            var mdl    = new YearValueFilterModel();

            mdl.Label         = label;
            mdl.ValueSource   = valueSource;
            mdl.ViewModelType = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_SingleValueFilterViewModel.Find(frozenCtx);
            mdl.RequestedKind = requestedKind;
            mdl.FilterArguments.Add(new FilterArgumentConfig(
                                        valMdl,
                                        /*cfg.ArgumentViewModel ?? */ ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Int32_.Find(frozenCtx)));

            if (setDefault)
            {
                // Defaults to this month
                valMdl.Value = DateTime.Today.FirstYearDay().Year;
            }

            return(mdl);
        }
Example #41
0
 public ColumnDisplayModel(string header, string name, ControlKind kind)
     : this(header, name, kind, ColumnType.PropertyModel)
 {
 }
Example #42
0
 public static RangeFilterModel Create <T>(IFrozenContext frozenCtx, string label, string predicate, ControlKind requestedKind, ControlKind requestedArgumentKind)
     where T : struct
 {
     return(Create(frozenCtx, label, predicate, typeof(T), requestedKind, requestedArgumentKind));
 }
Example #43
0
        public static DialogCreator AddString(this DialogCreator c, object key, string label, string value = null, bool allowNullInput = false, bool isReadOnly = false, ControlKind requestedKind = null, ViewModelDescriptor vmdesc = null, string description = null, string helpText = null)
        {
            if (c == null) throw new ArgumentNullException("c");
            if (key == null) throw new ArgumentNullException("key");

            var mdl = new ClassValueModel<string>(label, description, allowNullInput, isReadOnly);
            mdl.Value = value;
            mdl.HelpText = helpText;

            BaseValueViewModel vmdl;
            if (vmdesc != null)
                vmdl = c.ViewModelFactory.CreateViewModel<StringValueViewModel.Factory>(vmdesc).Invoke(c.DataContext, null, mdl);
            else
                vmdl = c.ViewModelFactory.CreateViewModel<StringValueViewModel.Factory>().Invoke(c.DataContext, null, mdl);

            if (requestedKind != null)
                vmdl.RequestedKind = requestedKind;

            c.Add(key, vmdl);
            return c;
        }
Example #44
0
        public static RangeFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource predicate, Type type, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var rfmdl = new RangeFilterModel()
            {
                Label         = label,
                ValueSource   = predicate,
                ViewModelType = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_RangeFilterViewModel.Find(frozenCtx),
                RequestedKind = requestedKind,
            };

            ViewModelDescriptor vDesc = null;
            BaseValueModel      mdl1  = null;
            BaseValueModel      mdl2  = null;

            if (type == typeof(decimal))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDecimalPropertyViewModel.Find(frozenCtx);
                mdl1  = new DecimalValueModel("", "", true, false, requestedArgumentKind);
                mdl2  = new DecimalValueModel("", "", true, false, requestedArgumentKind);
            }
            else if (type == typeof(int))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Int32_.Find(frozenCtx);
                mdl1  = new NullableStructValueModel <int>("", "", true, false, requestedArgumentKind);
                mdl2  = new NullableStructValueModel <int>("", "", true, false, requestedArgumentKind);
            }
            else if (type == typeof(double))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Double_.Find(frozenCtx);
                mdl1  = new NullableStructValueModel <double>("", "", true, false, requestedArgumentKind);
                mdl2  = new NullableStructValueModel <double>("", "", true, false, requestedArgumentKind);
            }
            else if (type == typeof(DateTime))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDateTimePropertyViewModel.Find(frozenCtx);
                mdl1  = new DateTimeValueModel("", "", true, false, DateTimeStyles.Date, requestedArgumentKind);
                mdl2  = new DateTimeValueModel("", "", true, false, DateTimeStyles.Date, requestedArgumentKind);
            }
            else
            {
                throw new NotSupportedException(string.Format("Rangefilters of Type {0} are not supported yet", type.Name));
            }

            rfmdl.FilterArguments.Add(new FilterArgumentConfig(mdl1, vDesc));
            rfmdl.FilterArguments.Add(new FilterArgumentConfig(mdl2, vDesc));

            return(rfmdl);
        }
Example #45
0
        public static OptionalPredicateFilterModel Create(IFrozenContext frozenCtx, string label, string predicate, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }

            var fmdl = new OptionalPredicateFilterModel()
            {
                Label         = label,
                ValueSource   = FilterValueSource.FromExpression(predicate),
                ViewModelType = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_OptionalPredicateFilterViewModel.Find(frozenCtx),
                RequestedKind = requestedKind,
            };
            var valueMdl = new BoolValueModel(label, "", false, false, requestedArgumentKind);

            valueMdl.Value = false;
            fmdl.FilterArguments.Add(new FilterArgumentConfig(valueMdl,
                                                              ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableBoolPropertyViewModel.Find(frozenCtx)));
            return(fmdl);
        }
Example #46
0
 public static void GetName(ControlKind kind, MethodReturnEventArgs<string> e)
 {
     e.Result = "Gui.ControlKinds." + Regex.Replace(kind.Name, "\\W", "_");
 }
Example #47
0
 public static SingleValueFilterModel Create(IFrozenContext frozenCtx, string label, string predicate, Guid enumDef, ControlKind requestedKind, ControlKind requestedArgumentKind)
 {
     return(Create(frozenCtx, label, FilterValueSource.FromExpression(predicate), enumDef, requestedKind, requestedArgumentKind));
 }
Example #48
0
        public DataObjectViewModel ShowObject(IDataObject obj, ControlKind requestedKind = null, bool activate = true)
        {
            obj = obj == null || obj.Context == DataContext
                ? obj
                : DataContext.Find(obj.Context.GetInterfaceType(obj), obj.ID);

            var vm = DataObjectViewModel.Fetch(ViewModelFactory, DataContext, this, obj);
            if (!Items.Contains(vm))
            {
                vm.RequestedKind = requestedKind;
                AddItem(vm);
            }

            if (activate)
            {
                SelectedItem = vm;
            }
            return vm;
        }
Example #49
0
 public static SingleValueFilterModel Create(IFrozenContext frozenCtx, string label, string predicate, ObjectClass referencedClass, ControlKind requestedKind, ControlKind requestedArgumentKind)
 {
     return(Create(frozenCtx, label, FilterValueSource.FromExpression(predicate), referencedClass, requestedKind, requestedArgumentKind));
 }
Example #50
0
 public Key( TypeRef vmd,
             Toolkit tk,
             ControlKind ck)
 {
     this.vmd = vmd.ExportGuid;
     this.tk = tk;
     this.ck = ck != null ? ck.ExportGuid : Guid.Empty;
 }
Example #51
0
        public static SingleValueFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource predicate, ObjectClass referencedClass, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }

            var fmdl = new SingleValueFilterModel()
            {
                Label                  = label,
                ValueSource            = predicate,
                Operator               = FilterOperators.Equals,
                ViewModelType          = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_SingleValueFilterViewModel.Find(frozenCtx),
                RequestedKind          = requestedKind,
                RefreshOnFilterChanged = true,
            };

            fmdl.FilterArguments.Add(new FilterArgumentConfig(
                                         new ObjectReferenceValueModel(label, "", true, false, requestedArgumentKind, referencedClass),
                                         ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_ObjectReferenceViewModel.Find(frozenCtx)));
            return(fmdl);
        }
 private static DataTemplate SelectTemplate(ViewModel mdl, ControlKind controlKind, IFrozenContext frozenCtx)
 {
     ViewModelDescriptor pmd = GuiExtensions.GetViewModelDescriptor(mdl, frozenCtx);
     if (pmd == null) return null;
     return CreateTemplate(pmd.GetViewDescriptor(Toolkit.WPF, controlKind));
 }
Example #53
0
 /// <summary>
 /// Creates a ColumnDisplayModel for a zetbox object property or property path
 /// </summary>
 /// <param name="mode">Requested mode (readonly, editable)</param>
 /// <param name="header">Label for the list header</param>
 /// <param name="kind">The requested editor kind or null if default should be used</param>
 /// <param name="gridPreviewKind">The requested preview kind or null if default should be used</param>
 /// <param name="requestedWidth">Requested list column width</param>
 /// <param name="requestedWidthAbsolute">Requested list column width in absolute toolkit units</param>
 /// <param name="p">list of properties to build column for</param>
 /// <returns>a ready configurated ColumnDisplayModel</returns>
 public static ColumnDisplayModel Create(GridDisplayConfiguration.Mode mode, string header, ControlKind kind, ControlKind gridPreviewKind, WidthHint requestedWidth, int? requestedWidthAbsolute, params Property[] p)
 {
     var colMdl = Create(mode, p);
     colMdl.Header = header;
     colMdl.ControlKind = kind;
     colMdl.GridPreEditKind = gridPreviewKind ?? kind;
     colMdl.RequestedWidth = requestedWidth;
     colMdl.RequestedWidthAbsolute = requestedWidthAbsolute;
     return colMdl;
 }
Example #54
0
 public static void GetName(ControlKind kind, MethodReturnEventArgs <string> e)
 {
     e.Result = "Gui.ControlKinds." + Regex.Replace(kind.Name, "\\W", "_");
 }
Example #55
0
        public static object CreateSpecificView(this IViewModelFactory self, ViewModel mdl, ControlKind kind, Control container)
        {
            if (self == null) { throw new ArgumentNullException("self"); }

            return AddControl(container, null /*self.CreateSpecificView(mdl, kind) */);
        }