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.wizard;
032:
033: import java.util.*;
034:
035: import de.ug2t.kernel.*;
036: import de.ug2t.unifiedGui.*;
037: import de.ug2t.unifiedGui.interfaces.*;
038:
039: public class WizardPlugin extends ADialogPlugin implements
040: IUnGuiEventListener {
041: public void pcmf_execListener(UnComponent xParam) throws Exception {
042: this .pcmf_start();
043: }
044:
045: public WizardPlugin() {
046: this .pem_prevB = IUnButton.Factory.create();
047: this .pem_prevB.pcmf_setValue("zurück");
048: this .pem_nextB = IUnButton.Factory.create();
049: this .pem_nextB.pcmf_setValue("vor");
050: this .pem_abortB = IUnButton.Factory.create();
051: this .pem_abortB.pcmf_setValue("abbrechen");
052: this .pem_saveB = IUnButton.Factory.create();
053: this .pem_saveB.pcmf_setValue("beenden");
054: this .pem_mess = IUnTextArea.Factory.create(1, 80);
055: }
056:
057: class SaveListener implements IUnGuiEventListener {
058: public void pcmf_execListener(UnComponent xParam)
059: throws Exception {
060: if (WizardPlugin.this .pem_cForm != null
061: && WizardPlugin.this .pem_cForm.pdm_post != null)
062: if (WizardPlugin.this .pem_cForm.pdm_post
063: .pcmf_doPrePost(
064: WizardPlugin.this ,
065: IWizardPrePostAction.CSC_WIZ_POSTACTION,
066: IWizardPrePostAction.CSC_WIZ_END) == false)
067: return;
068:
069: WizardPlugin.this .pcmf_save();
070: }
071: }
072:
073: class AbortListener implements IUnGuiEventListener {
074: public void pcmf_execListener(UnComponent xParam)
075: throws Exception {
076: WizardPlugin.this .pcmf_abort();
077: }
078: }
079:
080: class GoNextListener implements IUnGuiEventListener {
081: public void pcmf_execListener(UnComponent xParam)
082: throws Exception {
083: WizardPlugin.this .pemf_setNextForm();
084: }
085: }
086:
087: class GoPrevListener implements IUnGuiEventListener {
088: public void pcmf_execListener(UnComponent xParam)
089: throws Exception {
090: WizardPlugin.this .pemf_setPrevForm();
091: }
092: }
093:
094: public class WizardForm {
095: protected boolean pdm_preB = true;
096: protected boolean pdm_postB = true;
097: protected boolean pdm_saveB = true;
098: protected boolean pdm_abortB = true;
099:
100: protected IWizardPrePostAction pdm_pre = null;
101: protected IWizardPrePostAction pdm_post = null;
102:
103: protected UnComponent pdm_wizForm = null;
104: protected boolean pdm_isActive = true;
105: protected String pdm_title = "";
106:
107: public WizardForm(String xTitle, boolean xPreB, boolean xNextB,
108: boolean xSaveB, boolean xAbortB,
109: IWizardPrePostAction xPre, IWizardPrePostAction xPost,
110: UnComponent xWizForm, boolean xIsActive) {
111: this .pdm_preB = xPreB;
112: this .pdm_postB = xNextB;
113: this .pdm_saveB = xSaveB;
114: this .pdm_abortB = xAbortB;
115: this .pdm_pre = xPre;
116: this .pdm_post = xPost;
117: this .pdm_wizForm = xWizForm;
118: this .pdm_isActive = xIsActive;
119: this .pdm_title = xTitle;
120: }
121:
122: public void pcmf_setActive(boolean xActive) {
123: this .pdm_isActive = xActive;
124: }
125: }
126:
127: private IUnButton pem_prevB = null;
128: private IUnButton pem_nextB = null;
129: private IUnButton pem_abortB = null;
130: private IUnButton pem_saveB = null;
131: private IUnTextArea pem_mess = null;
132: private IUnLabel pem_ftitle = null;
133: private IWizardAuthentificator pem_auth = null;
134: private IWizardInit pem_init = null;
135: private IUnDialog pem_dlgFrame = null;
136: private String pem_title = "";
137:
138: private LinkedHashMap pem_forms = new LinkedHashMap();
139: private int pem_cIndex = -1;
140: private UnComponent pem_main = null;
141: private WizardForm pem_cForm = null;
142: private ArrayList pem_abort = null;
143: private ArrayList pem_save = null;
144:
145: private int pem_max = 0;
146: private int pem_current = 0;
147:
148: public void pcmf_addWizForm(String xId, String xTitle,
149: boolean xPreB, boolean xNextB, boolean xSaveB,
150: boolean xAbortB, IWizardPrePostAction xPre,
151: IWizardPrePostAction xPost, UnComponent xWizForm,
152: boolean xIsActive) {
153: xWizForm.pcmf_hide();
154: this .pem_forms.put(xId, new WizardForm(xTitle, xPreB, xNextB,
155: xSaveB, xAbortB, xPre, xPost, xWizForm, xIsActive));
156: }
157:
158: public void pcmf_showMessages(boolean xShow) {
159: if (xShow)
160: this .pem_mess.pcmf_unhide();
161: else
162: this .pem_mess.pcmf_hide();
163: }
164:
165: public void pcmf_setMessage(String xMessage) {
166: this .pem_mess.pcmf_setValue(xMessage);
167: }
168:
169: public void pcmf_addMessage(String xMessage) {
170: Object l_old = this .pem_mess.pcmf_getValue();
171: if (l_old == null || l_old.toString().trim().equals(""))
172: this .pcmf_setMessage(xMessage);
173: else
174: this .pcmf_setMessage(l_old + "\n" + xMessage);
175: }
176:
177: public String pcmf_getMessages() {
178: return ((String) this .pem_mess.pcmf_getValue());
179: }
180:
181: public void pcmf_setAbortLabel(String xLabel, String xKey) {
182: this .pem_abortB.pcmf_setValue(xLabel);
183: this .pem_abortB.pcmf_setKeyAccess(xKey.charAt(0));
184: }
185:
186: public void pcmf_setSaveLabel(String xLabel, String xKey) {
187: this .pem_saveB.pcmf_setValue(xLabel);
188: this .pem_saveB.pcmf_setKeyAccess(xKey.charAt(0));
189: }
190:
191: public void pcmf_setPrevLabel(String xLabel, String xKey) {
192: this .pem_prevB.pcmf_setValue(xLabel);
193: this .pem_prevB.pcmf_setKeyAccess(xKey.charAt(0));
194: }
195:
196: public void pcmf_setNextLabel(String xLabel, String xKey) {
197: this .pem_nextB.pcmf_setValue(xLabel);
198: this .pem_nextB.pcmf_setKeyAccess(xKey.charAt(0));
199: }
200:
201: public void pcmf_addAbortHandler(IWizardAbort xHdl) {
202: if (this .pem_abort == null)
203: this .pem_abort = new ArrayList();
204:
205: this .pem_abort.add(xHdl);
206: }
207:
208: public void pcmf_addSaveHandler(IWizardSave xHdl) {
209: if (this .pem_save == null)
210: this .pem_save = new ArrayList();
211:
212: this .pem_save.add(xHdl);
213: }
214:
215: public void pcmf_clearAbortHander() {
216: this .pem_abort = null;
217: }
218:
219: public void pcmf_clearSaveHander() {
220: this .pem_save = null;
221: }
222:
223: public void pcmf_setTitle(String xTitle) {
224: this .pem_title = xTitle;
225: }
226:
227: public WizardForm pcmf_getFormById(String xId) {
228: return ((WizardForm) this .pem_forms.get(xId));
229: }
230:
231: public int pcmf_getCurrent() {
232: return (this .pem_current);
233: }
234:
235: public WizardForm pcmf_getCurrectForm() {
236: return (this .pem_cForm);
237: }
238:
239: private String pemf_calculateWizState() {
240: ArrayList l_list = new ArrayList(this .pem_forms.values());
241: int l_current = 0;
242: int l_max = 0;
243: for (int i = 0; i < l_list.size(); i++) {
244: WizardForm l_wform = (WizardForm) l_list.get(i);
245: if (l_wform.pdm_isActive == true) {
246: l_max++;
247: if (l_wform == this .pem_cForm)
248: l_current = l_max;
249:
250: }
251: }
252: this .pem_current = l_current;
253: this .pem_max = l_max;
254: return ("(" + l_current + "/" + l_max + ")");
255: }
256:
257: public boolean pcmf_toForm(String xId, boolean xExecPre,
258: boolean xExecPost) {
259: this .pem_mess.pcmf_setValue("");
260:
261: if (this .pem_cForm != null && this .pem_cForm.pdm_post != null
262: && xExecPost)
263: if (this .pem_cForm.pdm_post.pcmf_doPrePost(this ,
264: IWizardPrePostAction.CSC_WIZ_POSTACTION,
265: IWizardPrePostAction.CSC_WIZ_DIRECT) == false)
266: return (false);
267:
268: WizardForm l_wform = (WizardForm) this .pem_forms.get(xId);
269: this .pem_cIndex = new ArrayList(this .pem_forms.values())
270: .indexOf(l_wform);
271: l_wform.pdm_isActive = true;
272:
273: KeTreeNode l_node = this .pem_main.pcmf_removeNode("WIZFORM");
274: if (l_node != null)
275: l_node.pcmf_hide();
276:
277: l_wform.pdm_wizForm.pcmf_unhide();
278:
279: this .pem_main.pcmf_addNode("WIZFORM", l_wform.pdm_wizForm, 0);
280: this .pem_main.pcmf_repaint();
281:
282: this .pem_cForm = l_wform;
283: this .pem_ftitle.pcmf_setValue(l_wform.pdm_title + " - "
284: + this .pemf_calculateWizState());
285: this .pemf_setButtons(l_wform);
286: this .pemf_disbaleNavButtonsIfNeed();
287:
288: if (this .pem_cForm != null && this .pem_cForm.pdm_pre != null
289: && xExecPre)
290: this .pem_cForm.pdm_pre.pcmf_doPrePost(this ,
291: IWizardPrePostAction.CSC_WIZ_PREACTION,
292: IWizardPrePostAction.CSC_WIZ_DIRECT);
293:
294: this .pem_mess.pcmf_setValue("");
295:
296: if (this .pem_current == this .pem_max)
297: this .pem_saveB.pcmf_requestFocus();
298:
299: return (true);
300: }
301:
302: public void pcmf_setAuthentifikator(IWizardAuthentificator xAuth) {
303: this .pem_auth = xAuth;
304: }
305:
306: public void pcmf_setInit(IWizardInit xInit) {
307: this .pem_init = xInit;
308: }
309:
310: public void pcmf_setDlgFrame(IUnDialog xDlg) {
311: this .pem_dlgFrame = xDlg;
312: }
313:
314: private void pemf_disbaleNavButtonsIfNeed() {
315: if (this .pem_current == this .pem_max)
316: this .pem_nextB.pcmf_disable();
317: if (this .pem_current == 1)
318: this .pem_prevB.pcmf_disable();
319: }
320:
321: private void pemf_setButtons(WizardForm xForm) {
322: if (xForm.pdm_preB)
323: this .pem_prevB.pcmf_enable();
324: else
325: this .pem_prevB.pcmf_disable();
326:
327: if (xForm.pdm_postB)
328: this .pem_nextB.pcmf_enable();
329: else
330: this .pem_nextB.pcmf_disable();
331:
332: if (xForm.pdm_saveB)
333: this .pem_saveB.pcmf_enable();
334: else
335: this .pem_saveB.pcmf_disable();
336:
337: if (xForm.pdm_abortB)
338: this .pem_abortB.pcmf_enable();
339: else
340: this .pem_abortB.pcmf_disable();
341: }
342:
343: private void pemf_setNextForm() {
344: this .pem_mess.pcmf_setValue("");
345:
346: if (this .pem_cForm != null && this .pem_cForm.pdm_post != null)
347: if (this .pem_cForm.pdm_post.pcmf_doPrePost(this ,
348: IWizardPrePostAction.CSC_WIZ_POSTACTION,
349: IWizardPrePostAction.CSC_WIZ_NEXT) == false)
350: return;
351:
352: ArrayList l_list = new ArrayList(this .pem_forms.values());
353: Iterator l_it = l_list.iterator();
354: for (int i = 0; i <= this .pem_cIndex; i++)
355: l_it.next();
356: WizardForm l_wform = null;
357:
358: while (l_it.hasNext()) {
359: this .pem_cIndex++;
360: l_wform = (WizardForm) l_it.next();
361: if (l_wform.pdm_isActive)
362: break;
363: }
364: KeTreeNode l_node = this .pem_main.pcmf_removeNode("WIZFORM");
365: if (l_node != null)
366: l_node.pcmf_hide();
367:
368: l_wform.pdm_wizForm.pcmf_unhide();
369:
370: this .pem_main.pcmf_addNode("WIZFORM", l_wform.pdm_wizForm, 0);
371: this .pem_main.pcmf_repaint();
372:
373: this .pem_cForm = l_wform;
374: this .pem_ftitle.pcmf_setValue(l_wform.pdm_title + " - "
375: + this .pemf_calculateWizState());
376: this .pemf_setButtons(l_wform);
377: this .pemf_disbaleNavButtonsIfNeed();
378:
379: if (this .pem_cForm != null && this .pem_cForm.pdm_pre != null)
380: this .pem_cForm.pdm_pre.pcmf_doPrePost(this ,
381: IWizardPrePostAction.CSC_WIZ_PREACTION,
382: IWizardPrePostAction.CSC_WIZ_NEXT);
383:
384: this .pem_mess.pcmf_setValue("");
385:
386: if (this .pem_current == this .pem_max)
387: this .pem_saveB.pcmf_requestFocus();
388: }
389:
390: private void pemf_setPrevForm() {
391: this .pem_mess.pcmf_setValue("");
392:
393: if (this .pem_cForm != null && this .pem_cForm.pdm_post != null)
394: if (this .pem_cForm.pdm_post.pcmf_doPrePost(this ,
395: IWizardPrePostAction.CSC_WIZ_POSTACTION,
396: IWizardPrePostAction.CSC_WIZ_PREV) == false)
397: return;
398:
399: ArrayList l_list = new ArrayList(this .pem_forms.values());
400: ListIterator l_it = l_list.listIterator(this .pem_cIndex);
401: WizardForm l_wform = null;
402: while (l_it.hasPrevious()) {
403: l_wform = (WizardForm) l_it.previous();
404: this .pem_cIndex--;
405: if (l_wform.pdm_isActive)
406: break;
407: }
408: KeTreeNode l_node = this .pem_main.pcmf_removeNode("WIZFORM");
409: if (l_node != null)
410: l_node.pcmf_hide();
411:
412: l_wform.pdm_wizForm.pcmf_unhide();
413: this .pem_main.pcmf_addNode("WIZFORM", l_wform.pdm_wizForm, 0);
414: this .pem_main.pcmf_repaint();
415:
416: this .pem_cForm = l_wform;
417: this .pem_ftitle.pcmf_setValue(l_wform.pdm_title + " - "
418: + this .pemf_calculateWizState());
419: this .pemf_setButtons(l_wform);
420: this .pemf_disbaleNavButtonsIfNeed();
421:
422: if (this .pem_cForm != null && this .pem_cForm.pdm_pre != null)
423: this .pem_cForm.pdm_pre.pcmf_doPrePost(this ,
424: IWizardPrePostAction.CSC_WIZ_PREACTION,
425: IWizardPrePostAction.CSC_WIZ_PREV);
426:
427: this .pem_mess.pcmf_setValue("");
428: }
429:
430: public boolean pcmf_start() throws Exception {
431: boolean l_ret = true;
432: this .pemf_setNextForm();
433:
434: this .pem_dlgFrame.pcmf_clear();
435: UnFixedSize l_fs = this .pcmf_getPluginObject()
436: .pcmf_getFixedSize();
437: this .pem_dlgFrame.pcmf_setPosition(100, 50,
438: l_fs.pcmf_getW() + 4, l_fs.pcmf_getH() + 40);
439: this .pem_dlgFrame
440: .pcmf_setCommonLayout(IUnLayouted.LAYOUT_GRIDBAG);
441: this .pem_dlgFrame.pcmf_addWidget("1", this
442: .pcmf_getPluginObject());
443: this .pem_dlgFrame.pcmf_setGuiObjPosition("1", 0, 0, 1, 1,
444: "WEST");
445: this .pem_dlgFrame.pcmf_setWeights("1", 100, 100);
446: this .pem_dlgFrame.pcmf_setFill("1", true, true);
447: this .pem_dlgFrame.pcmf_setTitle(this .pem_title);
448:
449: if (this .pem_auth != null)
450: l_ret = this .pem_auth.pcmf_doAuthentification(this );
451:
452: if (l_ret == true) {
453: if (this .pem_init != null)
454: this .pem_init.pcmf_init(this );
455:
456: this .pem_dlgFrame.pcmf_displayDialog();
457: } else
458: this .pcmf_delete();
459:
460: return (l_ret);
461: }
462:
463: private void pemf_decorate() {
464: UnComponent l_plo = this .pcmf_getPluginObject();
465: this .pem_main = l_plo;
466: UnFixedSize l_fs = l_plo.pcmf_getFixedSize();
467:
468: IUnBox l_bBox = IUnBox.Factory.create(IUnBox.HBOX);
469: l_bBox.pcmf_setFixedSize(l_fs.pcmf_getW(), 37,
470: UnFixedSize.FIX_SIZE);
471:
472: this .pem_mess.pcmf_setFgColor("red");
473: this .pem_mess.pcmf_setReadOnly(true);
474: this .pem_ftitle = IUnLabel.Factory.create("");
475:
476: this .pem_nextB.pcmf_addListener(new GoNextListener());
477: this .pem_prevB.pcmf_addListener(new GoPrevListener());
478: this .pem_saveB.pcmf_addListener(new SaveListener());
479: this .pem_abortB.pcmf_addListener(new AbortListener());
480:
481: IUnBox l_bBox2 = IUnBox.Factory.create(IUnBox.HBOX);
482: l_bBox2.pcmf_setGap(5);
483:
484: l_bBox.pcmf_addWidget("1", l_bBox2);
485:
486: l_bBox2.pcmf_addWidget("1", this .pem_prevB);
487: l_bBox2.pcmf_addWidget("2", this .pem_nextB);
488: l_bBox2.pcmf_addWidget("3", this .pem_abortB);
489: l_bBox2.pcmf_addWidget("4", this .pem_saveB);
490:
491: IUnBox l_mBox = IUnBox.Factory.create(IUnBox.VBOX);
492: l_bBox.pcmf_setGap(5);
493:
494: this .pcmf_setPluginObject(l_mBox.pcmf_getUnComponent());
495: l_mBox.pcmf_addWidget("0", this .pem_ftitle);
496: l_mBox.pcmf_addWidget("1", l_plo);
497: l_mBox.pcmf_addWidget("2", this .pem_mess);
498: l_mBox.pcmf_addWidget("3", l_bBox);
499:
500: l_mBox.pcmf_setFixedSize(l_fs.pcmf_getW() + 2,
501: l_fs.pcmf_getH() + 100, l_fs.pcmf_getType());
502: this .pem_mess.pcmf_setFixedSize(l_fs.pcmf_getW(), 60, l_fs
503: .pcmf_getType());
504: }
505:
506: public void pcmf_initPlugin(UnComponent xPl, Object xParam,
507: String xRoot) {
508: super .pcmf_initPlugin(xPl, xParam, xRoot);
509: this .pemf_decorate();
510: }
511:
512: public void pcmf_abort() {
513: try {
514: if (this .pem_abort != null) {
515: Iterator l_it = this .pem_abort.iterator();
516: while (l_it.hasNext()) {
517: IWizardAbort l_abort = (IWizardAbort) l_it.next();
518: boolean l_ret = l_abort.pcmf_abort(this );
519: if (l_ret == false)
520: return;
521: }
522: }
523: this .pem_dlgFrame.pcmf_hideDialog();
524: this .pcmf_delete();
525: } catch (Exception e) {
526: KeLog.pcmf_log("csc", "error aborting workflow", this ,
527: KeLog.APPL);
528: }
529: }
530:
531: public void pcmf_save() {
532: try {
533: if (this .pem_save != null) {
534: Iterator l_it = this .pem_save.iterator();
535: while (l_it.hasNext()) {
536: IWizardSave l_save = (IWizardSave) l_it.next();
537: boolean l_ret = l_save.pcmf_save(this );
538: if (l_ret == false)
539: break;
540: }
541: }
542:
543: this .pem_dlgFrame.pcmf_hideDialog();
544: this .pcmf_delete();
545: } catch (Exception e) {
546: KeLog.pcmf_log("csc", "error saving workflow", this ,
547: KeLog.APPL);
548: }
549: }
550:
551: public void pcmf_delete() throws Exception {
552: Iterator l_it = this .pem_forms.values().iterator();
553: while (l_it.hasNext()) {
554: WizardForm l_wf = (WizardForm) l_it.next();
555: l_wf.pdm_wizForm.pcmf_clearAndRelease();
556: }
557: this.pem_forms.clear();
558: super.pcmf_delete();
559: }
560: }
|