protected override void DoExecute(object data) { var parameter = Method.Parameter.Where(i => !i.IsReturnParameter).ToArray(); MethodInfo info = Object.GetType().FindMethod(Method.Name, parameter.Select(i => i.GetParameterType()).ToArray()); if (info == null) { throw new InvalidOperationException(string.Format(ActionViewModelResources.MethodNotFoundException, Method.Name)); } if (parameter.Length > 0) { var pitMdl = ViewModelFactory.CreateViewModel <ParameterInputTaskViewModel.Factory>().Invoke(DataContext, this, Method, (p) => { var result = info.Invoke(Object, p); HandleResult(result, data); }); ViewModelFactory.ShowDialog(pitMdl); } else { var result = info.Invoke(Object, new object[] { }); HandleResult(result, data); } }
/// <summary> /// Creates the property groups list. /// </summary> /// <remarks> /// Property groups are created based on the properties summary tags. Due to the fact, /// that properties can have more than one summary /// tag, properties may appear in more than one property group. Properties with no /// summary tags appears in the "Uncategorised" group. Note, that currently /// summary tags may not contain spaces as the space is defined as the seperator. /// You can override this method to add custom property groups. /// </remarks> /// <returns>List of property groups</returns> protected virtual List <PropertyGroupViewModel> CreatePropertyGroups() { FetchPropertyModels(); return(_propertyList .SelectMany(p => (String.IsNullOrEmpty(p.CategoryTags) ? Properties.Resources.Uncategorised : p.CategoryTags) .Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .Select(s => new { Category = s, Property = p })) .GroupBy(x => x.Category, x => x.Property) .OrderBy(group => group.Key) .Select <IGrouping <string, Property>, PropertyGroupViewModel>(group => { var lst = group.Select(p => _propertyModels[p]).Cast <ViewModel>().ToList(); if (lst.Count == 1) { return ViewModelFactory.CreateViewModel <SinglePropertyGroupViewModel.Factory>().Invoke( DataContext, this, group.Key, lst); } else { return ViewModelFactory.CreateViewModel <MultiplePropertyGroupViewModel.Factory>().Invoke( DataContext, this, group.Key, lst); } }) .ToList()); }
protected override List <PropertyGroupViewModel> CreatePropertyGroups() { var result = base.CreatePropertyGroups(); var relListMdl = ViewModelFactory.CreateViewModel <InstanceListViewModel.Factory>().Invoke(DataContext, this, () => DataContext, typeof(Relation).GetObjectClass(FrozenContext), () => DataContext.GetQuery <Relation>()); relListMdl.EnableAutoFilter = false; relListMdl.AddFilter(new ConstantValueFilterModel("A.Type = @0 || B.Type = @0", this.Object)); relListMdl.Commands.Add(ViewModelFactory.CreateViewModel <SimpleCommandViewModel.Factory>().Invoke(DataContext, this, "New Relation", "Creates a new Relation", CreateRelation, null, null)); var lblMdl = ViewModelFactory.CreateViewModel <LabeledViewContainerViewModel.Factory>().Invoke(DataContext, this, "Relations", "", relListMdl); var propGrpMdl = ViewModelFactory.CreateViewModel <SinglePropertyGroupViewModel.Factory>().Invoke(DataContext, this, "Relations", new ViewModel[] { lblMdl }); result.Add(propGrpMdl); return(result); }
protected override List <PropertyGroupViewModel> CreatePropertyGroups() { var result = base.CreatePropertyGroups(); if (_dataType is ObjectClass || _dataType is CompoundObject) { var singleMdl = result.Single(n => n.Name == "Properties"); var preview = ViewModelFactory.CreateViewModel <PropertiesPrewiewViewModel.Factory>().Invoke(DataContext, this, _dataType); var lblMdl = ViewModelFactory.CreateViewModel <LabeledViewContainerViewModel.Factory>().Invoke(DataContext, this, "Preview", "", preview); var grpMdl = ViewModelFactory.CreateViewModel <MultiplePropertyGroupViewModel.Factory>().Invoke(DataContext, this, "Properties", singleMdl.PropertyModels.Concat(new[] { lblMdl }).ToArray()); var idx = result.IndexOf(singleMdl); result.Remove(singleMdl); result.Insert(idx, grpMdl); } return(result); }
/// <summary> /// Initializes a new instance of the SelectionTaskModel class. This is protected since there /// is no ViewModelDescriptor for this class. Instead, either use the /// <see cref="DataObjectSelectionTaskViewModel"/> or inherit this for a specific type yourself and /// add your own ViewModelDescriptor and View. /// </summary> /// <param name="appCtx"></param> /// <param name="dataCtx"></param> /// <param name="parent">Parent ViewModel</param> /// <param name="type"></param> /// <param name="qry"></param> /// <param name="callback"></param> /// <param name="additionalActions"></param> public DataObjectSelectionTaskViewModel( IViewModelDependencies appCtx, IZetboxContext dataCtx, ViewModel parent, ObjectClass type, Func <IQueryable> qry, Action <IEnumerable <DataObjectViewModel> > callback, IList <CommandViewModel> additionalActions) : base(appCtx, dataCtx, parent) { _callback = callback; _additionalActions = new ReadOnlyCollection <CommandViewModel>(additionalActions ?? new CommandViewModel[] { }); ListViewModel = ViewModelFactory.CreateViewModel <InstanceListViewModel.Factory>().Invoke(dataCtx, this, () => dataCtx, type, qry); ListViewModel.AllowAddNew = true; ListViewModel.ObjectCreated += ListViewModel_ObjectCreated; ListViewModel.ItemsDefaultAction += ListViewModel_ItemsDefaultAction; ListViewModel.ViewMethod = InstanceListViewMethod.Details; foreach (var cmd in _additionalActions) { ListViewModel.Commands.Add(cmd); } }
private void DisplayErrors() { _errors.Clear(); foreach (var error in Parent.GetErrors()) { IDataObject obj = error as IDataObject; if (obj == null && error is ViewModel) { var vmdl = (ViewModel)error; if (vmdl.Parent is DataObjectViewModel) { obj = ((DataObjectViewModel)vmdl.Parent).Object; } } _errors.Add(ViewModelFactory.CreateViewModel <ErrorDescriptor.Factory>().Invoke( DataContext, this, obj == null ? null : DataObjectViewModel.Fetch(ViewModelFactory, DataContext, this, obj), new List <string>() { error.Error })); } }