public void ObjectChanged(INakedObject nakedObject, ILifecycleManager lifecycleManager, IMetamodelManager metamodel) { Log.DebugFormat("ObjectChanged nakedObject: {0}", nakedObject); if (nakedObject.ResolveState.RespondToChangesInPersistentObjects()) { if (nakedObject.Spec.ContainsFacet(typeof(IComplexTypeFacet))) { nakedObject.Updating(); nakedObject.Updated(); } else { ITypeSpec spec = nakedObject.Spec; if (spec.IsAlwaysImmutable() || (spec.IsImmutableOncePersisted() && nakedObject.ResolveState.IsPersistent())) { throw new NotPersistableException("cannot change immutable object"); } nakedObject.Updating(); objectStore.ExecuteSaveObjectCommand(nakedObject); nakedObject.Updated(); } } if (nakedObject.ResolveState.RespondToChangesInPersistentObjects() || nakedObject.ResolveState.IsTransient()) { } }
public void ObjectChanged(INakedObjectAdapter nakedObjectAdapter, ILifecycleManager lifecycleManager, IMetamodelManager metamodel) { if (nakedObjectAdapter.ResolveState.RespondToChangesInPersistentObjects()) { if (nakedObjectAdapter.Spec.ContainsFacet(typeof(IComplexTypeFacet))) { nakedObjectAdapter.Updating(); nakedObjectAdapter.Updated(); } else { ITypeSpec spec = nakedObjectAdapter.Spec; if (spec.IsAlwaysImmutable() || (spec.IsImmutableOncePersisted() && nakedObjectAdapter.ResolveState.IsPersistent())) { throw new NotPersistableException(Log.LogAndReturn("cannot change immutable object")); } nakedObjectAdapter.Updating(); if (!spec.IsNeverPersisted()) { objectStore.ExecuteSaveObjectCommand(nakedObjectAdapter); } nakedObjectAdapter.Updated(); } } if (nakedObjectAdapter.ResolveState.RespondToChangesInPersistentObjects() || nakedObjectAdapter.ResolveState.IsTransient()) { } }
public override IConsent IsUsable(INakedObjectAdapter target) { bool isPersistent = target.ResolveState.IsPersistent(); IConsent disabledConsent = IsUsableDeclaratively(isPersistent); if (disabledConsent != null) { return(disabledConsent); } var viewModelFacet = target.Spec.GetFacet <IViewModelFacet>(); if (viewModelFacet != null) { // all fields on a non-editable view model are disabled if (!viewModelFacet.IsEditView(target)) { return(new Veto(Resources.NakedObjects.FieldDisabled)); } } var immutableFacet = GetFacet <IImmutableFacet>(); if (immutableFacet != null) { WhenTo when = immutableFacet.Value; if (when == WhenTo.UntilPersisted && !isPersistent) { return(new Veto(Resources.NakedObjects.FieldDisabledUntil)); } if (when == WhenTo.OncePersisted && isPersistent) { return(new Veto(Resources.NakedObjects.FieldDisabledOnce)); } ITypeSpec tgtSpec = target.Spec; if (tgtSpec.IsAlwaysImmutable() || (tgtSpec.IsImmutableOncePersisted() && isPersistent)) { return(new Veto(Resources.NakedObjects.FieldDisabled)); } } var f = GetFacet <IDisableForContextFacet>(); string reason = f == null ? null : f.DisabledReason(target); if (reason == null) { var fs = GetFacet <IDisableForSessionFacet>(); reason = fs == null ? null : fs.DisabledReason(Session, target, LifecycleManager, MetamodelManager); } return(GetConsent(reason)); }
// TODO either move this into framework or (better?) add a VetoCause enum to Veto and use private static IConsent IsCurrentlyMutable(INakedObject target) { bool isPersistent = target.ResolveState.IsPersistent(); var immutableFacet = target.Spec.GetFacet<IImmutableFacet>(); if (immutableFacet != null) { WhenTo when = immutableFacet.Value; if (when == WhenTo.UntilPersisted && !isPersistent) { return new Veto(Resources.NakedObjects.FieldDisabledUntil); } if (when == WhenTo.OncePersisted && isPersistent) { return new Veto(Resources.NakedObjects.FieldDisabledOnce); } ITypeSpec tgtSpec = target.Spec; if (tgtSpec.IsAlwaysImmutable() || (tgtSpec.IsImmutableOncePersisted() && isPersistent)) { return new Veto(Resources.NakedObjects.FieldDisabled); } } return new Allow(); }
public bool IsImmutable(IObjectFacade objectFacade) { return(spec.IsAlwaysImmutable() || (spec.IsImmutableOncePersisted() && !objectFacade.IsTransient)); }
public bool IsImmutable(INakedObjectSurface nakedObject) { return(spec.IsAlwaysImmutable() || (spec.IsImmutableOncePersisted() && !nakedObject.IsTransient())); }