private IPKSimBuildingBlock subjectFor(WorkspaceLayoutItem layoutItem)
        {
            if (!_withIdRepository.ContainsObjectWithId(layoutItem.SubjectId))
            {
                return(null);
            }

            var subject = _withIdRepository.Get <IPKSimBuildingBlock>(layoutItem.SubjectId);

            _lazyLoadTask.Load(subject);
            return(subject);
        }
        private WorkspaceLayout createNewWorkspaceLayoutWithOpenPresenters()
        {
            var workspaceLayout = new WorkspaceLayout();

            foreach (var presenter in _applicationController.OpenedPresenters())
            {
                var withId = presenter.Subject.DowncastTo <IWithId>();
                if (withId == null)
                {
                    continue;
                }
                var workspaceLayoutItem = new WorkspaceLayoutItem {
                    WasOpenOnSave = true, SubjectId = withId.Id, PresentationSettings = presenter.GetSettings()
                };
                workspaceLayout.AddLayoutItem(workspaceLayoutItem);
            }
            return(workspaceLayout);
        }
Example #3
0
        public TPresentationSettings PresentationSettingsFor <TPresentationSettings>(string presentationKey, IWithId subject) where TPresentationSettings : class, IPresentationSettings, new()
        {
            var layoutItem = getMatchingLayoutItem(presentationKey, subject);

            if (layoutItem != null)
            {
                return(getPresenterSettingsFromLayout <TPresentationSettings>(layoutItem));
            }

            layoutItem = new WorkspaceLayoutItem
            {
                PresentationKey      = presentationKey,
                SubjectId            = subject.Id,
                PresentationSettings = new TPresentationSettings()
            };
            _withWorkspaceLayout.WorkspaceLayout.AddLayoutItem(layoutItem);

            return(layoutItem.PresentationSettings as TPresentationSettings);
        }
        private void restoreLayout(WorkspaceLayoutItem layoutItem)
        {
            var subject = subjectFor(layoutItem);

            if (subject == null)
            {
                return;
            }

            var presenter = _openSingleStartPresenterInvoker.OpenPresenterFor(subject);

            try
            {
                presenter.Edit(subject);
                presenter.RestoreSettings(layoutItem.PresentationSettings);
            }
            catch (Exception)
            {
                //exception while loading the subject. We need to close the presenter to avoid memory leaks
                _applicationController.Close(subject);
                throw;
            }
        }
 private bool workspaceAlreadyContainsLayoutItem(IWorkspaceLayout workspaceLayout, WorkspaceLayoutItem x)
 {
     return(workspaceLayout.LayoutItems.FirstOrDefault(layoutItem => string.Equals(layoutItem.PresentationKey, x.PresentationKey) && string.Equals(layoutItem.SubjectId, x.SubjectId)) != null);
 }
Example #6
0
 private static bool subjectMatchesLayoutItem(IWithId subject, WorkspaceLayoutItem x)
 {
     return(string.Equals(x.SubjectId, subject.Id));
 }
Example #7
0
 private static TPresenterSettings getPresenterSettingsFromLayout <TPresenterSettings>(WorkspaceLayoutItem layoutItem) where TPresenterSettings : class, IPresentationSettings, new()
 {
     if (!layoutItem.PresentationSettings.IsAnImplementationOf <TPresenterSettings>())
     {
         layoutItem.PresentationSettings = new TPresenterSettings();
     }
     return(layoutItem.PresentationSettings as TPresenterSettings);
 }
Example #8
0
 private void removeLayoutItem(WorkspaceLayoutItem item)
 {
     _withWorkspaceLayout.WorkspaceLayout.RemoveLayoutItem(item);
 }