]> 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
Changed architecture to enable TabViewPane and sharing actions in the toolbar, depend...
[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 return iView;
53 },
54
55 /**
56 * Registers a new viewPane
57 * @param viewPane {org.argeo.ria.components.ViewPane} The new ViewPane instance
58 */
59 registerViewPane : function(viewPane){
60 this.views[viewPane.getViewId()] = viewPane;
61 viewPane.addListener("changeSelection", function(e){
62 var viewSelection = e.getTarget().getViewSelection();
63 if(!viewSelection) return;
64 org.argeo.ria.event.CommandsManager.getInstance().refreshCommands(viewSelection);
65 });
66 viewPane.addListener("changeFocus", function(e){
67 for(var key in this.views){
68 this.views[key].blur();
69 }
70 viewPane.focus();
71 this.setCurrentFocus(viewPane);
72 }, this);
73 },
74 /**
75 * Returns a viewPane by its unique id.
76 * @param viewPaneId {String} The unique id
77 * @return {org.argeo.ria.components.ViewPane}
78 */
79 getViewPaneById : function(viewPaneId){
80 if(this.views[viewPaneId]) return this.views[viewPaneId];
81 throw new Error("Cannot find view '"+viewPaneId+"'");
82 },
83 /**
84 * Returns a viewPane current viewSelection object
85 * @param viewPaneId {String} The unique id.
86 * @return {org.argeo.ria.components.ViewSelection}
87 */
88 getViewPaneSelection : function(viewPaneId){
89 return this.getViewPaneById(viewPaneId).getViewSelection();
90 },
91 /**
92 * Changes a viewPane title dynamically.
93 * @param viewPaneId {String} ViewPane unique Id.
94 * @param viewTitle {String} the new title for this viewPane.
95 */
96 setViewPaneTitle : function(viewPaneId, viewTitle){
97 this.getViewPaneById(viewPaneId).setViewTitle(viewTitle);
98 }
99 }
100 });