Xaf-dashboardviewitem Management

Source: Internet
Author: User

I have previously written an article about Dynamically adding viewitem to the dashboard. As the project enters, more viewitems need to be operated on the dashboard, so a dashboard layout management class dashboardviewmanager is added, this class is mainly used to control the display of viewitem in a group.

For example, the structure of my dashboard is shown in:

Three Views are displayed on the page: statedetectionnavigation, timerange, and stateactioncontainer. The layout is organized into the root node main, and the main node has two layoutgroups: 1. the navigation group contains statedetectionnavigation; 2. the manigroup group contains two groups: Actions group and results group. The actions group contains timerange and stateactioncontainer. The results group is used to place dynamic results. By default, statedetectionnavigation is included.
The preview figure is as follows:

If a new result is generated, it must be displayed in the Results Group. You can perform the following steps:

1. Add a viewcontroller and set its targetviewid to the ID of our dashboardview. (For details, refer to the devexpress help document)

2. Add the following code to viewcontroller to display a listview to replace the view in the lower right corner.

Private dashboardviewmanager manager; Public myviewcontroller (): Base () {initializecomponent (); registeractions (components); Manager = new dashboardsolution. dashboardviewmanager ();} private void myviewcontroller_activated (Object sender, eventargs e) {// bind to this viewcontroller manager. bindtoviewcontroller (this); // open the listview In the dashboard and obtain its reference. If it does not exist, create it imodelviewitem viewitem = manager. openviewitem ("sensor_listview", true); // display the view to manager in the/main/manigroup/Results layout. showlayoutitems ("/main/manigroup/results", viewitem); // update the application model to display the manager. updatemodel ();}

Note: You must create a view in viewcontroller before calling the dashboardmanager. bindtoviewcontroller method. Otherwise, an exception is thrown.

The following code of dashboardviewmanager is provided for your reference and correction.

Using system; using system. collections. generic; using system. LINQ; using system. text; using devexpress. expressapp. model; using devexpress. expressapp. model. nodegenerators; using devexpress. expressapp; using devexpress. expressapp. layout; using system. componentmodel; namespace dashboardsolution {public class dashboardviewmanager {# region is bound to dashboardviewcontroller to obtain its view and application attribute private view dashboard; Private xafapplication application; Public void bindtoviewcontroller (viewcontroller) {If (! (Viewcontroller. View is dashboardview) {Throw new exception ("the view of the viewcontroller is not a dashboardview! ");} Dashboard = viewcontroller. view; application = viewcontroller. application ;}# endregion // use the default name Public String mainlayoutgroup {get {return modeldetailviewlayoutnodesgenerator for the main layout. mainlayoutgroupname ;}// update the model of the view. Each time you modify the model, the model must be updated to take effect. Public void updatemodel () {dashboard. loadmodel () ;}# region open the viewitem and obtain its reference/** if you create a dashboardviewitem and obtain its reference, only applicable to dashboardviewitem */Public imodelv Iewitem openviewitem (string viewid, bool createifnotexist) {imodelviewitem item = (imodelviewitem) (imodeldashboardview) dashboard. model ). items [viewid]); If (item = NULL & createifnotexist) {item = (imodeldashboardview) dashboard. model ). items. addnode <imodeldashboardviewitem> (); (imodeldashboardviewitem) item ). view = application. findmodelview (viewid); item. id = viewid;} return item;} # endregi On # region open layoutgroup; 1. if the parent node is known, open the child node group. use the node group path to open the node group. // if the parent node does not exist, open the main node (createifnotexist = true) Public imodellayoutgroup openlayoutgroup (string layoutgroupname, imodellayoutgroup parentgroup, bool createifnotexist) {If (parentgroup = NULL) {If (createifnotexist) Return (imodeldashboardview) dashboard. model ). layout. addnode <imodellayoutgroup> (modeldetailviewlayoutnodesgenerator. mainlayoutgroupna Me); else return NULL;} imodellayoutgroup group = (imodellayoutgroup) parentgroup. getnode (layoutgroupname); If (group = NULL) {If (createifnotexist) group = (imodellayoutgroup) parentgroup. addnode <imodellayoutgroup> (layoutgroupname); else return NULL;} return group;} public imodellayoutgroup openlayoutgroupbypath (string path, bool createifnotexist) {Path = path. trim (); If (path. startswith ("/")) Path = path. substring (1); If (path. endswith ("/") Path = path. substring (0, path. length-1); string [] token = path. split ('/'); If (token [0]! = Modeldetailviewlayoutnodesgenerator. mainlayoutgroupname) return NULL; imodellayoutgroup group = (imodeldashboardview) dashboard. Model). layout [token [0] As imodellayoutgroup; If (group = NULL &&! Createifnotexist) return NULL; else if (group = NULL & createifnotexist) group = (imodeldashboardview) dashboard. model ). layout. addnode <imodellayoutgroup> (token [0]); For (INT I = 1; I <token. length; I ++) {imodellayoutgroup g; string name = token [I]; G = (imodellayoutgroup) group. getnode (name); If (G = NULL) {If (! Createifnotexist) return NULL; else {G = (imodellayoutgroup) group. addnode <imodellayoutgroup> (name) ;}} group = g;} return group ;}# endregion/** sets the layout group subnode arrangement form: horizontal, vertical */Public void setlayoutgroupdirection (imodellayoutgroup group, bool ishorizontal) {group. direction = ishorizontal? Flowdirection. horizontal: flowdirection. vertical;} # region displays the public void showlayoutitems (imodellayoutgroup group, Params imodelviewitem [] viewitems) {group. clearnodes (); foreach (imodelviewitem item in viewitems) {imodellayoutitem layoutitem = group. addnode <imodellayoutitem> (item. ID); layoutitem. viewitem = item;} public void showlayoutitems (imodellayoutgroup group, Params string [] ID) {group. clearnodes (); foreach (string ID in ID) {imodellayoutitem layoutitem = group. addnode <imodellayoutitem> (ID); layoutitem. viewitem = (imodelviewitem) (imodeldashboardview) dashboard. model ). items [ID]) ;}} public void showlayoutitems (string grouppath, Params string [] ID) {imodellayoutgroup group = openlayoutgroupbypath (grouppath, true); showlayoutitems (group, ID );} public void showlayoutitems (string grouppath, Params imodelviewitem [] viewitems) {imodellayoutgroup group = groups (grouppath, true); showlayoutitems (group, viewitems);} # endregion }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.