@SuppressWarnings("unchecked") private void initEditorModel(ExternalContext externalContext, TableEditor tableEditor) { Map<String, Object> sessionMap = externalContext.getSessionMap(); synchronized (sessionMap) { Map editorModelMap = (Map) sessionMap.get(Constants.TABLE_EDITOR_MODEL_NAME); if (editorModelMap == null) { editorModelMap = new HashMap<String, TableEditorModel>(); sessionMap.put(Constants.TABLE_EDITOR_MODEL_NAME, editorModelMap); } TableEditorModel editorModel = (TableEditorModel) editorModelMap.get(tableEditor.getId()); if (editorModel != null) { editorModel.cancel(); } editorModel = new TableEditorModel(tableEditor); editorModel.setCollapseProps(tableEditor.isCollapseProps()); editorModel.setBeforeEditAction(tableEditor.getBeforeEditAction()); editorModel.setBeforeSaveAction(tableEditor.getBeforeSaveAction()); editorModel.setAfterSaveAction(tableEditor.getAfterSaveAction()); editorModelMap.put(tableEditor.getId(), editorModel); } }
protected TableModel initializeTableModel(String editorId) { TableEditorModel editorModel = getEditorModel(editorId); IGridTable table = editorModel.getGridTable(); int numRows = HTMLRenderer.getMaxNumRowsToDisplay(table); TableEditor editor = editorModel.getTableEditor(); String mode = editor.getMode(); if (mode == null && editor.isEditable()) { // This method is invoked only while editing the table. So we can assume that mode is EDIT. mode = Constants.MODE_EDIT; } return TableModel.initializeTableModel(table, null, numRows, editor.getLinkBuilder(), mode, editor.getView()); }
private void beforeRender(TableEditor editor) { String mode = editor.getMode(); boolean editing = Constants.MODE_EDIT.equals(mode); String action = editor.getBeforeEditAction(); if (action != null) { if (editing) { Boolean successful = (Boolean) FacesUtils.invokeMethodExpression(action); if (!successful) { editor.setEditable(false); editor.setMode(Constants.MODE_VIEW); } } } }
private void prepareForEdit(TableEditorModel editorModel) { TableEditor tableEditor = editorModel.getTableEditor(); String mode = tableEditor.getMode(); if ((mode == null || Constants.MODE_EDIT.equals(mode)) && tableEditor.isEditable()) { // Prepare workbook for edit (load it to memory before editing starts) editorModel.getGridTable().edit(); } }
if (!Constants.THIRD_PARTY_LIBS_PROTOTYPE.equalsIgnoreCase(editor.getExcludeScripts())) { result.append(renderJS("js/prototype/prototype-1.6.1.js")); result.append(renderJS("js/tableeditor.min.js")); result.append("<div id='").append(editor.getId()).append("' class='te_'>"); String mode = editor.getMode(); String editorJsVar = Constants.TABLE_EDITOR_PREFIX + editor.getId() result.append(renderEditorToolbar(editor.getId(), editorJsVar, mode)); result.append("<div id='").append(editor.getId()).append(Constants.TABLE_EDITOR_WRAPPER_PREFIX).append("' class='te_editor_wrapper'></div>"); if (editor.getTable() != null && (editor.isEditable() || CollectionUtils.isNotEmpty(actionLinks))) { String menuId = editor.getId() + Constants.ID_POSTFIX_MENU; result.append(renderActionMenu(menuId, editor.isEditable(), actionLinks)); if (editor.getTable() != null) { IGridFilter[] filters = editor.getFilters(); IGridTable table = editor.getTable().getGridTable(editor.getView()); int numRows = getMaxNumRowsToDisplay(table); TableModel tableModel = TableModel.initializeTableModel(table, filters, numRows, editor.getLinkBuilder(), mode, editor.getView()); String tableId = editor.getId() + Constants.ID_POSTFIX_TABLE; result.append(tableRenderer.render(editor.isShowFormulas(), errorCell, editor.getId(), editor.getRowIndex())); result.append("</div>");
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); TableEditor tableEditor = new TableEditor(context, component); if (tableEditor.getTable() == null) { // Required attribute return; } ExternalContext externalContext = context.getExternalContext(); Map<String, String> requestMap = externalContext.getRequestParameterMap(); String cellToEdit = requestMap.get(Constants.REQUEST_PARAM_CELL); String errorCell = requestMap.get(Constants.REQUEST_PARAM_ERROR_CELL); List<ActionLink> actionLinks = getActionLinks(component); if (tableEditor.isEditable()) { initEditorModel(externalContext, tableEditor); } beforeRender(tableEditor); writer.write(new HTMLRenderer().render(tableEditor, cellToEdit, actionLinks, errorCell)); }
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); TableEditor tableEditor = new TableEditor(context, component); if (tableEditor.getTable() == null) { // required attribute return; } writer.write(new HTMLRenderer().render(tableEditor)); }
public TableEditor(FacesContext context, UIComponent component) { Map<String, Object> attributes = component.getAttributes(); id = component.getClientId(context) + Constants.TABLE_EDITOR_PREFIX; table = (IOpenLTable) attributes.get(Constants.ATTRIBUTE_TABLE); editable = BooleanUtils.toBoolean(attributes.get(Constants.ATTRIBUTE_EDITABLE), true); mode = (String) attributes.get(Constants.ATTRIBUTE_MODE); view = (String) attributes.get(Constants.ATTRIBUTE_VIEW); linkBuilder = (LinkBuilder) attributes.get(Constants.ATTRIBUTE_LINK_BUILDER); showFormulas = BooleanUtils.toBoolean(attributes.get(Constants.ATTRIBUTE_SHOW_FORMULAS)); collapseProps = BooleanUtils.toBoolean(attributes.get(Constants.ATTRIBUTE_COLLAPSE_PROPS)); castToFilters(component.getAttributes().get(Constants.ATTRIBUTE_FILTERS)); beforeEditAction = FacesUtils.getValueExpressionString(component, Constants.ATTRIBUTE_BEFORE_EDIT_ACTION); beforeSaveAction = FacesUtils.getValueExpressionString(component, Constants.ATTRIBUTE_BEFORE_SAVE_ACTION); afterSaveAction = FacesUtils.getValueExpressionString(component, Constants.ATTRIBUTE_AFTER_SAVE_ACTION); onBeforeEdit = (String) attributes.get(Constants.ATTRIBUTE_ON_BEFORE_EDIT); onBeforeSave = (String) attributes.get(Constants.ATTRIBUTE_ON_BEFORE_SAVE); onError = (String) attributes.get(Constants.ATTRIBUTE_ON_ERROR); onAfterSave = (String) attributes.get(Constants.ATTRIBUTE_ON_AFTER_SAVE); onRequestStart = (String) attributes.get(Constants.ATTRIBUTE_ON_REQUEST_START); onRequestEnd = (String) attributes.get(Constants.ATTRIBUTE_ON_REQUEST_END); excludeScripts = (String) attributes.get(Constants.ATTRIBUTE_EXCLUDE_SCRIPTS); rowIndex = (Integer) attributes.get(Constants.ATTRIBUTE_ROW_INDEX); }
if (!Constants.THIRD_PARTY_LIBS_PROTOTYPE.equalsIgnoreCase(editor.getExcludeScripts())) { result.append(renderJS("js/prototype/prototype-1.6.1.js")); result.append(renderJS("js/tableeditor.min.js")); result.append("<div id='").append(editor.getId()).append("' class='te_'>"); String mode = editor.getMode(); String editorJsVar = Constants.TABLE_EDITOR_PREFIX + editor.getId() result.append(renderEditorToolbar(editor.getId(), editorJsVar, mode)); result.append("<div id='").append(editor.getId()).append(Constants.TABLE_EDITOR_WRAPPER_PREFIX).append("' class='te_editor_wrapper'></div>"); IOpenLTable openLTable = editor.getTable(); if (openLTable != null && (editor.isEditable() || CollectionUtils.isNotEmpty(actionLinks))) { String menuId = editor.getId() + Constants.ID_POSTFIX_MENU; result.append(renderActionMenu(menuId, editor.isEditable(), actionLinks)); IGridFilter[] filters = editor.getFilters(); IGridTable table = openLTable.getGridTable(editor.getView()); int numRows = getMaxNumRowsToDisplay(table); TableModel tableModel = TableModel.initializeTableModel(table, filters, numRows, editor.getLinkBuilder(), mode, editor.getView(), openLTable.getMetaInfoReader()); String tableId = editor.getId() + Constants.ID_POSTFIX_TABLE; result.append(tableRenderer.render(editor.isShowFormulas(), errorCell, editor.getId(), editor.getRowIndex())); result.append("</div>");
private void beforeRender(TableEditor editor) { String mode = editor.getMode(); boolean editing = Constants.MODE_EDIT.equals(mode); String action = editor.getBeforeEditAction(); if (action != null) { if (editing) { Boolean successful = (Boolean) FacesUtils.invokeMethodExpression(action); if (!successful) { editor.setEditable(false); editor.setMode(Constants.MODE_VIEW); } } } }
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); TableEditor tableEditor = new TableEditor(context, component); if (tableEditor.getTable() == null) { // Required attribute return; } ExternalContext externalContext = context.getExternalContext(); Map<String, String> requestMap = externalContext.getRequestParameterMap(); String cellToEdit = requestMap.get(Constants.REQUEST_PARAM_CELL); String errorCell = requestMap.get(Constants.REQUEST_PARAM_ERROR_CELL); List<ActionLink> actionLinks = getActionLinks(component); if (tableEditor.isEditable()) { initEditorModel(externalContext, tableEditor); } beforeRender(tableEditor); writer.write(new HTMLRenderer().render(tableEditor, cellToEdit, actionLinks, errorCell)); }
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); TableEditor tableEditor = new TableEditor(context, component); if (tableEditor.getTable() == null) { // required attribute return; } writer.write(new HTMLRenderer().render(tableEditor)); }
public TableEditor(FacesContext context, UIComponent component) { Map<String, Object> attributes = component.getAttributes(); id = component.getClientId(context) + Constants.TABLE_EDITOR_PREFIX; table = (IOpenLTable) attributes.get(Constants.ATTRIBUTE_TABLE); editable = BooleanUtils.toBoolean(attributes.get(Constants.ATTRIBUTE_EDITABLE), true); mode = (String) attributes.get(Constants.ATTRIBUTE_MODE); view = (String) attributes.get(Constants.ATTRIBUTE_VIEW); linkBuilder = (LinkBuilder) attributes.get(Constants.ATTRIBUTE_LINK_BUILDER); showFormulas = BooleanUtils.toBoolean(attributes.get(Constants.ATTRIBUTE_SHOW_FORMULAS)); collapseProps = BooleanUtils.toBoolean(attributes.get(Constants.ATTRIBUTE_COLLAPSE_PROPS)); castToFilters(component.getAttributes().get(Constants.ATTRIBUTE_FILTERS)); beforeEditAction = FacesUtils.getValueExpressionString(component, Constants.ATTRIBUTE_BEFORE_EDIT_ACTION); beforeSaveAction = FacesUtils.getValueExpressionString(component, Constants.ATTRIBUTE_BEFORE_SAVE_ACTION); afterSaveAction = FacesUtils.getValueExpressionString(component, Constants.ATTRIBUTE_AFTER_SAVE_ACTION); onBeforeEdit = (String) attributes.get(Constants.ATTRIBUTE_ON_BEFORE_EDIT); onBeforeSave = (String) attributes.get(Constants.ATTRIBUTE_ON_BEFORE_SAVE); onError = (String) attributes.get(Constants.ATTRIBUTE_ON_ERROR); onAfterSave = (String) attributes.get(Constants.ATTRIBUTE_ON_AFTER_SAVE); onRequestStart = (String) attributes.get(Constants.ATTRIBUTE_ON_REQUEST_START); onRequestEnd = (String) attributes.get(Constants.ATTRIBUTE_ON_REQUEST_END); excludeScripts = (String) attributes.get(Constants.ATTRIBUTE_EXCLUDE_SCRIPTS); rowIndex = (Integer) attributes.get(Constants.ATTRIBUTE_ROW_INDEX); }
@SuppressWarnings("unchecked") private void initEditorModel(ExternalContext externalContext, TableEditor tableEditor) { Map<String, Object> sessionMap = externalContext.getSessionMap(); synchronized (sessionMap) { Map editorModelMap = (Map) sessionMap.get(Constants.TABLE_EDITOR_MODEL_NAME); if (editorModelMap == null) { editorModelMap = new HashMap<String, TableEditorModel>(); sessionMap.put(Constants.TABLE_EDITOR_MODEL_NAME, editorModelMap); } TableEditorModel editorModel = (TableEditorModel) editorModelMap.get(tableEditor.getId()); if (editorModel != null) { editorModel.cancel(); } editorModel = new TableEditorModel(tableEditor); editorModel.setCollapseProps(tableEditor.isCollapseProps()); editorModel.setBeforeEditAction(tableEditor.getBeforeEditAction()); editorModel.setBeforeSaveAction(tableEditor.getBeforeSaveAction()); editorModel.setAfterSaveAction(tableEditor.getAfterSaveAction()); editorModelMap.put(tableEditor.getId(), editorModel); } }
private TableModel initializeTableModel(String editorId) { TableEditorModel editorModel = getEditorModel(editorId); IGridTable table = editorModel.getGridTable(); int numRows = HTMLRenderer.getMaxNumRowsToDisplay(table); TableEditor editor = editorModel.getTableEditor(); String mode = editor.getMode(); if (mode == null && editor.isEditable()) { // This method is invoked only while editing the table. So we can assume that mode is EDIT. mode = Constants.MODE_EDIT; } return TableModel.initializeTableModel(table, null, numRows, editor.getLinkBuilder(), mode, editor.getView(), editorModel.getMetaInfoReader()); }