summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/ui/WizardDialog.java
blob: 15b840fa9c89490c11a68b0868653336a5ffef97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: WizardDialog.java,v $
 * $Revision: 1.20 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
package com.sun.star.wizards.ui;

import java.beans.*;

import com.sun.star.wizards.ui.event.CommonListener;
import com.sun.star.wizards.ui.event.EventNames;
import com.sun.star.wizards.ui.event.MethodInvocation;
import com.sun.star.uno.UnoRuntime;
// import com.sun.star.awt.XItemEventBroadcaster;
import com.sun.star.awt.*;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.XInterface;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.wizards.common.Desktop;
import com.sun.star.wizards.common.Helper;
import com.sun.star.wizards.common.Resource;
import com.sun.star.container.XIndexContainer;
import com.sun.star.frame.XTerminateListener;
import com.sun.star.frame.TerminationVetoException;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.beans.*;

public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeListener, XTerminateListener, XCompletion
{

    private static final String NEXT_ACTION_PERFORMED = "gotoNextAvailableStep";
    private static final String BACK_ACTION_PERFORMED = "gotoPreviousAvailableStep";
    private static final String FINISH_ACTION_PERFORMED = "finishWizard_1";
    private static final String CANCEL_ACTION_PERFORMED = "cancelWizard_1";
    private static final String HELP_ACTION_PERFORMED = "callHelp";
    public VetoableChangeSupport vetos = new VetoableChangeSupport(this);
    private String[] sRightPaneHeaders;
    private int iButtonWidth = 50;
    private int nNewStep = 1;
    private int nOldStep = 1;
    private int nMaxStep = 1;
    protected XItemListener RoadmapItemListener;
    protected XControl xRoadmapControl;
    XItemEventBroadcaster xRoadmapBroadcaster;
    String[] sRMItemLabels;
    private Object oRoadmap;
    private XSingleServiceFactory xSSFRoadmap;
    public XIndexContainer xIndexContRoadmap;
    private Resource oWizardResource;
    public String sMsgEndAutopilot;
    private int hid;
    private boolean bTerminateListenermustberemoved = true;

    /** Creates a new instance of WizardDialog
     * the hid is used as following :
     * "HID:(hid)"   - the dialog
     * "HID:(hid+1)  - the help button
     * "HID:(hid+2)" - the back button
     * "HID:(hid+3)" - the next button
     * "HID:(hid+4)" - the create button
     * "HID:(hid+5)" - the cancel button
     * @param xMSF
     * @param hid_
     */
    public WizardDialog(XMultiServiceFactory xMSF, int hid_)
    {
        super(xMSF);
        hid = hid_;
        oWizardResource = new Resource(xMSF, "Common", "dbw");
        sMsgEndAutopilot = oWizardResource.getResText(UIConsts.RID_DB_COMMON + 33);

    //new Resource(xMSF,"Common","com");
    }

    /**
     *
     * @return
     */
    public Resource getResource()
    {
        return oWizardResource;
    }

    public void activate()
    {
        try
        {
            XTopWindow top = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, xWindow);
            if (top != null)
            {
                top.toFront();
            }
        }
        catch (Exception ex)
        {
            // do nothing;
        }
    }

    public void setMaxStep(int i)
    {
        nMaxStep = i;
    }

    public int getMaxStep()
    {
        return nMaxStep;
    }

    public void setOldStep(int i)
    {
        nOldStep = i;
    }

    public int getOldStep()
    {
        return nOldStep;
    }

    public void setNewStep(int i)
    {
        nNewStep = i;
    }

    public int getNewStep()
    {
        return nNewStep;
    }

    /**
     * @see java.beans.VetoableChangeListener#vetoableChange(java.beans.PropertyChangeEvent)
     */
    public void vetoableChange(java.beans.PropertyChangeEvent arg0)
    {
        nNewStep = nOldStep;
    }

    public void itemStateChanged(com.sun.star.awt.ItemEvent itemEvent)
    {
        try
        {
            nNewStep = itemEvent.ItemId;
            nOldStep = AnyConverter.toInt(Helper.getUnoPropertyValue(xDialogModel, "Step"));
            if (nNewStep != nOldStep)
            {
                switchToStep();
            }
        }
        catch (com.sun.star.lang.IllegalArgumentException exception)
        {
            exception.printStackTrace(System.out);
        }
    }

    public void setRoadmapInteractive(boolean _bInteractive)
    {
        Helper.setUnoPropertyValue(oRoadmap, "Activated", new Boolean(_bInteractive));
    }

    public void setRoadmapComplete(boolean bComplete)
    {
        Helper.setUnoPropertyValue(oRoadmap, "Complete", new Boolean(bComplete));
    }

    public boolean isRoadmapComplete()
    {
        try
        {
            return AnyConverter.toBoolean(Helper.getUnoPropertyValue(oRoadmap, "Complete"));
        }
        catch (IllegalArgumentException exception)
        {
            exception.printStackTrace(System.out);
            return false;
        }
    }

    public void setCurrentRoadmapItemID(short ID)
    {
        if (oRoadmap != null)
        {
            int nCurItemID = getCurrentRoadmapItemID();
            if (nCurItemID != ID)
            {
                Helper.setUnoPropertyValue(oRoadmap, "CurrentItemID", new Short(ID));
            }
        }
    }

    public int getCurrentRoadmapItemID()
    {
        try
        {
            return AnyConverter.toInt(Helper.getUnoPropertyValue(oRoadmap, "CurrentItemID"));
        }
        catch (com.sun.star.uno.Exception exception)
        {
            exception.printStackTrace(System.out);
            return -1;
        }
    }

    public void addRoadmap()
    {
        try
        {
            int iDialogHeight = ((Integer) Helper.getUnoPropertyValue(this.xDialogModel, "Height")).intValue();

            // the roadmap control has got no real TabIndex ever
            // that is not correct, but changing this would need time, so it is used
            // without TabIndex as before
            oRoadmap = insertControlModel("com.sun.star.awt.UnoControlRoadmapModel", "rdmNavi",
                    new String[]
                    {
                        "Height",
                        "PositionX",
                        "PositionY",
                        "Step",
                        "TabIndex",
                        "Tabstop",
                        "Width"
                    },
                    new Object[]
                    {
                        new Integer(iDialogHeight - 26),
                        new Integer(0),
                        new Integer(0),
                        new Integer(0),
                        new Short((short)0),
                        Boolean.TRUE,
                        new Integer(85)
                    });
            XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oRoadmap);
            xPSet.setPropertyValue("Name", "rdmNavi");

            xSSFRoadmap = (XSingleServiceFactory) UnoRuntime.queryInterface(XSingleServiceFactory.class, oRoadmap);
            xIndexContRoadmap = (XIndexContainer) UnoRuntime.queryInterface(XIndexContainer.class, oRoadmap);
            //    XPropertySet xPropRoadmapModel = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oRoadmap);
            //    xPropRoadmapModel.addPropertyChangeListener("CurrentItemID", new WizardDialog.RoadmapItemListener(this.xDialogModel));

            MethodInvocation mi = new MethodInvocation("itemStateChanged", this, com.sun.star.awt.ItemEvent.class);
            getGuiEventListener().add("rdmNavi", EventNames.EVENT_ITEM_CHANGED, mi);
            xRoadmapControl = this.xDlgContainer.getControl("rdmNavi");
            xRoadmapBroadcaster = (XItemEventBroadcaster) UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRoadmapControl);
            xRoadmapBroadcaster.addItemListener((XItemListener) getGuiEventListener());

            //     xRoadmapControl = this.xDlgContainer.getControl("rdmNavi");
            //     xRoadmapBroadcaster.addItemListener(new RoadmapItemListener());
            Helper.setUnoPropertyValue(oRoadmap, "Text", oWizardResource.getResText(UIConsts.RID_COMMON + 16));
        }
        catch (NoSuchMethodException ex)
        {
            Resource.showCommonResourceError(xMSF);
        }
        catch (java.lang.Exception jexception)
        {
            jexception.printStackTrace(System.out);
        }
    }

    public void setRMItemLabels(Resource _oResource, int StartResID)
    {
        sRMItemLabels = _oResource.getResArray(StartResID, nMaxStep);
    }

    public String[] getRMItemLabels()
    {
        return sRMItemLabels;
    }

    /*    public void insertRoadmapItems(int StartIndex, int RMCount)
    {
    Object oRoadmapItem;
    boolean bEnabled;
    for (int i = StartIndex; i < (StartIndex + RMCount); i++)
    insertSingleRoadmapItem(i, true, sRMItemLabels[i], i);
    }*/
    public int insertRoadmapItem(int _Index, boolean _bEnabled, int _LabelID, int _CurItemID)
    {
        return insertRoadmapItem(_Index, _bEnabled, sRMItemLabels[_LabelID], _CurItemID);
    }

    public int insertRoadmapItem(int Index, boolean _bEnabled, String _sLabel, int _CurItemID)
    {
        try
        {
            Object oRoadmapItem = xSSFRoadmap.createInstance();
            Helper.setUnoPropertyValue(oRoadmapItem, "Label", _sLabel);
            Helper.setUnoPropertyValue(oRoadmapItem, "Enabled", new Boolean(_bEnabled));
            Helper.setUnoPropertyValue(oRoadmapItem, "ID", new Integer(_CurItemID));
            xIndexContRoadmap.insertByIndex(Index, oRoadmapItem);
            int NextIndex = Index + 1;
            return NextIndex;
        }
        catch (com.sun.star.uno.Exception exception)
        {
            exception.printStackTrace(System.out);
            return -1;
        }
    }

    public int getRMItemCount()
    {
        return xIndexContRoadmap.getCount();
    }

    public XInterface getRoadmapItemByID(int _ID)
    {
        try
        {
            int CurID;
            XInterface CurRoadmapItem;
            for (int i = 0; i < xIndexContRoadmap.getCount(); i++)
            {
                CurRoadmapItem = (XInterface) xIndexContRoadmap.getByIndex(i);
                CurID = AnyConverter.toInt(Helper.getUnoPropertyValue(CurRoadmapItem, "ID"));
                if (CurID == _ID)
                {
                    return CurRoadmapItem;
                }
            }
            return null;
        }
        catch (com.sun.star.uno.Exception exception)
        {
            exception.printStackTrace(System.out);
            return null;
        }
    }

    public boolean switchToStep(int _nOldStep, int _nNewStep)
    {
        nOldStep = _nOldStep;
        nNewStep = _nNewStep;
        return switchToStep();
    }

    private boolean switchToStep()
    {
        leaveStep(nOldStep, nNewStep);
        if (nNewStep != nOldStep)
        {
            if (nNewStep == nMaxStep)
            {
                setControlProperty("btnWizardNext", "DefaultButton", Boolean.FALSE);
                setControlProperty("btnWizardFinish", "DefaultButton", Boolean.TRUE);
            }
            else
            {
                setControlProperty("btnWizardNext", "DefaultButton", Boolean.TRUE);
                setControlProperty("btnWizardFinish", "DefaultButton", Boolean.FALSE);
            }
            changeToStep(nNewStep);
            enterStep(nOldStep, nNewStep);
            return true;
        }
        return false;
    }

    abstract protected void leaveStep(int nOldStep, int nNewStep);

    abstract protected void enterStep(int nOldStep, int nNewStep);

    protected void changeToStep(int nNewStep)
    {
        Helper.setUnoPropertyValue(xDialogModel, "Step", new Integer(nNewStep));
        setCurrentRoadmapItemID((short) (nNewStep));
        enableNextButton(getNextAvailableStep() > 0);
        enableBackButton(nNewStep != 1);
    }


    /* (non-Javadoc)
     * @see com.sun.star.wizards.ui.XCompletion#iscompleted(int)
     */
    /**
     *
     * @param _ndialogpage
     * @return
     */
    public boolean iscompleted(int _ndialogpage)
    {
        return false;
    }
    /* (non-Javadoc)
     * @see com.sun.star.wizards.ui.XCompletion#ismodified(int)
     */

    /**
     *
     * @param _ndialogpage
     * @return
     */
    public boolean ismodified(int _ndialogpage)
    {
        return false;
    }
    /* (non-Javadoc)
     * @see com.sun.star.wizards.ui.XCompletion#setcompleted(int, boolean)
     */

    /**
     *
     * @param _ndialogpage
     * @param _biscompleted
     */
    public void setcompleted(int _ndialogpage, boolean _biscompleted)
    {
    }
    /* (non-Javadoc)
     * @see com.sun.star.wizards.ui.XCompletion#setmodified(int, java.lang.Object, java.lang.Object)
     */

    /**
     *
     * @param _ndialogpage
     * @param ooldValue
     * @param onewValue
     */
    public void setmodified(int _ndialogpage, Object ooldValue, Object onewValue)
    {
    }

    public void drawNaviBar()
    {

        try
        {
            short curtabindex = UIConsts.SOFIRSTWIZARDNAVITABINDEX;
            Integer IButtonWidth = new Integer(iButtonWidth);
            int iButtonHeight = 14;
            Integer IButtonHeight = new Integer(iButtonHeight);
            Integer ICurStep = new Integer(0);
            int iDialogHeight = ((Integer) Helper.getUnoPropertyValue(this.xDialogModel, "Height")).intValue();
            int iDialogWidth = ((Integer) Helper.getUnoPropertyValue(this.xDialogModel, "Width")).intValue();
            int iHelpPosX = 8;
            int iBtnPosY = iDialogHeight - iButtonHeight - 6;
            int iCancelPosX = iDialogWidth - iButtonWidth - 6;
            int iFinishPosX = iCancelPosX - 6 - iButtonWidth;
            int iNextPosX = iFinishPosX - 6 - iButtonWidth;
            int iBackPosX = iNextPosX - 3 - iButtonWidth;

            insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "lnNaviSep",
                    new String[]
                    {
                        "Height", "Orientation", "PositionX", "PositionY", "Step", "Width"
                    },
                    new Object[]
                    {
                        new Integer(1), new Integer(0), new Integer(0), new Integer(iDialogHeight - 26), ICurStep, new Integer(iDialogWidth)
                    });

            insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "lnRoadSep",
                    new String[]
                    {
                        "Height", "Orientation", "PositionX", "PositionY", "Step", "Width"
                    },
                    new Object[]
                    {
                        new Integer(iBtnPosY - 6), new Integer(1), new Integer(85), new Integer(0), ICurStep, new Integer(1)
                    });

            String[] propNames = new String[]
            {
                "Enabled", "Height", "HelpURL", "Label", "PositionX", "PositionY", "PushButtonType", "Step", "TabIndex", "Width"
            };

            Helper.setUnoPropertyValue(super.xDialogModel, "HelpURL", "HID:" + hid);
            insertButton("btnWizardHelp", HELP_ACTION_PERFORMED, new String[]
                    {
                        "Enabled", "Height", "Label", "PositionX", "PositionY", "PushButtonType", "Step", "TabIndex", "Width"
                    },
                    new Object[]
                    {
                        new Boolean(true), IButtonHeight, oWizardResource.getResText(UIConsts.RID_COMMON + 15), new Integer(iHelpPosX), new Integer(iBtnPosY), new Short((short) PushButtonType.HELP_value), ICurStep, new Short(curtabindex++), IButtonWidth
                    });
            insertButton("btnWizardBack", BACK_ACTION_PERFORMED, propNames,
                    new Object[]
                    {
                        new Boolean(false), IButtonHeight, "HID:" + (hid + 2), oWizardResource.getResText(UIConsts.RID_COMMON + 13), new Integer(iBackPosX), new Integer(iBtnPosY), new Short((short) PushButtonType.STANDARD_value), ICurStep, new Short(curtabindex++), IButtonWidth
                    });

            insertButton("btnWizardNext", NEXT_ACTION_PERFORMED, propNames,
                    new Object[]
                    {
                        new Boolean(true), IButtonHeight, "HID:" + (hid + 3), oWizardResource.getResText(UIConsts.RID_COMMON + 14), new Integer(iNextPosX), new Integer(iBtnPosY), new Short((short) PushButtonType.STANDARD_value), ICurStep, new Short(curtabindex++), IButtonWidth
                    });

            insertButton("btnWizardFinish", FINISH_ACTION_PERFORMED, propNames,
                    new Object[]
                    {
                        new Boolean(true), IButtonHeight, "HID:" + (hid + 4), oWizardResource.getResText(UIConsts.RID_COMMON + 12), new Integer(iFinishPosX), new Integer(iBtnPosY), new Short((short) PushButtonType.STANDARD_value), ICurStep, new Short(curtabindex++), IButtonWidth
                    });

            insertButton("btnWizardCancel", CANCEL_ACTION_PERFORMED, propNames,
                    new Object[]
                    {
                        new Boolean(true), IButtonHeight, "HID:" + (hid + 5), oWizardResource.getResText(UIConsts.RID_COMMON + 11), new Integer(iCancelPosX), new Integer(iBtnPosY), new Short((short) PushButtonType.STANDARD_value), ICurStep, new Short(curtabindex++), IButtonWidth
                    });

            setControlProperty("btnWizardNext", "DefaultButton", Boolean.TRUE);
            // add a window listener, to know
            // if the user used "escape" key to
            // close the dialog.
            MethodInvocation windowHidden = new MethodInvocation("windowHidden", this);
            xWindow.addWindowListener((CommonListener) getGuiEventListener());
            String dialogName = (String) Helper.getUnoPropertyValue(xDialogModel, "Name");
            getGuiEventListener().add(dialogName, EVENT_ACTION_PERFORMED, windowHidden);

        }
        catch (java.lang.Exception jexception)
        {
            jexception.printStackTrace(System.out);
        }
    }

    protected void insertRoadMapItems(String[] items, int[] steps, boolean[] enabled)
    {
        for (int i = 0; i < items.length; i++)
        {
            insertRoadmapItem(i, enabled[i], items[i], steps[i]);
        }
    }

    /** This method also enables and disables the "next" button,
     * if the step currently dis/enabled is the one of the next steps.
     * @param _nStep
     * @param bEnabled
     * @param enableNextButton
     */
    public void setStepEnabled(int _nStep, boolean bEnabled, boolean enableNextButton)
    {
        setStepEnabled(_nStep, bEnabled);
        if (getNextAvailableStep() > 0)
        {
            enableNextButton(bEnabled);
        }
    }

    public void enableNavigationButtons(boolean _bEnableBack, boolean _bEnableNext, boolean _bEnableFinish)
    {
        enableBackButton(_bEnableBack);
        enableNextButton(_bEnableNext);
        enableFinishButton(_bEnableFinish);
    }

    public void enableBackButton(boolean enabled)
    {
        setControlProperty("btnWizardBack", "Enabled", enabled ? Boolean.TRUE : Boolean.FALSE);
    }

    public void enableNextButton(boolean enabled)
    {
        setControlProperty("btnWizardNext", "Enabled", enabled ? Boolean.TRUE : Boolean.FALSE);
    }

    public void enableFinishButton(boolean enabled)
    {
        setControlProperty("btnWizardFinish", "Enabled", enabled ? Boolean.TRUE : Boolean.FALSE);
    }

    public void setStepEnabled(int _nStep, boolean bEnabled)
    {
        XInterface xRoadmapItem = getRoadmapItemByID(_nStep);
        if (xRoadmapItem != null)
        {
            Helper.setUnoPropertyValue(xRoadmapItem, "Enabled", new Boolean(bEnabled));
        }
    }

    public void enablefromStep(int _iStep, boolean _bDoEnable)
    {
        if (_iStep <= this.nMaxStep)
        {
            for (int i = _iStep; i <= nMaxStep; i++)
            {
                setStepEnabled(i, _bDoEnable);
            }
            enableFinishButton(_bDoEnable);
            if (!_bDoEnable)
            {
                enableNextButton(_iStep > getCurrentStep() + 1);
            }
            else
            {
                enableNextButton(!(getCurrentStep() == nMaxStep));
            }
        }
    }

    public boolean isStepEnabled(int _nStep)
    {
        try
        {
            boolean bIsEnabled;
            XInterface xRoadmapItem = getRoadmapItemByID(_nStep);
            if (xRoadmapItem == null)
            // Todo: In this case an exception should be thrown
            {
                return false;
            }
            bIsEnabled = AnyConverter.toBoolean(Helper.getUnoPropertyValue(xRoadmapItem, "Enabled"));
            return bIsEnabled;
        }
        catch (com.sun.star.uno.Exception exception)
        {
            exception.printStackTrace(System.out);
            return false;
        }
    }

    public synchronized void gotoPreviousAvailableStep()
    {
        boolean bIsEnabled;
        if (nNewStep > 1)
        {
            nOldStep = nNewStep;
            nNewStep--;
            while (nNewStep > 0)
            {
                bIsEnabled = isStepEnabled(nNewStep);
                if (bIsEnabled)
                {
                    break;
                }
                nNewStep--;
            }
            if (nNewStep == 0) // Exception???
            {
                nNewStep = nOldStep;
            }
            switchToStep();
        }
    }

    //TODO discuss with rp
    protected int getNextAvailableStep()
    {
        if (isRoadmapComplete())
        {
            for (int i = nNewStep + 1; i <= nMaxStep; i++)
            {
                if (isStepEnabled(i))
                {
                    return i;
                }
            }
        }
        return -1;
    }

    public synchronized void gotoNextAvailableStep()
    {
        nOldStep = nNewStep;
        nNewStep = getNextAvailableStep();
        if (nNewStep > -1)
        {
            switchToStep();
        }
    }

    public abstract void finishWizard();

    /**
     * This function will call if the finish button is pressed on the UI.
     */
    public void finishWizard_1()
    {
        enableFinishButton(false);
        finishWizard();
        removeTerminateListener();
    }

    public int getMaximalStep()
    {
        return this.nMaxStep;
    }

    public int getCurrentStep()
    {
        try
        {
            return AnyConverter.toInt(Helper.getUnoPropertyValue(this.MSFDialogModel, "Step"));
        }
        catch (com.sun.star.uno.Exception exception)
        {
            exception.printStackTrace(System.out);
            return -1;
        }
    }

    public void setCurrentStep(int _nNewstep)
    {
        nNewStep = _nNewstep;
        changeToStep(nNewStep);
    }

    public void setRightPaneHeaders(Resource _oResource, int StartResID, int _nMaxStep)
    {
        String[] sRightPaneHeaders = _oResource.getResArray(StartResID, _nMaxStep);
        setRightPaneHeaders(sRightPaneHeaders);
    }

    public void setRightPaneHeaders(String[] _sRightPaneHeaders)
    {
        this.nMaxStep = _sRightPaneHeaders.length;
        this.sRightPaneHeaders = _sRightPaneHeaders;
        FontDescriptor oFontDesc = new FontDescriptor();
        oFontDesc.Weight = com.sun.star.awt.FontWeight.BOLD;

        for (int i = 0; i < sRightPaneHeaders.length; i++)
        {
            insertLabel("lblQueryTitle" + String.valueOf(i),
                    new String[]
                    {
                        "FontDescriptor", "Height", "Label", "MultiLine", "PositionX", "PositionY", "Step", "TabIndex", "Width"
                    },
                    new Object[]
                    {
                        oFontDesc, new Integer(16), sRightPaneHeaders[i], Boolean.TRUE, new Integer(91), new Integer(8), new Integer(i + 1), new Short((short) 12), new Integer(212)
                    });
        }
    }

    public void cancelWizard()
    {
        //can be overwritten by extending class
        xDialog.endExecute();
    }

    public void callHelp()
    {
        //should be overwritten by extending class
    }

    public void removeTerminateListener()
    {
        if (bTerminateListenermustberemoved)
        {
            Desktop.getDesktop(xMSF).removeTerminateListener(this);
            bTerminateListenermustberemoved = false;
        }
    }

    /**
     * called by the cancel button and
     * by the window hidden event.
     * if this method was not called before,
     * perform a cancel.
     */
    public void cancelWizard_1()
    {
        cancelWizard();
        removeTerminateListener();
    }

    public void windowHidden()
    {
        cancelWizard_1();
    }

    public void notifyTermination(EventObject arg0)
    {
        cancelWizard_1();
    }

    public void queryTermination(EventObject arg0)
            throws TerminationVetoException
    {
        activate();
        throw new TerminationVetoException();
    }

    public void disposing(EventObject arg0)
    {
        cancelWizard_1();
    }
}