001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013:
014: package org.itsnat.impl.comp;
015:
016: import org.itsnat.comp.ItsNatTableCellEditor;
017: import javax.swing.event.CellEditorListener;
018: import javax.swing.table.TableModel;
019: import org.itsnat.comp.ItsNatComponent;
020: import org.itsnat.comp.ui.ItsNatTableCellUI;
021: import org.itsnat.comp.ui.ItsNatTableUI;
022: import org.w3c.dom.Element;
023: import org.w3c.dom.Node;
024: import org.w3c.dom.events.Event;
025:
026: /**
027: *
028: * @author jmarranz
029: */
030: public class TableCellEditorProcessor extends EditorProcessorBase
031: implements CellEditorListener {
032: protected ItsNatTableCellUI cellInfo;
033:
034: public TableCellEditorProcessor(ItsNatTableImpl compParent) {
035: super (compParent);
036: }
037:
038: public ItsNatTableImpl getItsNatTable() {
039: return (ItsNatTableImpl) compParent;
040: }
041:
042: public ItsNatTableCellEditor getItsNatTableCellEditor() {
043: return (ItsNatTableCellEditor) cellEditor;
044: }
045:
046: public void setItsNatTableCellEditor(
047: ItsNatTableCellEditor cellEditor) {
048: setCellEditor(cellEditor);
049: }
050:
051: public void setCurrentContext(ItsNatTableCellUI cellInfo) {
052: this .cellInfo = cellInfo;
053: }
054:
055: public int getRow() {
056: if (cellInfo == null)
057: return -1;
058: return cellInfo.getRowIndex();
059: }
060:
061: public int getColumn() {
062: if (cellInfo == null)
063: return -1;
064: return cellInfo.getColumnIndex();
065: }
066:
067: public void startEdition(int row, int column) {
068: if (prepareEdition()) {
069: openEditor(row, column);
070: }
071: }
072:
073: protected void openEditor(int row, int column) {
074: ItsNatTableUI bodyUI = getItsNatTable().getItsNatTableUI();
075: ItsNatTableCellUI cellInfo = bodyUI.getItsNatTableCellUIAt(row,
076: column);
077: openEditor(cellInfo);
078: }
079:
080: protected void openEditor(Event evt) {
081: Node nodeClicked = (Node) evt.getTarget(); // Puede ser un nodo interior del elemento pulsado
082:
083: ItsNatTableUI bodyUI = getItsNatTable().getItsNatTableUI();
084: ItsNatTableCellUI cellInfo = bodyUI
085: .getItsNatTableCellUIFromNode(nodeClicked);
086: openEditor(cellInfo);
087: }
088:
089: protected void openEditor(ItsNatTableCellUI cellInfo) {
090: if (cellInfo != null) // Se ha pulsado una celda verdaderamente
091: {
092: int row = cellInfo.getRowIndex();
093: int column = cellInfo.getColumnIndex();
094: ItsNatTableImpl table = getItsNatTable();
095: TableModel dataModel = table.getTableModel();
096: if (dataModel.isCellEditable(row, column)) {
097: setCurrentContext(cellInfo);
098: Element cellContentElem = cellInfo
099: .getCellContentElement();
100: Object value = dataModel.getValueAt(row, column);
101: boolean isSelected = table.isCellSelected(row, column);
102: beforeShow(cellContentElem);
103: ItsNatTableCellEditor cellEditor = getItsNatTableCellEditor();
104: ItsNatComponent compEditor = cellEditor
105: .getTableCellEditorComponent(table, row,
106: column, value, isSelected,
107: cellContentElem);
108: afterShow(compEditor);
109: }
110: }
111: }
112:
113: public void acceptNewValue(Object value) {
114: int row = cellInfo.getRowIndex();
115: int column = cellInfo.getColumnIndex();
116: getItsNatTable().getTableModel().setValueAt(value, row, column); // Si se ha cambiado se renderiza el cambio
117: }
118:
119: public void clearCurrentContext() {
120: setCurrentContext(null);
121: }
122: }
|