00001 import string
00002
00003 from wxPython.wx import *
00004
00005 from cdbVisCore import *
00006 from objectclasses import *
00007 import helper
00008
00009
00010
00011
00012
00013
00014 LINKTYPEID = 102
00015 LINKTYPENAME = 103
00016 COLORBUTTON = 104
00017 LINKTYPE_COMBO = 105
00018 ID_ADD = 106
00019 ID_REMOVE = 107
00020 CHECK_COMP = 108
00021 COMP_LINKTYPES = 109
00022
00023
00024
00025
00026
00027
00028
00029 class CreateLinkTypeWindow(wxDialog):
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 def __init__(self,parent,id,selectedsystem,creationmode=True,linktypeobj=None,linktypes=[]):
00048
00049 self.__creationmode = creationmode
00050 self.main = parent
00051 self.__linktypes = linktypes
00052
00053 if creationmode == True:
00054 title = "Create A Link Type"
00055 else:
00056 title = "Modify A Link Type"
00057 selectedsystem = linktypeobj.GetSystem()
00058 self.linktypeobj = linktypeobj
00059 self.renameobj = None
00060
00061 try:
00062 self.__linktypes.remove(linktypeobj.GetName())
00063
00064
00065
00066 except ValueError,err:
00067 pass
00068
00069 height = 200
00070
00071 wxDialog.__init__(self,parent,id,title,wxDefaultPosition,wxSize(260,height))
00072
00073
00074 self.__panel = wxPanel(self,-1,wxDLG_PNT(self,wxPoint(5,5)))
00075
00076
00077 if not self.__creationmode:
00078 id = linktypeobj.GetID()
00079 self.__linktypeidcaption = wxStaticText(self.__panel,-1,"Link Type ID:")
00080 self.__linktypeidtxtbox = wxTextCtrl(self.__panel,LINKTYPEID,str(id),wxDefaultPosition,wxSize(50,-1))
00081 self.__linktypeidtxtbox.Enable(False)
00082 name = linktypeobj.GetName()
00083 style = wxCB_READONLY
00084 else:
00085 name = ""
00086 my_links = []
00087 style = 0
00088
00089 self.__linktypecaption = wxStaticText(self.__panel,-1,"Link Type Name(20):")
00090 self.__linktypetxtbox = wxTextCtrl(self.__panel,LINKTYPENAME,name,wxDefaultPosition,wxSize(120,-1))
00091
00092
00093 self.__compositelinktype = wxCheckBox(self.__panel,CHECK_COMP,"Composite linktype?")
00094 EVT_CHECKBOX(self.__panel,CHECK_COMP,self.CheckboxClicked)
00095
00096 self.__linktypescaption = wxStaticText(self.__panel,-1,"Created linktypes:")
00097 self.__linktypescmbbox = wxComboBox(self.__panel,LINKTYPE_COMBO,"",choices=self.__linktypes,size=wxSize(120,-1))
00098 self.__addbutton = wxButton(self.__panel,ID_ADD,"&Add",size=wxSize(60,-1))
00099 EVT_BUTTON(self.__panel,ID_ADD,self.OnAdd)
00100 self.__rembutton = wxButton(self.__panel,ID_REMOVE,"&Remove",size=wxSize(60,-1))
00101 EVT_BUTTON(self.__panel,ID_REMOVE,self.OnRemove)
00102 self.__complinktypes = wxTextCtrl(self.__panel,COMP_LINKTYPES,"",wxDefaultPosition,wxSize(220,50),style=wxTE_MULTILINE | wxTE_READONLY)
00103
00104 self.CheckboxClicked(None)
00105
00106
00107 self.__okbutton = wxButton(self.__panel,wxID_OK,"&Ok")
00108 self.__cancelbutton = wxButton(self.__panel,wxID_CANCEL,"&Cancel")
00109
00110 EVT_BUTTON(self,wxID_OK,self.OkButtonClicked)
00111
00112
00113 self.__layout = wxBoxSizer(wxVERTICAL)
00114 buttonlayout = wxBoxSizer(wxHORIZONTAL)
00115 buttonlayout.Add(self.__okbutton)
00116 buttonlayout.Add(self.__cancelbutton)
00117
00118 namelayout = wxBoxSizer(wxVERTICAL)
00119 namelayout.Add(self.__linktypecaption)
00120 namelayout.Add(self.__linktypetxtbox)
00121 linklayout = wxBoxSizer(wxHORIZONTAL)
00122 linklayout.Add(namelayout)
00123 if not creationmode:
00124 idlayout = wxBoxSizer(wxVERTICAL)
00125 idlayout.Add(self.__linktypeidcaption)
00126 idlayout.Add(self.__linktypeidtxtbox)
00127 linklayout.AddSpacer((10,-1))
00128 linklayout.Add(idlayout)
00129 self.__layout.Add(linklayout)
00130
00131 linktypeslayout = wxBoxSizer(wxHORIZONTAL)
00132 linktypeslayout.Add(self.__linktypescmbbox)
00133 linktypeslayout.Add(self.__addbutton)
00134 linktypeslayout.Add(self.__rembutton)
00135
00136 self.__layout.Add(self.__compositelinktype)
00137 self.__layout.AddSpacer((-1,5))
00138 self.__layout.Add(self.__linktypescaption)
00139 self.__layout.Add(linktypeslayout)
00140 self.__layout.Add(self.__complinktypes)
00141
00142 self.__layout.AddSpacer((-1,5))
00143 self.__layout.Add(buttonlayout)
00144
00145 self.SetSizer(self.__layout)
00146 self.SetAutoLayout(1)
00147 self.__layout.Fit(self.__panel)
00148
00149
00150
00151
00152 def CheckboxClicked(self,event=None):
00153
00154 if self.__compositelinktype.GetValue() == False:
00155 self.__linktypescaption.Enable(False)
00156 self.__linktypescmbbox.Enable(False)
00157 self.__addbutton.Enable(False)
00158 self.__rembutton.Enable(False)
00159 self.__complinktypes.Enable(False)
00160 else:
00161 self.__linktypescaption.Enable(True)
00162 self.__linktypescmbbox.Enable(True)
00163 self.__addbutton.Enable(True)
00164 self.__rembutton.Enable(True)
00165
00166
00167
00168
00169
00170
00171 def OnAdd(self,event):
00172
00173 val = self.__linktypescmbbox.GetValue()
00174 if string.find(self.__complinktypes.GetValue(),val,0) != -1:
00175 self.main.ShowError("The linktype is already added to the composite linktype.",ERR_ERROR)
00176 else:
00177 self.__complinktypes.SetValue(self.__complinktypes.GetValue() + val + ",")
00178
00179
00180
00181
00182
00183
00184 def OnRemove(self,event):
00185
00186 val = self.__linktypescmbbox.GetValue()
00187 if string.find(self.__complinktypes.GetValue(),val,0) == -1:
00188 self.main.ShowError("This linktype is not a part of the composite linktype, and cannot be removed.",ERR_ERROR)
00189 else:
00190 myvals = self.__complinktypes.GetValue()
00191 myvals = myvals.replace(val + ",","")
00192 self.__complinktypes.SetValue(myvals)
00193
00194
00195
00196
00197
00198
00199
00200 def SaveObject(self):
00201
00202 if self.__creationmode:
00203 create = True
00204 else:
00205 create = False
00206
00207 try:
00208 if self.__creationmode:
00209 if self.__linktypetxtbox.GetValue() in self.__linktypes:
00210 raise ValidationError, "Cannot create linktype as the name you chose is already in use."
00211
00212 else:
00213 if self.__linktypetxtbox.GetValue() != self.linktypeobj.GetName():
00214 ans = wxMessageBox("You have renamed the link type, was that your intention? Remember that you can not undo renaming, \nbut you can rename the object as many times as you want.","Rename?",wxYES_NO | wxICON_QUESTION)
00215 if ans == wxNO:
00216 self.__linktypetxtbox.SetValue(self.linktypeobj.GetName())
00217 return False
00218
00219 if self.__linktypetxtbox.GetValue() in self.__linktypes:
00220 raise ValidationError,"The linktype cannot be created as the name you have given is already in use."
00221
00222 self.renameobj = LinkType(self.main.GetActiveSystem(),self.__linktypetxtbox.GetValue(),True)
00223 self.renameobj.SetOldName(self.linktypeobj.GetName())
00224 self.renameobj.SetSaveStatus(RENAME)
00225
00226
00227 self.lktypeobj = LinkType(self.main.GetActiveSystem(),self.__linktypetxtbox.GetValue(),create)
00228 self.lktypeobj.SetName(self.__linktypetxtbox.GetValue())
00229
00230
00231 if self.__compositelinktype.GetValue() == True:
00232 if self.__complinktypes.GetValue() == "":
00233 raise ValidationError,"You have set this type as composite linktype, but you haven't added any linktypes to this linktype."
00234 else:
00235 self.lktypeobj.SetCompositeLinks(self.__complinktypes.GetValue())
00236
00237
00238 if not self.__creationmode and self.__linktypeidtxtbox != "":
00239 self.lktypeobj.SetID(int(self.__linktypeidtxtbox.GetValue()))
00240
00241 return True
00242 except ValidationError,err:
00243 self.main.ShowError(str(err),ERR_ERROR,True)
00244 return False
00245 except ValueError,err:
00246 self.main.ShowError("The link ID is not a legal integer value.",ERR_ERROR,True)
00247 return False
00248
00249
00250
00251
00252
00253
00254
00255 def OkButtonClicked(self,event):
00256
00257 if self.__linktypetxtbox.GetValue() == "":
00258 self.main.ShowError("The link type has to be given a name.",ERR_ERROR)
00259 return False
00260
00261 success = self.SaveObject()
00262 if not success:
00263 return False
00264
00265 event.Skip()
00266
00267
00268
00269
00270
00271
00272 def IsCreationMode(self):
00273
00274 return self.__creationmode
00275
00276
00277
00278
00279
00280
00281
00282
00283 def GetLinkTypeObj(self):
00284
00285 if self.__creationmode:
00286 return self.lktypeobj
00287 else:
00288 return self.lktypeobj,self.renameobj
00289
00290