New Posts New Posts RSS Feed: DockPanelWorkspace. Reactivation of smartpart: error
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

DockPanelWorkspace. Reactivation of smartpart: error

 Post Reply Post Reply
Author
vecs View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Dec-2007
Location: Russian Federation
Posts: 17
Post Options Post Options   Quote vecs Quote  Post ReplyReply Direct Link To This Post Topic: DockPanelWorkspace. Reactivation of smartpart: error
    Posted: 25-Dec-2007 at 2:55am
Hello,

I have made new shell layout contained freeware DockPanelWorkspace from http://www.codeplex.com/cabext as "ShellContent":
CAB%20dock%20workspace
But I am getting an exception when try to close and then reopen the same page.
It seems that View (SmartPart) were disposed and removed from its WorkItem when I closed tab. So when I try to activate this View (SmartPart) again the PageController can not find this View and raises exception ("Cannot access a disposed object. Object name: '...'."). Or sometimes SmartPart removed from Workspace and "The smartpart is not present in the workspace" error raised when try to activate View second time.
BTW I found the same problem with ModalWindowsWorkspace ("The smartpart is not present in the workspace" error) on reactivation.

Any suggestions how to solve this problem?

For now I suppose one solution for this:
Find the way to dispose PageController when its MainView closed in DockWorkspace or in ModalWindowsWorkspace. But I dont know how implement this.

For a while I have disabled tabs closing so that tab once appeared remain alive till the end of user session. But IMHO it is not rational..




Edited by vecs - 27-Dec-2007 at 1:33am
I am a newbie, be gentle
Back to Top
Bill Jensen View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Jul-2007
Location: United States
Posts: 229
Post Options Post Options   Quote Bill Jensen Quote  Post ReplyReply Direct Link To This Post Posted: 28-Dec-2007 at 4:50pm
Well, you could try this:
 
In your PageController's static ShowPage() method, after calling the ShowPage<TController> base method, get the controller instance and setup a handler for the SmartPartClosing event of the main workspace:
 

// Get the controller instance

Page1PageController controller = GetPageController<Page1PageController>(pParentWorkItem, pPageWorkItemId);

// Handle the SmartPartClosing event (with an instance event handler)

controller.MainWorkspace.SmartPartClosing += new System.EventHandler<WorkspaceCancelEventArgs>(controller.MainWorkspace_SmartPartClosing);

Then add the handler:
 

// A SmartPart in the main workspace is closing

// Check to see if it's ours

private void MainWorkspace_SmartPartClosing(object sender, WorkspaceCancelEventArgs e)

{

// If it's our main view that's closing

if (e.SmartPart.Equals(this.MainView))

{

// Terminate this controlled workitem

// So a new controller will be created and initialized on the next Show() call

this.Terminate(e);

}

}

The Terminate(WorkspaceCancelEventArgs e) method is a a little bit tricky.  It sets the cancel flag in the event args to true.  If this isn't done, exceptions happen.

I've tried this briefly with a WindowWorkspace and it seems to work, but I'm not sure it will work with your DockPanelWorkspace.
 
Let me know if this helps.
 
Good luck,
Bill Jensen
Back to Top
vecs View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Dec-2007
Location: Russian Federation
Posts: 17
Post Options Post Options   Quote vecs Quote  Post ReplyReply Direct Link To This Post Posted: 29-Dec-2007 at 1:10am
Thank you very much, Bill!
It is exactly what we needed.
This work perfect with DockPanelWorkspace too.

But I found it does not work with "ModalWindows" workspace when I set this:
((WindowSmartPartInfo)MainView.SmartPartInfo).Modal = true;
The reason is that controller.MainWorkspace.SmartPartClosing event not
fired after dialog closing.


I am a newbie, be gentle
Back to Top
DeLight View Drop Down
Newbie
Newbie


Joined: 23-Aug-2007
Location: Belarus
Posts: 15
Post Options Post Options   Quote DeLight Quote  Post ReplyReply Direct Link To This Post Posted: 10-Jan-2008 at 1:38am
as I remember, the problem is:
1.
    public void Show() {
      ...
      MainWorkspace.Show(MainView);
      if ( IsFirstShow ) OnFirstShow();
      ...
    }
...
    private void OnFirstShow() {
      if ( IsFirstShow ) {
        IWorkspace editorWs = MainWorkspace;
        editorWs.SmartPartClosing += EditorClosingHandler;
        IsFirstShow = false;
      }
    }
in EntityEditorController.
2. MainWorkspace.Show(MainView) calls Form.ShowDialog() (in case of modal dialogs) so OnFirstShow() is not called until dialog window is closed. So editorWs.SmartPartClosing += EditorClosingHandler; is not called until dialog is closed. So SmartPartClosing event is not processed (not "not fired").
 
btw, solwed the "Reactivation of smartpart: error" problem with:
1. processing closing event in all pagecontrollers (not only editors).
mainWs.SmartPartClosing += PageClosingHandler;

protected void PageClosingHandler(object sender, WorkspaceCancelEventArgs e)

{

if (e.SmartPart != MainView)

return; // not this Editor

PageClosingHandlerCore(sender, e);

if (e.Cancel)

return;

Terminate(e);

}

protected virtual void PageClosingHandlerCore(object sender, WorkspaceCancelEventArgs e) { }

2. if we need the page to be hidden (not closed) when pushing the close button:
protected override void PageClosingHandlerCore(object sender, WorkspaceCancelEventArgs e)

{

((IWorkspace) sender).Hide(this.MainView);

e.Cancel = true;

}

щьёрт, не заметил Russian Federation. ко мне можно и по-русски. а лучше в аське сразу - 376440623 (рабочая), 108588 (домашняя). опыт работы с кабаной почти год уже, поделиться не против.


Edited by DeLight - 10-Jan-2008 at 2:29am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down