+++ /dev/null
-/* ************************************************************************\r
-\r
- Copyright: 2008 Argeo\r
-\r
- License: LGPL\r
-\r
- Authors: Charles du Jeu\r
-\r
-************************************************************************ */\r
-\r
-/* ************************************************************************\r
-\r
-#asset(slc/*)\r
-\r
-************************************************************************ */\r
-\r
-/**\r
- * This is the main application class of an Argeo RIA.\r
- */\r
-qx.Class.define("org.argeo.ria.Application",\r
-{\r
- extend : qx.application.Standalone,\r
- \r
- statics : {\r
- INSTANCE : null \r
- },\r
- \r
- properties : {\r
- /**\r
- * Available perspective detected in the current compilation.\r
- */\r
- perspectives : {\r
- check : "Map",\r
- init : {}\r
- },\r
- /**\r
- * Currently layouted perspective label\r
- */\r
- activePerspectiveName : {\r
- check : "String",\r
- init : ""\r
- },\r
- /**\r
- * Currently layouted perspective.\r
- */\r
- activePerspective : {\r
- init : null\r
- },\r
- /**\r
- * Basic command associated to the application, applicable to all perspectives.\r
- */\r
- commandsDefinitions : {\r
- init : {\r
- "stop" : {\r
- label : "Stop", \r
- icon : "resource/slc/process-stop.png",\r
- shortcut : "Control+s",\r
- enabled : false,\r
- menu : null,\r
- toolbar : "list",\r
- callback : function(e){},\r
- command : null\r
- },\r
- "switchperspective" : {\r
- label : "Switch Perspective", \r
- icon : "resource/slc/view-pane-tree.png",\r
- shortcut : "",\r
- enabled : true,\r
- menu : "View",\r
- toolbar : false,\r
- submenu : [],\r
- submenuCallback : function(commandId){\r
- // Defer execution to assure that the submenu is closed \r
- // before it is rebuilt.\r
- qx.event.Timer.once(function(){\r
- org.argeo.ria.Application.INSTANCE.loadPerspective(commandId);\r
- }, this, 10); \r
- },\r
- callback : function(e){},\r
- command : null \r
- }, \r
- "log" : {\r
- label : "Show Console", \r
- icon : "resource/slc/help-contents.png",\r
- shortcut : "",\r
- enabled : true,\r
- menu : "View",\r
- menuPosition: "last",\r
- toolbar : false,\r
- callback : function(e){ \r
- org.argeo.ria.components.Logger.getInstance().toggle();\r
- }, \r
- command : null\r
- },\r
- "help" : {\r
- label : "About...", \r
- icon : "resource/slc/help-about.png",\r
- shortcut : "Control+h",\r
- enabled : true,\r
- menu : "View",\r
- toolbar : false,\r
- callback : function(e){\r
- var win = new org.argeo.ria.components.Modal("About SLC", null, "SLC is a product from Argeo.");\r
- win.attachAndShow();\r
- }, \r
- command : null\r
- }\r
- }\r
- }\r
- },\r
-\r
- members :\r
- {\r
- /**\r
- * This method contains the initial application code and gets called \r
- * during startup of the application\r
- */\r
- main : function()\r
- {\r
- // Call super class\r
- this.base(arguments);\r
- this.self(arguments).INSTANCE = this;\r
- this.views = {};\r
- \r
- var viewsManager = org.argeo.ria.components.ViewsManager.getInstance();\r
- viewsManager.setApplicationRoot(this.getRoot());\r
- \r
- /*\r
- var appli = this;\r
- qx.bom.Event.addNativeListener(window, "unload", function(){\r
- // TODO : Close perspective if one is open. \r
- if(appli.getActivePerspective()){\r
- alert(appli.getActivePerspective());\r
- appli.getActivePerspective().remove(org.argeo.ria.components.ViewsManager.getInstance());\r
- } \r
- });\r
- */\r
- // Enable logging in debug variant\r
- if (qx.core.Variant.isSet("qx.debug", "on"))\r
- {\r
- qx.log.appender.Native;\r
- qx.log.appender.Console;\r
- }\r
- var winLogger = org.argeo.ria.components.Logger.getInstance();\r
- this.getRoot().add(winLogger);\r
- qx.log.Logger.register(winLogger);\r
-\r
- // Main layout\r
- var layout = new qx.ui.layout.VBox();\r
- var container = new qx.ui.container.Composite(layout);\r
- viewsManager.setViewPanesContainer(container);\r
- // Document is the application root \r
- this.getRoot().add(container, {left:0,right:0,top:0,bottom:0});\r
- \r
- // Find available perspectives\r
- var allPerspectives = {};\r
- for(var key in qx.Bootstrap.$$registry){\r
- if(qx.Class.hasInterface(qx.Bootstrap.$$registry[key], org.argeo.ria.components.IPerspective)){\r
- allPerspectives[key] = qx.Bootstrap.$$registry[key];\r
- }\r
- }\r
- var perspectiveNumber = qx.lang.Object.getLength(allPerspectives);\r
- if(!perspectiveNumber){\r
- this.error("Cannot find a perspective for startup!");\r
- return;\r
- }\r
- this.setPerspectives(allPerspectives);\r
- // Choose startup perspective, delete switch menu if only one perspective.\r
- if(perspectiveNumber <= 1){\r
- delete this.getCommandsDefinitions()["switchperspective"];\r
- this.setActivePerspectiveName(qx.lang.Object.getKeys(allPerspectives)[0]);\r
- }\r
- else{\r
- var startupSetting;\r
- try{\r
- startupSetting = qx.core.Setting.get("ria.StartupPerspective");\r
- }catch(e){}\r
- if(startupSetting && allPerspectives[startupSetting]){\r
- this.setActivePerspectiveName(startupSetting);\r
- }else{\r
- this.setActivePerspectiveName(qx.lang.Object.getKeys(allPerspectives)[0]);\r
- }\r
- this.rebuildPerspectiveMenus();\r
- }\r
- \r
- var menuBar = new qx.ui.menubar.MenuBar();\r
- var toolbar = new qx.ui.toolbar.ToolBar();\r
- var commandManager = org.argeo.ria.event.CommandsManager.getInstance();\r
- commandManager.init(this.getCommandsDefinitions());\r
- commandManager.createCommands();\r
- commandManager.registerMenuBar(menuBar);\r
- commandManager.registerToolBar(toolbar);\r
- toolbar.setShow("both");\r
- commandManager.addToolbarContextMenu(toolbar);\r
-\r
- var stopCommand = commandManager.getCommandById("stop");\r
- var serviceManager = org.argeo.ria.remote.RequestManager.getInstance();\r
- serviceManager.setStopCommand(stopCommand);\r
-\r
- container.add(menuBar);\r
- container.add(toolbar); \r
-\r
- this.loadPerspective();\r
- },\r
- \r
- /**\r
- * Load a given perspective by its name.\r
- * @param perspectiveName {String} Perspective to load\r
- */\r
- loadPerspective : function(perspectiveName){\r
- if(perspectiveName){\r
- this.setActivePerspectiveName(perspectiveName);\r
- this.rebuildPerspectiveMenus();\r
- }else{\r
- perspectiveName = this.getActivePerspectiveName();\r
- }\r
- var viewsManager = org.argeo.ria.components.ViewsManager.getInstance();\r
- if(this.getActivePerspective()){\r
- this.getActivePerspective().remove(viewsManager);\r
- }\r
- var allPerspectives = this.getPerspectives(); \r
- var perspectiveClass = allPerspectives[perspectiveName];\r
- if(!perspectiveClass){\r
- this.error("Cannot find class for startup perspective : "+perspectiveName);\r
- return;\r
- }\r
- var perspective = new perspectiveClass;\r
- perspective.initViewPanes(viewsManager);\r
- perspective.initViews(viewsManager);\r
- this.setActivePerspective(perspective);\r
- },\r
- \r
- /**\r
- * After switching perspective, call this function to rebuild menu with the right selected.\r
- */\r
- rebuildPerspectiveMenus : function(){\r
- var switchCommand = this.getCommandsDefinitions()["switchperspective"];\r
- switchCommand.submenu = [];\r
- var allPerspectives = this.getPerspectives();\r
- for(var key in allPerspectives){\r
- switchCommand.submenu.push({\r
- "label":(allPerspectives[key].LABEL || key)+(key==this.getActivePerspectiveName()?" (current)":""),\r
- "icon" :(allPerspectives[key].ICON || null),\r
- "commandId":key,\r
- "disabled" : (key==this.getActivePerspectiveName()?true:false)\r
- });\r
- }\r
- if(switchCommand.command){ // Command already created : force reload\r
- switchCommand.command.clearMenus();\r
- switchCommand.command.setMenu(switchCommand.submenu);\r
- }\r
- },\r
-\r
- /**\r
- * Specific action of calling an external URL without triggering the "close()" method\r
- * of Application.\r
- * @param hrefValue {String} A download url that should reply with specific "attachment" header to avoid leaving the application.\r
- */\r
- javascriptDownloadLocation: function(hrefValue){\r
- this.interruptClose = true;\r
- document.location.href = hrefValue;\r
- this.interruptClose = false;\r
- },\r
- \r
- /**\r
- * Called at Application ending (closing the browser).\r
- */\r
- close : function(){\r
- if(this.interruptClose) return ; \r
- if(this.getActivePerspective()){\r
- this.getActivePerspective().remove(org.argeo.ria.components.ViewsManager.getInstance());\r
- } \r
- this.base(arguments);\r
-\r
- }\r
- \r
- }\r
-});
\ No newline at end of file