How to access workitem

Topics: CAB & Smart Client Software Factory
Jun 23, 2006 at 7:30 AM
originally posted by: ksunair

I would like to access workitem inside a view (which is part of another view), how can I access it? or is it possible at all?
Jun 23, 2006 at 10:41 AM
originally posted by: ksunair

I found one way to do it based on

http://geekswithblogs.net/kobush/archive/2006/01/09/65305.aspx

It looks like the presenter can get the access to current workitem but not the view. Can someone explain why and how it gets WorkItem access??

Thanks.
Jun 23, 2006 at 11:33 AM
originally posted by: nermind

Well this is the way I understand it:

Presenter inherits from Controller which exposes WorkItem property.

If you declare a Presenter reference/property in following way (property within a view with CreateNew attribute):

CreateNew
public MyViewPresenter Presenter
{
get { return presenter; }
set {
presenter = value;
presenter.View = this;
}
}

then you are allowing object builder to construct your Presenter instance. object builder then initializes a reference to the WorkItem for you.

That also solves your problem of having to access the WorkItem from the view, since you can use Presenter.WorkItem within the view.

All we have to know is that: It is magic and it just works.


Hope that helps
Jun 23, 2006 at 12:54 PM
originally posted by: ksunair

Very good, the magic spell is CreateNew in the view.
Thanks.
Jun 23, 2006 at 6:45 PM
originally posted by: DapinderSingh

Not sure, but what if we use InjectionConstructor and in the constructor of the view, write the following Code :

class TestView
{
private WorkItem _workItem;

InjectionConstructor
public TestView(ServiceDependency WorkItem workitem)
{
this._workitem = workitem; //this will return the base workitem of the shell.
}
}
Please let me know if this is of any help
Jun 23, 2006 at 8:13 PM
originally posted by: matiaswoloski

It depends on the context where you are adding the item (item = {view, service, child workitem, event topic, component}
Suppose you have this hierarchy of workitems.

RootWorkItem
|- WorkItemA
| |- WorkItemA1
| |- WorkItemA2
|- WorkItemB

Let's use this code to inject the WorkItem on the item

ServiceDepenency
public WorkItem WorkItem {
...
}

If you add that code to the Shell form, you will get the RootWorkItem
If you add that code to a View (UserControl) that has been added to the WorkItemA, you will get the WorkItemA
If you add that code to a View (UserControl) that has been added to the WorkItemB, you will get the WorkItemB
and so on

So it does depends on the logical hierarchy of WorkItems, not the phisical location of the item and the worktem

To be more specific, you can have this code in WorkItemA1 Run method

public void Run() {
this.RootWorkItem.Items.AddNew<MyView>();
}

And because we are adding the view to the RootWorkItem, when the WorkItem is injected (using ServiceDependency) in the view, then you will be getting the RootWorkItem and not the WorkItemA1.

Make sense?

Matias
Smart Client Software Factory Team
http://staff.southworks.net/blogs/matiaswoloski
Jun 23, 2006 at 8:19 PM
originally posted by: DapinderSingh

Thanks a lot. It has also cleared a lot of my doubts. To the point answer.... i must say !!.
Jun 24, 2006 at 5:33 AM
originally posted by: ksunair

Matis, Thanks again for great answer.