]>
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());
116 // Enable logging in debug variant
117 if (qx
.core
.Variant
.isSet("qx.debug", "on"))
119 qx
.log
.appender
.Native
;
120 qx
.log
.appender
.Console
;
122 var winLogger
= org
.argeo
.ria
.components
.Logger
.getInstance();
123 this.getRoot().add(winLogger
);
124 qx
.log
.Logger
.register(winLogger
);
127 var layout
= new qx
.ui
.layout
.VBox();
128 var container
= new qx
.ui
.container
.Composite(layout
);
129 viewsManager
.setViewPanesContainer(container
);
130 // Document is the application root
131 this.getRoot().add(container
, {left
:0,right
:0,top
:0,bottom
:0});
133 // Find available perspectives
134 var allPerspectives
= {};
135 for(var key
in qx
.Bootstrap
.$$registry
){
136 if(qx
.Class
.hasInterface(qx
.Bootstrap
.$$registry
[key
], org
.argeo
.ria
.components
.IPerspective
)){
137 allPerspectives
[key
] = qx
.Bootstrap
.$$registry
[key
];
140 var perspectiveNumber
= qx
.lang
.Object
.getLength(allPerspectives
);
141 if(!perspectiveNumber
){
142 this.error("Cannot find a perspective for startup!");
145 this.setPerspectives(allPerspectives
);
146 // Choose startup perspective, delete switch menu if only one perspective.
147 if(perspectiveNumber
<= 1){
148 delete this.getCommandsDefinitions()["switchperspective"];
149 this.setActivePerspectiveName(qx
.lang
.Object
.getKeys(allPerspectives
)[0]);
154 startupSetting
= qx
.core
.Setting
.get("ria.StartupPerspective");
156 if(startupSetting
&& allPerspectives
[startupSetting
]){
157 this.setActivePerspectiveName(startupSetting
);
159 this.setActivePerspectiveName(qx
.lang
.Object
.getKeys(allPerspectives
)[0]);
161 this.rebuildPerspectiveMenus();
164 var menuBar
= new qx
.ui
.menubar
.MenuBar();
165 var toolbar
= new qx
.ui
.toolbar
.ToolBar();
166 var commandManager
= org
.argeo
.ria
.event
.CommandsManager
.getInstance();
167 commandManager
.init(this.getCommandsDefinitions());
168 commandManager
.createCommands();
169 commandManager
.registerMenuBar(menuBar
);
170 commandManager
.registerToolBar(toolbar
);
171 toolbar
.setShow("both");
172 commandManager
.addToolbarContextMenu(toolbar
);
174 var stopCommand
= commandManager
.getCommandById("stop");
175 var serviceManager
= org
.argeo
.ria
.remote
.RequestManager
.getInstance();
176 serviceManager
.setStopCommand(stopCommand
);
178 container
.add(menuBar
);
179 container
.add(toolbar
);
181 this.loadPerspective();
184 loadPerspective : function(perspectiveName
){
186 this.setActivePerspectiveName(perspectiveName
);
187 this.rebuildPerspectiveMenus();
189 perspectiveName
= this.getActivePerspectiveName();
191 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
192 if(this.getActivePerspective()){
193 this.getActivePerspective().remove(viewsManager
);
195 var allPerspectives
= this.getPerspectives();
196 var perspectiveClass
= allPerspectives
[perspectiveName
];
197 if(!perspectiveClass
){
198 this.error("Cannot find class for startup perspective : "+perspectiveName
);
201 var perspective
= new perspectiveClass
;
202 perspective
.initViewPanes(viewsManager
);
203 perspective
.initViews(viewsManager
);
204 this.setActivePerspective(perspective
);
207 rebuildPerspectiveMenus : function(){
208 var switchCommand
= this.getCommandsDefinitions()["switchperspective"];
209 switchCommand
.submenu
= [];
210 var allPerspectives
= this.getPerspectives();
211 for(var key
in allPerspectives
){
212 switchCommand
.submenu
.push({
213 "label":(allPerspectives
[key
].LABEL
|| key
)+(key
==this.getActivePerspectiveName()?" (current)":""),
214 "icon" :(allPerspectives
[key
].ICON
|| null),
216 "disabled" : (key
==this.getActivePerspectiveName()?true:false)
219 if(switchCommand
.command
){ // Command already created : force reload
220 switchCommand
.command
.clearMenus();
221 switchCommand
.command
.setMenu(switchCommand
.submenu
);