001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.unifiedGui.loader;
032:
033: import javax.swing.event.*;
034: import javax.swing.table.*;
035:
036: import de.ug2t.kernel.*;
037: import de.ug2t.unifiedGui.cellRenderer.*;
038: import de.ug2t.unifiedGui.interfaces.*;
039:
040: /**
041: * @author Dirk
042: *
043: * date: 14.02.2005
044: *
045: * <p>
046: * Purpose:
047: * </p>
048: */
049: public class UnTableLoader extends KeRegisteredObject implements
050: IUnLoader, TableModelListener {
051: private TableModel pem_myModel = null;
052: private IUnTable pem_wdg = null;
053: private IUnTableItemRenderer pem_renderer = null;
054: private boolean pem_inTr = false;
055: private KeTable pem_tbuffer = null;
056: private IKeExecutable pem_postFct = null;
057:
058: public UnTableLoader(TableModel xModel, IUnTable xWdg) {
059: super (false);
060:
061: this .pem_myModel = xModel;
062: this .pem_wdg = xWdg;
063:
064: this .pcmf_load();
065:
066: this .pem_myModel.addTableModelListener(this );
067: }
068:
069: public UnTableLoader(TableModel xModel, IUnTable xWdg,
070: IUnTableItemRenderer xRenderer) {
071: super (false);
072:
073: if (xModel == null)
074: xModel = xWdg.pcmf_getComplete().pcmf_toTableModel();
075:
076: this .pem_myModel = xModel;
077: this .pem_wdg = xWdg;
078: this .pem_renderer = xRenderer;
079:
080: this .pcmf_load();
081:
082: this .pem_myModel.addTableModelListener(this );
083: }
084:
085: public void pcmf_setRenderer(IUnTableItemRenderer xRenderer) {
086: this .pem_renderer = xRenderer;
087: }
088:
089: public void pcmf_setPostFct(IKeExecutable xPostFct) {
090: this .pem_postFct = xPostFct;
091: }
092:
093: public void pcmf_beginTr() {
094: this .pem_inTr = true;
095: }
096:
097: public void pcmf_commitTr() {
098: this .pcmf_load();
099: this .pem_inTr = false;
100: if (this .pem_postFct != null)
101: this .pem_postFct.pcmf_execObj(this .pem_wdg);
102: }
103:
104: public void pcmf_disconnectModel() {
105: this .pem_myModel.removeTableModelListener(this );
106: }
107:
108: public void pcmf_connectModel(Object xModel) {
109: this .pem_myModel = (TableModel) xModel;
110: this .pem_myModel.addTableModelListener(this );
111: }
112:
113: public TableModel pcmf_getModel() {
114: return (this .pem_myModel);
115: }
116:
117: public void pcmf_load() {
118: try {
119: this .pem_wdg.pcmf_getUnComponent().pcmf_getAppl()
120: .pcmf_beginSessionTR();
121:
122: int l_cols = this .pem_myModel.getColumnCount();
123: int l_rows = this .pem_myModel.getRowCount() + 1;
124:
125: if (this .pem_tbuffer != null) {
126: this .pem_tbuffer.pcmf_clearAndRelease();
127: this .pem_tbuffer.pcmf_delete();
128: }
129:
130: this .pem_tbuffer = new KeTable(l_rows - 1, l_cols);
131:
132: for (int r = 0; r < l_rows; r++)
133: for (int c = 0; c < l_cols; c++) {
134: Object l_cell = null;
135:
136: if (r == 0)
137: l_cell = this .pem_myModel.getColumnName(c);
138: else
139: l_cell = this .pem_myModel.getValueAt(r - 1, c);
140:
141: if (this .pem_renderer != null)
142: l_cell = this .pem_renderer
143: .pcmf_getRenderWidget(l_cell, r, c,
144: this .pem_wdg);
145:
146: if (r == 0)
147: this .pem_tbuffer.pcmf_setHeaderValue(c, l_cell);
148: else
149: this .pem_tbuffer
150: .pcmf_setValue(r - 1, c, l_cell);
151: }
152:
153: this .pem_wdg.pcmf_setComplete(pem_tbuffer);
154:
155: if (this .pem_renderer != null
156: && this .pem_renderer.pcmf_doCellPropSettings()) {
157: for (int r = 0; r < l_rows; r++)
158: for (int c = 0; c < l_cols; c++) {
159: Object l_cell = null;
160:
161: if (r == 0)
162: l_cell = this .pem_myModel.getColumnName(c);
163: else
164: l_cell = this .pem_myModel.getValueAt(r - 1,
165: c);
166:
167: this .pem_renderer.pcmf_setCellProps(l_cell, r,
168: c, this .pem_wdg);
169: }
170: }
171:
172: this .pem_wdg.pcmf_relockCol();
173: this .pem_wdg.pcmf_repaint();
174: this .pem_wdg.pcmf_getUnComponent().pcmf_getAppl()
175: .pcmf_commitSessionTR();
176: } catch (Exception e) {
177: KeLog.pcmf_logException("ug2t", this , e);
178: KeLog.pcmf_log("ug2t", "error loading table", this ,
179: KeLog.ERROR);
180: this .pem_wdg.pcmf_getUnComponent().pcmf_getAppl()
181: .pcmf_commitSessionTR();
182: }
183: }
184:
185: public void pcmf_loadCellProps() {
186: if (this .pem_renderer != null
187: && this .pem_renderer.pcmf_doCellPropSettings()) {
188: int l_cols = this .pem_myModel.getColumnCount();
189: int l_rows = this .pem_myModel.getRowCount() + 1;
190:
191: for (int r = 0; r < l_rows; r++)
192: for (int c = 0; c < l_cols; c++) {
193: Object l_cell = null;
194:
195: if (r == 0)
196: l_cell = this .pem_myModel.getColumnName(c);
197: else
198: l_cell = this .pem_myModel.getValueAt(r - 1, c);
199:
200: this .pem_renderer.pcmf_setCellProps(l_cell, r, c,
201: this .pem_wdg);
202: }
203: }
204:
205: this .pem_wdg.pcmf_repaint();
206: this .pem_wdg.pcmf_getUnComponent().pcmf_getAppl()
207: .pcmf_commitSessionTR();
208: }
209:
210: public void tableChanged(TableModelEvent arg0) {
211: Object l_value = this .pem_wdg.pcmf_getUnComponent()
212: .pcmf_getValue();
213:
214: if (this .pem_inTr == false)
215: this.pcmf_load();
216:
217: this.pem_wdg.pcmf_getUnComponent().pcmf_setValue(l_value);
218: }
219: }
|