]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/components/ViewsManager.js
Cosmetics (set label Rich)
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / argeo-ria-src / class / org / argeo / ria / components / ViewsManager.js
1 /**
2 * The main "view" manager (in a standard MVC conception) of the application.
3 * It register various containers org.argeo.ria.components.viewPane and feed them with org.argeo.ria.components.IView implementations.
4 * It is a singleton and can thus be called by any part of the application.
5 *
6 * @author Charles du Jeu
7 */
8 qx.Class.define("org.argeo.ria.components.ViewsManager",
9 {
10 type : "singleton",
11 extend : qx.core.Object,
12
13 properties : {
14 /**
15 * The application root (like Application.getRoot()), used to attach and show modal windows.
16 */
17 applicationRoot : {init : null},
18 /**
19 * The main container for the org.argeo.ria.components.ViewPane instances.
20 */
21 viewPanesContainer : {init: null},
22 currentFocus : {init :null}
23 },
24 construct : function(){
25 this.views = {};
26 },
27 members : {
28 /**
29 * Initialize and load a given IView implementation into a viewPane.
30 * The IView itself is returned.
31 *
32 * @param classObj {Clazz} The class object to instantiate
33 * @param viewPaneId {String} The unique ID of the view pane
34 * @return {org.argeo.ria.components.IView}
35 */
36 initIViewClass: function(classObj, viewPaneId, data){
37 var viewPane = this.getViewPaneById(viewPaneId);
38 var iView = new classObj;
39 iView.init(viewPane, data);
40 var existingView = viewPane.contentExists(iView.getInstanceId());
41 if(existingView){
42 delete iView;
43 return existingView;
44 }
45 var commands = iView.getCommands();
46 //viewPane.empty();
47 if(commands){
48 viewPane.setCommands(commands);
49 org.argeo.ria.event.CommandsManager.getInstance().addCommands(commands, "view:"+viewPaneId, viewPaneId);
50 }
51 viewPane.setContent(iView);
52 this.setViewPaneFocus(viewPane);
53 return iView;
54 },
55
56 /**
57 * Registers a new viewPane
58 * @param viewPane {org.argeo.ria.components.ViewPane} The new ViewPane instance
59 */
60 registerViewPane : function(viewPane){
61 this.views[viewPane.getViewId()] = viewPane;
62 viewPane.addListener("changeSelection", function(e){
63 var viewSelection = e.getTarget().getViewSelection();
64 if(!viewSelection) return;
65 org.argeo.ria.event.CommandsManager.getInstance().refreshCommands(viewSelection);
66 });
67 viewPane.addListener("changeFocus", function(e){
68 this.setViewPaneFocus(e.getTarget());
69 }, this);
70 },
71 setViewPaneFocus : function(viewPane){
72 for(var key in this.views){
73 this.views[key].blur();
74 }
75 this.setCurrentFocus(viewPane);
76 viewPane.focus();
77 },
78 /**
79 * Returns a viewPane by its unique id.
80 * @param viewPaneId {String} The unique id
81 * @return {org.argeo.ria.components.ViewPane}
82 */
83 getViewPaneById : function(viewPaneId){
84 if(this.views[viewPaneId]) return this.views[viewPaneId];
85 throw new Error("Cannot find view '"+viewPaneId+"'");
86 },
87 /**
88 * Returns a viewPane current viewSelection object
89 * @param viewPaneId {String} The unique id.
90 * @return {org.argeo.ria.components.ViewSelection}
91 */
92 getViewPaneSelection : function(viewPaneId){
93 return this.getViewPaneById(viewPaneId).getViewSelection();
94 },
95 /**
96 * Changes a viewPane title dynamically.
97 * @param viewPaneId {String} ViewPane unique Id.
98 * @param viewTitle {String} the new title for this viewPane.
99 */
100 setViewPaneTitle : function(viewPaneId, viewTitle){
101 this.getViewPaneById(viewPaneId).setViewTitle(viewTitle);
102 }
103 }
104 });