]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-lib/slc/class/org/argeo/slc/ria/NewLauncherApplet.js
2 * A simple Hello World applet for documentation purpose.
3 * The only associated command is the "Close" command.
5 qx
.Class
.define("org.argeo.slc.ria.NewLauncherApplet",
7 extend
: qx
.ui
.container
.Composite
,
8 implement
: [org
.argeo
.ria
.components
.IView
],
10 construct : function(){
12 this.setLayout(new qx
.ui
.layout
.Dock());
18 * The viewPane inside which this applet is added.
25 check
:"org.argeo.ria.components.ViewSelection"
27 instanceId
: {init
:""},
28 instanceLabel
: {init
:""},
30 * A boolean registering whether the SpecEditor must autoOpen or not when a spec is added to the Batch.
37 * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
42 label
: "Execute Batch On...",
43 icon
: "resource/slc/media-playback-start.png",
48 callback : function(e
){},
50 submenuCallback : function(commandId
){
51 //alert("Execute Batch on Agent "+commandId);
52 this.executeBatchOnAgent(commandId
);
57 label
: "Add to batch",
58 icon
: "resource/slc/list-add.png",
63 callback : function(e
){
64 this._addFlowToBatch();
66 selectionChange : function(viewId
, selection
){
67 if(viewId
!= "form:tree") return;
68 if(!selection
|| selection
.length
!= 1) return;
69 var item
= selection
[0];
70 this.setEnabled(false);
71 if(qx
.Class
.isSubClassOf(qx
.Class
.getByName(item
.classname
), qx
.ui
.tree
.TreeFile
)){
72 this.setEnabled(true);
80 icon
: "resource/slc/document-open.png",
84 toggleInitialState
: true,
87 callback : function(event
){
88 var state
= event
.getTarget().getUserData("slc.command.toggleState");
89 this.setAutoOpen(state
);
93 "editexecutionspecs" : {
94 label
: "Edit Execution Specs",
95 icon
: "resource/slc/document-open.png",
100 callback : function(e
){
101 var sel
= this.list
.getSortedSelection();
103 var specEditor
= new org
.argeo
.slc
.ria
.execution
.SpecEditor(item
.getUserData("batchEntrySpec"));
104 specEditor
.attachAndShow();
106 selectionChange : function(viewId
, selection
){
107 if(viewId
!= "form:list") return;
108 this.setEnabled(false);
109 if((selection
&& selection
.length
== 1)) this.setEnabled(true);
113 "removefrombatch" : {
114 label
: "Remove from batch",
115 icon
: "resource/slc/edit-delete.png",
120 callback : function(e
){
121 var sel
= this.list
.getSortedSelection();
122 var modal
= new org
.argeo
.ria
.components
.Modal("Confirm", null);
123 modal
.addConfirm("Are you sure you want to remove<br> the selected test" + (sel
.length
>1?"s":"") + " from the Batch?");
124 modal
.addListener("ok", function(){
125 for(var i
=0;i
<sel
.length
;i
++){
126 this.list
.remove(sel
[i
]);
129 modal
.attachAndShow();
131 selectionChange : function(viewId
, selection
){
132 if(viewId
!= "form:list") return;
133 this.setEnabled(false);
134 if((selection
&& selection
.length
> 0)) this.setEnabled(true);
139 label
: "Reload Agents",
140 icon
: "resource/slc/view-refresh.png",
141 shortcut
: "Control+r",
144 toolbar
: "launcher",
145 callback : function(e
){
146 var req
= org
.argeo
.slc
.ria
.SlcApi
.getListAgentsService("agents");
153 icon
: "resource/slc/view-refresh.png",
154 shortcut
: "Control+m",
157 toolbar
: "launcher",
158 callback : function(e
){
159 var selected
= this.tree
.getSelectedItem();
160 if(selected
.classname
== "org.argeo.ria.components.DynamicTreeFolder"){
161 if(selected
.getUserData("moduleData")){
162 // It's a "module" node, first trigger the reloadBundle.service
163 selected
.setEnabled(false);
164 selected
.setOpen(false);
165 var moduleData
= selected
.getUserData("moduleData");
166 var bundleService
= org
.argeo
.slc
.ria
.SlcApi
.getReloadBundleService(moduleData
.name
, moduleData
.version
);
167 bundleService
.addListener("completed", function(response
){
168 selected
.setEnabled(true);
169 selected
.setOpen(true);
172 //bundleService.send();
173 //Do not send, not implemented yet, false timer instead.
174 qx
.event
.Timer
.once(function(response
){
175 selected
.setEnabled(true);
176 selected
.setOpen(true);
184 selectionChange : function(viewId
, selection
){
185 if(viewId
!= "form:tree") return;
186 if(!selection
|| selection
.length
!= 1) return;
187 var item
= selection
[0];
188 if(!qx
.Class
.isSubClassOf(qx
.Class
.getByName(item
.classname
), qx
.ui
.tree
.AbstractTreeItem
)) return;
189 this.setEnabled(false);
190 if(qx
.Class
.isSubClassOf(qx
.Class
.getByName(item
.classname
), org
.argeo
.ria
.components
.DynamicTreeFolder
)){
191 this.setEnabled(true);
199 * A map containing all currently registered agents.
204 event
: "changeRegisteredTopics"
210 * Loader for the "flow" level : takes a folder containing "moduleData" and create its children.
211 * @param folder {qx.ui.tree.TreeFolder} A Tree folder containing in the key "moduleData" of its user data a map containing the keys {name,version}
213 flowLoader : function(folder
){
214 var moduleData
= folder
.getUserData("moduleData");
215 //var req = org.argeo.ria.remote.RequestManager.getInstance().getRequest("../argeo-ria-src/stub.xml", "GET", "application/xml");
216 var req
= org
.argeo
.slc
.ria
.SlcApi
.getLoadExecutionDescriptorService(moduleData
.name
, moduleData
.version
);
217 req
.addListener("completed", function(response
){
218 var executionModule
= new org
.argeo
.slc
.ria
.execution
.Module();
219 executionModule
.setXmlNode(response
.getContent());
220 var execFlows
= executionModule
.getExecutionFlows();
221 for(var key
in execFlows
){
222 if(execFlows
[key
].getPath()){
223 // Build a more complex tree with the path
225 var file
= new qx
.ui
.tree
.TreeFile(key
);
226 file
.setUserData("executionModule", executionModule
);
227 file
.setUserData("executionFlow", execFlows
[key
]);
230 folder
.setLoaded(true);
236 * Loader for the "modules" level : takes any tree folder, currently the root folder.
237 * @param folder {qx.ui.tree.TreeFolder} The root folder
239 modulesLoader : function(folder
){
240 var req
= org
.argeo
.slc
.ria
.SlcApi
.getListModulesService();
241 req
.addListener("completed", function(response
){
242 var descriptors
= org
.argeo
.ria
.util
.Element
.selectNodes(response
.getContent(), "slc:object-list/slc:execution-module-descriptor");
244 for(var i
=0;i
<descriptors
.length
; i
++){
245 var name
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(descriptors
[i
], "slc:name");
246 var version
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(descriptors
[i
], "slc:version");
247 if(!mods
[name
]) mods
[name
] = [];
248 mods
[name
].push(version
);
250 var flowLoader
= org
.argeo
.slc
.ria
.NewLauncherApplet
.flowLoader
;
251 for(var key
in mods
){
252 for(var i
=0;i
<mods
[key
].length
;i
++){
253 var versionFolder
= new org
.argeo
.ria
.components
.DynamicTreeFolder(
254 key
+ ' ('+mods
[key
][i
]+')',
259 folder
.add(versionFolder
);
260 versionFolder
.setUserData("moduleData", {name
:key
, version
:mods
[key
][i
]});
262 folder
.setLoaded(true);
272 * Called at applet creation. Just registers viewPane.
273 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
275 init : function(viewPane
){
276 this.setView(viewPane
);
277 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
278 this._amqClient
= org
.argeo
.ria
.remote
.JmsClient
.getInstance();
279 this._amqClient
.uri
= "/org.argeo.slc.webapp/amq";
280 this._amqClient
.startPolling();
287 this._createLayout();
288 this.getView().setViewTitle("Execution Launcher");
289 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(reloadEvent
){
290 if(reloadEvent
.getDataType()!= "agents") return ;
291 var xmlDoc
= reloadEvent
.getContent();
292 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xmlDoc
, "//slc:slc-agent-descriptor");
294 for(var i
=0;i
<nodes
.length
;i
++){
295 var uuid
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(nodes
[i
], "@uuid");
296 var host
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(nodes
[i
], "slc:host");
297 newTopics
[uuid
] = host
+" ("+uuid
+")";
299 this.setRegisteredTopics(newTopics
);
301 this.addListener("changeRegisteredTopics", function(event
){
302 //this._refreshTopicsSubscriptions(event);
303 this._feedSelector(event
);
305 var reloadHandler = function(message
){
306 // Delay reload to be sure the jms was first integrated by the db, then ask the db.
307 qx
.event
.Timer
.once(function(){
308 org
.argeo
.ria
.event
.CommandsManager
.getInstance().getCommandById("reloadagents").execute();
311 this._amqClient
.addListener("agentregister", "topic://agent.register", reloadHandler
, this);
312 this._amqClient
.addListener("agentunregister", "topic://agent.unregister", reloadHandler
, this);
316 addScroll : function(){
321 this._amqClient
.removeListener("agentregister", "topic://agent.register");
322 this._amqClient
.removeListener("agentunregister", "topic://agent.unregister");
323 this._amqClient
.removeListener("modulesResponse", "topic://modulesManager.response");
324 this.setRegisteredTopics({});
325 this._amqClient
.stopPolling();
329 * Creates the main applet layout.
331 _createLayout : function(){
333 var splitPane
= new qx
.ui
.splitpane
.Pane("vertical");
334 splitPane
.setDecorator(null);
337 this.formPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.VBox(5));
338 this.scroll
= new qx
.ui
.container
.Scroll(this.formPane
);
339 this.formPane
.setPadding(10);
341 this.tree
= new qx
.ui
.tree
.Tree();
342 this.tree
.setDecorator(null);
350 var root
= new org
.argeo
.ria
.components
.DynamicTreeFolder(
352 this.self(arguments
).modulesLoader
,
356 this.tree
.setRoot(root
);
358 this.tree
.setContextMenu(org
.argeo
.ria
.event
.CommandsManager
.getInstance().createMenuFromIds(["addtobatch", "reloadtree"]));
360 this.tree
.addListener("changeSelection", function(e
){
361 var viewSelection
= this.getViewSelection();
362 viewSelection
.setViewId("form:tree");
363 viewSelection
.clear();
364 var sel
= this.tree
.getSortedSelection();
365 for(var i
=0;i
<sel
.length
;i
++){
366 viewSelection
.addNode(sel
[i
]);
370 this.listPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Dock());
371 var listToolBar
= new qx
.ui
.toolbar
.ToolBar();
372 var toolGroup
= new qx
.ui
.toolbar
.Part();
373 listToolBar
.add(toolGroup
);
375 var execButton
= this.getCommands()["submitform"].command
.getToolbarButton();
376 toolGroup
.add(execButton
);
378 listToolBar
.addSpacer();
379 listToolBar
.setPaddingRight(4);
380 var delButton
= this.getCommands()["removefrombatch"].command
.getToolbarButton();
381 var formButton
= this.getCommands()["editexecutionspecs"].command
.getToolbarButton();
382 delButton
.setShow("icon");
383 formButton
.setShow("icon");
384 listToolBar
.add(formButton
);
385 listToolBar
.add(delButton
);
387 this.listPane
.add(listToolBar
, {edge
:"north"});
389 var indicator
= new qx
.ui
.core
.Widget();
390 indicator
.setDecorator(new qx
.ui
.decoration
.Single().set({top
:[1,"solid","#33508D"]}));
391 indicator
.setHeight(0);
392 indicator
.setOpacity(0.5);
393 indicator
.setZIndex(100);
394 indicator
.setLayoutProperties({left
:-1000,top
:-1000});
395 org
.argeo
.ria
.Application
.INSTANCE
.getRoot().add(indicator
);
398 this.list
= new qx
.ui
.form
.List();
399 this.list
.setDecorator(null);
400 this.list
.setSelectionMode("multi");
401 this.list
.setDroppable(true);
402 this.list
.setDraggable(true);
403 this.list
.setContextMenu(org
.argeo
.ria
.event
.CommandsManager
.getInstance().createMenuFromIds(["editexecutionspecs", "removefrombatch"]));
406 this.list
.addListener("dragstart", function(e
){
407 e
.addType(["items"]);
408 e
.addAction(["move"]);
410 this.list
.addListener("dragend", function(e
){
411 indicator
.setDomPosition(-1000,-1000);
413 this.list
.addListener("dragover", function(e
){
414 var orig
= e
.getOriginalTarget();
415 var origCoords
= orig
.getContainerLocation();
416 indicator
.setWidth(orig
.getBounds().width
);
417 indicator
.setDomPosition(origCoords
.left
, origCoords
.bottom
);
419 this.list
.addListener("drag", function(e
){
420 var orig
= e
.getOriginalTarget();
421 var origCoords
= orig
.getContainerLocation();
422 indicator
.setWidth(orig
.getBounds().width
);
423 indicator
.setDomPosition(origCoords
.left
, origCoords
.bottom
);
426 this.list
.addListener("drop", function(e
){
427 var target
= e
.getRelatedTarget();
428 var afterItem
= e
.getOriginalTarget();
429 indicator
.setDomPosition(-1000,-1000);
430 if(afterItem
.classname
!= "qx.ui.form.ListItem") afterItem
= null;
432 target
= this.list
.getSortedSelection()[0];
434 this._addFlowToBatch(target
, afterItem
);
436 this.listPane
.add(this.list
, {edge
:"center"});
438 this.list
.addListener("changeSelection", function(e
){
439 var viewSelection
= this.getViewSelection();
440 viewSelection
.setViewId("form:list");
441 viewSelection
.clear();
442 var listSel
= this.list
.getSortedSelection();
443 for(var i
=0;i
<listSel
.length
;i
++){
444 viewSelection
.addNode(listSel
[i
]);
448 splitPane
.add(this.tree
, 0);
449 splitPane
.add(this.listPane
, 1);
453 * Adds a given ExecutionFlow to the batch
454 * @param target {mixed} The dropped target, can be a TreeFile (add) or a ListItem (reorder).
455 * @param after {qx.ui.form.ListItem} Optional list item : if set, the flow will be added as a new list item positionned after this one.
457 _addFlowToBatch : function(target
, after
){
458 //this.debug(target);
460 target
= this.tree
.getSelectedItem();
462 }else if(target
.classname
== "qx.ui.form.ListItem"){
464 if(after
== "first") this.list
.addAt(target
, 0);
465 else this.list
.addAfter(target
, after
);
468 var executionModule
= target
.getUserData("executionModule");
469 var executionFlow
= target
.getUserData("executionFlow");
470 var batchEntry
= new org
.argeo
.slc
.ria
.execution
.BatchEntrySpec(executionModule
, executionFlow
);
471 var label
= batchEntry
.getLabel();
472 var icon
= target
.getIcon();
473 var item
= new qx
.ui
.form
.ListItem(label
, icon
);
474 item
.addListener("dblclick", function(e
){
475 this.getCommands()["editexecutionspecs"].command
.execute();
477 item
.setUserData("batchEntrySpec", batchEntry
);
478 item
.setPaddingTop(1);
479 item
.setPaddingBottom(2);
481 if(after
== "first") this.list
.addAt(item
, 0);
482 else this.list
.addAfter(item
, after
);
486 this.list
.select(item
);
487 if(this.getAutoOpen()){
488 this.getCommands()["editexecutionspecs"].command
.execute();
493 * Refresh the selector when the topics are updated.
494 * @param changeTopicsEvent {qx.event.type.DataEvent} The reload event.
496 _feedSelector : function(changeTopicsEvent
){
497 var topics
= changeTopicsEvent
.getData();
498 var command
= this.getCommands()["submitform"].command
;
499 command
.setEnabled(false);
501 for(var key
in topics
){
502 var submenu
= {"label":topics
[key
],"icon":"resource/slc/mime-xsl.png", "commandId":key
};
507 menu
.push({"label":"Fake Agent", "icon":"resource/slc/mime-xsl.png", "commandId":"fake_agent_uuid"});
509 command
.clearMenus();
510 command
.setMenu(menu
);
511 if(menu
.length
) command
.setEnabled(true);
516 * Called at execution
517 * @param agentUuid {String} The id of the target agent
519 executeBatchOnAgent : function(agentUuid
){
520 var selection
= this.list
.getChildren();
521 if(!selection
.length
) return;
522 var slcExecMessage
= new org
.argeo
.slc
.ria
.execution
.Message();
523 for(var i
=0;i
<selection
.length
;i
++){
524 var batchEntrySpec
= selection
[i
].getUserData("batchEntrySpec");
525 slcExecMessage
.addBatchEntrySpec(batchEntrySpec
);
527 this._amqClient
.sendMessage(
528 "topic://agent.newExecution",
529 slcExecMessage
.toXml(),
530 {"slc-agentId":agentUuid
}
532 // Force logs refresh right now!
533 qx
.event
.Timer
.once(function(){
534 var command
= org
.argeo
.ria
.event
.CommandsManager
.getInstance().getCommandById("reloadlogs");