From: Charles du Jeu Date: Fri, 22 May 2009 22:09:16 +0000 (+0000) Subject: Spec editor is an independant view X-Git-Tag: argeo-slc-2.1.7~1890 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=d8f7abb3102580b01ffbeecc201f7bdfbd082150;hp=2dad63f97c21e34db947b740c7f728fd34ae11a5;p=gpl%2Fargeo-slc.git Spec editor is an independant view git-svn-id: https://svn.argeo.org/slc/trunk@2435 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/server/org.argeo.slc.ria/src/argeo-ria-lib/slc-web/class/org/argeo/slc/web/LauncherPerspective.js b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc-web/class/org/argeo/slc/web/LauncherPerspective.js index 8138bd0d8..aa6eabeb0 100644 --- a/server/org.argeo.slc.ria/src/argeo-ria-lib/slc-web/class/org/argeo/slc/web/LauncherPerspective.js +++ b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc-web/class/org/argeo/slc/web/LauncherPerspective.js @@ -23,21 +23,30 @@ qx.Class.define("org.argeo.slc.web.LauncherPerspective", this._splitPane = new qx.ui.splitpane.Pane("horizontal"); this._secondSplit = new qx.ui.splitpane.Pane("vertical"); this._secondSplit.setDecorator(null); + this._thirdSplit = new qx.ui.splitpane.Pane("horizontal"); + this._thirdSplit.setDecorator(null); var selectorPane = new org.argeo.ria.components.ViewPane("selector", "Available Scripts"); selectorPane.set({width:290}); viewsManager.registerViewPane(selectorPane); var batchPane = new org.argeo.ria.components.ViewPane("batch", "Batch"); - batchPane.set({height:300}); + batchPane.set({width: 600, height:300}); viewsManager.registerViewPane(batchPane); var logPane = new org.argeo.ria.components.ViewPane("main", "Executions Log"); - viewsManager.registerViewPane(logPane); + viewsManager.registerViewPane(logPane); - this._secondSplit.add(batchPane, 0); + var specEditorPane = new org.argeo.ria.components.ViewPane("editor", "Specs Editor"); + specEditorPane.set({width:200}); + viewsManager.registerViewPane(specEditorPane); + + this._secondSplit.add(this._thirdSplit, 0); this._secondSplit.add(logPane, 1); + this._thirdSplit.add(batchPane, 0); + this._thirdSplit.add(specEditorPane, 1); + this._splitPane.add(selectorPane, 0); this._splitPane.add(this._secondSplit, 1); @@ -53,6 +62,9 @@ qx.Class.define("org.argeo.slc.web.LauncherPerspective", var batchApplet = viewsManager.initIViewClass(org.argeo.slc.ria.BatchView, "batch"); batchApplet.load(); + var editor = viewsManager.initIViewClass(org.argeo.slc.ria.SpecsEditorView, "editor"); + editor.load(); + var logger = viewsManager.initIViewClass(org.argeo.slc.ria.SlcExecLoggerApplet, "main"); logger.load(); }, diff --git a/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/BatchView.js b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/BatchView.js index 8769751bb..18deeaf49 100644 --- a/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/BatchView.js +++ b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/BatchView.js @@ -28,6 +28,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView", }, command : null }, + /* "toggleopenonadd" : { label : "Auto edit on Add", icon : "resource/slc/document-open.png", @@ -59,7 +60,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView", } }, selectionChange : function(viewId, selection) { - if (viewId != "form:list") + if (viewId != "batch:list") return; this.setEnabled(false); if ((selection && selection.length == 1)) { @@ -71,6 +72,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView", }, command : null }, + */ "removefrombatch" : { label : "Remove from batch", icon : "resource/slc/edit-delete.png", @@ -95,7 +97,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView", modal.attachAndShow(); }, selectionChange : function(viewId, selection) { - if (viewId != "form:list") + if (viewId != "batch:list") return; this.setEnabled(false); if ((selection && selection.length > 0)) @@ -198,8 +200,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView", this.list.setDroppable(true); this.list.setDraggable(true); this.list.setContextMenu(org.argeo.ria.event.CommandsManager - .getInstance().createMenuFromIds(["editexecutionspecs", - "removefrombatch"])); + .getInstance().createMenuFromIds(["removefrombatch"])); this.list.addListener("dragstart", function(e) { e.addType(["items"]); @@ -242,7 +243,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView", this.list.addListener("changeSelection", function(e) { var viewSelection = this.getViewSelection(); - viewSelection.setViewId("form:list"); + viewSelection.setViewId("batch:list"); viewSelection.clear(); var listSel = this.list.getSortedSelection(); for (var i = 0; i < listSel.length; i++) { @@ -319,10 +320,12 @@ qx.Class.define("org.argeo.slc.ria.BatchView", var label = batchEntry.getLabel(); var icon = target.getIcon() || "resource/slc/office-document.png"; var item = new qx.ui.form.ListItem(label, icon); + /* item.addListener("dblclick", function(e) { this.getCommands()["editexecutionspecs"].command .execute(); }, this); + */ item.setUserData("batchEntrySpec", batchEntry); item.setPaddingTop(1); item.setPaddingBottom(2); @@ -335,9 +338,11 @@ qx.Class.define("org.argeo.slc.ria.BatchView", this.list.add(item); } this.list.select(item); + /* if (this.getAutoOpen() && !skipAutoOpen) { this.getCommands()["editexecutionspecs"].command.execute(); } + */ }, /** diff --git a/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/SpecsEditorView.js b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/SpecsEditorView.js new file mode 100644 index 000000000..4837ceb45 --- /dev/null +++ b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/SpecsEditorView.js @@ -0,0 +1,160 @@ +/** + * Applet for the batch manager + */ +qx.Class.define("org.argeo.slc.ria.SpecsEditorView", +{ + extend : qx.ui.container.Composite, + implement : [org.argeo.ria.components.IView], + + properties : + { + /** + * The commands definition Map that will be automatically added and wired to the menubar and toolbar. + * See {@link org.argeo.ria.event.CommandsManager#definitions} for the keys to use for defining commands. + */ + commands : { + init : { + "updateData" : { + label : "Edit Execution Specs", + icon : "resource/slc/document-open.png", + shortcut : null, + enabled : false, + menu : null, + toolbar : null, + callback : function(e) {}, + selectionChange : function(viewId, selection) { + if (viewId != "batch:list") + return; + if ((selection && selection.length == 1)) { + var view = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent(); + view.setBatchEntrySpec(selection[0].getUserData("batchEntrySpec")); + } + }, + command : null + } + } + }, + view : { + init : null + }, + viewSelection : { + nullable:false, + check:"org.argeo.ria.components.ViewSelection" + }, + instanceId : {init:""}, + instanceLabel : {init:""}, + batchEntrySpec : { + init : null, + nullable:true, + event : "changeBatchEntrySpec" + } + + }, + + construct : function(){ + this.base(arguments); + this.setLayout(new qx.ui.layout.Dock()); + }, + + members : { + /** + * The implementation should contain the GUI initialisation. + * This is the role of the manager to actually add the graphical component to the pane, + * so it's not necessary to do it here. + * @param viewPane {org.argeo.ria.components.ViewPane} The pane manager + * @param data {Mixed} Any object or data passed by the initiator of the view + * @return {Boolean} + */ + init : function(viewPane, data){ + this.setView(viewPane); + this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId())); + + this.addListener("changeBatchEntrySpec", this.updateData, this); + }, + /** + * The implementation should contain the real data loading (i.o. query...) + * @return {Boolean} + */ + load : function(){ + this._createLayout(); + this.getView().setViewTitle("Specs Editor"); + }, + + /** + * Update the table + * @param event {qx.event.type.DataEvent} + */ + updateData : function(event){ + var batchEntry = event.getData(); + if(batchEntry == null){ + this.tableModel.setData([]); + return; + } + var values = batchEntry.getValues(); + var data = []; + for(var key in values){ + var valueObj = values[key]; + var hidden = valueObj.getHidden(); + var type = valueObj.getSpecType(); + if(type == "primitive" && !hidden){ + metadata = { + key : key, + disabled : valueObj.getFrozen(), + type : type, + subType : valueObj.getSpecSubType() + } + data.push([key, valueObj.getValue(), metadata]); + } + } + this.tableModel.setData(data); + }, + + /** + * Creates the main applet layout. + */ + _createLayout : function() { + this.tableModel = new qx.ui.table.model.Simple(); + this.tableModel.setColumns(["Attribute Name", "Value"]); + this.tableModel.setColumnEditable(1, true); + this.table = new qx.ui.table.Table(this.tableModel, { + tableColumnModel: function(obj){ + return new qx.ui.table.columnmodel.Resize(obj) + } + }); + this.table.set({ + decorator : null, + statusBarVisible: false, + showCellFocusIndicator:true, + columnVisibilityButtonVisible : false + }); + + this.table.addListener("dataEdited", function(e){ + var data = e.getData(); + var rowData = this.tableModel.getRowData(data.row); + var metaData = rowData[2]; + var values = this.getBatchEntrySpec().getValues(); + values[metaData.key].setValue(data.value); + }, this); + + var columnModel = this.table.getTableColumnModel(); + var factory = new org.argeo.slc.ria.execution.CellEditorFactory(); + columnModel.setCellEditorFactory(1, factory); + columnModel.setDataCellRenderer(1, factory); + columnModel.getBehavior().setWidth(0, "70%"); + this.add(this.table, {edge:"center"}); + }, + + /** + * Whether this component is already contained in a scroller (return false) or not (return true). + * @return {Boolean} + */ + addScroll : function(){return false;}, + /** + * Called at destruction time + * Perform all the clean operations (stopping polling queries, etc.) + */ + close : function(){return true;} + } + + +}); \ No newline at end of file diff --git a/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/CellEditorFactory.js b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/CellEditorFactory.js new file mode 100644 index 000000000..1be480836 --- /dev/null +++ b/server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/CellEditorFactory.js @@ -0,0 +1,126 @@ +/******************************************************************************* + * + * 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(); + } + + 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.selectAll(); + }); + + 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); + + return cellEditor; + }, + + // interface implementation + getCellEditorValue : function(cellEditor) { + var value = cellEditor.getValue(); + var validationFunc = cellEditor.getUserData("validationFunc"); + + // validation function will be called with new and old value + // var validationFunc = this.getValidationFunction(); + if (validationFunc) { + value = validationFunc(value, cellEditor.originalValue); + } + + if (typeof cellEditor.originalValue == "number") { + value = parseFloat(value); + } + + return value; + } + } +});