construct : function(){
this.base(arguments);
- this.setLayout(new qx.ui.layout.Dock());
+ this.setLayout(new qx.ui.layout.Dock());
+
+ this.COMMON_FORM_HEADER_LABEL = "Choose Agent";
+ this.CHOOSE_AGENT_LABEL = "Agent Uuid";
+ this.CHOOSE_FORM_PART_LABEL = "Test Type";
},
properties :
view : {
init : null
},
+ viewSelection : {
+ nullable:false,
+ check:"org.argeo.ria.components.ViewSelection"
+ },
+ instanceId : {init:""},
+ instanceLabel : {init:""},
/**
* Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
*/
menu : "Launcher",
toolbar : "launcher",
callback : function(e){
- this.getView().getContent().submitForm();
+ this.submitForm();
},
command : null
},
}
}
},
+ /**
+ * A map containing all currently registered agents.
+ */
registeredTopics : {
init : {},
check : "Map",
*/
init : function(viewPane){
this.setView(viewPane);
+ this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
this._createLayout();
this._createForm();
this._amqClient = org.argeo.ria.remote.JmsClient.getInstance();
load : function(){
this.getView().setViewTitle("Execution Launcher");
this.addListener("changeRegisteredTopics", function(event){
- this._refreshTopicsSubscriptions(event);
+ //this._refreshTopicsSubscriptions(event);
this._feedSelector(event);
}, this);
var reloadHandler = function(message){
- org.argeo.ria.event.CommandsManager.getInstance().getCommandById("reloadagents").execute();
+ // Delay reload to be sure the jms was first integrated by the db, then ask the db.
+ qx.event.Timer.once(function(){
+ org.argeo.ria.event.CommandsManager.getInstance().getCommandById("reloadagents").execute();
+ }, this, 1000);
}
this._amqClient.addListener("agentregister", "topic://agent.register", reloadHandler, this);
- //qx.event.Timer.once(function(){
- this._amqClient.addListener("agentunregister", "topic://agent.unregister", reloadHandler, this);
- //}, this, 500);
+ this._amqClient.addListener("agentunregister", "topic://agent.unregister", reloadHandler, this);
reloadHandler();
},
this._amqClient.stopPolling();
},
+ /**
+ * Creates the main applet layout.
+ */
_createLayout : function(){
this.formPane = new qx.ui.container.Composite(new qx.ui.layout.VBox(5));
this.scroll = new qx.ui.container.Scroll(this.formPane);
- this.scroll.setWidth(290);
this.formPane.setPadding(10);
- this.add(this.scroll, {edge:'west'});
+ this.add(this.scroll, {edge:'center'});
- this.logModel = new qx.ui.table.model.Simple();
- this.logModel.setColumns(["Date", "Agent Uuid", "Status"]);
- this.logPane = new qx.ui.table.Table(this.logModel, {
- tableColumnModel: function(obj){
- return new qx.ui.table.columnmodel.Resize(obj)
- }
- });
- this._initLogger();
- this.add(this.logPane, {edge:'center'});
},
-
- _initLogger : function(){
- this.logPane.set({
- statusBarVisible: false,
- showCellFocusIndicator:false
- });
- var columnModel = this.logPane.getTableColumnModel();
- columnModel.getBehavior().setWidth(2, "12%");
- },
-
+
+ /**
+ * Creates the form.
+ */
_createForm : function(){
this.fields = {};
+ this.hiddenFields = {};
this.freeFields = [];
var execButtonPane = new qx.ui.container.Composite(new qx.ui.layout.Dock());
this.setRegisteredTopics(newTopics);
}, this);
- this._addFormHeader("Choose Agent Uuid");
- this._addFormEntry(new qx.ui.basic.Label("Agent Uuid"), this.agentSelector);
- this._addFormHeader("Set Execution Parameters");
- this._addFormInputText("status", "Status", "STARTED");
- this._addFormInputText("host", "Host", "localhost");
- this._addFormInputText("user", "User", "user");
+ var commonForm = {pane:this.formPane};
+ this._addFormHeader(commonForm, this.COMMON_FORM_HEADER_LABEL);
+ this._addFormEntry(commonForm, new qx.ui.basic.Label(this.CHOOSE_AGENT_LABEL), this.agentSelector);
+ this._createFormVariableParts();
+ if(!this.parts) return;
+ if(qx.lang.Object.getLength(this.parts) > 1){
+ // Add chooser
+ this.partChooser = new qx.ui.form.SelectBox();
+ for(var key in this.parts){
+ this.partChooser.add(new qx.ui.form.ListItem(this.parts[key].label, null, key));
+ }
+ this._addFormEntry(commonForm, new qx.ui.basic.Label(this.CHOOSE_FORM_PART_LABEL), this.partChooser);
+ this.partChooser.addListener("changeValue", function(ev){
+ this._showSelectedPart(ev.getData());
+ }, this);
+ }
+ this._showSelectedPart(qx.lang.Object.getKeys(this.parts)[0]);
+ },
+
+ /**
+ * Show a form part given its id.
+ * @param partId {String} The part id
+ */
+ _showSelectedPart : function(partId){
+ if(!this.parts) return;
+ if(!this.partsContainer){
+ this.partsContainer = new qx.ui.container.Composite(new qx.ui.layout.Canvas());
+ this.formPane.add(this.partsContainer);
+ }
+ for(var i in this.parts){
+ var formObject = this.parts[i];
+ if(!formObject.added){
+ this.partsContainer.add(formObject.pane, {top:0, left:0});
+ formObject.added = true;
+ }
+ formObject.pane.hide();
+ }
+ if(this.parts[partId]){
+ this.parts[partId].pane.show();
+ }
+ },
+
+ /**
+ * Init a form part : creates a pane, a set of fields, etc.
+ * @param formId {String} A unique ID
+ * @param label {String} A label
+ * @return {Map} The form part.
+ */
+ _initFormPart : function(formId, label){
+ if(!this.parts) this.parts = {};
+ var formObject = {};
+ formObject.hiddenFields = {};
+ formObject.freeFields = [];
+ formObject.fields = {};
+ formObject.id = formId;
+ formObject.label = label;
+ this.parts[formId] = formObject;
+ formObject.pane = new qx.ui.container.Composite(new qx.ui.layout.VBox(5));
+ return formObject;
+ },
+
+ /**
+ * To be overriden by this class children.
+ */
+ _createFormVariableParts : function(){
+ var standard = this._initFormPart("standard", "Canonical");
+ this._createStandardForm(standard);
+ var simple = this._initFormPart("simple", "SLC Sample");
+ this._createSimpleForm(simple);
+ },
+
+ /**
+ * Creates a form for SLC demo
+ * @param formObject {Map} The form part
+ */
+ _createSimpleForm : function(formObject){
+
+ this._addFormInputText(formObject, "ant.file", "File", "Category1/SubCategory2/build.xml");
+ var moreButton = new qx.ui.basic.Image("resource/slc/list-add.png");
+ moreButton.setToolTip(new qx.ui.tooltip.ToolTip("Add a parameter"));
+ moreButton.setCursor("pointer");
+ moreButton.addListener("click", function(){
+ this._addFormInputText(formObject);
+ }, this);
+ this._addFormHeader(formObject, "Add optionnal parameters", moreButton);
+ this._addFormInputText(formObject);
+ this._addFormInputText(formObject);
+
+ },
+
+ /**
+ * Create a canonical form.
+ * @param formObject {Map} The form part
+ */
+ _createStandardForm : function(formObject){
+
+ this._addFormHeader(formObject, "Set Execution Parameters");
+ this._addFormInputText(formObject, "status", "Status", "STARTED");
+ this._addFormInputText(formObject, "host", "Host", "localhost");
+ this._addFormInputText(formObject, "user", "User", "user");
var moreButton = new qx.ui.basic.Image("resource/slc/list-add.png");
moreButton.setToolTip(new qx.ui.tooltip.ToolTip("Add a parameter"));
moreButton.setCursor("pointer");
moreButton.addListener("click", function(){
- this._addFormInputText();
+ this._addFormInputText(formObject);
}, this);
- this._addFormHeader("Add optionnal parameters", moreButton);
- this._addFormInputText();
- this._addFormInputText();
+ this._addFormHeader(formObject, "Add optionnal parameters", moreButton);
+ this._addFormInputText(formObject);
+ this._addFormInputText(formObject);
+ },
+
+ /**
+ * Add an hidden field to the form
+ * @param formObject {Map} The form part
+ * @param fieldName {String} Name
+ * @param fieldValue {String} Value
+ */
+ _addFormHiddenField : function(formObject, fieldName, fieldValue){
+ formObject.hiddenFields[fieldName] = fieldValue;
},
- _addFormInputText : function(fieldName, fieldLabel, defaultValue){
+ /**
+ * Creates a simple label/input form entry.
+ * @param formObject {Map} The form part
+ * @param fieldName {String} Name
+ * @param fieldLabel {String} Label of the field
+ * @param defaultValue {String} The default value
+ * @param choiceValues {Map} An map of values
+ */
+ _addFormInputText : function(formObject, fieldName, fieldLabel, defaultValue, choiceValues){
var labelElement;
- var fieldElement = new qx.ui.form.TextField();
+ if(choiceValues){
+ var fieldElement = new qx.ui.form.SelectBox();
+ for(var key in choiceValues){
+ fieldElement.add(new qx.ui.form.ListItem(choiceValues[key], null, key));
+ }
+ }else{
+ var fieldElement = new qx.ui.form.TextField();
+ }
if(defaultValue){
fieldElement.setValue(defaultValue);
}
if(fieldName && fieldLabel){
labelElement = new qx.ui.basic.Label(fieldLabel);
- this.fields[fieldName] = fieldElement;
+ formObject.fields[fieldName] = fieldElement;
}else{
labelElement = new qx.ui.form.TextField();
- this.freeFields.push({
+ formObject.freeFields.push({
labelEl:labelElement,
valueEl:fieldElement
});
}
- this._addFormEntry(labelElement, fieldElement);
+ this._addFormEntry(formObject, labelElement, fieldElement);
},
- _addFormHeader : function(content, additionnalButton){
+ /**
+ * Add an header
+ * @param formObject {Map} The form part
+ * @param content {Mixed} Content to add.
+ * @param additionnalButton {Mixed} Any widget to add on the east.
+ */
+ _addFormHeader : function(formObject, content, additionnalButton){
var header = new qx.ui.basic.Label('<b>'+content+'</b>');
header.setRich(true);
if(!additionnalButton){
header.setPaddingTop(10);
- this.formPane.add(header);
+ formObject.pane.add(header);
}else{
var pane = new qx.ui.container.Composite(new qx.ui.layout.Dock());
pane.setPaddingTop(10);
pane.setPaddingRight(10);
pane.add(header, {edge:'center'});
pane.add(additionnalButton, {edge:'east'});
- this.formPane.add(pane);
+ formObject.pane.add(pane);
}
},
- _addFormEntry : function(labelElement, fieldElement){
+ /**
+ * Adds a label/input like entry in the form.
+ * @param formObject {Map} The form part
+ * @param labelElement {Object} Either a label or an input
+ * @param fieldElement {Object} Any form input.
+ */
+ _addFormEntry : function(formObject, labelElement, fieldElement){
var entryPane = new qx.ui.container.Composite(new qx.ui.layout.HBox(5));
labelElement.setWidth(100);
labelElement.setTextAlign("right");
entryPane.add(new qx.ui.basic.Label(':'));
fieldElement.setWidth(150);
entryPane.add(fieldElement);
- this.formPane.add(entryPane);
+ formObject.pane.add(entryPane);
},
+ /*
_refreshTopicsSubscriptions : function(changeTopicsEvent){
var oldTopics = changeTopicsEvent.getOldData() || {};
var newTopics = changeTopicsEvent.getData();
var added = [];
for(var key in oldTopics){
if(!newTopics[key]) {
- this._removeAmqListener(key);
+ //this._removeAmqListener(key);
}
}
for(var key in newTopics){
if(!oldTopics[key]) {
- this._addAmqListener(key);
+ //this._addAmqListener(key);
}
}
},
+ */
+ /**
+ * Refresh the selector when the topics are updated.
+ * @param changeTopicsEvent {qx.event.type.DataEvent} The reload event.
+ */
_feedSelector : function(changeTopicsEvent){
var topics = changeTopicsEvent.getData();
this.agentSelector.removeAll();
}
},
+ /*
_addAmqListener: function(uuid){
this._amqClient.addListener("slcExec", "topic://agent."+uuid+".newExecution", function(response){
var message = org.argeo.ria.util.Element.selectSingleNode(response, "slc:slc-execution");
_removeAmqListener : function(uuid){
this._amqClient.removeListener("slcExec", "topic://agent."+uuid+".newExecution");
},
+ */
+ /**
+ * Make an SlcExecutionMessage from the currently displayed form.
+ * @param crtPartId {String} The form part currently displayed
+ * @param slcExec {org.argeo.slc.ria.SlcExecutionMessage} The message to fill.
+ * @param fields {Map} The fields of the form
+ * @param hiddenFields {Map} The hidden ones
+ * @param freeFields {Array} The free fields.
+ */
+ _prepareSlcExecutionMessage : function(crtPartId, slcExec, fields, hiddenFields, freeFields){
+ if(crtPartId == "standard"){
+ slcExec.setStatus(fields.status.getValue());
+ slcExec.setHost(fields.host.getValue());
+ slcExec.setUser(fields.user.getValue());
+ }else{
+ slcExec.addAttribute("ant.file", fields["ant.file"].getValue());
+ }
+ for(var i=0;i<freeFields.length;i++){
+ var fF = freeFields[i];
+ if(fF.labelEl.getValue() != "" && fF.valueEl.getValue() != ""){
+ slcExec.addAttribute(fF.labelEl.getValue(), fF.valueEl.getValue());
+ }
+ }
+ },
+
+ /**
+ * Called when the user clicks the "Execute" button.
+ */
submitForm : function(){
var currentUuid = this.agentSelector.getValue();
if(!currentUuid) return;
- var slcExec = new org.argeo.slc.ria.SlcExecutionMessage(currentUuid);
- slcExec.setStatus(this.fields.status.getValue());
- slcExec.setHost(this.fields.host.getValue());
- slcExec.setUser(this.fields.user.getValue());
- for(var i=0;i<this.freeFields.length;i++){
- var fF = this.freeFields[i];
- if(fF.labelEl.getValue() != "" && fF.valueEl.getValue() != ""){
- slcExec.addAttribute(fF.labelEl.getValue(), fF.valueEl.getValue());
+ var slcExec = new org.argeo.slc.ria.SlcExecutionMessage();
+
+ var fields = {};
+ var hiddenFields = {};
+ var freeFields = {};
+ var crtPartId = "";
+ if(this.parts){
+ if(this.partChooser){
+ crtPartId = this.partChooser.getValue();
+ }else{
+ crtPartId = qx.lang.Object.getKeys(this.parts)[0];
}
+ var crtPart = this.parts[crtPartId];
+ fields = crtPart.fields;
+ hiddenFields = crtPart.hiddenFields;
+ freeFields = crtPart.freeFields;
}
- var destination = "topic://agent."+currentUuid+".newExecution";
- this._amqClient.sendMessage(destination, slcExec.toXml());
+
+ this._prepareSlcExecutionMessage(crtPartId, slcExec, fields, hiddenFields, freeFields);
+
+ this._amqClient.sendMessage(
+ "topic://agent.newExecution",
+ slcExec.toXml(),
+ {"slc-agentId":currentUuid}
+ );
+ // Force logs refresh right now!
+ qx.event.Timer.once(function(){
+ var command = org.argeo.ria.event.CommandsManager.getInstance().getCommandById("reloadlogs");
+ if(command){
+ command.execute();
+ }
+ }, this, 2000);
}
}