1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.wizards.ui;
24 
25 import java.beans.*;
26 
27 import com.sun.star.wizards.ui.event.CommonListener;
28 import com.sun.star.wizards.ui.event.EventNames;
29 import com.sun.star.wizards.ui.event.MethodInvocation;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.awt.*;
32 import com.sun.star.uno.AnyConverter;
33 import com.sun.star.uno.XInterface;
34 import com.sun.star.lang.EventObject;
35 import com.sun.star.lang.XSingleServiceFactory;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.wizards.common.Desktop;
38 import com.sun.star.wizards.common.Helper;
39 import com.sun.star.wizards.common.Resource;
40 import com.sun.star.container.XIndexContainer;
41 import com.sun.star.frame.XTerminateListener;
42 import com.sun.star.frame.TerminationVetoException;
43 import com.sun.star.lang.IllegalArgumentException;
44 import com.sun.star.beans.*;
45 import com.sun.star.wizards.common.HelpIds;
46 import com.sun.star.wizards.common.PropertyNames;
47 
48 public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeListener, XTerminateListener, XCompletion
49 {
50 
51     private static final String NEXT_ACTION_PERFORMED = "gotoNextAvailableStep";
52     private static final String BACK_ACTION_PERFORMED = "gotoPreviousAvailableStep";
53     private static final String FINISH_ACTION_PERFORMED = "finishWizard_1";
54     private static final String CANCEL_ACTION_PERFORMED = "cancelWizard_1";
55     private static final String HELP_ACTION_PERFORMED = "callHelp";
56     public VetoableChangeSupport vetos = new VetoableChangeSupport(this);
57     private String[] sRightPaneHeaders;
58     private int iButtonWidth = 50;
59     private int nNewStep = 1;
60     private int nOldStep = 1;
61     private int nMaxStep = 1;
62     protected XItemListener RoadmapItemListener;
63     protected XControl xRoadmapControl;
64     XItemEventBroadcaster xRoadmapBroadcaster;
65     String[] sRMItemLabels;
66     private Object oRoadmap;
67     private XSingleServiceFactory xSSFRoadmap;
68     public XIndexContainer xIndexContRoadmap;
69     private Resource oWizardResource;
70     public String sMsgEndAutopilot;
71     private int hid;
72     private boolean bTerminateListenermustberemoved = true;
73 
74     /** Creates a new instance of WizardDialog
75      * the hid is used as following :
76      * "HID:(hid)"   - the dialog
77      * "HID:(hid+1)  - the help button
78      * "HID:(hid+2)" - the back button
79      * "HID:(hid+3)" - the next button
80      * "HID:(hid+4)" - the create button
81      * "HID:(hid+5)" - the cancel button
82      * @param xMSF
83      * @param hid_
84      */
WizardDialog(XMultiServiceFactory xMSF, int hid_)85     public WizardDialog(XMultiServiceFactory xMSF, int hid_)
86     {
87         super(xMSF);
88         hid = hid_;
89         oWizardResource = new Resource(xMSF, "Common", "dbw");
90         sMsgEndAutopilot = oWizardResource.getResText(UIConsts.RID_DB_COMMON + 33);
91 
92     //new Resource(xMSF,"Common","com");
93     }
94 
95     /**
96      *
97      * @return
98      */
getResource()99     public Resource getResource()
100     {
101         return oWizardResource;
102     }
103 
activate()104     public void activate()
105     {
106         try
107         {
108             XTopWindow top = UnoRuntime.queryInterface(XTopWindow.class, xWindow);
109             if (top != null)
110             {
111                 top.toFront();
112             }
113         }
114         catch (Exception ex)
115         {
116             // do nothing;
117         }
118     }
119 
setMaxStep(int i)120     public void setMaxStep(int i)
121     {
122         nMaxStep = i;
123     }
124 
getMaxStep()125     public int getMaxStep()
126     {
127         return nMaxStep;
128     }
129 
setOldStep(int i)130     public void setOldStep(int i)
131     {
132         nOldStep = i;
133     }
134 
getOldStep()135     public int getOldStep()
136     {
137         return nOldStep;
138     }
139 
setNewStep(int i)140     public void setNewStep(int i)
141     {
142         nNewStep = i;
143     }
144 
getNewStep()145     public int getNewStep()
146     {
147         return nNewStep;
148     }
149 
150     /**
151      * @see java.beans.VetoableChangeListener#vetoableChange(java.beans.PropertyChangeEvent)
152      */
vetoableChange(java.beans.PropertyChangeEvent arg0)153     public void vetoableChange(java.beans.PropertyChangeEvent arg0)
154     {
155         nNewStep = nOldStep;
156     }
157 
itemStateChanged(com.sun.star.awt.ItemEvent itemEvent)158     public void itemStateChanged(com.sun.star.awt.ItemEvent itemEvent)
159     {
160         try
161         {
162             nNewStep = itemEvent.ItemId;
163             nOldStep = AnyConverter.toInt(Helper.getUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_STEP));
164             if (nNewStep != nOldStep)
165             {
166                 switchToStep();
167             }
168         }
169         catch (com.sun.star.lang.IllegalArgumentException exception)
170         {
171             exception.printStackTrace(System.out);
172         }
173     }
174 
setRoadmapInteractive(boolean _bInteractive)175     public void setRoadmapInteractive(boolean _bInteractive)
176     {
177         Helper.setUnoPropertyValue(oRoadmap, "Activated", Boolean.valueOf(_bInteractive));
178     }
179 
setRoadmapComplete(boolean bComplete)180     public void setRoadmapComplete(boolean bComplete)
181     {
182         Helper.setUnoPropertyValue(oRoadmap, "Complete", Boolean.valueOf(bComplete));
183     }
184 
isRoadmapComplete()185     public boolean isRoadmapComplete()
186     {
187         try
188         {
189             return AnyConverter.toBoolean(Helper.getUnoPropertyValue(oRoadmap, "Complete"));
190         }
191         catch (IllegalArgumentException exception)
192         {
193             exception.printStackTrace(System.out);
194             return false;
195         }
196     }
197 
setCurrentRoadmapItemID(short ID)198     public void setCurrentRoadmapItemID(short ID)
199     {
200         if (oRoadmap != null)
201         {
202             int nCurItemID = getCurrentRoadmapItemID();
203             if (nCurItemID != ID)
204             {
205                 Helper.setUnoPropertyValue(oRoadmap, "CurrentItemID", new Short(ID));
206             }
207         }
208     }
209 
getCurrentRoadmapItemID()210     public int getCurrentRoadmapItemID()
211     {
212         try
213         {
214             return AnyConverter.toInt(Helper.getUnoPropertyValue(oRoadmap, "CurrentItemID"));
215         }
216         catch (com.sun.star.uno.Exception exception)
217         {
218             exception.printStackTrace(System.out);
219             return -1;
220         }
221     }
222 
addRoadmap()223     public void addRoadmap()
224     {
225         try
226         {
227             int iDialogHeight = ((Integer) Helper.getUnoPropertyValue(this.xDialogModel, PropertyNames.PROPERTY_HEIGHT)).intValue();
228 
229             // the roadmap control has got no real TabIndex ever
230             // that is not correct, but changing this would need time, so it is used
231             // without TabIndex as before
232             oRoadmap = insertControlModel("com.sun.star.awt.UnoControlRoadmapModel", "rdmNavi",
233                     new String[]
234                     {
235                         PropertyNames.PROPERTY_HEIGHT,
236                         PropertyNames.PROPERTY_POSITION_X,
237                         PropertyNames.PROPERTY_POSITION_Y,
238                         PropertyNames.PROPERTY_STEP,
239                         PropertyNames.PROPERTY_TABINDEX,
240                         "Tabstop",
241                         PropertyNames.PROPERTY_WIDTH
242                     },
243                     new Object[]
244                     {
245                         new Integer(iDialogHeight - 26),
246                         0,
247                         0,
248                         0,
249                         new Short((short)0),
250                         Boolean.TRUE,
251                         85
252                     });
253             XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, oRoadmap);
254             xPSet.setPropertyValue(PropertyNames.PROPERTY_NAME, "rdmNavi");
255 
256             xSSFRoadmap = UnoRuntime.queryInterface(XSingleServiceFactory.class, oRoadmap);
257             xIndexContRoadmap = UnoRuntime.queryInterface(XIndexContainer.class, oRoadmap);
258             //    XPropertySet xPropRoadmapModel = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oRoadmap);
259             //    xPropRoadmapModel.addPropertyChangeListener("CurrentItemID", new WizardDialog.RoadmapItemListener(this.xDialogModel));
260 
261             MethodInvocation mi = new MethodInvocation("itemStateChanged", this, com.sun.star.awt.ItemEvent.class);
262             getGuiEventListener().add("rdmNavi", EventNames.EVENT_ITEM_CHANGED, mi);
263             xRoadmapControl = this.xDlgContainer.getControl("rdmNavi");
264             xRoadmapBroadcaster = UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRoadmapControl);
265             xRoadmapBroadcaster.addItemListener((XItemListener) getGuiEventListener());
266 
267             //     xRoadmapControl = this.xDlgContainer.getControl("rdmNavi");
268             //     xRoadmapBroadcaster.addItemListener(new RoadmapItemListener());
269             Helper.setUnoPropertyValue(oRoadmap, "Text", oWizardResource.getResText(UIConsts.RID_COMMON + 16));
270         }
271         catch (NoSuchMethodException ex)
272         {
273             Resource.showCommonResourceError(xMSF);
274         }
275         catch (java.lang.Exception jexception)
276         {
277             jexception.printStackTrace(System.out);
278         }
279     }
280 
setRMItemLabels(Resource _oResource, int StartResID)281     public void setRMItemLabels(Resource _oResource, int StartResID)
282     {
283         sRMItemLabels = _oResource.getResArray(StartResID, nMaxStep);
284     }
285 
getRMItemLabels()286     public String[] getRMItemLabels()
287     {
288         return sRMItemLabels;
289     }
290 
291     /*    public void insertRoadmapItems(int StartIndex, int RMCount)
292     {
293     Object oRoadmapItem;
294     boolean bEnabled;
295     for (int i = StartIndex; i < (StartIndex + RMCount); i++)
296     insertSingleRoadmapItem(i, true, sRMItemLabels[i], i);
297     }*/
insertRoadmapItem(int _Index, boolean _bEnabled, int _LabelID, int _CurItemID)298     public int insertRoadmapItem(int _Index, boolean _bEnabled, int _LabelID, int _CurItemID)
299     {
300         return insertRoadmapItem(_Index, _bEnabled, sRMItemLabels[_LabelID], _CurItemID);
301     }
302 
insertRoadmapItem(int Index, boolean _bEnabled, String _sLabel, int _CurItemID)303     public int insertRoadmapItem(int Index, boolean _bEnabled, String _sLabel, int _CurItemID)
304     {
305         try
306         {
307             Object oRoadmapItem = xSSFRoadmap.createInstance();
308             Helper.setUnoPropertyValue(oRoadmapItem, PropertyNames.PROPERTY_LABEL, _sLabel);
309             Helper.setUnoPropertyValue(oRoadmapItem, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bEnabled));
310             Helper.setUnoPropertyValue(oRoadmapItem, "ID", new Integer(_CurItemID));
311             xIndexContRoadmap.insertByIndex(Index, oRoadmapItem);
312             return Index + 1;
313         }
314         catch (com.sun.star.uno.Exception exception)
315         {
316             exception.printStackTrace(System.out);
317             return -1;
318         }
319     }
320 
getRMItemCount()321     public int getRMItemCount()
322     {
323         return xIndexContRoadmap.getCount();
324     }
325 
getRoadmapItemByID(int _ID)326     public XInterface getRoadmapItemByID(int _ID)
327     {
328         try
329         {
330             int CurID;
331             XInterface CurRoadmapItem;
332             for (int i = 0; i < xIndexContRoadmap.getCount(); i++)
333             {
334                 CurRoadmapItem = (XInterface) xIndexContRoadmap.getByIndex(i);
335                 CurID = AnyConverter.toInt(Helper.getUnoPropertyValue(CurRoadmapItem, "ID"));
336                 if (CurID == _ID)
337                 {
338                     return CurRoadmapItem;
339                 }
340             }
341             return null;
342         }
343         catch (com.sun.star.uno.Exception exception)
344         {
345             exception.printStackTrace(System.out);
346             return null;
347         }
348     }
349 
switchToStep(int _nOldStep, int _nNewStep)350     public boolean switchToStep(int _nOldStep, int _nNewStep)
351     {
352         nOldStep = _nOldStep;
353         nNewStep = _nNewStep;
354         return switchToStep();
355     }
356 
switchToStep()357     private boolean switchToStep()
358     {
359         leaveStep(nOldStep, nNewStep);
360         if (nNewStep != nOldStep)
361         {
362             if (nNewStep == nMaxStep)
363             {
364                 setControlProperty("btnWizardNext", "DefaultButton", Boolean.FALSE);
365                 setControlProperty("btnWizardFinish", "DefaultButton", Boolean.TRUE);
366             }
367             else
368             {
369                 setControlProperty("btnWizardNext", "DefaultButton", Boolean.TRUE);
370                 setControlProperty("btnWizardFinish", "DefaultButton", Boolean.FALSE);
371             }
372             changeToStep(nNewStep);
373             enterStep(nOldStep, nNewStep);
374             return true;
375         }
376         return false;
377     }
378 
leaveStep(int nOldStep, int nNewStep)379     abstract protected void leaveStep(int nOldStep, int nNewStep);
380 
enterStep(int nOldStep, int nNewStep)381     abstract protected void enterStep(int nOldStep, int nNewStep);
382 
changeToStep(int nNewStep)383     protected void changeToStep(int nNewStep)
384     {
385         Helper.setUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_STEP, new Integer(nNewStep));
386         setCurrentRoadmapItemID((short) (nNewStep));
387         enableNextButton(getNextAvailableStep() > 0);
388         enableBackButton(nNewStep != 1);
389     }
390 
391 
392     /* (non-Javadoc)
393      * @see com.sun.star.wizards.ui.XCompletion#iscompleted(int)
394      */
395     /**
396      *
397      * @param _ndialogpage
398      * @return
399      */
iscompleted(int _ndialogpage)400     public boolean iscompleted(int _ndialogpage)
401     {
402         return false;
403     }
404     /* (non-Javadoc)
405      * @see com.sun.star.wizards.ui.XCompletion#ismodified(int)
406      */
407 
408     /**
409      *
410      * @param _ndialogpage
411      * @return
412      */
ismodified(int _ndialogpage)413     public boolean ismodified(int _ndialogpage)
414     {
415         return false;
416     }
417     /* (non-Javadoc)
418      * @see com.sun.star.wizards.ui.XCompletion#setcompleted(int, boolean)
419      */
420 
421     /**
422      *
423      * @param _ndialogpage
424      * @param _biscompleted
425      */
setcompleted(int _ndialogpage, boolean _biscompleted)426     public void setcompleted(int _ndialogpage, boolean _biscompleted)
427     {
428     }
429     /* (non-Javadoc)
430      * @see com.sun.star.wizards.ui.XCompletion#setmodified(int, java.lang.Object, java.lang.Object)
431      */
432 
433     /**
434      *
435      * @param _ndialogpage
436      * @param ooldValue
437      * @param onewValue
438      */
setmodified(int _ndialogpage, Object ooldValue, Object onewValue)439     public void setmodified(int _ndialogpage, Object ooldValue, Object onewValue)
440     {
441     }
442 
drawNaviBar()443     public void drawNaviBar()
444     {
445 
446         try
447         {
448             short curtabindex = UIConsts.SOFIRSTWIZARDNAVITABINDEX;
449             Integer IButtonWidth = new Integer(iButtonWidth);
450             int iButtonHeight = 14;
451             Integer IButtonHeight = new Integer(iButtonHeight);
452             Integer ICurStep = 0;
453             int iDialogHeight = ((Integer) Helper.getUnoPropertyValue(this.xDialogModel, PropertyNames.PROPERTY_HEIGHT)).intValue();
454             int iDialogWidth = ((Integer) Helper.getUnoPropertyValue(this.xDialogModel, PropertyNames.PROPERTY_WIDTH)).intValue();
455             int iHelpPosX = 8;
456             int iBtnPosY = iDialogHeight - iButtonHeight - 6;
457             int iCancelPosX = iDialogWidth - iButtonWidth - 6;
458             int iFinishPosX = iCancelPosX - 6 - iButtonWidth;
459             int iNextPosX = iFinishPosX - 6 - iButtonWidth;
460             int iBackPosX = iNextPosX - 3 - iButtonWidth;
461 
462             insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "lnNaviSep",
463                     new String[]
464                     {
465                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.ORIENTATION, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH
466                     },
467                     new Object[]
468                     {
469                         1, 0, 0, new Integer(iDialogHeight - 26), ICurStep, new Integer(iDialogWidth)
470                     });
471 
472             insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "lnRoadSep",
473                     new String[]
474                     {
475                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.ORIENTATION, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH
476                     },
477                     new Object[]
478                     {
479                         new Integer(iBtnPosY - 6), 1, 85, 0, ICurStep, 1
480                     });
481 
482             String[] propNames = new String[]
483             {
484                 PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, "PushButtonType", PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
485             };
486 
487             Helper.setUnoPropertyValue(super.xDialogModel, PropertyNames.PROPERTY_HELPURL, HelpIds.getHelpIdString(hid));
488             insertButton("btnWizardHelp", HELP_ACTION_PERFORMED, new String[]
489                     {
490                         PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, "PushButtonType", PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
491                     },
492                     new Object[]
493                     {
494                         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
495                     });
496             insertButton("btnWizardBack", BACK_ACTION_PERFORMED, propNames,
497                     new Object[]
498                     {
499                         false, IButtonHeight, HelpIds.getHelpIdString(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
500                     });
501 
502             insertButton("btnWizardNext", NEXT_ACTION_PERFORMED, propNames,
503                     new Object[]
504                     {
505                         true, IButtonHeight, HelpIds.getHelpIdString(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
506                     });
507 
508             insertButton("btnWizardFinish", FINISH_ACTION_PERFORMED, propNames,
509                     new Object[]
510                     {
511                         true, IButtonHeight, HelpIds.getHelpIdString(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
512                     });
513 
514             insertButton("btnWizardCancel", CANCEL_ACTION_PERFORMED, propNames,
515                     new Object[]
516                     {
517                         true, IButtonHeight, HelpIds.getHelpIdString(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
518                     });
519 
520             setControlProperty("btnWizardNext", "DefaultButton", Boolean.TRUE);
521             // add a window listener, to know
522             // if the user used "escape" key to
523             // close the dialog.
524             MethodInvocation windowHidden = new MethodInvocation("windowHidden", this);
525             xWindow.addWindowListener((CommonListener) getGuiEventListener());
526             String dialogName = (String) Helper.getUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_NAME);
527             getGuiEventListener().add(dialogName, EVENT_ACTION_PERFORMED, windowHidden);
528 
529         }
530         catch (java.lang.Exception jexception)
531         {
532             jexception.printStackTrace(System.out);
533         }
534     }
535 
insertRoadMapItems(String[] items, int[] steps, boolean[] enabled)536     protected void insertRoadMapItems(String[] items, int[] steps, boolean[] enabled)
537     {
538         for (int i = 0; i < items.length; i++)
539         {
540             insertRoadmapItem(i, enabled[i], items[i], steps[i]);
541         }
542     }
543 
544     /** This method also enables and disables the "next" button,
545      * if the step currently dis/enabled is the one of the next steps.
546      * @param _nStep
547      * @param bEnabled
548      * @param enableNextButton
549      */
setStepEnabled(int _nStep, boolean bEnabled, boolean enableNextButton)550     public void setStepEnabled(int _nStep, boolean bEnabled, boolean enableNextButton)
551     {
552         setStepEnabled(_nStep, bEnabled);
553         if (getNextAvailableStep() > 0)
554         {
555             enableNextButton(bEnabled);
556         }
557     }
558 
enableNavigationButtons(boolean _bEnableBack, boolean _bEnableNext, boolean _bEnableFinish)559     public void enableNavigationButtons(boolean _bEnableBack, boolean _bEnableNext, boolean _bEnableFinish)
560     {
561         enableBackButton(_bEnableBack);
562         enableNextButton(_bEnableNext);
563         enableFinishButton(_bEnableFinish);
564     }
565 
enableBackButton(boolean enabled)566     public void enableBackButton(boolean enabled)
567     {
568         setControlProperty("btnWizardBack", PropertyNames.PROPERTY_ENABLED, enabled ? Boolean.TRUE : Boolean.FALSE);
569     }
570 
enableNextButton(boolean enabled)571     public void enableNextButton(boolean enabled)
572     {
573         setControlProperty("btnWizardNext", PropertyNames.PROPERTY_ENABLED, enabled ? Boolean.TRUE : Boolean.FALSE);
574     }
575 
enableFinishButton(boolean enabled)576     public void enableFinishButton(boolean enabled)
577     {
578         setControlProperty("btnWizardFinish", PropertyNames.PROPERTY_ENABLED, enabled ? Boolean.TRUE : Boolean.FALSE);
579     }
580 
setStepEnabled(int _nStep, boolean bEnabled)581     public void setStepEnabled(int _nStep, boolean bEnabled)
582     {
583         XInterface xRoadmapItem = getRoadmapItemByID(_nStep);
584         if (xRoadmapItem != null)
585         {
586             Helper.setUnoPropertyValue(xRoadmapItem, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bEnabled));
587         }
588     }
589 
enablefromStep(int _iStep, boolean _bDoEnable)590     public void enablefromStep(int _iStep, boolean _bDoEnable)
591     {
592         if (_iStep <= this.nMaxStep)
593         {
594             for (int i = _iStep; i <= nMaxStep; i++)
595             {
596                 setStepEnabled(i, _bDoEnable);
597             }
598             enableFinishButton(_bDoEnable);
599             if (!_bDoEnable)
600             {
601                 enableNextButton(_iStep > getCurrentStep() + 1);
602             }
603             else
604             {
605                 enableNextButton(!(getCurrentStep() == nMaxStep));
606             }
607         }
608     }
609 
isStepEnabled(int _nStep)610     public boolean isStepEnabled(int _nStep)
611     {
612         try
613         {
614             boolean bIsEnabled;
615             XInterface xRoadmapItem = getRoadmapItemByID(_nStep);
616             if (xRoadmapItem == null)
617             // Todo: In this case an exception should be thrown
618             {
619                 return false;
620             }
621             bIsEnabled = AnyConverter.toBoolean(Helper.getUnoPropertyValue(xRoadmapItem, PropertyNames.PROPERTY_ENABLED));
622             return bIsEnabled;
623         }
624         catch (com.sun.star.uno.Exception exception)
625         {
626             exception.printStackTrace(System.out);
627             return false;
628         }
629     }
630 
gotoPreviousAvailableStep()631     public synchronized void gotoPreviousAvailableStep()
632     {
633         boolean bIsEnabled;
634         if (nNewStep > 1)
635         {
636             nOldStep = nNewStep;
637             nNewStep--;
638             while (nNewStep > 0)
639             {
640                 bIsEnabled = isStepEnabled(nNewStep);
641                 if (bIsEnabled)
642                 {
643                     break;
644                 }
645                 nNewStep--;
646             }
647             if (nNewStep == 0) // Exception???
648             {
649                 nNewStep = nOldStep;
650             }
651             switchToStep();
652         }
653     }
654 
655     //TODO discuss with rp
getNextAvailableStep()656     protected int getNextAvailableStep()
657     {
658         if (isRoadmapComplete())
659         {
660             for (int i = nNewStep + 1; i <= nMaxStep; i++)
661             {
662                 if (isStepEnabled(i))
663                 {
664                     return i;
665                 }
666             }
667         }
668         return -1;
669     }
670 
gotoNextAvailableStep()671     public synchronized void gotoNextAvailableStep()
672     {
673         nOldStep = nNewStep;
674         nNewStep = getNextAvailableStep();
675         if (nNewStep > -1)
676         {
677             switchToStep();
678         }
679     }
680 
finishWizard()681     public abstract boolean finishWizard();
682 
683     /**
684      * This function will call if the finish button is pressed on the UI.
685      */
finishWizard_1()686     public void finishWizard_1()
687     {
688         enableFinishButton(false);
689         boolean success = false;
690         try
691         {
692             success = finishWizard();
693         }
694         finally
695         {
696             if ( !success )
697                 enableFinishButton( true );
698         }
699         if ( success )
700             removeTerminateListener();
701     }
702 
getMaximalStep()703     public int getMaximalStep()
704     {
705         return this.nMaxStep;
706     }
707 
getCurrentStep()708     public int getCurrentStep()
709     {
710         try
711         {
712             return AnyConverter.toInt(Helper.getUnoPropertyValue(this.MSFDialogModel, PropertyNames.PROPERTY_STEP));
713         }
714         catch (com.sun.star.uno.Exception exception)
715         {
716             exception.printStackTrace(System.out);
717             return -1;
718         }
719     }
720 
setCurrentStep(int _nNewstep)721     public void setCurrentStep(int _nNewstep)
722     {
723         nNewStep = _nNewstep;
724         changeToStep(nNewStep);
725     }
726 
setRightPaneHeaders(Resource _oResource, int StartResID, int _nMaxStep)727     public void setRightPaneHeaders(Resource _oResource, int StartResID, int _nMaxStep)
728     {
729         String[] sRightPaneHeaders = _oResource.getResArray(StartResID, _nMaxStep);
730         setRightPaneHeaders(sRightPaneHeaders);
731     }
732 
setRightPaneHeaders(String[] _sRightPaneHeaders)733     public void setRightPaneHeaders(String[] _sRightPaneHeaders)
734     {
735         this.nMaxStep = _sRightPaneHeaders.length;
736         this.sRightPaneHeaders = _sRightPaneHeaders;
737         FontDescriptor oFontDesc = new FontDescriptor();
738         oFontDesc.Weight = com.sun.star.awt.FontWeight.BOLD;
739 
740         for (int i = 0; i < sRightPaneHeaders.length; i++)
741         {
742             insertLabel("lblQueryTitle" + String.valueOf(i),
743                     new String[]
744                     {
745                         PropertyNames.FONT_DESCRIPTOR, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
746                     },
747                     new Object[]
748                     {
749                         oFontDesc, 16, sRightPaneHeaders[i], Boolean.TRUE, 91, 8, new Integer(i + 1), new Short((short) 12), 212
750                     });
751         }
752     }
753 
cancelWizard()754     public void cancelWizard()
755     {
756         //can be overwritten by extending class
757         xDialog.endExecute();
758     }
759 
callHelp()760     public void callHelp()
761     {
762         //should be overwritten by extending class
763     }
764 
removeTerminateListener()765     public void removeTerminateListener()
766     {
767         if (bTerminateListenermustberemoved)
768         {
769             Desktop.getDesktop(xMSF).removeTerminateListener(this);
770             bTerminateListenermustberemoved = false;
771         }
772     }
773 
774     /**
775      * called by the cancel button and
776      * by the window hidden event.
777      * if this method was not called before,
778      * perform a cancel.
779      */
cancelWizard_1()780     public void cancelWizard_1()
781     {
782         cancelWizard();
783         removeTerminateListener();
784     }
785 
windowHidden()786     public void windowHidden()
787     {
788         cancelWizard_1();
789     }
790 
notifyTermination(EventObject arg0)791     public void notifyTermination(EventObject arg0)
792     {
793         cancelWizard_1();
794     }
795 
queryTermination(EventObject arg0)796     public void queryTermination(EventObject arg0)
797             throws TerminationVetoException
798     {
799         activate();
800         throw new TerminationVetoException();
801     }
802 
disposing(EventObject arg0)803     public void disposing(EventObject arg0)
804     {
805         cancelWizard_1();
806     }
807 }
808