Workspace inside workspace

Topics: CAB & Smart Client Software Factory
Sep 19, 2007 at 5:30 PM
Hi,

I have a module (modRetrieve) which contains a workspace. This module is loaded into the layout view and all is ok. This module contains various workspaces which will be used by other modules.

When this module is loaded up, I trigger an event in the OnViewReady which is captured by another and I'm trying to load it inside a workspaces which is contained in (modRetrieve) but I keep getting an error when the specific module is trying to load (itself) inside the specific workspace.

This is the code:

<EventSubscription(EventTopicNames.LoadViewer, ThreadOption.UserInterface)> _
Public Sub OnLoadViewer(ByVal sender As System.Object, ByVal eventArgs As System.EventArgs)

ViewerView = ShowViewInWorkspace(Of ViewerView)(WorkspaceNames.RetrieveViewerWorkspace)

End Sub

This code is in the modulecontroller of my viewer and as you can see it tries to show to view when the event is captured but I keep getting "Object variable not set..."?

Any ideas or help would be greatly appreciated? Its like the workitem is not initialized or something similar?

Thanks.

T.
Sep 19, 2007 at 9:57 PM
Hi again,

It's definitely my workspace which not set? Any ideas why?

When I step through this code:

Protected Overridable Function ShowViewInWorkspace(Of TView)(ByVal workspaceName As String) As TView
Dim view As TView = WorkItem.SmartParts.AddNew(Of TView)()
WorkItem.Workspaces(workspaceName).Show(view)
Return view
End Function

If I check WorkItem.Workspaces(workspaceName) it returns "nothing" which means it has not been set. Why this one and not the others?

I'll try to explain simply what happens:

Shell is loaded and contains a deckworkspace called LayoutWorkspace - all ok so far
Layoutview is loaded into LayoutWorkspace and contains a deckworkspace called MainWorkspace - all ok so far
RetrieveModule is a module which contains multiple workspaces and is loaded into MainWorkspace - One of the workspace is called RetrieveViewerWorkspace - all ok so far

When the RetrieveModule is loaded, in the OnViewReady event, I publish an event called LoadViewer - all ok so far

When the event is captured by the viewer module, I try to call

ViewerView = ShowViewInWorkspace(Of ViewerView)(WorkspaceNames.RetrieveViewerWorkspace)

and this is where the error occurs!! Basically the workspace with the id (RetrieveViewerWorkspace) does not exists? Why? I've hadn't had to add any code to add the other workspaces, so what's happening here?

Thanks.

T.
Sep 20, 2007 at 6:06 PM
Hi

I think I understood what you’re trying to do, and I’ve recreated the scenario and got it to work. The best way to achieve what you are proposing is following these steps:
  • Register the constant name of the workspace contained in the view in the Infrastructure.Interface.Constants -> WorkspaceNames, as it will be acting as a “global” Workspace.
  • Load the View (which contains the Worskpace) of the Module on the Shell.
  • Register the Workspace in the RootWorkItem:
Dim WS as IWorkspace = Me.WorkItem.Workspaces(WorkspaceNames.MyModuleWorkspace)
Me.WorkItem.RootWorkItem.Workspaces.Add(WS, WorkspaceNames.MyModuleWorkspace)
  • Publish the event in the OnViewReady() method of the View.
  • Subscribe to this event in the ModuleController.cs of each Module which will have a view that will be displayed in the Workspace of the View added to the Shell.
  • Finally, you’ll be able to load the view of any module on that Workspace:
ShowViewInWorkspace(Of OtherModuleView)(WorkspaceNames.MyModuleWorkspace)

Please let me know if this helps!

Ignacio Baumann Fonay
http://staff.southworks.net/blogs/ibaumann/
Sep 20, 2007 at 11:35 PM
Hi Ignacio,

Thanks for the reply. I'm going to try what you suggested but as mentioned to someone else, I'd swear I already tried this. Is there a recommend place where to put this code?

Dim WS as IWorkspace = Me.WorkItem.Workspaces(WorkspaceNames.MyModuleWorkspace)
Me.WorkItem.RootWorkItem.Workspaces.Add(WS, WorkspaceNames.MyModuleWorkspace)

Thanks.

T.
Sep 21, 2007 at 8:18 AM
Hi again,

I've tried what you suggested and it is partially working. By this I mean, that the code you gave me worked. I put :

Dim WS as IWorkspace = Me.WorkItem.Workspaces(WorkspaceNames.MyModuleWorkspace)
Me.WorkItem.RootWorkItem.Workspaces.Add(WS, WorkspaceNames.MyModuleWorkspace)

in my module's presenter as follows:

Public Overrides Sub OnViewReady()
MyBase.OnViewReady()

If WorkItem.RootWorkItem.Workspaces(WorkspaceNames.IndexViewerWorkspace) Is Nothing Then
Dim WS As IWorkspace = WorkItem.Workspaces(WorkspaceNames.IndexViewerWorkspace)
WorkItem.RootWorkItem.Workspaces.Add(WS, WorkspaceNames.IndexViewerWorkspace)
End If

OnLoadViewer(New EventArgs(Of String)(WorkspaceNames.IndexViewerWorkspace))

End Sub

As you can see I'm not passing the workspacename to the event that will be captured by the viewer, but the only problem now is that while I no longer get any errors, when I click on Index first for example, it will display my viewer ok but then if I click on retrieve, it will not display it and vice versa. It's like whoever has displayed the viewer first will keep it in its workspace.

Do I need to unload/hide the viewer first everytime? How do I do that?

This is the code in the viewer:

<EventSubscription(EventTopicNames.LoadViewer, ThreadOption.UserInterface)> _
Public Sub OnLoadViewer(ByVal sender As System.Object, ByVal e As EventArgs(Of String))

ViewerView = ShowViewInWorkspace(Of ViewerView)("Viewer", e.data)

End Sub

As you can see, the eventarg receives the workspacename and then it passed to the function?

Any ideas?

Thanks.

T.
Sep 21, 2007 at 8:26 AM
Hi,

Sorry I was too quick on the trigger with the previous post. As I stepped through the code, I realised that I was passing a ID ("Viewer") when showing the viewer in the workspace. The minute I removed the idea, the viewer now loads in both workspace.

Thanks again.

Thierry