WindowWorkspace: How to return a view back?

Topics: CAB & Smart Client Software Factory
May 8, 2007 at 3:48 PM
Hello,

I've tried to implement a sample where a View can be used as a control within DeckWorkspace and also be opened as a modal window within WindowWorkspace.

Normally this View opens within DeckWorkspace. In that view I have a button that fires a global event says that this view should be opened within WindowWorkspace as a modal form. I published this event in View's Presenter and fire it here as well. This event is caught by using EventSubscription in ModuleController where this View opens via

WorlItem.Workspaces Constants.WorkspaceNames.ModalWindows .Show( WorkItem.Items.Get<ViewClass>( "ViewClassId" ) )

and this works well - ViewClass opens as a modal dialog.

But if I close this modal window I got the Cannot Access a Disposed Object exception next time I try to view this View in DeckWorkspace.
Maybe this is an event publisher or a view itself...

Could you please point me out to the direction I should go on implementing this feature?


-
Thanks,
Leonid Shirmanov
Mar 20, 2008 at 9:10 PM
Hello, Leonid.
Did you find the solution of this task?
Mar 21, 2008 at 1:16 PM


SlyEjik wrote:
Hello, Leonid.
Did you find the solution of this task?


If you are encountering issues with the view not being disposed perhaps clicking on this link may provide you a solution - it addresses issues with Views not being properly disposed.
Mar 21, 2008 at 9:09 PM
Edited Mar 22, 2008 at 6:49 AM
Hello, Bill.
Thanks for link. l've corrected this BUG thanks to you previously.
Here's, such situation. In that view I have the "close" button and the "X" button. When I click "close" btn, a view is hide by WindowWorkspaceExtended OnClose method. That's correct. But if I click on the "X", that view closing without this method. On second pass described above raises "Cannot Access a Disposed Object exception", but view is't disposed.
But I encounter this error when my workitem is't modal.

!Sorry for my bad english!

Some Example:

[EventSubscription(EventTopicNames.AddrElementsSelectionViewShow, ThreadOption.UserInterface)]
public void EditorViewShow(object sender, EventArgs<string> e)
{
  IAddrElementsSelectionView _view = WorkItem.Items.Get<AddrElementsSelectionView>(WorkspaceNames.AddrElementsSelectionModuleLayout);
  if (_view == null)
    _view = WorkItem.Items.AddNew<AddrElementsSelectionView>(WorkspaceNames.AddrElementsSelectionModuleLayout);
 
// 1 pass - OK on next expression
// 2 pass - Cannot Access a Disposed Object exception on next expression
  WorkItem.Workspaces[WorkspaceNames.ModalWindows].Show(_view);
}
Mar 21, 2008 at 11:48 PM
Edited Mar 21, 2008 at 11:50 PM
I tried to duplicate the problem and the only way I could was to remove the following bug fix from the presenter.cs file:
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_workItem != null)
                {
                    // WK.2007.12.08 - View object not being released
                    // Remove view from _workItem collection
                    if (this.View != null)   {
                        OnCloseView();
                        _workItem.Items.Remove(this.View);                    
                    }
                    _workItem.Items.Remove(this);
                }
            }
        }

There is another bug that could be contributing/causing your problem. If you created your project using the "Foundational Model" recipe and configured it to provide a view and presenter there will be code missing in your <view>.Designer.cs Dispose() method. It will look as follows:
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

The presenter will never be disposed and as such the bugfix never run. This is what a "Business Module" recipe looks like in the <view>.designer.cs Dispose() method:

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_presenter != null)
                    _presenter.Dispose();    // <===== This fires the cleanup code
 
                if (components != null)
                    components.Dispose();
            }
 
            base.Dispose(disposing);
        }

Your problem is that the view is disposed and was never removed from the WorkItem.SmartParts - if you put a breakpoint on line 02 below you should always have a _view==null result for your Modal view (since it was closed).
00 public void EditorViewShow(object sender, EventArgs<string> e)
01 {
02    IAddrElementsSelectionView _view = WorkItem.Items.Get<AddrElementsSelectionView>(WorkspaceNames.AddrElementsSelectionModuleLayout);
03    if (_view == null)
04        _view = WorkItem.Items.AddNew<AddrElementsSelectionView>(WorkspaceNames.AddrElementsSelectionModuleLayout);
05    WorkItem.WorkspacesWorkspaceNames.ModalWindows.Show(_view);
06 }
If the above doesn't provide a clue to your problem let me know and we'll try something else.

BTW, your doing well with your english :) and if you use {{ code here }} brackets the wiki won't parse your code.
Mar 22, 2008 at 6:18 AM
Edited Mar 22, 2008 at 6:20 AM
Bill, great thanks!
I lost sight of destructor of my view. This is what I need. Thanks again.

Ejik

Some code Example ))