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.*;
034: import javax.swing.event.*;
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 UnListLoader extends KeRegisteredObject implements
050: ListDataListener, IUnLoader {
051: private ListModel pem_myModel = null;
052: private IUnListComponent pem_wdg = null;
053: private IUnListItemRenderer pem_renderer = null;
054: private boolean pem_inTr = false;
055: private IKeExecutable pem_postFct = null;
056:
057: public UnListLoader(ListModel xModel, IUnListComponent xWdg) {
058: super (false);
059:
060: if (xModel == null) {
061: xModel = new DefaultListModel();
062: ((DefaultListModel) xModel).copyInto(xWdg.pcmf_getValues()
063: .values().toArray());
064: }
065:
066: this .pem_myModel = xModel;
067: this .pem_wdg = xWdg;
068:
069: this .pcmf_load();
070:
071: this .pem_myModel.addListDataListener(this );
072: }
073:
074: public UnListLoader(ListModel xModel, IUnListComponent xWdg,
075: IUnListItemRenderer xRenderer) {
076: super (false);
077:
078: this .pem_myModel = xModel;
079: this .pem_wdg = xWdg;
080: this .pem_renderer = xRenderer;
081:
082: this .pcmf_load();
083:
084: this .pem_myModel.addListDataListener(this );
085: }
086:
087: public void pcmf_setRenderer(IUnListItemRenderer xRenderer) {
088: this .pem_renderer = xRenderer;
089: }
090:
091: public void pcmf_setPostFct(IKeExecutable xPostFct) {
092: this .pem_postFct = xPostFct;
093: }
094:
095: public void pcmf_load() {
096: this .pem_wdg.pcmf_clearAndReleaseListWidget();
097:
098: int l = this .pem_myModel.getSize();
099:
100: this .pem_wdg.pcmf_getUnComponent().pcmf_getAppl()
101: .pcmf_beginSessionTR();
102: this .pem_wdg.pcmf_beginTr();
103:
104: for (int i = 0; i < l; i++) {
105: Object l_obj = this .pem_myModel.getElementAt(i);
106: if (this .pem_renderer != null)
107: l_obj = this .pem_renderer
108: .pcmf_getRenderWidget(l_obj, i, Integer
109: .toString(i).equals(
110: this .pem_wdg
111: .pcmf_getUnComponent()
112: .pcmf_getValue()),
113: this .pem_wdg);
114:
115: if (l_obj instanceof KeRegisteredObject)
116: this .pem_wdg.pcmf_addValueObj(Integer.toString(i),
117: (KeRegisteredObject) l_obj);
118: else
119: this .pem_wdg.pcmf_addValue(Integer.toString(i), l_obj
120: .toString());
121: }
122: this .pem_wdg.pcmf_commitTr();
123: this .pem_wdg.pcmf_getUnComponent().pcmf_repaint();
124: this .pem_wdg.pcmf_getUnComponent().pcmf_getAppl()
125: .pcmf_commitSessionTR();
126: }
127:
128: public void pcmf_beginTr() {
129: this .pem_inTr = true;
130: }
131:
132: public void pcmf_commitTr() {
133: this .pcmf_load();
134: this .pem_inTr = false;
135: if (this .pem_postFct != null)
136: this .pem_postFct.pcmf_execObj(this .pem_wdg);
137: }
138:
139: public void pcmf_disconnectModel() {
140: this .pem_myModel.removeListDataListener(this );
141: }
142:
143: public void pcmf_connectModel(Object xModel) {
144: this .pem_myModel = (ListModel) xModel;
145: this .pem_myModel.addListDataListener(this );
146: }
147:
148: public ListModel pcmf_getModel() {
149: return (this .pem_myModel);
150: }
151:
152: public void contentsChanged(ListDataEvent arg0) {
153: if (this .pem_inTr == false)
154: this .pcmf_load();
155: }
156:
157: public void intervalAdded(ListDataEvent arg0) {
158: Object l_value = this .pem_wdg.pcmf_getUnComponent()
159: .pcmf_getValue();
160:
161: if (this .pem_inTr == false)
162: this .pcmf_load();
163:
164: this .pem_wdg.pcmf_getUnComponent().pcmf_setValue(l_value);
165: }
166:
167: public void intervalRemoved(ListDataEvent arg0) {
168: Object l_value = this .pem_wdg.pcmf_getUnComponent()
169: .pcmf_getValue();
170:
171: if (this .pem_inTr == false)
172: this .pcmf_load();
173:
174: for (int i = arg0.getIndex0(); i <= arg0.getIndex1(); i++) {
175: if (l_value.equals(this.pem_myModel.getElementAt(i)
176: .toString())) {
177: this.pem_wdg.pcmf_getUnComponent().pcmf_setValue(
178: l_value);
179: return;
180: }
181: }
182: }
183: }
|