Activate WorkItem From TabWorkspace

Topics: CAB & Smart Client Software Factory
Jul 12, 2007 at 5:18 PM
I have seen a number of postings that deal with calling the workItem.Activate() method when tabbing through a TabWorkspace (since an existing Tab will not change the active workitem). The resolution to call .Activate() seems fine but I am having trouble understanding how to actually OVERRIDE that method in SCSF. Any help or suggestions would be appreciated. I must be missing a simple point here (I hope).
Jul 13, 2007 at 11:53 PM
The way I do it is to call smartpart.activate() on the smartpart currently being shown in my TabWorkspace, this will automatically propagate out and activate the containing workitem. You cannot override the WorkItem.Activate() method but you can handle the Activated or Activating events..
Jul 16, 2007 at 4:47 PM

sefstrat wrote:
The way I do it is to call smartpart.activate() on the smartpart currently being shown in my TabWorkspace, this will automatically propagate out and activate the containing workitem. You cannot override the WorkItem.Activate() method but you can handle the Activated or Activating events..


Do you call the activate when you switch between tabs? or are you calling activate after the creation or showing of the smart part?

thanks,
Jordon
Jul 16, 2007 at 4:50 PM
Thank you. I can see that IWorkspace has an .Activate() but not a smartpart view. When I add a view, I run the following:

public void ShowInWorkspace(WorkItem workItem, Control smartPart, ISmartPartInfo info, string workspace)
{
//Get the workspace
IWorkspace myWorkspace = workItem.Workspacesworkspace;
//Show or activate it
if (myWorkspace.SmartParts.Contains(smartPart))
{
myWorkspace.Activate(smartPart);
}
else
{
myWorkspace.Show(smartPart, info);
}
}

I will try that avenue. In testing, I do get the events Activated and Deactivated on the WorkItem to fire. BUT not on a tab click but when I click inside the tab contents. This seems to be working mainly. I did see an Infragistics posting on using a CabUserControl (a override to USercontrol with a WorkItem property). Then combine that with the Smartpart activated, and now the WorkItem is set on the tab click (code below):

private void rightTabWorkspaceSmartPartActivated(object sender, Microsoft.Practices.CompositeUI.SmartParts.WorkspaceEventArgs e)
{
if (e.SmartPart is CabUserControl)
{
//This process can obtain a WorkItem fro the SmartPart...
((CabUserControl)e.SmartPart).WorkItem.Activate();
}
}

I noticed the Activate behavior differs with this added. That seemed to be the easy way to get the WorkItem activated on clicking the tab (without entering into the content area. This is all good stuff and helps me move closer.

Thanks for you help!
Jul 21, 2007 at 11:39 PM
If you want to catch it on a tab click rather than when you click inside the tab contents, handle the SmartPartActivated event of the TabWorkspace.

for instance, I put this in the Run() override in my work item controller..
_tabWorkspace.SmartPartActivated += new EventHandler<WorkspaceEventArgs>(SmartPartActivated);

then the handler..
private void SmartPartActivated(object sender, WorkspaceEventArgs e)
{
if (e.SmartPart.Equals(_view1))
//not necessary to activate this view
else if (e.SmartPart.Equals(_view2))
_view2.Activate();
else if (e.SmartPart.Equals(_view3))
_view3.Activate();
}

(in this scenario, view1 is the tab that is initially active, all the other tabs are set not to activate when initially added to the workspace, you can set this property in tabsmartpartinfo)

I use this to keep tabs from initializing their components or loading data until a user activates that tab, each tab keeps track of whether it has been activated and if it has not then it does not initialize its controls or load any data, that way I can have many workitems active without having a huge memory footprint.