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
|
from UnoDialog2 import *
from common.Resource import Resource
from abc import ABCMeta, abstractmethod
from com.sun.star.lang import NoSuchMethodException
from com.sun.star.uno import Exception as UnoException
from com.sun.star.lang import IllegalArgumentException
from com.sun.star.frame import TerminationVetoException
from common.HelpIds import *
from com.sun.star.awt.PushButtonType import HELP, STANDARD
from event.MethodInvocation import *
from event.EventNames import EVENT_ITEM_CHANGED
class WizardDialog(UnoDialog2):
__metaclass__ = ABCMeta
__NEXT_ACTION_PERFORMED = "gotoNextAvailableStep"
__BACK_ACTION_PERFORMED = "gotoPreviousAvailableStep"
__FINISH_ACTION_PERFORMED = "finishWizard_1"
__CANCEL_ACTION_PERFORMED = "cancelWizard_1"
__HELP_ACTION_PERFORMED = "callHelp"
'''
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_
'''
def __init__(self, xMSF, hid_):
super(WizardDialog,self).__init__(xMSF)
self.__hid = hid_
self.__iButtonWidth = 50
self.__nNewStep = 1
self.__nOldStep = 1
self.__nMaxStep = 1
self.__bTerminateListenermustberemoved = True
self.__oWizardResource = Resource(xMSF, "dbw")
self.sMsgEndAutopilot = self.__oWizardResource.getResText(UIConsts.RID_DB_COMMON + 33)
#self.vetos = VetoableChangeSupport.VetoableChangeSupport_unknown(this)
def getResource(self):
return self.__oWizardResource
def activate(self):
try:
if self.xUnoDialog != None:
self.xUnoDialog.toFront()
except UnoException, ex:
pass
# do nothing;
def setMaxStep(self, i):
self.__nMaxStep = i
def getMaxStep(self):
return self.__nMaxStep
def setOldStep(self, i):
self.__nOldStep = i
def getOldStep(self):
return self.__nOldStep
def setNewStep(self, i):
self.__nNewStep = i
def getNewStep(self):
return self.__nNewStep
#@see java.beans.VetoableChangeListener#vetoableChange(java.beans.PropertyChangeEvent)
def vetoableChange(self, arg0):
self.__nNewStep = self.__nOldStep
def itemStateChanged(self, itemEvent):
try:
self.__nNewStep = itemEvent.ItemId
self.__nOldStep = int(Helper.getUnoPropertyValue(self.xDialogModel, PropertyNames.PROPERTY_STEP))
if self.__nNewStep != self.__nOldStep:
switchToStep()
except IllegalArgumentException, exception:
traceback.print_exc()
def setRoadmapInteractive(self, _bInteractive):
Helper.setUnoPropertyValue(self.oRoadmap, "Activated", _bInteractive)
def setRoadmapComplete(self, bComplete):
Helper.setUnoPropertyValue(self.oRoadmap, "Complete", bComplete)
def isRoadmapComplete(self):
try:
return bool(Helper.getUnoPropertyValue(self.oRoadmap, "Complete"))
except IllegalArgumentException, exception:
traceback.print_exc()
return False
def setCurrentRoadmapItemID(self, ID):
if self.oRoadmap != None:
nCurItemID = self.getCurrentRoadmapItemID()
if nCurItemID != ID:
Helper.setUnoPropertyValue(self.oRoadmap, "CurrentItemID", uno.Any("short",ID))
def getCurrentRoadmapItemID(self):
try:
return int(Helper.getUnoPropertyValue(self.oRoadmap, "CurrentItemID"))
except UnoException, exception:
traceback.print_exc()
return -1
def addRoadmap(self):
try:
iDialogHeight = Helper.getUnoPropertyValue(self.xDialogModel, PropertyNames.PROPERTY_HEIGHT)
# 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
self.oRoadmap = self.insertControlModel("com.sun.star.awt.UnoControlRoadmapModel", "rdmNavi", (PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Tabstop", PropertyNames.PROPERTY_WIDTH),((iDialogHeight - 26), 0, 0, 0, 0, True, uno.Any("short",85)))
self.oRoadmap.setPropertyValue(PropertyNames.PROPERTY_NAME, "rdmNavi")
mi = MethodInvocation("itemStateChanged", self)
self.guiEventListener.add("rdmNavi", EVENT_ITEM_CHANGED, mi)
self.xRoadmapControl = self.xUnoDialog.getControl("rdmNavi")
self.xRoadmapControl.addItemListener(ItemListenerProcAdapter(self.guiEventListener))
Helper.setUnoPropertyValue(self.oRoadmap, "Text", self.__oWizardResource.getResText(UIConsts.RID_COMMON + 16))
except NoSuchMethodException, ex:
Resource.showCommonResourceError(xMSF)
except UnoException, jexception:
traceback.print_exc()
def setRMItemLabels(self, _oResource, StartResID):
self.sRMItemLabels = _oResource.getResArray(StartResID, self.__nMaxStep)
def getRMItemLabels(self):
return self.sRMItemLabels
def insertRoadmapItem(self, _Index, _bEnabled, _LabelID, _CurItemID):
return insertRoadmapItem(_Index, _bEnabled, self.sRMItemLabels(_LabelID), _CurItemID)
def insertRoadmapItem(self, Index, _bEnabled, _sLabel, _CurItemID):
try:
oRoadmapItem = self.oRoadmap.createInstance()
Helper.setUnoPropertyValue(oRoadmapItem, PropertyNames.PROPERTY_LABEL, _sLabel)
Helper.setUnoPropertyValue(oRoadmapItem, PropertyNames.PROPERTY_ENABLED, _bEnabled)
Helper.setUnoPropertyValue(oRoadmapItem, "ID", _CurItemID)
self.oRoadmap.insertByIndex(Index, oRoadmapItem)
NextIndex = Index + 1
return NextIndex
except UnoException, exception:
traceback.print_exc()
return -1
def getRMItemCount(self):
return self.oRoadmap.getCount()
def getRoadmapItemByID(self, _ID):
try:
i = 0
while i < self.oRoadmap.getCount():
CurRoadmapItem = self.oRoadmap.getByIndex(i)
CurID = int(Helper.getUnoPropertyValue(CurRoadmapItem, "ID"))
if CurID == _ID:
return CurRoadmapItem
i += 1
return None
except UnoException, exception:
traceback.print_exc()
return None
def switchToStep(self,_nOldStep=None, _nNewStep=None):
if _nOldStep and _nNewStep:
self.__nOldStep = _nOldStep
self.__nNewStep = _nNewStep
leaveStep(self.__nOldStep, self.__nNewStep)
if self.__nNewStep != self.__nOldStep:
if self.__nNewStep == self.__nMaxStep:
setControlProperty("btnWizardNext", "DefaultButton", False)
setControlProperty("btnWizardFinish", "DefaultButton", True)
else:
setControlProperty("btnWizardNext", "DefaultButton", True)
setControlProperty("btnWizardFinish", "DefaultButton", False)
changeToStep(self.__nNewStep)
enterStep(self.__nOldStep, self.__nNewStep)
return True
return False
@abstractmethod
def leaveStep(self, nOldStep, nNewStep):
pass
@abstractmethod
def enterStep(self, nOldStep, nNewStep):
pass
def changeToStep(self, nNewStep):
Helper.setUnoPropertyValue(self.xDialogModel, PropertyNames.PROPERTY_STEP, nNewStep)
setCurrentRoadmapItemID((short)(nNewStep))
enableNextButton(getNextAvailableStep() > 0)
enableBackButton(nNewStep != 1)
def iscompleted(self, _ndialogpage):
return False
def ismodified(self, _ndialogpage):
return False
def drawNaviBar(self):
try:
curtabindex = UIConsts.SOFIRSTWIZARDNAVITABINDEX
iButtonWidth = self.__iButtonWidth
iButtonHeight = 14
iCurStep = 0
iDialogHeight = Helper.getUnoPropertyValue(self.xDialogModel, PropertyNames.PROPERTY_HEIGHT)
iDialogWidth = Helper.getUnoPropertyValue(self.xDialogModel, PropertyNames.PROPERTY_WIDTH)
iHelpPosX = 8
iBtnPosY = iDialogHeight - iButtonHeight - 6
iCancelPosX = iDialogWidth - self.__iButtonWidth - 6
iFinishPosX = iCancelPosX - 6 - self.__iButtonWidth
iNextPosX = iFinishPosX - 6 - self.__iButtonWidth
iBackPosX = iNextPosX - 3 - self.__iButtonWidth
self.insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "lnNaviSep", (PropertyNames.PROPERTY_HEIGHT, "Orientation", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH), (1, 0, 0, iDialogHeight - 26, iCurStep, iDialogWidth))
self.insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "lnRoadSep",(PropertyNames.PROPERTY_HEIGHT, "Orientation", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH),(iBtnPosY - 6, 1, 85, 0, iCurStep, 1))
propNames = (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)
Helper.setUnoPropertyValue(self.xDialogModel, PropertyNames.PROPERTY_HELPURL, HelpIds.getHelpIdString(self.__hid))
self.insertButton("btnWizardHelp", WizardDialog.__HELP_ACTION_PERFORMED,(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),(True, iButtonHeight, self.__oWizardResource.getResText(UIConsts.RID_COMMON + 15), iHelpPosX, iBtnPosY, uno.Any("short",HELP), iCurStep, uno.Any("short",(curtabindex + 1)), iButtonWidth))
self.insertButton("btnWizardBack", WizardDialog.__BACK_ACTION_PERFORMED, propNames,(False, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 2), self.__oWizardResource.getResText(UIConsts.RID_COMMON + 13), iBackPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep, uno.Any("short",(curtabindex + 1)), iButtonWidth))
self.insertButton("btnWizardNext", WizardDialog.__NEXT_ACTION_PERFORMED, propNames,(True, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 3), self.__oWizardResource.getResText(UIConsts.RID_COMMON + 14), iNextPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep, uno.Any("short",(curtabindex + 1)), iButtonWidth))
self.insertButton("btnWizardFinish", WizardDialog.__FINISH_ACTION_PERFORMED, propNames,(True, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 4), self.__oWizardResource.getResText(UIConsts.RID_COMMON + 12), iFinishPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep, uno.Any("short",(curtabindex + 1)), iButtonWidth))
self.insertButton("btnWizardCancel", WizardDialog.__CANCEL_ACTION_PERFORMED, propNames,(True, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 5), self.__oWizardResource.getResText(UIConsts.RID_COMMON + 11), iCancelPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep, uno.Any("short",(curtabindex + 1)), iButtonWidth))
self.setControlProperty("btnWizardNext", "DefaultButton", True)
# add a window listener, to know
# if the user used "escape" key to
# close the dialog.
windowHidden = MethodInvocation("windowHidden", self)
self.xUnoDialog.addWindowListener(WindowListenerProcAdapter(self.guiEventListener))
dialogName = Helper.getUnoPropertyValue(self.xDialogModel, PropertyNames.PROPERTY_NAME)
self.guiEventListener.add(dialogName, EVENT_ACTION_PERFORMED, windowHidden)
except Exception, exception:
traceback.print_exc()
def insertRoadMapItems(self, items, steps, enabled):
i = 0
while i < items.length:
insertRoadmapItem(i, enabled(i), items(i), steps(i))
i += 1
def setStepEnabled(self, _nStep, bEnabled, enableNextButton):
setStepEnabled(_nStep, bEnabled)
if getNextAvailableStep() > 0:
enableNextButton(bEnabled)
def enableNavigationButtons(self, _bEnableBack, _bEnableNext, _bEnableFinish):
enableBackButton(_bEnableBack)
enableNextButton(_bEnableNext)
enableFinishButton(_bEnableFinish)
def enableBackButton(self, enabled):
setControlProperty("btnWizardBack", PropertyNames.PROPERTY_ENABLED, enabled)
def enableNextButton(self, enabled):
setControlProperty("btnWizardNext", PropertyNames.PROPERTY_ENABLED, enabled)
def enableFinishButton(self, enabled):
setControlProperty("btnWizardFinish", PropertyNames.PROPERTY_ENABLED, enabled)
def setStepEnabled(self, _nStep, bEnabled):
xRoadmapItem = getRoadmapItemByID(_nStep)
if xRoadmapItem != None:
Helper.setUnoPropertyValue(xRoadmapItem, PropertyNames.PROPERTY_ENABLED, bEnabled)
def enablefromStep(self, _iStep, _bDoEnable):
if _iStep <= self.__nMaxStep:
i = _iStep
while i <= self.__nMaxStep:
setStepEnabled(i, _bDoEnable)
i += 1
enableFinishButton(_bDoEnable)
if not _bDoEnable:
enableNextButton(_iStep > getCurrentStep() + 1)
else:
enableNextButton(not (getCurrentStep() == self.__nMaxStep))
def isStepEnabled(self, _nStep):
try:
xRoadmapItem = getRoadmapItemByID(_nStep)
# Todo: In this case an exception should be thrown
if (xRoadmapItem == None):
return False
bIsEnabled = bool(Helper.getUnoPropertyValue(xRoadmapItem, PropertyNames.PROPERTY_ENABLED))
return bIsEnabled
except UnoException, exception:
traceback.print_exc()
return False
def gotoPreviousAvailableStep(self):
if self.__nNewStep > 1:
self.__nOldStep = self.__nNewStep
self.__nNewStep -= 1
while self.__nNewStep > 0:
bIsEnabled = isStepEnabled(self.__nNewStep)
if bIsEnabled:
break;
self.__nNewStep -= 1
# Exception???
if (self.__nNewStep == 0):
self.__nNewStep = self.__nOldStep
switchToStep()
#TODO discuss with rp
def getNextAvailableStep(self):
if isRoadmapComplete():
i = self.__nNewStep + 1
while i <= self.__nMaxStep:
if isStepEnabled(i):
return i
i += 1
return -1
def gotoNextAvailableStep(self):
self.__nOldStep = self.__nNewStep
self.__nNewStep = getNextAvailableStep()
if self.__nNewStep > -1:
switchToStep()
@abstractmethod
def finishWizard(self):
pass
#This function will call if the finish button is pressed on the UI.
def finishWizard_1(self):
enableFinishButton(False)
success = False
try:
success = finishWizard()
finally:
if not success:
enableFinishButton(True)
if success:
removeTerminateListener()
def getMaximalStep(self):
return self.__nMaxStep
def getCurrentStep(self):
try:
return int(Helper.getUnoPropertyValue(self.MSFDialogModel, PropertyNames.PROPERTY_STEP))
except UnoException, exception:
traceback.print_exc()
return -1
def setCurrentStep(self, _nNewstep):
self.__nNewStep = _nNewstep
changeToStep(self.__nNewStep)
def setRightPaneHeaders(self, _oResource, StartResID, _nMaxStep):
self.sRightPaneHeaders = _oResource.getResArray(StartResID, _nMaxStep)
setRightPaneHeaders(self.sRightPaneHeaders)
def setRightPaneHeaders(self, _sRightPaneHeaders):
self.__nMaxStep = _sRightPaneHeaders.length
self.sRightPaneHeaders = _sRightPaneHeaders
oFontDesc = FontDescriptor.FontDescriptor()
oFontDesc.Weight = com.sun.star.awt.FontWeight.BOLD
i = 0
while i < self.sRightPaneHeaders.length:
insertLabel("lblQueryTitle" + String.valueOf(i),("FontDescriptor", 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),(oFontDesc, 16, self.sRightPaneHeaders(i), True, 91, 8, i + 1, uno.Any("short",12), 212))
i += 1
def cancelWizard(self):
#can be overwritten by extending class
xDialog.endExecute()
def removeTerminateListener(self):
if self.__bTerminateListenermustberemoved:
#COMMENTED
#Desktop.getDesktop(self.xMSF).removeTerminateListener( \
# ActionListenerProcAdapter(self))
self.__bTerminateListenermustberemoved = False
'''
called by the cancel button and
by the window hidden event.
if this method was not called before,
perform a cancel.
'''
def cancelWizard_1(self):
cancelWizard()
removeTerminateListener()
def windowHidden(self):
cancelWizard_1()
def notifyTermination(self, arg0):
cancelWizard_1()
def queryTermination(self, arg0):
activate()
raise TerminationVetoException ();
def disposing(self, arg0):
cancelWizard_1()
|