1 #----------------------------------------------------------------------------
3 # Purpose: Shared UI stuff
5 # Author: Matt Fryer, Morgan Hua
9 # Copyright: (c) 2005-2006 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
18 import activegrid
.util
.appdirs
as appdirs
19 import activegrid
.util
.fileutils
as fileutils
20 import activegrid
.util
.strutils
as strutils
21 import activegrid
.util
.sysutils
as sysutils
22 import activegrid
.util
.xmlutils
as xmlutils
25 def CreateDirectoryControl( parent
, fileLabel
=_("File Name:"), dirLabel
=_("Directory:"), fileExtension
="*", startingName
="", startingDirectory
=None, choiceDirs
=None, appDirDefaultStartDir
=False, returnAll
=False, useDirDialog
=False):
31 if appDirDefaultStartDir
:
32 appDirectory
= wx
.ConfigBase_Get().Read(ProjectEditor
.PROJECT_DIRECTORY_KEY
, ProjectEditor
.NEW_PROJECT_DIRECTORY_DEFAULT
)
34 appDirectory
= wx
.ConfigBase_Get().Read(ProjectEditor
.PROJECT_DIRECTORY_KEY
)
36 choiceDirs
.append(appDirectory
)
37 if appDirDefaultStartDir
and not startingDirectory
:
38 startingDirectory
= appDirectory
40 projectService
= wx
.GetApp().GetService(ProjectEditor
.ProjectService
)
42 curProjectDoc
= projectService
.GetCurrentProject()
44 homeDir
= curProjectDoc
.GetAppDocMgr().homeDir
45 if homeDir
and (homeDir
not in choiceDirs
):
46 choiceDirs
.append(homeDir
)
47 if not startingDirectory
:
48 startingDirectory
= homeDir
50 for projectDoc
in projectService
.GetOpenProjects():
51 if projectDoc
== curProjectDoc
:
53 homeDir
= projectDoc
.GetAppDocMgr().homeDir
54 if homeDir
and (homeDir
not in projectDirs
):
55 projectDirs
.append(homeDir
)
56 projectDirs
.sort(CaseInsensitiveCompare
)
57 for projectDir
in projectDirs
:
58 if projectDir
not in choiceDirs
:
59 choiceDirs
.append(projectDir
)
61 if startingDirectory
and (startingDirectory
not in choiceDirs
):
62 choiceDirs
.insert(0, startingDirectory
)
64 if os
.getcwd() not in choiceDirs
:
65 choiceDirs
.append(os
.getcwd())
66 if appdirs
.getSystemDir() not in choiceDirs
:
67 choiceDirs
.append(appdirs
.getSystemDir())
69 if not startingDirectory
:
70 startingDirectory
= os
.getcwd()
72 nameControl
= wx
.TextCtrl(parent
, -1, startingName
, size
=(-1,-1))
73 nameLabelText
= wx
.StaticText(parent
, -1, fileLabel
)
74 dirLabelText
= wx
.StaticText(parent
, -1, dirLabel
)
75 dirControl
= wx
.ComboBox(parent
, -1, startingDirectory
, size
=(-1,-1), choices
=choiceDirs
)
76 dirControl
.SetToolTipString(startingDirectory
)
77 button
= wx
.Button(parent
, -1, _("Browse..."))
78 allControls
= [nameControl
, nameLabelText
, dirLabelText
, dirControl
, button
]
80 def OnFindDirClick(event
):
82 nameCtrlValue
= nameControl
.GetValue()
84 root
, ext
= os
.path
.splitext( nameCtrlValue
)
85 if ext
== '.' + fileExtension
:
88 name
= _("%s.%s") % (nameCtrlValue
, fileExtension
)
91 dlg
= wx
.FileDialog(parent
, _("Choose a filename and directory"),
92 defaultDir
= dirControl
.GetValue().strip(),
94 wildcard
= "*.%s" % fileExtension
,
95 style
=wx
.SAVE|wx
.CHANGE_DIR
)
97 dlg
= wx
.DirDialog(wx
.GetApp().GetTopWindow(),
98 _("Choose a directory:"),
99 defaultPath
=dirControl
.GetValue().strip(),
100 style
=wx
.DD_DEFAULT_STYLE|wx
.DD_NEW_DIR_BUTTON
)
102 if dlg
.ShowModal() != wx
.ID_OK
:
110 dir, filename
= os
.path
.split(path
)
111 if dirControl
.FindString(dir) == wx
.NOT_FOUND
:
112 dirControl
.Insert(dir, 0)
113 dirControl
.SetValue(dir)
114 dirControl
.SetToolTipString(dir)
115 nameControl
.SetValue(filename
)
117 dirControl
.SetValue(path
)
118 dirControl
.SetToolTipString(path
)
120 parent
.Bind(wx
.EVT_BUTTON
, OnFindDirClick
, button
)
122 def Validate(allowOverwriteOnPrompt
=False, infoString
='', validClassName
=False, ignoreFileConflicts
=False):
123 projName
= nameControl
.GetValue().strip()
125 wx
.MessageBox(_("Please provide a %sfile name.") % infoString
, _("Provide a File Name"))
127 if projName
.find(' ') != -1:
128 wx
.MessageBox(_("Please provide a %sfile name that does not contains spaces.") % infoString
, _("Spaces in File Name"))
131 if projName
[0].isdigit():
132 wx
.MessageBox(_("File name cannot start with a number. Please enter a different name."), _("Invalid File Name"))
134 if projName
.endswith(".agp"):
135 projName2
= projName
[:-4]
138 if not projName2
.replace("_", "a").isalnum(): # [a-zA-Z0-9_] note '_' is allowed and ending '.agp'.
139 wx
.MessageBox(_("Name must be alphanumeric ('_' allowed). Please enter a valid name."), _("Project Name"))
142 dirName
= dirControl
.GetValue().strip()
144 wx
.MessageBox(_("No directory. Please provide a directory."), _("Provide a Directory"))
146 if os
.sep
== "\\" and dirName
.find("/") != -1:
147 wx
.MessageBox(_("Wrong delimiter '/' found in directory path. Use '%s' as delimiter.") % os
.sep
, _("Provide a Valid Directory"))
149 if not os
.path
.exists(dirName
):
150 wx
.MessageBox(_("That %sdirectory does not exist. Please choose an existing directory.") % infoString
, _("Provide a Valid Directory"))
152 if not ignoreFileConflicts
:
153 filePath
= os
.path
.join(dirName
, MakeNameEndInExtension(projName
, "." + fileExtension
))
154 if os
.path
.exists(filePath
):
155 if allowOverwriteOnPrompt
:
156 res
= wx
.MessageBox(_("That %sfile already exists. Would you like to overwrite it.") % infoString
, "File Exists", style
=wx
.YES_NO|wx
.NO_DEFAULT
)
157 return (res
== wx
.YES
)
159 wx
.MessageBox(_("That %sfile already exists. Please choose a different name.") % infoString
, "File Exists")
164 flexGridSizer
= wx
.FlexGridSizer(cols
= 3, vgap
= HALF_SPACE
, hgap
= HALF_SPACE
)
165 flexGridSizer
.AddGrowableCol(1,1)
167 flexGridSizer
.Add(nameLabelText
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT
)
168 flexGridSizer
.Add(nameControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
)
169 flexGridSizer
.Add(button
, flag
=wx
.ALIGN_RIGHT|wx
.LEFT
, border
=HALF_SPACE
)
170 flexGridSizer
.Add(dirLabelText
, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT
)
171 flexGridSizer
.Add(dirControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
)
172 flexGridSizer
.Add(wx
.StaticText(parent
, -1, ""), 0)
174 flexGridSizer
.Add(nameLabelText
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT
)
175 flexGridSizer
.Add(nameControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
)
176 flexGridSizer
.Add(wx
.StaticText(parent
, -1, ""), 0)
177 flexGridSizer
.Add(dirLabelText
, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT
)
178 flexGridSizer
.Add(dirControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
)
179 flexGridSizer
.Add(button
, flag
=wx
.ALIGN_RIGHT|wx
.LEFT
, border
=HALF_SPACE
)
182 return nameControl
, dirControl
, flexGridSizer
, Validate
, allControls
184 return nameControl
, dirControl
, flexGridSizer
, Validate
187 def CreateDirectoryOnlyControl( parent
, dirLabel
=_("Location:"), startingDirectory
=None, choiceDirs
=None, appDirDefaultStartDir
=False):
193 if appDirDefaultStartDir
:
194 appDirectory
= wx
.ConfigBase_Get().Read(ProjectEditor
.PROJECT_DIRECTORY_KEY
, ProjectEditor
.NEW_PROJECT_DIRECTORY_DEFAULT
)
196 appDirectory
= wx
.ConfigBase_Get().Read(ProjectEditor
.PROJECT_DIRECTORY_KEY
)
198 choiceDirs
.append(appDirectory
)
199 if appDirDefaultStartDir
and not startingDirectory
:
200 startingDirectory
= appDirectory
202 projectService
= wx
.GetApp().GetService(ProjectEditor
.ProjectService
)
204 curProjectDoc
= projectService
.GetCurrentProject()
206 homeDir
= curProjectDoc
.GetAppDocMgr().homeDir
207 if homeDir
and (homeDir
not in choiceDirs
):
208 choiceDirs
.append(homeDir
)
209 if not startingDirectory
:
210 startingDirectory
= homeDir
212 for projectDoc
in projectService
.GetOpenProjects():
213 if projectDoc
== curProjectDoc
:
215 homeDir
= projectDoc
.GetAppDocMgr().homeDir
216 if homeDir
and (homeDir
not in projectDirs
):
217 projectDirs
.append(homeDir
)
218 projectDirs
.sort(CaseInsensitiveCompare
)
219 for projectDir
in projectDirs
:
220 if projectDir
not in choiceDirs
:
221 choiceDirs
.append(projectDir
)
223 if startingDirectory
and (startingDirectory
not in choiceDirs
):
224 choiceDirs
.insert(0, startingDirectory
)
226 if os
.getcwd() not in choiceDirs
:
227 choiceDirs
.append(os
.getcwd())
228 if appdirs
.getSystemDir() not in choiceDirs
:
229 choiceDirs
.append(appdirs
.getSystemDir())
232 if not startingDirectory
:
233 startingDirectory
= os
.getcwd()
235 dirLabelText
= wx
.StaticText(parent
, -1, dirLabel
)
236 dirControl
= wx
.ComboBox(parent
, -1, startingDirectory
, size
=(-1,-1), choices
=choiceDirs
)
237 dirControl
.SetToolTipString(startingDirectory
)
238 button
= wx
.Button(parent
, -1, _("Browse..."))
240 def OnFindDirClick(event
):
241 dlg
= wx
.DirDialog(wx
.GetApp().GetTopWindow(),
242 _("Choose a directory:"),
243 defaultPath
=dirControl
.GetValue().strip(),
244 style
=wx
.DD_DEFAULT_STYLE|wx
.DD_NEW_DIR_BUTTON
)
246 if dlg
.ShowModal() == wx
.ID_OK
:
248 if dirControl
.FindString(dir) == wx
.NOT_FOUND
:
249 dirControl
.Insert(dir, 0)
250 dirControl
.SetValue(dir)
251 dirControl
.SetToolTipString(dir)
254 parent
.Bind(wx
.EVT_BUTTON
, OnFindDirClick
, button
)
256 def Validate(allowOverwriteOnPrompt
=False):
257 dirName
= dirControl
.GetValue().strip()
259 wx
.MessageBox(_("Please provide a directory."), _("Provide a Directory"))
261 if os
.sep
== "\\" and dirName
.find("/") != -1:
262 wx
.MessageBox(_("Wrong delimiter '/' found in directory path. Use '%s' as delimiter.") % os
.sep
, _("Provide a Valid Directory"))
264 if not os
.path
.exists(dirName
):
265 wx
.MessageBox(_("That directory does not exist. Please choose an existing directory."), _("Provide a Valid Directory"))
270 flexGridSizer
= wx
.FlexGridSizer(cols
= 3, vgap
= HALF_SPACE
, hgap
= HALF_SPACE
)
271 flexGridSizer
.AddGrowableCol(1,1)
272 flexGridSizer
.Add(dirLabelText
, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT|wx
.RIGHT
, border
=HALF_SPACE
)
273 flexGridSizer
.Add(dirControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
, border
=HALF_SPACE
)
274 flexGridSizer
.Add(button
, flag
=wx
.ALIGN_RIGHT|wx
.LEFT
, border
=HALF_SPACE
)
276 return dirControl
, flexGridSizer
, Validate
279 def CreateNameOnlyControl( parent
, fileLabel
, startingName
="", startingDirectoryControl
=None):
281 fileLabelText
= wx
.StaticText(parent
, -1, fileLabel
)
282 nameControl
= wx
.TextCtrl(parent
, -1, startingName
, size
=(-1,-1))
284 def Validate(allowOverwriteOnPrompt
=False, validClassName
=False):
285 projName
= nameControl
.GetValue().strip()
287 wx
.MessageBox(_("Blank name. Please enter a valid name."), _("Project Name"))
289 if projName
.find(' ') != -1:
290 wx
.MessageBox(_("Spaces in name. Name cannot have spaces."), _("Project Name"))
293 if projName
[0].isdigit():
294 wx
.MessageBox(_("Name cannot start with a number. Please enter a valid name."), _("Project Name"))
296 if projName
.endswith(".agp"):
297 projName2
= projName
[:-4]
300 if not projName2
.replace("_", "a").isalnum(): # [a-zA-Z0-9_] note '_' is allowed and ending '.agp'.
301 wx
.MessageBox(_("Name must be alphanumeric ('_' allowed). Please enter a valid name."), _("Project Name"))
303 path
= os
.path
.join(startingDirectoryControl
.GetValue().strip(), projName
)
304 if os
.path
.exists(path
):
305 if os
.path
.isdir(path
):
306 message
= _("Project '%s' already exists. Would you like to overwrite the contents of the project?") % projName
307 else: # os.path.isfile(path):
308 message
= _("'%s' already exists as a file. Would you like to replace it with the project?") % nameControl
.GetValue().strip()
310 yesNoMsg
= wx
.MessageDialog(wx
.GetApp().GetTopWindow(),
312 _("Project Directory Exists"),
313 wx
.YES_NO|wx
.ICON_QUESTION
315 yesNoMsg
.CenterOnParent()
316 status
= yesNoMsg
.ShowModal()
318 if status
== wx
.ID_NO
:
323 flexGridSizer
= wx
.FlexGridSizer(cols
= 2, vgap
= HALF_SPACE
, hgap
= HALF_SPACE
)
324 flexGridSizer
.AddGrowableCol(1,1)
325 flexGridSizer
.Add(fileLabelText
, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT|wx
.TOP|wx
.RIGHT
, border
=HALF_SPACE
)
326 flexGridSizer
.Add(nameControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
, border
=HALF_SPACE
)
328 return nameControl
, flexGridSizer
, Validate
331 def ValidateName(name
, ext
=None, hint
="name"):
332 """ Returns an error string if there is something wrong with the name.
333 Otherwise it returns None
336 return _("Blank %s. Please enter a valid %s.") % (hint
, hint
)
338 if name
.find(' ') != -1:
339 return _("Spaces in %s. %s cannot have spaces.") % (hint
, hint
.title())
341 if name
[0].isdigit():
342 return _("%s cannot start with a number. Please enter a valid %s.") % (hint
.title(), hint
)
344 if ext
and name
.endswith(ext
): # strip extension if provided
346 name
= name
[:-lenExt
]
348 if not name
.replace("_", "a").isalnum(): # [a-zA-Z0-9_] note '_' is allowed and ext ending.
349 return _("%s must be alphanumeric ('_' allowed). Please enter a valid %s.") % (hint
.title(), hint
)
354 def GetCurrentProject():
355 projectDocument
= None
356 projectService
= wx
.GetApp().GetService(ProjectEditor
.ProjectService
)
358 projectDocument
= projectService
.GetCurrentProject()
359 return projectDocument
361 def AddFilesToCurrentProject(paths
, folderPath
=None, types
=None, names
=None, save
=False):
362 projectService
= wx
.GetApp().GetService(ProjectEditor
.ProjectService
)
364 projectDocument
= projectService
.GetCurrentProject()
366 files
= projectDocument
.GetFiles()
371 projectDocument
.GetCommandProcessor().Submit(ProjectEditor
.ProjectAddFilesCommand(projectDocument
, paths
, folderPath
=folderPath
, types
=types
, names
=names
))
373 projectDocument
.OnSaveDocument(projectDocument
.GetFilename())
375 def AddFilesToProject(projectDocument
, paths
, types
=None, names
=None, save
=False):
377 files
= projectDocument
.GetFiles()
382 projectDocument
.GetCommandProcessor().Submit(ProjectEditor
.ProjectAddFilesCommand(projectDocument
, paths
, types
=types
, names
=names
))
384 projectDocument
.OnSaveDocument(projectDocument
.GetFilename())
387 def MakeNameEndInExtension(name
, extension
):
390 root
, ext
= os
.path
.splitext(name
)
394 return name
+ extension
397 def GetPythonExecPath():
398 pythonExecPath
= wx
.ConfigBase_Get().Read("ActiveGridPythonLocation")
399 if not pythonExecPath
:
400 pythonExecPath
= sysutils
.pythonExecPath
401 return pythonExecPath
404 def GetPHPExecPath():
405 PHPExecPath
= wx
.ConfigBase_Get().Read("ActiveGridPHPLocation")
410 PHPINIPath
= wx
.ConfigBase_Get().Read("ActiveGridPHPINILocation")
414 def _DoRemoveRecursive(path
, skipFile
=None, skipped
=False):
417 elif os
.path
.isdir(path
):
418 for file in os
.listdir(path
):
419 file_or_dir
= os
.path
.join(path
,file)
420 if skipFile
== file_or_dir
:
422 elif os
.path
.isdir(file_or_dir
) and not os
.path
.islink(file_or_dir
):
423 if _DoRemoveRecursive(file_or_dir
, skipFile
): # it's a directory recursive call to function again
426 os
.remove(file_or_dir
) # it's a file, delete it
428 os
.rmdir(path
) # delete the directory here
435 def RemoveRecursive(path
, skipFile
=None):
436 _DoRemoveRecursive(path
, skipFile
)
439 def CaseInsensitiveCompare(s1
, s2
):
440 """ Method used by sort() to sort values in case insensitive order """
441 return strutils
.caseInsensitiveCompare(s1
, s2
)
444 def GetAnnotation(model
, elementName
):
445 """ Get an object's annotation used for tooltips """
446 if hasattr(model
, "_complexType"):
447 ct
= model
._complexType
448 elif hasattr(model
, "__xsdcomplextype__"):
449 ct
= model
.__xsdcomplextype
__
454 el
= ct
.findElement(elementName
)
455 if el
and el
.annotation
:
461 def GetDisplayName(doc
, name
):
463 appDocMgr
= doc
.GetAppDocMgr()
465 name
= appDocMgr
.toDisplayTypeName(name
)
467 namespace
, name
= xmlutils
.splitType(name
)
468 if namespace
and hasattr(doc
.GetModel(), "getXmlNamespaces"):
469 for xmlkey
, xmlval
in doc
.GetModel().getXmlNamespaces().iteritems():
470 if xmlval
== namespace
:
471 name
= "%s:%s" % (xmlkey
, name
)
475 import activegrid
.model
.schema
as schemalib
476 baseTypeName
= schemalib
.mapXsdType(name
)
483 def GetInternalName(doc
, name
):
485 appDocMgr
= doc
.GetAppDocMgr()
487 name
= appDocMgr
.toInternalTypeName(name
)
489 namespace
, name
= xmlutils
.splitType(name
)
490 if namespace
and hasattr(doc
.GetModel(), "getXmlNamespaces"):
491 for xmlkey
, xmlval
in doc
.GetModel().getXmlNamespaces().iteritems():
492 if xmlkey
== namespace
:
493 name
= "%s:%s" % (xmlval
, name
)
496 import activegrid
.model
.schema
as schemalib
497 name
= schemalib
.mapAGType(name
)
502 #----------------------------------------------------------------------------
503 # Methods for finding application level info
504 #----------------------------------------------------------------------------
506 def GetProjectForDoc(doc
):
507 """ Given a document find which project it belongs to.
508 Tries to intelligently resolve conflicts if it is in more than one open project.
510 projectService
= wx
.GetApp().GetService(ProjectEditor
.ProjectService
)
512 projectDoc
= projectService
.FindProjectFromMapping(doc
)
516 projectDoc
= projectService
.GetCurrentProject()
519 if projectDoc
.IsFileInProject(doc
.GetFilename()):
523 openDocs
= wx
.GetApp().GetDocumentManager().GetDocuments()
524 for openDoc
in openDocs
:
525 if openDoc
== projectDoc
:
527 if(isinstance(openDoc
, ProjectEditor
.ProjectDocument
)):
528 if openDoc
.IsFileInProject(doc
.GetFilename()):
529 projects
.append(openDoc
)
532 if len(projects
) == 1:
535 choices
= [os
.path
.basename(project
.GetFilename()) for project
in projects
]
536 dlg
= wx
.SingleChoiceDialog(wx
.GetApp().GetTopWindow(), _("'%s' found in more than one project.\nWhich project should be used for this operation?") % os
.path
.basename(doc
.GetFilename()), _("Select Project"), choices
, wx
.DEFAULT_DIALOG_STYLE|wx
.RESIZE_BORDER|wx
.OK|wx
.CENTRE
)
539 if dlg
.ShowModal() == wx
.ID_OK
:
540 i
= dlg
.GetSelection()
541 projectDoc
= projects
[i
]
548 def GetAppInfoForDoc(doc
):
549 """ Get the AppInfo for a given document """
550 projectDoc
= GetProjectForDoc(doc
)
552 return projectDoc
.GetAppInfo()
556 def GetAppDocMgrForDoc(doc
):
557 """ Get the AppDocMgr for a given document """
558 projectDoc
= GetProjectForDoc(doc
)
560 return projectDoc
.GetModel()
564 def GetAppInfoLanguage(doc
=None):
565 from activegrid
.server
.projectmodel
import LANGUAGE_DEFAULT
568 language
= doc
.GetAppInfo().language
573 config
= wx
.ConfigBase_Get()
574 language
= config
.Read(ProjectEditor
.APP_LAST_LANGUAGE
, LANGUAGE_DEFAULT
)
577 doc
.GetAppInfo().language
= language
# once it is selected, it must be set.
581 def AddWsdlAgToProjectFromWsdlRegistration(wsdlRegistration
):
582 """Add wsdl ag for registry entry."""
584 wsdlPath
= wsdlRegistration
.path
586 serviceRefName
= wsdlRegistration
.name
588 agwsDoc
= _InitWsdlAg(wsdlPath
, rootPath
, serviceRefName
)
590 if (agwsDoc
== None):
593 serviceRef
= agwsDoc
.GetModel()
595 serviceRef
.serviceType
= wsdlRegistration
.type
597 import activegrid
.server
.deployment
as deployment
599 if (serviceRef
.serviceType
== deployment
.SERVICE_LOCAL
):
600 serviceRef
.localService
= deployment
.LocalService(
601 wsdlRegistration
.codeFile
)
603 elif (serviceRef
.serviceType
== deployment
.SERVICE_DATABASE
):
604 serviceRef
.databaseService
= deployment
.DatabaseService(
605 wsdlRegistration
.datasourceName
)
607 elif (serviceRef
.serviceType
== deployment
.SERVICE_SOAP
):
610 elif (serviceRef
.serviceType
== deployment
.SERVICE_RSS
):
611 serviceRef
.rssService
= deployment
.RssService(wsdlRegistration
.feedUrl
)
613 elif (serviceRef
.serviceType
== deployment
.SERVICE_REST
):
614 serviceRef
.restService
= deployment
.RestService(
615 wsdlRegistration
.baseUrl
)
617 raise AssertionError("Unknown service type")
619 _AddToProject(agwsDoc
, addWsdl
=True)
622 def AddWsdlAgToProject(wsdlPath
, rootPath
=fileutils
.AG_SYSTEM_STATIC_VAR_REF
,
623 serviceRefName
=None, className
=None, serviceType
=None,
624 dataSourceName
=None):
626 wsdlPath: path to wsdl from rootPath. If wsdlPath is absolute, rootPath
627 is ignored. rootPath is also ignored when rootPath is set to None.
628 rootPath: defaults to ${AG_SYSTEM_STATIC}.
629 serviceRefName: If None, it will be set to the wsdl file name without
630 the .wsdl file extension.
631 className: if not None, will be used for the the wsdlag's ClassName.
632 serviceType: defaults to local.
633 dataSourceName: if serviceType is deployment.DATABASE, the ds must be
638 import activegrid
.model
.basedocmgr
as basedocmgr
639 import activegrid
.server
.deployment
as deployment
641 if (serviceType
== None):
642 serviceType
= deployment
.SERVICE_LOCAL
645 agwsDoc
= _InitWsdlAg(wsdlPath
, rootPath
, serviceRefName
)
647 if (agwsDoc
== None):
650 serviceRef
= agwsDoc
.GetModel()
652 serviceRef
.serviceType
= serviceType
654 if (serviceType
== deployment
.SERVICE_DATABASE
and dataSourceName
!= None):
655 serviceRef
.databaseService
= deployment
.DatabaseService(dataSourceName
)
657 serviceRef
.localService
= deployment
.LocalService(className
=className
)
659 _AddToProject(agwsDoc
)
662 def _AddToProject(agwsDoc
, addWsdl
=False):
663 import activegrid
.model
.basedocmgr
as basedocmgr
664 projectDoc
= GetCurrentProject()
665 agwsDoc
.OnSaveDocument(agwsDoc
.GetFilename())
667 files
= [agwsDoc
.fileName
]
668 types
= [basedocmgr
.FILE_TYPE_SERVICE
]
669 names
= [agwsDoc
.GetModel().name
]
671 m
= agwsDoc
.GetModel()
672 wsdlName
= os
.path
.splitext(os
.path
.basename(m
.filePath
))[0]
673 appDocMgr
= projectDoc
.GetAppDocMgr()
674 if (appDocMgr
.findService(wsdlName
) == None):
675 m
= agwsDoc
.GetModel()
676 files
.append(m
.filePath
)
678 names
.append(wsdlName
)
680 ProjectEditor
.ProjectAddFilesCommand(projectDoc
, files
, types
=types
,
684 def _InitWsdlAg(wsdlPath
, rootPath
=fileutils
.AG_SYSTEM_STATIC_VAR_REF
,
685 serviceRefName
=None):
687 projectDoc
= GetCurrentProject()
688 appDocMgr
= projectDoc
.GetAppDocMgr()
690 if (serviceRefName
== None):
691 serviceRefName
= os
.path
.splitext(os
.path
.basename(wsdlPath
))[0]
693 if (appDocMgr
.findServiceRef(serviceRefName
) != None):
698 import activegrid
.server
.deployment
as deployment
700 template
= XFormWizard
.GetTemplate(WsdlAgEditor
.WsdlAgDocument
)
701 ext
= template
.GetDefaultExtension()
702 fullPath
= os
.path
.join(appDocMgr
.homeDir
, serviceRefName
+ ext
)
704 agwsDoc
= template
.CreateDocument(
705 fullPath
, flags
=(wx
.lib
.docview
.DOC_NO_VIEW|wx
.lib
.docview
.DOC_NEW|
706 wx
.lib
.docview
.DOC_OPEN_ONCE
))
708 serviceRef
= agwsDoc
.GetModel()
709 serviceRef
.name
= serviceRefName
711 if (rootPath
== None or os
.path
.isabs(wsdlPath
)):
712 serviceRef
.filePath
= wsdlPath
714 # make sure to use forward slashes for the path to the .wsdl
715 wsdlPath
= wsdlPath
.replace("\\", "/")
717 if not wsdlPath
.startswith("/"):
718 wsdlPath
= "/%s" % wsdlPath
719 serviceRef
.filePath
= "%s%s" % (rootPath
, wsdlPath
)
721 agwsDoc
.fileName
= fullPath
726 def GetSchemaName(schema
):
727 return os
.path
.basename(schema
.fileName
)
730 class AGChoice(wx
.Choice
):
731 """Extension to wx.Choice that fixes linux bug where first item of choices
732 passed into ctor would be visible, but not selected."""
733 def __init__(self
, parent
, id, choices
=[]):
734 super(AGChoice
, self
).__init
__(parent
=parent
, id=id)
735 self
.AppendItems(choices
)