/******************************************************************************* * * Argeo * ******************************************************************************/ /** * A cell editor factory creating text fields or disabled text fields. * */ qx.Class.define("org.argeo.slc.ria.execution.CellEditorFactory", { extend : qx.ui.table.cellrenderer.Default, implement : qx.ui.table.ICellEditorFactory, /* * **************************************************************************** * CONSTRUCTOR * **************************************************************************** */ construct : function() { this.base(arguments); }, /* * **************************************************************************** * PROPERTIES * **************************************************************************** */ properties : { /** * function that validates the result the function will be called with * the new value and the old value and is supposed to return the value * that is set as the table value. */ validationFunction : { check : "Function", nullable : true, init : null } }, /* * **************************************************************************** * MEMBERS * **************************************************************************** */ members : { // overridden _getContentHtml : function(cellInfo) { var table = cellInfo.table; var tableModel = table.getTableModel(); var rowData = tableModel.getRowData(cellInfo.row); var metaData = rowData[2]; if (metaData.disabled) { return '' + qx.bom.String.escape(this._formatValue(cellInfo)) + ''; }else{ return qx.bom.String.escape(this._formatValue(cellInfo)); } }, // interface implementation createCellEditor : function(cellInfo) { var table = cellInfo.table; var tableModel = table.getTableModel(); var rowData = tableModel.getRowData(cellInfo.row); var metaData = rowData[2]; if (metaData.disabled) { return null; // var cellEditor = new // qx.ui.table.celleditor.TextField(); } if(metaData.type == "primitive"){ var cellEditor = new qx.ui.form.TextField; cellEditor.setAppearance("table-editor-textfield"); cellEditor.originalValue = cellInfo.value; if (cellInfo.value === null) { cellInfo.value = ""; } cellEditor.setValue("" + cellInfo.value); cellEditor.addListener("appear", function() { cellEditor.selectAllText(); }); var validationFunc; if (metaData.subType == "integer") { validationFunc = function(newValue, oldValue){ var isNum = !isNaN(newValue * 1); if (!isNum) { alert("Warning, this field only accepts Integers!"); return oldValue; } return newValue; }; } cellEditor.setUserData("validationFunc", validationFunc); }else if(metaData.type == "ref"){ var cellEditor = new qx.ui.form.SelectBox().set({ appearance: "table-editor-selectbox" }); cellEditor.setUserData("validationFunc", function(value, oldValue){ if(value == "__empty__"){ alert("Warning, value cannot be empty! You must select at least one option below."); return oldValue; } return value; }); var value = cellInfo.value; cellEditor.originalValue = value; // replace null values if ( value === null ) { value = ""; } if(value == ""){ var li = new qx.ui.form.ListItem(""); li.setModel("__empty__"); cellEditor.add(li); } var list = metaData.refList; if (list) { var item; for (var i=0,l=list.length; i