Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
 void TaskSetLabelNormalWindow(NormalWindow nw, ModifiableEntity entity)
 {
     ShortcutHelper.SetLabelShortcuts(nw);
 }
Beispiel #5
0
        void TaskSetIconNormalWindow(NormalWindow nw, ModifiableEntity entity)
        {
            var icon = GetEntityIcon(entity.GetType(), true);

            nw.Icon = icon;
        }
Beispiel #6
0
 public NormalWindowAutomationPeer(NormalWindow normalWindow)
     : base(normalWindow)
 {
 }
Beispiel #7
0
 public NormalWindowAutomationPeer(NormalWindow normalWindow)
     : base(normalWindow)
 {
 }