RunWorkItem and ActivateWorkItem

Topics: CAB & Smart Client Software Factory
Apr 3, 2007 at 7:47 PM
Edited Apr 3, 2007 at 10:02 PM
Hi,

I´m using CAB and SCSF to develop a smart client. i use a deckWorkspace in my shell, and I use Commnands associate with click event of shell buttons to create 4 view of a workitem.
I want to navigate between this views and activate them without recerate them. Now each time i click in the buttons the views are recreate. i join you my WorkItem Controler Code :

public class DailyInfoController : WorkItemController
{
private ToolStripStatusLabel _offlineNotificationLabel;
private DailyView _MyGDDailyView = null;
private BrowserView _MyWebBrowserView = null;
private DispatchView _MyDispatchView = null;
private DailyButtonsView _MyButtonsView = null;

IshellExtensionService ShellService = null;

public override void Run()
{
AddServices();
ExtendMenu();
ExtendToolStrip();
ExtendStatusStrip();
AddViews();

DisableCommands();
ExecuteActions();
}

public void RunWorkItem(int CaseView)
{
//retrieve s reference to IshellExtensionService
ShellService = WorkItem.Services.Get<IshellExtensionService>();
//Add Daily Informacion Services to be use in runtime in presenter.
WorkItem.Services.AddNew<DailyInformationServices>();

switch (CaseView)
{
case 1:
if (_MyGDDailyView == null)
{
_MyGDDailyView =
WorkItem.SmartParts.AddNew<DailyView>(Guid.NewGuid().ToString());
}
break;
case 2:
if (_MyWebBrowserView == null)
{
_MyWebBrowserView = WorkItem.SmartParts.AddNew<BrowserView>(Guid.NewGuid().ToString());
}
break;
case 3:
if (_MyDispatchView == null)
{
_MyDispatchView = WorkItem.SmartParts.AddNew<DispatchView>(Guid.NewGuid().ToString());
}
break;
case 4:
if (_MyButtonsView == null)
{
_MyButtonsView = WorkItem.SmartParts.AddNew<DailyButtonsView>(Guid.NewGuid().ToString());
// Messagebox.show(_MyButtonsView.Name);
}
break;
default:
break;
}
}

public void ActivateWorkItem(String WorkSpace, string title,int CaseView)
{
//Create a SmartPartInfo
SmartPartInfo info = new SmartPartInfo();
info.Title = title;

switch (CaseView)
{
case 1:
// Show instance of GDDailyView in workSpaces.
ShellService.showinWorkSpace(_MyGDDailyView, info, WorkSpace);
break;
case 2:
// Show instance of BrowserView in workSpaces.
ShellService.showinWorkSpace(_MyWebBrowserView, info, WorkSpace);
break;
case 3:
// Show instance of DispatchView in workSpaces.
ShellService.showinWorkSpace(_MyDispatchView, info, WorkSpace);
break;
case 4:
// Show instance of DispatchView in workSpaces.
ShellService.showinWorkSpace(_MyButtonsView, info, WorkSpace);
break;
default:
break;
}
}

private void DisableCommands()
{
foreach (KeyValuePair<string, Command> cmd in WorkItem.Commands)
{
cmd.Value.Status = CommandStatus.Disabled;
}
}

private IActionCatalogService _ActionCatalog;
ServiceDependency
public IActionCatalogService ActionCatalog
{
get { return _ActionCatalog;}
set { _ActionCatalog = value;}
}


private void ExecuteActions()
{
// Create the action-catalog to show all the uiextension authorise by users.
WorkItem.Items.AddNew<DailyInfoActionCatalog>();
ActionCatalog.Execute(ActionNames.DailyInfoAction, this.WorkItem, this, null);
ActionCatalog.Execute(ActionNames.NominationAction, this.WorkItem, this, null);
ActionCatalog.Execute(ActionNames.UserConfAction, this.WorkItem, this, null);

}



private void ExtendStatusStrip()
{
UIExtensionSite status = WorkItem.UIExtensionSitesUIExtensionSiteNames.MainStatus;
_offlineNotificationLabel = new ToolStripStatusLabel();
_offlineNotificationLabel.BorderStyle = Border3DStyle.Sunken;
_offlineNotificationLabel.Spring = true;
_offlineNotificationLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
_offlineNotificationLabel.BackColor = System.Drawing.Color.Transparent;
status.Add(_offlineNotificationLabel);
}


private delegate void UpdateNotificationLabelsDelegate(string text);

private void UpdateNotificationLabels(string text)
{
_offlineNotificationLabel.Text = text;
}

private void OnServiceOperationNotification(object sender, EventArgs<bool> args)
{
if (_offlineNotificationLabel != null && _offlineNotificationLabel.IsDisposed == false)
{
string text = (args.Data) ? string.Empty : Properties.Resources.ServiceNotAvailable;
if (_offlineNotificationLabel.Owner.InvokeRequired)
_offlineNotificationLabel.Owner.BeginInvoke(new UpdateNotificationLabelsDelegate(UpdateNotificationLabels), text);
else
UpdateNotificationLabels(text);
}
}


// Add CommandHandlers and/or Event Subscriptions

// Launch all the workitems in a daily view
CommandHandler(CommandNames.LaunchDailyView)
public void CreateDefaultDailyView(object sender, EventArgs e)
{
ControlledWorkItem<DailyInfoController> NewDailyButtonsView;

if (WorkItem.WorkItems.Get("DefaultDailyButtonsView") == null)
{
// Create a new daily info buttons view
NewDailyButtonsView = WorkItem.WorkItems.AddNew<ControlledWorkItem<DailyInfoController>>("DefaultDailyButtonsView");
NewDailyButtonsView.Controller.RunWorkItem(4);
}

NewDailyButtonsView = WorkItem.WorkItems"DefaultDailyButtonsView" as ControlledWorkItem<DailyInfoController>;
NewDailyButtonsView.Controller.ActivateWorkItem(WorkspaceNames.NavigationWorkspace, "Daily Info navigation", 4);

}


CommandHandler(CommandNames.LaunchGasDailyView)
public void CreateDefaultGasDailyView(object sender, EventArgs e)
{
ControlledWorkItem<DailyInfoController> NewDailyInfo;

if (WorkItem.WorkItems.Get("DefaultDailyInfo") == null)
{
// Create a new workitem GDDailyView
NewDailyInfo = WorkItem.WorkItems.AddNew<ControlledWorkItem<DailyInfoController>>("DefaultDailyInfo");
// Generate a new ID
//string WiId = string.Format("DailyInfoWorkItem#{0}", WorkItem.WorkItems.Count - 1);
// Create a new workitem
//NewDailyInfo = WorkItem.WorkItems.AddNew<ControlledWorkItem<ModuleController>>(WiId);
NewDailyInfo.Controller.RunWorkItem(1);
}

NewDailyInfo = WorkItem.WorkItems"DefaultDailyInfo" as ControlledWorkItem<DailyInfoController>;
NewDailyInfo.Controller.ActivateWorkItem(WorkspaceNames.MainWorkspace, "GasDaily information", 1);
}


CommandHandler(CommandNames.LaunchDispatchView)
public void CreateDefaultDispatchView(object sender, EventArgs e)
{
ControlledWorkItem<DailyInfoController> DispatchInfo;

if (WorkItem.WorkItems.Get("DefaultDispatchInfo") == null)
{
// Create a new workitem WebBrowserInfo
DispatchInfo = WorkItem.WorkItems.AddNew<ControlledWorkItem<DailyInfoController>>("DefaultDispatchInfo");
DispatchInfo.Controller.RunWorkItem(3);
}

DispatchInfo = WorkItem.WorkItems"DefaultDispatchInfo" as ControlledWorkItem<DailyInfoController>;
DispatchInfo.Controller.ActivateWorkItem(WorkspaceNames.MainWorkspace, "Dispatch", 3);
}



CommandHandler(CommandNames.LaunchWebIceView)
CommandHandler(CommandNames.LaunchWebIceView)
public void CreateDefaultWebIceView(object sender, EventArgs e)
{
// Create a new workitem WebIceDailyView ***********************************************************

ControlledWorkItem<DailyInfoController> WebBrowserInfo;

if (WorkItem.WorkItems.Get("DefaultWebBrowserInfo") == null)
{
// Create a new workitem WebBrowserInfo
WebBrowserInfo = WorkItem.WorkItems.AddNew<ControlledWorkItem<DailyInfoController>>("DefaultWebBrowserInfo");
WebBrowserInfo.Controller.RunWorkItem(2);
}

WebBrowserInfo = WorkItem.WorkItems"DefaultWebBrowserInfo" as ControlledWorkItem<DailyInfoController>;
WebBrowserInfo.Controller.ActivateWorkItem(WorkspaceNames.MainWorkspace, "Web Browser", 2);
}


How can i activate the view without recerating them.
Thanks you for your response.

Apr 6, 2007 at 11:14 PM
Instead of recreating all the smart parts again and again (Its really expensive), use Workspace.Show(smartpart) and Workspave.Hide(smartpart) methods. These methods simply shows/hides in the workspace. In DeckWorkspace, it simply sends back or brings to front. Instead of sending back in th deck, if you want to hide really. You can get the smartPart object using the string which you have used while adding the new instance. And do type cast to Control object and set visible to true/false

/// <summary>
/// Hides the smart part.
/// </summary>
protected virtual void OnHide(Control smartPart)
{
smartPart.SendToBack();

ActivateTopmost();
}
Apr 7, 2007 at 1:54 AM
Thanks for your response, I actualy use your method and use Worksspace.Show and use these code to see if my smartpart is allready create :

_MyDispatchView = _MyDispatchView ?? Items.AddNew<DispatchView>();
mainWorkspace.Show(_MyDispatchView, inf);

Thanks for your response.

Danisam