]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/components/ViewsManager.js
Refactoring
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / source / 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 = eval("new "+iViewClass+"()");
37 //var classObj = qx.Class.getByName(iViewClass);
38 var iView = new classObj;
39 var viewPane = this.getViewPaneById(viewPaneId);
40 iView.init(viewPane);
41 var commands = iView.getCommands();
42 viewPane.empty();
43 if(commands){
44 viewPane.setCommands(commands);
45 org.argeo.ria.event.CommandsManager.getInstance().addCommands(commands, iView);
46 }
47 viewPane.setContent(iView);
48 return iView;
49 },
50
51 /**
52 * Registers a new viewPane
53 * @param viewPane {org.argeo.ria.components.ViewPane} The new ViewPane instance
54 */
55 registerViewPane : function(viewPane){
56 this.views[viewPane.getViewId()] = viewPane;
57 viewPane.getViewSelection().addListener("changeSelection", function(e){
58 org.argeo.ria.event.CommandsManager.getInstance().refreshCommands(e.getData());
59 });
60 },
61 /**
62 * Returns a viewPane by its unique id.
63 * @param viewPaneId {String} The unique id
64 * @return {org.argeo.ria.components.ViewPane}
65 */
66 getViewPaneById : function(viewPaneId){
67 if(this.views[viewPaneId]) return this.views[viewPaneId];
68 throw new Error("Cannot find view '"+viewPaneId+"'");
69 },
70 /**
71 * Returns a viewPane current viewSelection object
72 * @param viewPaneId {String} The unique id.
73 * @return {org.argeo.ria.components.ViewSelection}
74 */
75 getViewPaneSelection : function(viewPaneId){
76 return this.getViewPaneById(viewPaneId).getViewSelection();
77 },
78 /**
79 * Changes a viewPane title dynamically.
80 * @param viewPaneId {String} ViewPane unique Id.
81 * @param viewTitle {String} the new title for this viewPane.
82 */
83 setViewPaneTitle : function(viewPaneId, viewTitle){
84 this.getViewPaneById(viewPaneId).setViewTitle(viewTitle);
85 }
86 }
87 });