Пример #1
0
        internal protected virtual bool OnIsCreable(Type type, bool isSearchEntity)
        {
            EntitySettings es = EntitySettings.TryGetC(type);

            if (es != null)
            {
                if (!es.OnIsCreable(isSearchEntity))
                {
                    return(false);
                }
            }
            else
            {
                if (type.IsEntity())//HACK
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            foreach (var isCreable in IsCreable.GetInvocationListTyped())
            {
                if (!isCreable(type))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        internal protected virtual bool OnIsViewable(Type type, ModifiableEntity entity)
        {
            EntitySettings es = EntitySettings.TryGetC(type);

            return
                (es != null &&
                 es.HasView() &&
                 IsViewableBase(type, entity) &&
                 es.OnIsViewable());
        }
Пример #3
0
        internal protected virtual bool OnIsNavigable(Type type, IEntity entity, bool isSearchEntity)
        {
            EntitySettings es = EntitySettings.TryGetC(type);

            return
                (es != null &&
                 es.HasView() &&
                 IsViewableBase(type, (ModifiableEntity)entity) &&
                 es.OnIsNavigable(isSearchEntity));
        }
Пример #4
0
        public ImageSource GetEntityIcon(Type type, bool useDefault)
        {
            EntitySettings es = EntitySettings.TryGetC(type);

            if (es != null && es.Icon != null)
            {
                return(es.Icon);
            }

            return(useDefault ? DefaultEntityIcon : null);
        }
Пример #5
0
        public virtual void Navigate(object entityOrLite, NavigateOptions options)
        {
            if (entityOrLite == null)
            {
                throw new ArgumentNullException("entity");
            }

            Type type = entityOrLite is Lite <Entity>?((Lite <Entity>)entityOrLite).EntityType : entityOrLite.GetType();

            OpenIndependentWindow(() =>
            {
                NormalWindow win = CreateNormalWindow();
                win.SetTitleText(NormalWindowMessage.Loading0.NiceToString().FormatWith(type.NiceName()));
                return(win);
            },
                                  afterShown: win =>
            {
                try
                {
                    ModifiableEntity entity = entityOrLite as ModifiableEntity;
                    if (entity == null)
                    {
                        Lite <Entity> lite = (Lite <Entity>)entityOrLite;
                        entity             = lite.EntityOrNull ?? Server.RetrieveAndForget(lite);
                    }

                    EntitySettings es = AssertViewableEntitySettings(entity);
                    if (!es.OnIsNavigable(true))
                    {
                        throw new Exception("{0} is not navigable".FormatWith(entity));
                    }

                    if (entity is EmbeddedEntity)
                    {
                        throw new InvalidOperationException("ViewSave is not allowed for EmbeddedEntities");
                    }

                    Control ctrl = options.View != null ? options.View() : es.CreateView(entity, null);
                    ctrl         = es.OnOverrideView(entity, ctrl);


                    SetNormalWindowEntity(win, (ModifiableEntity)entity, options, es, ctrl);
                }
                catch
                {
                    win.Close();
                    throw;
                }
            },
                                  closed: options.Closed);
        }
Пример #6
0
        private void RecalculateVisibility(object oldValue, object newValue)
        {
            if (AutoChild)
            {
                // when datacontext change is fired but its not loaded, it's quite possible that some Common.Routes are not working yet
                if (newValue == null /* || !IsLoaded*/)
                {
                    Child = null;
                }
                else
                {
                    EntitySettings es = Navigator.Manager.EntitySettings.TryGetC(newValue.GetType());
                    if (es == null)
                    {
                        Child = new TextBox
                        {
                            Text       = "No EntitySettings for {0}".FormatWith(newValue.GetType()),
                            Foreground = Brushes.Red,
                            FontWeight = FontWeights.Bold
                        }
                    }
                    ;
                    else
                    {
                        Child = es.CreateView((ModifiableEntity)newValue, Common.GetPropertyRoute(this));
                    }
                }
            }
            if (Child != null)
            {
                if (newValue == null)
                {
                    Child.Visibility = Visibility.Hidden;
                }
                else
                {
                    Child.Visibility = Visibility.Visible;
                }

                if (oldValue != null && newValue != null)
                {
                    Child.BeginAnimation(UIElement.OpacityProperty, animation);
                }
            }
        }
Пример #7
0
        protected internal virtual Implementations FindImplementations(PropertyRoute pr)
        {
            if (typeof(ModelEntity).IsAssignableFrom(pr.RootType))
            {
                EntitySettings es = EntitySettings.TryGetC(pr.RootType);

                if (es != null) //Not mandatory, on windows it's usual not to register model entities.
                {
                    return(es.FindImplementations(pr));
                }

                return(ModelEntity.GetImplementations(pr));
            }
            else
            {
                return(Server.FindImplementations(pr));
            }
        }
Пример #8
0
        public virtual ImageSource GetFindIcon(object queryName, bool useDefault)
        {
            var qs = QuerySettings.TryGetC(queryName);

            if (qs != null && qs.Icon != null)
            {
                return(qs.Icon);
            }

            if (queryName is Type)
            {
                EntitySettings es = Navigator.Manager.EntitySettings.TryGetC((Type)queryName);
                if (es != null && es.Icon != null)
                {
                    return(es.Icon);
                }
            }

            return(useDefault ? DefaultFindIcon : null);
        }
Пример #9
0
        internal protected virtual EntitySettings AssertViewableEntitySettings(ModifiableEntity entity)
        {
            EntitySettings es = EntitySettings.TryGetC(entity.GetType());

            if (es == null)
            {
                throw new InvalidOperationException("No EntitySettings for type {0}".FormatWith(entity.GetType().Name));
            }

            if (!es.HasView())
            {
                throw new InvalidOperationException("No view has been set in the EntitySettings for {0}".FormatWith(entity.GetType().Name));
            }

            if (!IsViewableBase(entity.GetType(), entity))
            {
                throw new InvalidOperationException("Entities of type {0} are not viewable".FormatWith(entity.GetType().Name));
            }

            return(es);
        }
Пример #10
0
        internal protected virtual bool OnIsReadOnly(Type type, ModifiableEntity entity)
        {
            EntitySettings es = EntitySettings.TryGetC(type);

            if (es != null)
            {
                if (es.OnIsReadonly())
                {
                    return(true);
                }
            }

            foreach (var isReadOnly in IsReadOnly.GetInvocationListTyped())
            {
                if (isReadOnly(type, entity))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #11
0
        protected virtual NormalWindow SetNormalWindowEntity(NormalWindow win, ModifiableEntity entity, ViewOptionsBase options, EntitySettings es, Control ctrl)
        {
            Type entityType = entity.GetType();

            win.MainControl    = ctrl;
            win.ShowOperations = options.ShowOperations;
            win.ViewMode       = options.ViewButtons;

            entity = options.Clone ? (ModifiableEntity)((ICloneable)entity).Clone() : entity;
            win.OnPreEntityLoaded(entity);
            win.DataContext = entity;

            if (options.ReadOnly ?? OnIsReadOnly(entityType, entity))
            {
                Common.SetIsReadOnly(win, true);
            }

            if (options is ViewOptions)
            {
                win.SaveProtected = ((ViewOptions)options).RequiresSaveOperation ??
                                    (typeof(Entity).IsAssignableFrom(entityType) && EntityKindCache.RequiresSaveOperation(entityType)); //Matters even on Ok
            }
            TaskNormalWindow?.Invoke(win, entity);

            return(win);
        }
Пример #12
0
        public virtual object View(object entityOrLite, ViewOptions options)
        {
            if (entityOrLite == null)
            {
                throw new ArgumentNullException("entity");
            }

            ModifiableEntity entity   = entityOrLite as ModifiableEntity;
            Type             liteType = null;

            if (entity == null)
            {
                liteType = Lite.Extract(entityOrLite.GetType());
                entity   = Server.Retrieve((Lite <Entity>)entityOrLite);
            }

            EntitySettings es = AssertViewableEntitySettings(entity);

            if (!es.OnIsViewable())
            {
                throw new Exception("{0} is not viewable".FormatWith(entity));
            }

            Control ctrl = options.View ?? es.CreateView(entity, options.PropertyRoute);

            ctrl = es.OnOverrideView(entity, ctrl);

            NormalWindow win = CreateNormalWindow();

            SetNormalWindowEntity(win, (ModifiableEntity)entity, options, es, ctrl);

            if (options.AllowErrors != AllowErrors.Ask)
            {
                win.AllowErrors = options.AllowErrors;
            }

            bool?ok = win.ShowDialog();

            if (ok != true)
            {
                return(null);
            }

            object result = win.DataContext;

            if (liteType != null)
            {
                Entity ident = (Entity)result;

                bool saveProtected = ((ViewOptions)options).RequiresSaveOperation ?? EntityKindCache.RequiresSaveOperation(ident.GetType());

                if (GraphExplorer.HasChanges(ident))
                {
                    if (saveProtected)
                    {
                        throw new InvalidOperationException("The lite '{0}' of type '{1}' is SaveProtected but has changes. Consider setting SaveProtected = false in ViewOptions".FormatWith(entityOrLite, liteType.TypeName()));
                    }

                    return(ident.ToLiteFat());
                }

                return(ident.ToLite());
            }
            return(result);
        }
Пример #13
0
 public static void AddSetting(EntitySettings setting)
 {
     Navigator.Manager.EntitySettings.AddOrThrow(setting.StaticType, setting, "EntitySettings {0} repeated");
 }