]> git.argeo.org Git - gpl/argeo-slc.git/blob - server/org.argeo.slc.ria/src/argeo-ria-src/class/org/argeo/ria/components/ViewsManager.js
Get rid of all SLC reference in Argeo RIA / Split icons.
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / 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 * Keeps the currently focused viewPane.
24 */
25 currentFocus : {init :null}
26 },
27 construct : function(){
28 this.views = {};
29 },
30 members : {
31 /**
32 * Initialize and load a given IView implementation into a viewPane.
33 * The IView itself is returned.
34 *
35 * @param classObj {Clazz} The class object to instantiate
36 * @param viewPaneId {String} The unique ID of the view pane
37 * @param data {Mixed} Any data provided by the opener.
38 * @return {org.argeo.ria.components.IView}
39 */
40 initIViewClass: function(classObj, viewPaneId, data){
41 var viewPane = this.getViewPaneById(viewPaneId);
42 var iView = new classObj;
43 iView.init(viewPane, data);
44 var existingView = viewPane.contentExists(iView.getInstanceId());
45 if(existingView){
46 delete iView;
47 return existingView;
48 }
49 var commands = iView.getCommands();
50 //viewPane.empty();
51 if(commands){
52 viewPane.setCommands(commands);
53 org.argeo.ria.event.CommandsManager.getInstance().addCommands(commands, "view:"+viewPaneId, viewPaneId);
54 }
55 viewPane.setContent(iView);
56 this.setViewPaneFocus(viewPane);
57 return iView;
58 },
59
60 /**
61 * Registers a new viewPane
62 * @param viewPane {org.argeo.ria.components.ViewPane} The new ViewPane instance
63 */
64 registerViewPane : function(viewPane){
65 this.views[viewPane.getViewId()] = viewPane;
66 viewPane.addListener("changeSelection", function(e){
67 var viewSelection = e.getTarget().getViewSelection();
68 if(!viewSelection) return;
69 org.argeo.ria.event.CommandsManager.getInstance().refreshCommands(viewSelection);
70 });
71 viewPane.addListener("changeFocus", function(e){
72 this.setViewPaneFocus(e.getTarget());
73 }, this);
74 },
75 /**
76 * Sets a given viewPane as the currently focused one. Blur the others.
77 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane (or TabbedViewPane) to focus on.
78 */
79 setViewPaneFocus : function(viewPane){
80 for(var key in this.views){
81 this.views[key].blur();
82 }
83 this.setCurrentFocus(viewPane);
84 viewPane.focus();
85 },
86 /**
87 * Returns a viewPane by its unique id.
88 * @param viewPaneId {String} The unique id
89 * @return {org.argeo.ria.components.ViewPane}
90 */
91 getViewPaneById : function(viewPaneId){
92 if(this.views[viewPaneId]) return this.views[viewPaneId];
93 throw new Error("Cannot find view '"+viewPaneId+"'");
94 },
95 /**
96 * Returns a viewPane current viewSelection object
97 * @param viewPaneId {String} The unique id.
98 * @return {org.argeo.ria.components.ViewSelection}
99 */
100 getViewPaneSelection : function(viewPaneId){
101 return this.getViewPaneById(viewPaneId).getViewSelection();
102 },
103 /**
104 * Changes a viewPane title dynamically.
105 * @param viewPaneId {String} ViewPane unique Id.
106 * @param viewTitle {String} the new title for this viewPane.
107 */
108 setViewPaneTitle : function(viewPaneId, viewTitle){
109 this.getViewPaneById(viewPaneId).setViewTitle(viewTitle);
110 }
111 }
112 });