]>
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
1 /* ************************************************************************
7 Authors: Charles du Jeu
9 ************************************************************************ */
11 /* ************************************************************************
15 ************************************************************************ */
18 * This is the main application class of an Argeo RIA.
20 qx
.Class
.define("org.argeo.ria.Application",
22 extend
: qx
.application
.Standalone
,
33 activePerspectiveName
: {
40 commandsDefinitions
: {
44 icon
: "resource/slc/process-stop.png",
45 shortcut
: "Control+s",
49 callback : function(e
){},
52 "switchperspective" : {
53 label
: "Switch Perspective",
54 icon
: "resource/slc/view-pane-tree.png",
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
);
67 callback : function(e
){},
71 label
: "Show Console",
72 icon
: "resource/slc/help-contents.png",
78 callback : function(e
){
79 org
.argeo
.ria
.components
.Logger
.getInstance().toggle();
85 icon
: "resource/slc/help-about.png",
86 shortcut
: "Control+h",
90 callback : function(e
){
91 var win
= new org
.argeo
.ria
.components
.Modal("About SLC", null, "SLC is a product from Argeo.");
103 * This method contains the initial application code and gets called
104 * during startup of the application
109 this.base(arguments
);
110 this.self(arguments
).INSTANCE
= this;
113 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
114 viewsManager
.setApplicationRoot(this.getRoot());
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());
126 // Enable logging in debug variant
127 if (qx
.core
.Variant
.isSet("qx.debug", "on"))
129 qx
.log
.appender
.Native
;
130 qx
.log
.appender
.Console
;
132 var winLogger
= org
.argeo
.ria
.components
.Logger
.getInstance();
133 this.getRoot().add(winLogger
);
134 qx
.log
.Logger
.register(winLogger
);
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});
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
];
150 var perspectiveNumber
= qx
.lang
.Object
.getLength(allPerspectives
);
151 if(!perspectiveNumber
){
152 this.error("Cannot find a perspective for startup!");
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]);
164 startupSetting
= qx
.core
.Setting
.get("ria.StartupPerspective");
166 if(startupSetting
&& allPerspectives
[startupSetting
]){
167 this.setActivePerspectiveName(startupSetting
);
169 this.setActivePerspectiveName(qx
.lang
.Object
.getKeys(allPerspectives
)[0]);
171 this.rebuildPerspectiveMenus();
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
);
184 var stopCommand
= commandManager
.getCommandById("stop");
185 var serviceManager
= org
.argeo
.ria
.remote
.RequestManager
.getInstance();
186 serviceManager
.setStopCommand(stopCommand
);
188 container
.add(menuBar
);
189 container
.add(toolbar
);
191 this.loadPerspective();
194 loadPerspective : function(perspectiveName
){
196 this.setActivePerspectiveName(perspectiveName
);
197 this.rebuildPerspectiveMenus();
199 perspectiveName
= this.getActivePerspectiveName();
201 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
202 if(this.getActivePerspective()){
203 this.getActivePerspective().remove(viewsManager
);
205 var allPerspectives
= this.getPerspectives();
206 var perspectiveClass
= allPerspectives
[perspectiveName
];
207 if(!perspectiveClass
){
208 this.error("Cannot find class for startup perspective : "+perspectiveName
);
211 var perspective
= new perspectiveClass
;
212 perspective
.initViewPanes(viewsManager
);
213 perspective
.initViews(viewsManager
);
214 this.setActivePerspective(perspective
);
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),
226 "disabled" : (key
==this.getActivePerspectiveName()?true:false)
229 if(switchCommand
.command
){ // Command already created : force reload
230 switchCommand
.command
.clearMenus();
231 switchCommand
.command
.setMenu(switchCommand
.submenu
);
236 if(this.getActivePerspective()){
237 this.getActivePerspective().remove(org
.argeo
.ria
.components
.ViewsManager
.getInstance());
239 this.base(arguments
);