]> 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
Much more safe way of attaching the callback contexts at runtime. Was already necessa...
[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 },
23 construct : function(){
24 this.views = {};
25 },
26 members : {
27 /**
28 * Initialize and load a given IView implementation into a viewPane.
29 * The IView itself is returned.
30 *
31 * @param classObj {Clazz} The class object to instantiate
32 * @param viewPaneId {String} The unique ID of the view pane
33 * @return {org.argeo.ria.components.IView}
34 */
35 initIViewClass: function(classObj, viewPaneId){
36 var iView = new classObj;
37 var viewPane = this.getViewPaneById(viewPaneId);
38 iView.init(viewPane);
39 var commands = iView.getCommands();
40 viewPane.empty();
41 if(commands){
42 viewPane.setCommands(commands);
43 org.argeo.ria.event.CommandsManager.getInstance().addCommands(commands, "view:"+viewPaneId);
44 }
45 viewPane.setContent(iView);
46 return iView;
47 },
48
49 /**
50 * Registers a new viewPane
51 * @param viewPane {org.argeo.ria.components.ViewPane} The new ViewPane instance
52 */
53 registerViewPane : function(viewPane){
54 this.views[viewPane.getViewId()] = viewPane;
55 viewPane.getViewSelection().addListener("changeSelection", function(e){
56 org.argeo.ria.event.CommandsManager.getInstance().refreshCommands(e.getData());
57 });
58 },
59 /**
60 * Returns a viewPane by its unique id.
61 * @param viewPaneId {String} The unique id
62 * @return {org.argeo.ria.components.ViewPane}
63 */
64 getViewPaneById : function(viewPaneId){
65 if(this.views[viewPaneId]) return this.views[viewPaneId];
66 throw new Error("Cannot find view '"+viewPaneId+"'");
67 },
68 /**
69 * Returns a viewPane current viewSelection object
70 * @param viewPaneId {String} The unique id.
71 * @return {org.argeo.ria.components.ViewSelection}
72 */
73 getViewPaneSelection : function(viewPaneId){
74 return this.getViewPaneById(viewPaneId).getViewSelection();
75 },
76 /**
77 * Changes a viewPane title dynamically.
78 * @param viewPaneId {String} ViewPane unique Id.
79 * @param viewTitle {String} the new title for this viewPane.
80 */
81 setViewPaneTitle : function(viewPaneId, viewTitle){
82 this.getViewPaneById(viewPaneId).setViewTitle(viewTitle);
83 }
84 }
85 });