Print Page | Close Window

Process for creating new Base View?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=443
Printed Date: 06-May-2024 at 2:16am


Topic: Process for creating new Base View?
Posted By: orcities
Subject: Process for creating new Base View?
Date Posted: 20-Sep-2007 at 11:01am
Is this correct?
Below is the process I used to create a new base view and add views/controls to that view.
 
Goal View: Has Three SmartPartPlaceholders on it.
TopPlaceHolder -> will hold grid view
MiddlePlaceHolder -> will hold action buttons
BottomPlaceHolder -> will hold current values
 
1. Create View Class and add to <Business>.<App>.Foundation.Views
   ThreePaneView.cs
2. Add SmartPartPlaceholders
3. In View Constructor add method call: SetSmartPartPlaceHolderNames();
4. Build SetSmartPartPlaceHolderNames(); method:
private void SetSmartPartPlaceHolderNames() {
// Critical! Must set SmartPartPlaceHolder name immediately or mysterious exception during create.
mAvailableSmartPartPlaceholder.SmartPartName = WorkspaceNames.AvailableSmartPartPlaceholder;
mActionSmartPartPlaceHolder.SmartPartName =
WorkspaceNames.ActionSmartPartPlaceholder;
mAvailableSmartPartPlaceholder.SmartPartName = WorkspaceNames.AssignedSmartPartPlaceholder;
}
5. Add reference to Placeholders in  <Business>.<App>.Interface.Constants.Workspaces
6.
public const string AvailableSmartPartPlaceholder = "AvailableSmartPartPlaceholder";
public const string AssignedSmartPartPlaceholder = "AssignedSmartPartPlaceholder";
public const string ActionSmartPartPlaceholder = "ActionSmartPartPlaceholder";
7. Create Grid View to place in "AssignedSmartPartPlaceholder";
8. Create UserRolesGridView displays Roles that are assigned to User in the UserRoles Entity.
9. Create TabController - ManageUserRolesTabControl
10. Add/Modify CreateView() method to get data and show control
public override void CreateView(){
mBindingSource =new EntityBindingSource(typeof(Role), EntityManager, mEmptyList, String.Empty);
ViewId = "UserRolesGridView";
//Choose DetailRoleGrid
IGridBuilderService pGridBuilderService = this.WorkItem.Services.Get<IGridBuilderService>();
GridBuilderBase pGridBulderProtoType = pGridBuilderService.Get("DetailRole"); 

GridViewContext detailRoles = GridViewContext.AddNew(WorkItem, ViewId, mBindingSource);

detailRoles.GridBuilderPrototype = pGridBulderProtoType;
//CreateView<UserRolesGridView>(); //Just adds the grid to page

UserRolesGridView mAssignedView = WorkItem.SmartParts.AddNew<UserRolesGridView>();

AssignedWorkspace.Show(mAssignedView);
}
11. Get the ThreePanelView Control's SmartPart Placeholder
private IWorkspace ActionWorkspace{
get{ return WorkItem.Workspaces[WorkspaceNames.ActionSmartPartPlaceholder];
}

}

 

I either run into a problem with binding.

The item type of the BindingSource that you selected [LOC.CEMS.Model.User] does not match  the BoundType of this BindingManager [LOC.CEMS.Model.Role].
 
Or if I try to add a control with user type just to see if it works I get:
Value cannot be null.
Parameter name: id
 
In the GridViewPresenterBase class. Funny thing is I am not trying to bind any grid.
Altered CreateView() as such. ActionButtonView just has 2 buttons on it. And to get it to run to this point I changed the boundtype to be User.

public override void CreateView(){

ActionButtonsView mActionButtonView = WorkItem.SmartParts.AddNew<ActionButtonsView>();

ActionWorkspace.Show(mActionButtonView);
}



Replies:
Posted By: Bill Jensen
Date Posted: 20-Sep-2007 at 1:18pm

You're definitely on the right track.  I'm actually working on your problem myself as well.

The tab controller for your ThreePanel view composes and manages the display of sub views (the easy part), but also must handle synchronization of the data sources for the sub views (the tricky part).  This requires a clear understanding of the sub views' binding sources and their relation to the main binding source of the layout view.
I need to understand the entity relationships involved.
 
1.  The ThreePanel view will be displayed in a tab in the detail portion of a Summary/Detail or Search/Summary/Detail page whose root entity is "User".  Correct.
 
2.  What entity type will be displayed in each of the three sub views (Available, Assigned, and Action)?   Role?
 
3.  What is the relationship between the entities displayed in each sub view?  A child relation of User?
 
4.  You want the subviews to stay "in sync" with each other and with the main summary view as you navigate between users, right?
 
What is the application functionality you're trying to achieve?  Are you trying to manage the roles assigned to users (a many-to-many relationship) by displaying two lists and using buttons to move items from the available to the assigned list?
 
Bill J.


Posted By: orcities
Date Posted: 20-Sep-2007 at 1:22pm
Available: will be all roles in the database (Role Grid)
Action: Buttons to add and delete user roles
Assigned: all the users currently assigned roles (Role Grid) of UserRole
 
Users - UserId ...
UserRole - UserId, RoleId
Role - RoleId ...
 
I do wish for them to be in sync.
 
That is exactly what I am trying to do.
 


Posted By: Bill Jensen
Date Posted: 20-Sep-2007 at 8:13pm
Hi Dan and Bill (and anyone else reading this thread),
 
In order to offer better guidance, I needed to get some experience with what you're trying to do myself.  My earlier advice to start with the MasterDetail view and tab view controller was a bit bogus...it's much easier to start with a simple view and work up.
 
After a conversation with Ward, I constructed a three-panel layout like the one you're trying to create and made a specialized version populated with grids and a button control.
 
The results are available at:
 
http://www.IdeaBlade.com/Friends/LayoutDemo.zip - www.IdeaBlade.com/Friends/LayoutDemo.zip
 
Note:  Ward has promised to put it up in the Friends area tonight.  If it's not there by tomorrow morning, ask.
 
It's a standard wizard-generated Cabana project that should build and run.  (You may need to adjust the connection string in IdeaBlade.ibconfig.)  If you run it, be sure to navigate through the various users--only some of them have UserSecurityCodes configured.  Also, my grid builders are very primitive--displaying the Name property only.
 
My earlier advice to start with the MasterDetail view and tab view controller was a bit bogus...it's much easier to start with a simple view and work up.
 
You're on exactly the right track in creating the ThreePanel view and adding names to WorkspaceNames and ViewNames. 
 
As you can see, the only logic in my ThreePanelView layout view is to get the sub view ids from the context (which it gets from the presenter)  and assign them to the SmartPartPlaceHolders.  (These are unique ids for the instances of the grid and action views.)
 
The ThreePanelView presenter has no special purpose logic at all.
 
The only complexity is in the ThreePanelViewTabViewController.  I simply inherit from the base TabViewController and override a few methods.
 
It creates a context for the layout view, but delegates its configuration to the child class in ConfigureThreePanelViewContextCore().  There are also three properties that supply unique ids for the child views.
 
My child class is UserRolesTabViewController, added to the page's TabViewControllers collection at the usual place in the PageController.  It simply creates a context for each sub view and adds it to the workitem, then uses the ViewFactoryService to add the view to the workitem.   (I added registration of the views with the ViewFactoryService to the ModuleController.)
 
I provided some very basic data sources for the two grids.
 
The ActionView is just a placeholder with two buttons.  I could field the click events in the view, invoke methods on the presenter, and either do the updates there or invoke methods on the ActionViewContext (or some object passed in the context) to update the entities.
 
This process clarified for me the process of creating a layout view and adding child views to it.  It's all done by adding contexts and views to the workitem, then supplying the unique view ids to the SmartPartPlaceholders.
 
Let me know if this helps get you back on the air.
 
Bill J.
 
 
 
 


Posted By: orcities
Date Posted: 21-Sep-2007 at 7:10am
Bill, I really appreciate it. The modules provided with the Cabana project were very simply and it was hard to see how to extend to a new view.
 
I am looking through the code now. I might have some questions later but right now I am ok.
 
 
I really appreciate all your help on this.


Posted By: orcities
Date Posted: 21-Sep-2007 at 9:31am
Excellent example. Thanks.
The only question I have now is:
 
How do I know what is selected by the Roles Grid in the ActionView?
 
I have tried to look at other examples, like the SimpleSearch Widget, but can't find an example that works.
 
You mentioned passing an object through the Context. I assume you can do that with the parameters value of the ViewFactory.Add method.
 
But how do you get the value back out?


Posted By: orcities
Date Posted: 21-Sep-2007 at 1:44pm
I believe, but I am not sure, that I get the context of the grid ok. But I can not reference any of the grids properties. LIke the selected rows.


Posted By: Bill Jensen
Date Posted: 21-Sep-2007 at 2:08pm
Try this (terminology is from my LayoutDemo app):
 
Add fields to the ActionViewContext for the RoleBindingSource and UserRoleBindingSource.  Set these in the UserRolesTabViewController (be sure both binding sources are created before creating the ActionViewContext).
 
Then you'll have access to them in the ActionViewPresenter (from the Context property).  [You can override OnContextSet() so you know when the context is available].
 
EntityBindingSources expose a Current property that is the current selected item.  They also expose a CurrentItemChanged event.  With these and the events from the Add and Remove buttons in the view, the ActionViewPresenter should be able to implement the functionality you need.
 
Bill J.


Posted By: orcities
Date Posted: 24-Sep-2007 at 8:03am
Updates in Red
I appreciate your help. That worked.
 
But I am still having one issue. When I go to add. It does not add the UserRole to the grid. UserRole.Create(MainPm.Manager, User, Role))
 
Update: I understand this adds it to the cache. Since it didn't show I tried to add it to the BindingSource as well and I get the following error: Collection was of fixed size.
 
When I go to delete it the action seems to work, but the grid is not updated. ((UserRole)UserRoleBindingSource.Current).Delete();
 
Then when I save after deleting it tells me I can't "You are not allowed to delete LOC.CEMS.Model.UserRole.
 
When I try and save after an add it says there is nothing to save.
But when I hit add a second time on the same role it gives me a foreign key conflict error.
 
It doesn't seem to hit the Refresh for the TabController after an action has take place.
 
 


Posted By: orcities
Date Posted: 24-Sep-2007 at 9:12am
**Please read edits to previous post


Posted By: Bill Jensen
Date Posted: 24-Sep-2007 at 3:35pm
First:
 
In my LayoutDemo application, I populated the UserRolesBindingManager with:

IList list = pParent.GetChildren<UserSecurityCode>(EntityRelations.User_UserSecurityCode, pStrategy);

You'll note that GetChildren() returns an array of UserSecurityCode objects--a fixed length list.  Instead, we need to perform a query:

EntityQuery query = new EntityQuery(typeof(UserSecurityCode), UserSecurityCode.UserIdEntityColumn, EntityQueryOp.EQ, user.Id);

list = EntityManager.PersistenceManager.GetEntities<UserSecurityCode>(query, pStrategy);

to get a managed EntityList.
 
Second:
 
In the Add() method of the ActionViewPresenter, I tried to add the selected Role directly to the UserRole BindingList.  That won't work, since they're of different entity types.  We need to create a new UserRole ("UserSecurityCode" in the LayoutDemo model) entity using its Create() method and add THAT to the binding source:
 

UserSecurityCode newItem = UserSecurityCode.Create(currentUser, selectedRole);

mUserRolesBindingSource.Add(newItem);

The "selectedRole" is just the current item in the RolesBindingManager.
 
The current user is the current item in the parent binding manager but  unfortunately, the parent binding manager isn't available in the ActionViewPresenter.  You could either pass it in via the ActionViewContext, or move the Add and Remove logic out to the UserRolesTabViewController and pass a reference to IT in the ActionViewContext.
 
In Remove() we need to actually remove the UserSecurityCode entity from the PM:

UserSecurityCode selectedUserRole = mUserRolesBindingSource.Current as UserSecurityCode;

if (selectedUserRole != null)

{

selectedUserRole.Delete();

}

That updates the UserRolesBindingSource and the grid automatically.
 
In my version I can save additions of user roles OK, but I also get the "Validation Issue" message when I try to save a deletion.  I'll investigate that further.
 
Hope this helps.
 
Bill J.


Posted By: orcities
Date Posted: 24-Sep-2007 at 5:02pm
When doing the UserSecurityCode.Create() why don't you have to pass then Persistence Manager?


Posted By: orcities
Date Posted: 25-Sep-2007 at 7:27am
ActionViewPresenter methods are all static correct?


Posted By: orcities
Date Posted: 25-Sep-2007 at 7:28am
I meant ActionViewContext


Posted By: orcities
Date Posted: 25-Sep-2007 at 8:27am

I can now move from one grid to the other. But when I save an added UserRole it says nothing to save, as it did before. Then as you know the delete gives an error.

Why would it be saying  nothing to save?



Posted By: orcities
Date Posted: 25-Sep-2007 at 8:45am
My code: And it says nothing to save:
      
        /// <summary>
        /// Add a new Role to the Parent User
        /// </summary>
        public void AddRole()
        {
            Role mSelectedRole = (Role)ActionViewContext.RolesBindingSource.Current;
            User mUser = (User)ActionViewContext.ParentBindingSource.Current;
 
            UserRole newUserRole = UserRole.Create(MainPm.Manager, mUser, mSelectedRole);
            ActionViewContext.UserRolesBindingSource.Add(newUserRole);
        }
 
        /// <summary>
        /// Delete the currently selected UserRole
        /// </summary>
        public void DeleteRole()
        {
            UserRole selectedUserRole = ActionViewContext.UserRolesBindingSource.Current as UserRole;
 
            if (selectedUserRole != null)
                selectedUserRole.Delete();
        }


Posted By: Linguinut
Date Posted: 25-Sep-2007 at 9:41am
I don't think there is only one persistence manager involved.  I vaguely remember Ward saying something in training one time about a pm per view, or something like that.  Is it possible that you are calling the save on a pm that does not have the changes that you made?  Just a thought...you probably already checked that, though.


Posted By: orcities
Date Posted: 25-Sep-2007 at 9:47am
The problem is that I am not controlling the save button. It is in the PageView control.
 
 


Posted By: Linguinut
Date Posted: 25-Sep-2007 at 9:52am

You may have to implement your own save/delete routines for the triple-pane layout that you created.  I suppose you could somehow wiggle into the context of the parent layout, but that'll take some work, too.  Hopefully, the big guns will weigh in on this again someday.



Posted By: Bill Jensen
Date Posted: 25-Sep-2007 at 10:37am
I think Bill C. is right; it's a problem with the wrong persistence manager.
 
In my update to the LayoutDemo app posted earlier in this thread, the UserSecurityCode entity has a static Create() method that doesn't accept a persistence manager:

UserSecurityCode newItem = UserSecurityCode.Create(currentUser, selectedRole);

Inside this create method is the line:

UserSecurityCode assoc =

pUser.PersistenceManager.CreateEntity<UserSecurityCode>();

As you can see, it uses the persistence manager it retrieves from the User entity.  I suggest you try this.
 
Within pages whose page controller inherit from PageController<entitytype>, the persistence manager is wrapped in an EntityManager that assists in maintaining synchrony between multiple views without round trips to the persistence server.  Again in my earlier post on this thread, I retrieve the initial UserSecurityCodes with:

RdbQuery query = new RdbQuery(typeof(UserSecurityCode), UserSecurityCode.UserIdEntityColumn, EntityQueryOp.EQ, user.Id);

list = EntityManager.PersistenceManager.GetEntities<UserSecurityCode>(query, pStrategy);

It is on this persistence manager that SaveChanges() will be called when Save is selected.
 
Hope this helps.
 
Bill J.


Posted By: orcities
Date Posted: 25-Sep-2007 at 10:44am
tx. That worked. A
 
 
Any idea about the delete?


Posted By: Bill Jensen
Date Posted: 25-Sep-2007 at 5:14pm
Yeah.
 
It turns out that in CommonEntity (in IdeaBlade.Common.EntityModel) there are three methods:
 
AllowCreate()
AllowUpdate()
AllowDelete()
 
By default the first two return true and the third returns false.  You can override these in your entity classes (or in BaseEntity) to control what is allowed and disallowed.  In them you could place whatever logic you want to determine if the operation should proceed.  Your presenter or controller logic can also invoke them before carrying out an operation.
 
If you simply override AllowDelete() in your UserRole entity and return true you'll be able to delete.
 
Sorry not to have this sooner.
 
Bill J.


Posted By: orcities
Date Posted: 25-Sep-2007 at 5:23pm
tx. I am out until next Monday. But I will give it a shot then.
 



Print Page | Close Window