]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/Application.js
New services
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / argeo-ria-src / class / org / argeo / ria / Application.js
1 /* ************************************************************************
2
3 Copyright: 2008 Argeo
4
5 License: LGPL
6
7 Authors: Charles du Jeu
8
9 ************************************************************************ */
10
11 /* ************************************************************************
12
13 #asset(slc/*)
14
15 ************************************************************************ */
16
17 /**
18 * This is the main application class of an Argeo RIA.
19 */
20 qx.Class.define("org.argeo.ria.Application",
21 {
22 extend : qx.application.Standalone,
23
24 statics : {
25 INSTANCE : null
26 },
27
28 properties : {
29 perspectives : {
30 check : "Map",
31 init : {}
32 },
33 activePerspectiveName : {
34 check : "String",
35 init : ""
36 },
37 activePerspective : {
38 init : null
39 },
40 commandsDefinitions : {
41 init : {
42 "stop" : {
43 label : "Stop",
44 icon : "resource/slc/process-stop.png",
45 shortcut : "Control+s",
46 enabled : false,
47 menu : null,
48 toolbar : "list",
49 callback : function(e){},
50 command : null
51 },
52 "switchperspective" : {
53 label : "Switch Perspective",
54 icon : "resource/slc/view-pane-tree.png",
55 shortcut : "",
56 enabled : true,
57 menu : "View",
58 toolbar : false,
59 submenu : [],
60 submenuCallback : function(commandId){
61 // Defer execution to assure that the submenu is closed
62 // before it is rebuilt.
63 qx.event.Timer.once(function(){
64 org.argeo.ria.Application.INSTANCE.loadPerspective(commandId);
65 }, this, 10);
66 },
67 callback : function(e){},
68 command : null
69 },
70 "log" : {
71 label : "Show Console",
72 icon : "resource/slc/help-contents.png",
73 shortcut : "",
74 enabled : true,
75 menu : "View",
76 menuPosition: "last",
77 toolbar : false,
78 callback : function(e){
79 org.argeo.ria.components.Logger.getInstance().toggle();
80 },
81 command : null
82 },
83 "help" : {
84 label : "About...",
85 icon : "resource/slc/help-about.png",
86 shortcut : "Control+h",
87 enabled : true,
88 menu : "View",
89 toolbar : false,
90 callback : function(e){
91 var win = new org.argeo.ria.components.Modal("About SLC", null, "SLC is a product from Argeo.");
92 win.attachAndShow();
93 },
94 command : null
95 }
96 }
97 }
98 },
99
100 members :
101 {
102 /**
103 * This method contains the initial application code and gets called
104 * during startup of the application
105 */
106 main : function()
107 {
108 // Call super class
109 this.base(arguments);
110 this.self(arguments).INSTANCE = this;
111 this.views = {};
112
113 var viewsManager = org.argeo.ria.components.ViewsManager.getInstance();
114 viewsManager.setApplicationRoot(this.getRoot());
115
116 /*
117 var appli = this;
118 qx.bom.Event.addNativeListener(window, "unload", function(){
119 // TODO : Close perspective if one is open.
120 if(appli.getActivePerspective()){
121 alert(appli.getActivePerspective());
122 appli.getActivePerspective().remove(org.argeo.ria.components.ViewsManager.getInstance());
123 }
124 });
125 */
126 // Enable logging in debug variant
127 if (qx.core.Variant.isSet("qx.debug", "on"))
128 {
129 qx.log.appender.Native;
130 qx.log.appender.Console;
131 }
132 var winLogger = org.argeo.ria.components.Logger.getInstance();
133 this.getRoot().add(winLogger);
134 qx.log.Logger.register(winLogger);
135
136 // Main layout
137 var layout = new qx.ui.layout.VBox();
138 var container = new qx.ui.container.Composite(layout);
139 viewsManager.setViewPanesContainer(container);
140 // Document is the application root
141 this.getRoot().add(container, {left:0,right:0,top:0,bottom:0});
142
143 // Find available perspectives
144 var allPerspectives = {};
145 for(var key in qx.Bootstrap.$$registry){
146 if(qx.Class.hasInterface(qx.Bootstrap.$$registry[key], org.argeo.ria.components.IPerspective)){
147 allPerspectives[key] = qx.Bootstrap.$$registry[key];
148 }
149 }
150 var perspectiveNumber = qx.lang.Object.getLength(allPerspectives);
151 if(!perspectiveNumber){
152 this.error("Cannot find a perspective for startup!");
153 return;
154 }
155 this.setPerspectives(allPerspectives);
156 // Choose startup perspective, delete switch menu if only one perspective.
157 if(perspectiveNumber <= 1){
158 delete this.getCommandsDefinitions()["switchperspective"];
159 this.setActivePerspectiveName(qx.lang.Object.getKeys(allPerspectives)[0]);
160 }
161 else{
162 var startupSetting;
163 try{
164 startupSetting = qx.core.Setting.get("ria.StartupPerspective");
165 }catch(e){}
166 if(startupSetting && allPerspectives[startupSetting]){
167 this.setActivePerspectiveName(startupSetting);
168 }else{
169 this.setActivePerspectiveName(qx.lang.Object.getKeys(allPerspectives)[0]);
170 }
171 this.rebuildPerspectiveMenus();
172 }
173
174 var menuBar = new qx.ui.menubar.MenuBar();
175 var toolbar = new qx.ui.toolbar.ToolBar();
176 var commandManager = org.argeo.ria.event.CommandsManager.getInstance();
177 commandManager.init(this.getCommandsDefinitions());
178 commandManager.createCommands();
179 commandManager.registerMenuBar(menuBar);
180 commandManager.registerToolBar(toolbar);
181 toolbar.setShow("both");
182 commandManager.addToolbarContextMenu(toolbar);
183
184 var stopCommand = commandManager.getCommandById("stop");
185 var serviceManager = org.argeo.ria.remote.RequestManager.getInstance();
186 serviceManager.setStopCommand(stopCommand);
187
188 container.add(menuBar);
189 container.add(toolbar);
190
191 this.loadPerspective();
192 },
193
194 loadPerspective : function(perspectiveName){
195 if(perspectiveName){
196 this.setActivePerspectiveName(perspectiveName);
197 this.rebuildPerspectiveMenus();
198 }else{
199 perspectiveName = this.getActivePerspectiveName();
200 }
201 var viewsManager = org.argeo.ria.components.ViewsManager.getInstance();
202 if(this.getActivePerspective()){
203 this.getActivePerspective().remove(viewsManager);
204 }
205 var allPerspectives = this.getPerspectives();
206 var perspectiveClass = allPerspectives[perspectiveName];
207 if(!perspectiveClass){
208 this.error("Cannot find class for startup perspective : "+perspectiveName);
209 return;
210 }
211 var perspective = new perspectiveClass;
212 perspective.initViewPanes(viewsManager);
213 perspective.initViews(viewsManager);
214 this.setActivePerspective(perspective);
215 },
216
217 rebuildPerspectiveMenus : function(){
218 var switchCommand = this.getCommandsDefinitions()["switchperspective"];
219 switchCommand.submenu = [];
220 var allPerspectives = this.getPerspectives();
221 for(var key in allPerspectives){
222 switchCommand.submenu.push({
223 "label":(allPerspectives[key].LABEL || key)+(key==this.getActivePerspectiveName()?" (current)":""),
224 "icon" :(allPerspectives[key].ICON || null),
225 "commandId":key,
226 "disabled" : (key==this.getActivePerspectiveName()?true:false)
227 });
228 }
229 if(switchCommand.command){ // Command already created : force reload
230 switchCommand.command.clearMenus();
231 switchCommand.command.setMenu(switchCommand.submenu);
232 }
233 },
234
235 close : function(){
236 if(this.getActivePerspective()){
237 this.getActivePerspective().remove(org.argeo.ria.components.ViewsManager.getInstance());
238 }
239 this.base(arguments);
240
241 }
242
243 }
244 });