001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 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.channel.ho.server.generic;
032:
033: import java.util.*;
034:
035: import de.ug2t.kernel.*;
036: import de.ug2t.unifiedGui.*;
037: import de.ug2t.unifiedGui.interfaces.*;
038: import de.ug2t.xmlScript.*;
039:
040: public final class HoSrvGenericListBox extends AHoSrvGenericComponent
041: implements IUnListBox, IUnSyncComponent {
042: private HashMap pem_values = new LinkedHashMap();
043: private int pem_size = 0;
044: private int pem_xScroll = 0;
045: private int pem_yScroll = 0;
046:
047: public HoSrvGenericListBox(String xName, String xValue,
048: String xString, int xSize, IUnApplication xAppl,
049: String xClass) throws Exception {
050: super (xName);
051: this .pcmf_setAppl(xAppl);
052: this .pcmf_setLocalValue(xValue);
053: pem_values.put(xValue, xString);
054: this .pem_size = xSize;
055:
056: if (xClass == null)
057: pdm_clientClass = "de.ug2t.channel.ho.client.swing.HoSwingListBox";
058: else
059: pdm_clientClass = xClass;
060:
061: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
062: "");
063:
064: if (this .pdm_session.pcmf_isInTransaction()) {
065: ScXmlScript.pcmf_createPBody(l_remCall);
066: } else {
067: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
068: ScXmlScript.pcmf_addProc(l_remCall, null);
069: }
070: ;
071: ScXmlScript.pcmf_addDecl(l_remCall, this .pcmf_getRemName(),
072: this .pdm_clientClass, "global");
073: ScXmlScript.pcmf_addDeclPar(l_remCall, xName, "false",
074: "java.lang.String");
075: ScXmlScript.pcmf_addDeclPar(l_remCall, xValue, "false",
076: "java.lang.String");
077: ScXmlScript.pcmf_addDeclPar(l_remCall, xString, "false",
078: "java.lang.String");
079: ScXmlScript.pcmf_addDeclPar(l_remCall, Integer.toString(xSize),
080: "false", "int");
081: ScXmlScript.pcmf_addDeclPar(l_remCall,
082: ((HoSrvGenericApplication) xAppl).pcmf_getRemName(),
083: "true", "de.ug2t.unifiedGui.interfaces.IUnApplication");
084:
085: ScXmlScript.pcmf_endAll(l_remCall);
086:
087: this .pdm_session.pcmf_call(l_remCall.toString(), this );
088:
089: return;
090: };
091:
092: public void pcmf_addValue(String xValue, String xString) {
093: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
094: "");
095:
096: if (this .pdm_session.pcmf_isInTransaction()) {
097: ScXmlScript.pcmf_createPBody(l_remCall);
098: } else {
099: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
100: ScXmlScript.pcmf_addProc(l_remCall, null);
101: }
102: ;
103: ScXmlScript.pcmf_addCall(l_remCall, null, this
104: .pcmf_getRemName(), "pcmf_addValue");
105: ScXmlScript.pcmf_addCallPar(l_remCall, xValue, "false",
106: "java.lang.String");
107: ScXmlScript.pcmf_addCallPar(l_remCall, xString, "false",
108: "java.lang.String");
109: ScXmlScript.pcmf_endAll(l_remCall);
110:
111: this .pdm_session.pcmf_call(l_remCall.toString(), this );
112:
113: pem_values.put(xValue, xString);
114: };
115:
116: public void pcmf_addValueObj(String xValue, KeRegisteredObject xObj) {
117: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
118: "");
119:
120: if (this .pdm_session.pcmf_isInTransaction()) {
121: ScXmlScript.pcmf_createPBody(l_remCall);
122: } else {
123: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
124: ScXmlScript.pcmf_addProc(l_remCall, null);
125: }
126: ;
127: ScXmlScript.pcmf_addCall(l_remCall, null, this
128: .pcmf_getRemName(), "pcmf_addValueObj");
129: ScXmlScript.pcmf_addCallPar(l_remCall, xValue, "false",
130: "java.lang.String");
131: ScXmlScript.pcmf_addCallPar(l_remCall, xObj.pcmf_getRemName(),
132: "true", "de.ug2t.kernel.KeRegisteredObject");
133: ScXmlScript.pcmf_endAll(l_remCall);
134:
135: this .pdm_session.pcmf_call(l_remCall.toString(), this );
136:
137: pem_values.put(xValue, xObj);
138:
139: if (xObj instanceof KeTreeNode)
140: this .pcmf_addNode(xValue, (KeTreeNode) xObj);
141: };
142:
143: public void pcmf_beginTr() {
144: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
145: "");
146:
147: if (this .pdm_session.pcmf_isInTransaction()) {
148: ScXmlScript.pcmf_createPBody(l_remCall);
149: } else {
150: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
151: ScXmlScript.pcmf_addProc(l_remCall, null);
152: }
153: ;
154: ScXmlScript.pcmf_addCall(l_remCall, null, this
155: .pcmf_getRemName(), "pcmf_beginTr");
156: ScXmlScript.pcmf_endAll(l_remCall);
157:
158: this .pdm_session.pcmf_call(l_remCall.toString(), this );
159: }
160:
161: public void pcmf_commitTr() {
162: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
163: "");
164:
165: if (this .pdm_session.pcmf_isInTransaction()) {
166: ScXmlScript.pcmf_createPBody(l_remCall);
167: } else {
168: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
169: ScXmlScript.pcmf_addProc(l_remCall, null);
170: }
171: ;
172: ScXmlScript.pcmf_addCall(l_remCall, null, this
173: .pcmf_getRemName(), "pcmf_commitTr");
174: ScXmlScript.pcmf_endAll(l_remCall);
175:
176: this .pdm_session.pcmf_call(l_remCall.toString(), this );
177: }
178:
179: public void pcmf_removeValue(String xValue) {
180: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
181: "");
182:
183: if (this .pdm_session.pcmf_isInTransaction()) {
184: ScXmlScript.pcmf_createPBody(l_remCall);
185: } else {
186: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
187: ScXmlScript.pcmf_addProc(l_remCall, null);
188: }
189: ;
190: ScXmlScript.pcmf_addCall(l_remCall, null, this
191: .pcmf_getRemName(), "pcmf_removeValue");
192: ScXmlScript.pcmf_addCallPar(l_remCall, xValue, "false",
193: "java.lang.String");
194: ScXmlScript.pcmf_endAll(l_remCall);
195:
196: this .pdm_session.pcmf_call(l_remCall.toString(), this );
197:
198: pem_values.remove(xValue);
199: this .pcmf_removeNode(xValue);
200: };
201:
202: public void pcmf_clearListBox() {
203: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
204: "");
205:
206: if (this .pdm_session.pcmf_isInTransaction()) {
207: ScXmlScript.pcmf_createPBody(l_remCall);
208: } else {
209: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
210: ScXmlScript.pcmf_addProc(l_remCall, null);
211: }
212: ;
213: ScXmlScript.pcmf_addCall(l_remCall, null, this
214: .pcmf_getRemName(), "pcmf_clearListBox");
215: ScXmlScript.pcmf_endAll(l_remCall);
216:
217: this .pdm_session.pcmf_call(l_remCall.toString(), this );
218:
219: Iterator l_it = new ArrayList(this .pcmf_getAllSubs())
220: .iterator();
221: Object l_obj = null;
222: while (l_it.hasNext()) {
223: l_obj = l_it.next();
224: if (l_obj instanceof IUnContextMenu
225: || l_obj instanceof IUnEventChannel)
226: continue;
227:
228: this .pcmf_removeNode((KeTreeNode) l_obj);
229: }
230: };
231:
232: public void pcmf_clearAndReleaseListBox() {
233: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
234: "");
235:
236: if (this .pdm_session.pcmf_isInTransaction()) {
237: ScXmlScript.pcmf_createPBody(l_remCall);
238: } else {
239: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
240: ScXmlScript.pcmf_addProc(l_remCall, null);
241: }
242: ;
243: ScXmlScript.pcmf_addCall(l_remCall, null, this
244: .pcmf_getRemName(), "pcmf_clearAndReleaseListBox");
245: ScXmlScript.pcmf_endAll(l_remCall);
246:
247: this .pdm_session.pcmf_call(l_remCall.toString(), this );
248:
249: Iterator l_it = new ArrayList(this .pcmf_getAllSubs())
250: .iterator();
251: Object l_obj = null;
252:
253: this .pdm_session.pcmf_beginTr();
254: while (l_it.hasNext()) {
255: l_obj = l_it.next();
256: if (l_obj instanceof IUnContextMenu
257: || l_obj instanceof IUnEventChannel)
258: continue;
259:
260: this .pcmf_removeNode((KeTreeNode) l_obj);
261: ((KeTreeNode) l_obj).pcmf_releaseSubs();
262: }
263: this .pdm_session.pcmf_commitTr();
264: };
265:
266: public Object pcmf_getSelectedObject() {
267: int l_idx = this .pcmf_getSelectedRow();
268: if (l_idx == -1)
269: return (null);
270:
271: Object l_ret = this .pem_values.keySet().toArray()[l_idx];
272: return (l_ret);
273: }
274:
275: public Object pcmf_setSelectedRow(int xRow) {
276: if (xRow >= this .pem_values.size())
277: return (null);
278:
279: Object l_ret = this .pem_values.keySet().toArray()[xRow];
280: this .pcmf_setLocalValue(l_ret);
281:
282: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
283: "");
284:
285: if (this .pdm_session.pcmf_isInTransaction()) {
286: ScXmlScript.pcmf_createPBody(l_remCall);
287: } else {
288: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
289: ScXmlScript.pcmf_addProc(l_remCall, null);
290: }
291: ;
292: ScXmlScript.pcmf_addCall(l_remCall, null, this
293: .pcmf_getRemName(), "pcmf_setSelectedRow");
294: ScXmlScript.pcmf_addCallPar(l_remCall, Integer.toString(xRow),
295: "false", "int");
296: ScXmlScript.pcmf_endAll(l_remCall);
297:
298: this .pdm_session.pcmf_call(l_remCall.toString(), this );
299:
300: return (l_ret);
301: }
302:
303: public int pcmf_getSelectedRow() {
304: return (new ArrayList(this .pem_values.keySet()).indexOf(this
305: .pcmf_getValue()));
306: }
307:
308: public AHoSrvGenericComponent pcmf_buildRefObj() throws Exception {
309: Object l_key = null;
310: AHoSrvGenericComponent l_obj = null;
311: Iterator l_it = this .pcmf_getValues().keySet().iterator();
312: while (l_it.hasNext()) {
313: l_key = l_it.next();
314: if (l_obj == null) {
315: l_obj = new HoSrvGenericListBox(this .pcmf_getName(),
316: l_key.toString(), this .pcmf_getValues().get(
317: l_key.toString()).toString(),
318: this .pem_size, this .pcmf_getAppl(),
319: this .pdm_clientClass);
320: continue;
321: }
322: ;
323:
324: ((HoSrvGenericListBox) l_obj).pcmf_addValue(l_key
325: .toString(), this .pcmf_getValues().get(
326: l_key.toString()).toString());
327: }
328: ;
329:
330: l_obj.pcmf_setGlobal(true);
331: this .pcmf_setGlobal(true);
332: l_obj.pcmf_setAutoEcho(this .pcmf_doAutoEcho());
333: l_obj.pcmf_setRefFrom(this );
334: this .pcmf_addRef(l_obj);
335:
336: return l_obj;
337: };
338:
339: public int pcmf_getVisibleRows() {
340: return (this .pem_size);
341: };
342:
343: public void pcmf_scrollXRel(int xPx) {
344: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
345: "");
346:
347: if (this .pdm_session.pcmf_isInTransaction()) {
348: ScXmlScript.pcmf_createPBody(l_remCall);
349: } else {
350: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
351: ScXmlScript.pcmf_addProc(l_remCall, null);
352: }
353: ;
354: ScXmlScript.pcmf_addCall(l_remCall, null, this
355: .pcmf_getRemName(), "pcmf_scrollXRel");
356: ScXmlScript.pcmf_addCallPar(l_remCall, Integer.toString(xPx),
357: "false", "int");
358: ScXmlScript.pcmf_endAll(l_remCall);
359:
360: this .pdm_session.pcmf_call(l_remCall.toString(), this );
361:
362: return;
363: }
364:
365: public void pcmf_scrollXAbs(int xPx) {
366: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
367: "");
368:
369: if (this .pdm_session.pcmf_isInTransaction()) {
370: ScXmlScript.pcmf_createPBody(l_remCall);
371: } else {
372: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
373: ScXmlScript.pcmf_addProc(l_remCall, null);
374: }
375: ;
376: ScXmlScript.pcmf_addCall(l_remCall, null, this
377: .pcmf_getRemName(), "pcmf_scrollXAbs");
378: ScXmlScript.pcmf_addCallPar(l_remCall, Integer.toString(xPx),
379: "false", "int");
380: ScXmlScript.pcmf_endAll(l_remCall);
381:
382: this .pdm_session.pcmf_call(l_remCall.toString(), this );
383:
384: return;
385: }
386:
387: public void pcmf_scrollYRel(int xPy) {
388: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
389: "");
390:
391: if (this .pdm_session.pcmf_isInTransaction()) {
392: ScXmlScript.pcmf_createPBody(l_remCall);
393: } else {
394: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
395: ScXmlScript.pcmf_addProc(l_remCall, null);
396: }
397: ;
398: ScXmlScript.pcmf_addCall(l_remCall, null, this
399: .pcmf_getRemName(), "pcmf_scrollYRel");
400: ScXmlScript.pcmf_addCallPar(l_remCall, Integer.toString(xPy),
401: "false", "int");
402: ScXmlScript.pcmf_endAll(l_remCall);
403:
404: this .pdm_session.pcmf_call(l_remCall.toString(), this );
405:
406: return;
407: }
408:
409: public void pcmf_scrollYAbs(int xPy) {
410: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
411: "");
412:
413: if (this .pdm_session.pcmf_isInTransaction()) {
414: ScXmlScript.pcmf_createPBody(l_remCall);
415: } else {
416: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
417: ScXmlScript.pcmf_addProc(l_remCall, null);
418: }
419: ;
420: ScXmlScript.pcmf_addCall(l_remCall, null, this
421: .pcmf_getRemName(), "pcmf_scrollYAbs");
422: ScXmlScript.pcmf_addCallPar(l_remCall, Integer.toString(xPy),
423: "false", "int");
424: ScXmlScript.pcmf_endAll(l_remCall);
425:
426: this .pdm_session.pcmf_call(l_remCall.toString(), this );
427:
428: return;
429: }
430:
431: public int pcmf_getXScroll() {
432: return (this .pem_xScroll);
433: }
434:
435: public int pcmf_getYScroll() {
436: return (this .pem_yScroll);
437: }
438:
439: private boolean pem_readOnly = false;
440:
441: public void pcmf_setReadOnly(boolean xReadOnly) {
442: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
443: "");
444:
445: if (this .pdm_session.pcmf_isInTransaction()) {
446: ScXmlScript.pcmf_createPBody(l_remCall);
447: } else {
448: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
449: ScXmlScript.pcmf_addProc(l_remCall, null);
450: }
451: ;
452: ScXmlScript.pcmf_addCall(l_remCall, null, this
453: .pcmf_getRemName(), "pcmf_setReadOnly");
454: ScXmlScript.pcmf_addCallPar(l_remCall, Boolean
455: .toString(xReadOnly), "false", "boolean");
456: ScXmlScript.pcmf_endAll(l_remCall);
457:
458: this .pdm_session.pcmf_call(l_remCall.toString(), this );
459: this .pem_readOnly = xReadOnly;
460: }
461:
462: public boolean pcmf_isReadOnly() {
463: return (this .pem_readOnly);
464: }
465:
466: private int pem_syncCnt = 0;
467:
468: public Object pcmf_getValueToSync() {
469: return (this .pcmf_getValue());
470: }
471:
472: public void pcmf_setSynced() {
473: this .pem_syncCnt++;
474: }
475:
476: public void pcmf_unSync() {
477: this .pem_syncCnt--;
478: if (this .pem_syncCnt < 0)
479: this .pem_syncCnt = 0;
480: }
481:
482: public boolean pcmf_isSynced() {
483: if (this .pem_syncCnt == 0)
484: return (false);
485: else
486: return (true);
487: }
488:
489: public HashMap pcmf_getValues() {
490: return (pem_values);
491: }
492:
493: public void pcmf_clearListWidget() {
494: this .pcmf_clearListBox();
495: }
496:
497: public void pcmf_clearAndReleaseListWidget() {
498: this .pcmf_clearAndReleaseListBox();
499: }
500:
501: public void pcmf_setVisibleRows(int xSize) {
502: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
503: "");
504:
505: if (this .pdm_session.pcmf_isInTransaction()) {
506: ScXmlScript.pcmf_createPBody(l_remCall);
507: } else {
508: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
509: ScXmlScript.pcmf_addProc(l_remCall, null);
510: }
511: ;
512: ScXmlScript.pcmf_addCall(l_remCall, null, this
513: .pcmf_getRemName(), "pcmf_setVisibleRows");
514: ScXmlScript.pcmf_addCallPar(l_remCall, Integer.toString(xSize),
515: "false", "int");
516: ScXmlScript.pcmf_endAll(l_remCall);
517:
518: this .pdm_session.pcmf_call(l_remCall.toString(), this );
519: this .pem_size = xSize;
520: }
521:
522: public boolean pcmf_isSelectable() {
523: return (true);
524: }
525:
526: public void pcmf_setScrollInfo(int xX, int xY) {
527: if (xX != this .pem_xScroll || xY != this .pem_yScroll) {
528: this .pem_xScroll = xX;
529: this .pem_yScroll = xY;
530:
531: Iterator l_it = this .pcmf_getSubIterator();
532: while (l_it.hasNext()) {
533: Object l_obj = l_it.next();
534: if (l_obj instanceof IUnEventChannel) {
535: if (((IUnEventChannel) l_obj).pcmf_getType() == IUnEventChannel.EVENT_SCROLL) {
536: IUnEventChannel l_ch = (IUnEventChannel) l_obj;
537: l_ch
538: .pcmf_getUnComponent()
539: .pcmf_setValue(
540: IUnEventChannel.EVENTs[IUnEventChannel.EVENT_SCROLL]
541: + ":" + xX + "," + xY);
542: l_ch.pcmf_getUnComponent().pcmf_setRefresh();
543:
544: if (l_ch.pcmf_isRefreshParent())
545: ((UnComponent) l_ch.pcmf_getUnComponent()
546: .pcmf_getParentNode())
547: .pcmf_setRefresh();
548:
549: try {
550: if (l_ch.pcmf_getUnComponent()
551: .pcmf_isSubmit())
552: l_ch.pcmf_getUnComponent()
553: .pcmf_dispatchEvent();
554: } catch (Exception e) {
555: KeLog.pcmf_logException("ug2t", this , e);
556: KeLog.pcmf_log("ug2t",
557: "error dispatch scroll event",
558: this, KeLog.ERROR);
559: }
560: }
561: break;
562: }
563: }
564: }
565: }
566: }
|