/** * @author Charles * */ qx.Class.define("org.argeo.slc.web.event.CommandsManager", { extend : qx.core.Object, construct : function(application){ this.base(arguments); this.application = application; }, properties : { definitions : { init : { "loadtestlist" : { label : "Load Tests", icon : "resource/slc/view-refresh.png", shortcut : "Control+l", enabled : true, menu : "File", toolbar : "list", callback : function(e){ this.loadTable("/com.capco.sparta.web/resultList.sparta"); }, command : null }, "quit" : { label : "Quit", icon : "resource/slc/system-shutdown.png", shortcut : "Control+q", enabled : true, menu : "File", toolbar : false, callback : function(e){}, command : null }, "opentest" : { label : "Open", icon : "resource/slc/document-open.png", shortcut : "Control+o", enabled : false, menu : "Test", toolbar : "test", callback : function(e){ var xmlNodes = this.getSelectionForView("list").getNodes(); this.createTestApplet(xmlNodes[0]); }, selectionChange : function(viewId, xmlNodes){ if(viewId != "list") return; this.setEnabled(false); if(xmlNodes == null) return; var applet = qx.xml.Element.selectSingleNode(xmlNodes[0],'report[@type="applet"]'); if(applet != null && qx.dom.Node.getText(applet) != ""){ this.setEnabled(true); } }, command : null }, "download" : { label : "Download as...", icon : "resource/slc/go-down.png", shortcut : null, enabled : false, menu : "Test", toolbar : "test", callback : function(e){ }, command : null, submenu : {}, submenuCallback : function(commandId){ qx.log.Logger.info(commandId); }, selectionChange : function(viewId, xmlNodes){ if(viewId!="list")return; this.clearMenus(); this.setEnabled(false); if(xmlNodes == null) return; var reports = qx.xml.Element.selectNodes(xmlNodes[0],'report[@type="download"]'); if(reports == null || !reports.length)return; reports.map(function(report){ this.addSubMenuButton( qx.dom.Node.getText(report), qx.dom.Node.getText(qx.xml.Element.selectSingleNode(report, "@icon")), qx.dom.Node.getText(qx.xml.Element.selectSingleNode(report, "@commandid")) ); }, this); this.setEnabled(true); this.fireDataEvent("changeMenu", this.getMenu()); } }, "deletetest" : { label : "Delete", icon : "resource/slc/edit-delete.png", shortcut : "Control+d", enabled : false, menu : "Test", toolbar : "test", callback : function(e){ // Call service to delete }, command : null }, "copytocollection" : { label : "Copy to...", icon : "resource/slc/edit-copy.png", shortcut : "Control+c", enabled : false, menu : "Test", toolbar : "test", callback : function(e){ // Call service to copy }, command : null }, "log" : { label : "Toggle Console", icon : "resource/slc/help-contents.png", shortcut : "", enabled : true, menu : "Help", toolbar : false, callback : function(e){ qx.log.appender.Console.toggle(); }, command : null }, "help" : { label : "About...", icon : "resource/slc/help-about.png", shortcut : "Control+h", enabled : true, menu : "Help", toolbar : false, callback : function(e){ var wm1 = new qx.ui.window.Window("About SLC"); wm1.set({ showMaximize : false, showMinimize : false, width: 200, height: 150 }); wm1.setLayout(new qx.ui.layout.Dock()); wm1.add(new qx.ui.basic.Label("SLC is a product from Argeo."), {edge:'center', width:'100%'}); var closeButton = new qx.ui.form.Button("Close"); closeButton.addListener("execute", function(e){ this.hide(); this.destroy(); }, wm1); wm1.add(closeButton, {edge:'south'}); wm1.setModal(true); wm1.center(); this.getRoot().add(wm1); wm1.show(); }, command : null } } } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { createCommands : function(){ this.menus = {}; this.toolbars = {}; var defs = this.getDefinitions(); for(var key in defs){ var definition = defs[key]; var command = new org.argeo.slc.web.event.Command(key, definition.label, definition.icon, definition.shortcut); if(definition.submenu){ var menu = new qx.ui.menu.Menu(); command.setMenu(menu); if(definition.submenuCallback){ command.setMenuCallback(definition.submenuCallback); } } command.setEnabled(definition.enabled); command.addListener("execute", definition.callback, this.application); definition.command = command; if(definition.menu){ if(!this.menus[definition.menu]) this.menus[definition.menu] = []; this.menus[definition.menu].push(command); } if(definition.toolbar){ if(!this.toolbars[definition.toolbar]) this.toolbars[definition.toolbar] = []; this.toolbars[definition.toolbar].push(command); } } this.setDefinitions(defs); }, refreshCommands : function(viewSelection){ var defs = this.getDefinitions(); var xmlNodes = null; if(viewSelection.getCount() > 0){ var xmlNodes = viewSelection.getNodes(); } for(var key in defs){ var definition = defs[key]; if(!definition.selectionChange) continue; var binded = qx.lang.Function.bind(definition.selectionChange, definition.command); binded(viewSelection.getViewId(), xmlNodes); } }, createMenuButtons : function(menuBar){ for(var key in this.menus){ var menu = new qx.ui.menu.Menu(); var button = new qx.ui.menubar.Button(key, null, menu); for(var i=0; i