class TaskEnvironmentPanel(wx.Panel): def __init__(self, parent, dp): wx.Panel.__init__(self, parent, TASK_PANELENVIRONMENT_ID) self.dbProxy = dp self.theTaskId = None self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL) mainSizer.Add(environmentListSizer, 0, wx.EXPAND) self.environmentList = EnvironmentListCtrl(self, TASK_LISTENVIRONMENTS_ID, self.dbProxy) environmentListSizer.Add(self.environmentList, 1, wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer, 1, wx.EXPAND) nbBox = wx.StaticBox(self, -1) nbBoxSizer = wx.StaticBoxSizer(nbBox, wx.VERTICAL) environmentDimSizer.Add(nbBoxSizer, 1, wx.EXPAND) self.notebook = TaskEnvironmentNotebook(self, self.dbProxy) nbBoxSizer.Add(self.notebook, 1, wx.EXPAND) self.dependenciesCtrl = self.notebook.FindWindowById( TASK_TEXTDEPENDENCIES_ID) self.personaList = self.notebook.FindWindowById(TASK_LISTPERSONAS_ID) self.assetList = self.notebook.FindWindowById(TASK_LISTASSETS_ID) self.caList = self.notebook.FindWindowById( TASK_LISTCONCERNASSOCIATIONS_ID) self.narrativeCtrl = self.notebook.FindWindowById( TASK_TEXTNARRATIVE_ID) self.consequencesCtrl = self.notebook.FindWindowById( TASK_TEXTCONSEQUENCES_ID) self.benefitsCtrl = self.notebook.FindWindowById(TASK_TEXTBENEFITS_ID) self.SetSizer(mainSizer) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) self.dependenciesCtrl.Disable() self.personaList.Disable() self.assetList.Disable() self.caList.Disable() self.narrativeCtrl.Disable() self.consequencesCtrl.Disable() self.benefitsCtrl.Disable() self.theDimMenu = wx.Menu() self.theDimMenu.Append(DIMLIST_MENUADD_ID, 'Add Goal') self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown) wx.EVT_MENU(self.theDimMenu, DIMLIST_MENUADD_ID, self.onAddGoal) def OnRightDown(self, evt): self.PopupMenu(self.theDimMenu) def onAddGoal(self, evt): print 'goal' def loadControls(self, task): self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) self.theTaskId = task.id() environmentNames = [] for cp in task.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in task.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentNames.append(environmentName) environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] self.dependenciesCtrl.SetValue(p.dependencies()) self.personaList.setEnvironment(environmentName) self.assetList.setEnvironment(environmentName) self.caList.setEnvironment(environmentName) self.narrativeCtrl.setEnvironment(environmentName) self.personaList.load(p.personas()) self.assetList.load(p.assets()) self.caList.load(p.concernAssociations()) self.narrativeCtrl.SetValue(p.narrative()) self.consequencesCtrl.SetValue(p.consequences()) self.benefitsCtrl.SetValue(p.benefits()) self.narrativeCtrl.setCodes(p.codes('narrative')) self.consequencesCtrl.setCodes(p.codes('consequences')) self.benefitsCtrl.setCodes(p.codes('benefits')) self.environmentList.Select(0) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.dependenciesCtrl.Enable() self.personaList.Enable() self.assetList.Enable() self.caList.Enable() self.narrativeCtrl.Enable() self.consequencesCtrl.Enable() self.benefitsCtrl.Enable() self.theSelectedIdx = 0 self.narrativeCtrl.setTask(task.name()) def OnEnvironmentSelected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.dependenciesCtrl.SetValue(p.dependencies()) self.personaList.setEnvironment(environmentName) self.assetList.setEnvironment(environmentName) self.caList.setEnvironment(environmentName) self.personaList.load(p.personas()) self.assetList.load(p.assets()) self.caList.load(p.concernAssociations()) self.narrativeCtrl.SetValue(p.narrative()) self.consequencesCtrl.SetValue(p.consequences()) self.benefitsCtrl.SetValue(p.benefits()) self.narrativeCtrl.setCodes(p.codes('narrative')) self.consequencesCtrl.setCodes(p.codes('consequences')) self.benefitsCtrl.setCodes(p.codes('benefits')) self.dependenciesCtrl.Enable() self.personaList.Enable() self.assetList.Enable() self.caList.Enable() self.narrativeCtrl.Enable() self.consequencesCtrl.Enable() self.benefitsCtrl.Enable() self.narrativeCtrl.setEnvironment(environmentName) def OnEnvironmentDeselected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) envCodebook = { 'narrative': self.narrativeCtrl.codes(), 'consequences': self.consequencesCtrl.codes(), 'benefits': self.benefitsCtrl.codes() } self.theEnvironmentDictionary[ environmentName] = TaskEnvironmentProperties( environmentName, self.dependenciesCtrl.GetValue(), self.personaList.dimensions(), self.assetList.dimensions(), self.caList.dimensions(), self.narrativeCtrl.GetValue(), self.consequencesCtrl.GetValue(), self.benefitsCtrl.GetValue(), envCodebook) self.dependenciesCtrl.SetValue('') self.personaList.setEnvironment('') self.assetList.setEnvironment('') self.caList.setEnvironment('') self.narrativeCtrl.setEnvironment('') self.personaList.DeleteAllItems() self.assetList.DeleteAllItems() self.caList.DeleteAllItems() self.narrativeCtrl.SetValue('') self.consequencesCtrl.SetValue('') self.benefitsCtrl.SetValue('') self.narrativeCtrl.setCodes({}) self.consequencesCtrl.setCodes({}) self.benefitsCtrl.setCodes({}) self.theSelectedIdx = -1 self.dependenciesCtrl.Disable() self.personaList.Disable() self.assetList.Disable() self.caList.Disable() self.narrativeCtrl.Disable() self.consequencesCtrl.Disable() self.benefitsCtrl.Disable() def OnAddEnvironment(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = TaskEnvironmentProperties(environmentName) self.environmentList.Select(self.theSelectedIdx) self.personaList.setEnvironment(environmentName) self.assetList.setEnvironment(environmentName) self.caList.setEnvironment(environmentName) self.narrativeCtrl.setEnvironment(environmentName) self.personaList.DeleteAllItems() self.assetList.DeleteAllItems() self.caList.DeleteAllItems() self.dependenciesCtrl.SetValue('') self.narrativeCtrl.SetValue('') self.consequencesCtrl.SetValue('') self.benefitsCtrl.SetValue('') self.narrativeCtrl.setCodes({}) self.consequencesCtrl.setCodes({}) self.benefitsCtrl.setCodes({}) self.dependenciesCtrl.Enable() self.personaList.Enable() self.assetList.Enable() self.caList.Enable() self.narrativeCtrl.Enable() self.consequencesCtrl.Enable() self.benefitsCtrl.Enable() inheritedEnv = self.environmentList.inheritedEnvironment() if (inheritedEnv != '' and self.theTaskId != None): p = self.dbProxy.inheritedTaskProperties(self.theTaskId, inheritedEnv) self.theEnvironmentDictionary[environmentName] = p self.dependenciesCtrl.SetValue(p.dependencies()) self.personaList.setEnvironment(environmentName) self.assetList.setEnvironment(environmentName) self.caList.setEnvironment(environmentName) self.narrativeCtrl.setEnvironment(environmentName) self.personaList.load(p.personas()) self.assetList.load(p.assets()) self.caList.load(p.concernAssociations()) self.narrativeCtrl.SetValue(p.narrative()) self.consequencesCtrl.SetValue(p.consequences()) self.benefitsCtrl.SetValue(p.benefits()) self.narrativeCtrl.setCodes(p.codes('narrative')) self.consequencesCtrl.setCodes(p.codes('consequences')) self.benefitsCtrl.setCodes(p.codes('benefits')) self.dependenciesCtrl.Enable() self.personaList.Enable() self.assetList.Enable() self.caList.Enable() self.narrativeCtrl.Enable() self.consequencesCtrl.Enable() self.benefitsCtrl.Enable() def OnDeleteEnvironment(self, evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 self.dependenciesCtrl.SetValue('') self.personaList.setEnvironment('') self.assetList.setEnvironment('') self.caList.setEnvironment('') self.narrativeCtrl.setEnvironment('') self.personaList.DeleteAllItems() self.assetList.DeleteAllItems() self.caList.DeleteAllItems() self.narrativeCtrl.SetValue('') self.consequencesCtrl.SetValue('') self.benefitsCtrl.SetValue('') self.narrativeCtrl.setCodes({}) self.consequencesCtrl.setCodes({}) self.benefitsCtrl.setCodes({}) self.dependenciesCtrl.Disable() self.personaList.Disable() self.assetList.Disable() self.caList.Disable() self.narrativeCtrl.Disable() self.consequencesCtrl.Disable() self.benefitsCtrl.Disable() def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) envCodebook = { 'narrative': self.narrativeCtrl.codes(), 'consequences': self.consequencesCtrl.codes(), 'benefits': self.benefitsCtrl.codes() } self.theEnvironmentDictionary[ environmentName] = TaskEnvironmentProperties( environmentName, self.dependenciesCtrl.GetValue(), self.personaList.dimensions(), self.assetList.dimensions(), self.caList.dimensions(), self.narrativeCtrl.GetValue(), self.consequencesCtrl.GetValue(), self.benefitsCtrl.GetValue(), envCodebook) return self.theEnvironmentDictionary.values()
class ReqToGoalEnvironmentPanel(wx.Panel): def __init__(self,parent,goalDef,goalCat,goalPri,goalFc,goalIssue,goalAssets,defaultEnv): wx.Panel.__init__(self,parent,armid.GOAL_PANELENVIRONMENT_ID) b = Borg() self.dbProxy = b.dbProxy self.theGoalId = None self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 self.theGoalDefinition = goalDef self.theGoalCategory = goalCat self.theGoalPriority = goalPri self.theGoalFitCriterion = goalFc self.theGoalIssue = goalIssue self.theGoalAssets = goalAssets mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL) mainSizer.Add(environmentListSizer,0,wx.EXPAND) self.environmentList = EnvironmentListCtrl(self,armid.GOAL_LISTENVIRONMENTS_ID,self.dbProxy) environmentListSizer.Add(self.environmentList,1,wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer,1,wx.EXPAND) nbBox = wx.StaticBox(self,-1) nbSizer = wx.StaticBoxSizer(nbBox,wx.VERTICAL) environmentDimSizer.Add(nbSizer,1,wx.EXPAND) self.notebook = ReqToGoalNotebook(self,self.dbProxy) nbSizer.Add(self.notebook,1,wx.EXPAND) self.SetSizer(mainSizer) self.goalAssociationCtrl = self.notebook.FindWindowById(armid.GOAL_LISTGOALREFINEMENTS_ID) self.subGoalAssociationCtrl = self.notebook.FindWindowById(armid.GOAL_LISTSUBGOALREFINEMENTS_ID) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment) self.goalAssociationCtrl.Disable() self.subGoalAssociationCtrl.Disable() self.theEnvironmentDictionary[defaultEnv] = GoalEnvironmentProperties(defaultEnv) self.environmentList.Select(0) self.goalAssociationCtrl.setEnvironment(defaultEnv) self.goalAssociationCtrl.DeleteAllItems() self.subGoalAssociationCtrl.setEnvironment(defaultEnv) self.subGoalAssociationCtrl.DeleteAllItems() self.goalAssociationCtrl.Enable() self.subGoalAssociationCtrl.Enable() def OnEnvironmentSelected(self,evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.goalAssociationCtrl.setEnvironment(environmentName) self.goalAssociationCtrl.load(p.goalRefinements()) self.subGoalAssociationCtrl.setEnvironment(environmentName) self.subGoalAssociationCtrl.load(p.subGoalRefinements()) self.goalAssociationCtrl.Enable() self.subGoalAssociationCtrl.Enable() def OnEnvironmentDeselected(self,evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[environmentName] = GoalEnvironmentProperties(environmentName,'',self.theGoalDefinition,self.theGoalCategory,self.theGoalPriority,self.theGoalFitCriterion,self.theGoalIssue,self.goalAssociationCtrl.dimensions(),self.subGoalAssociationCtrl.dimensions(),self.theGoalAssets,[]) self.goalAssociationCtrl.DeleteAllItems() self.goalAssociationCtrl.setEnvironment('') self.subGoalAssociationCtrl.DeleteAllItems() self.subGoalAssociationCtrl.setEnvironment('') self.theSelectedIdx = -1 self.goalAssociationCtrl.Disable() self.subGoalAssociationCtrl.Disable() def OnAddEnvironment(self,evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[environmentName] = GoalEnvironmentProperties(environmentName) self.environmentList.Select(self.theSelectedIdx) self.goalAssociationCtrl.setEnvironment(environmentName) self.goalAssociationCtrl.DeleteAllItems() self.subGoalAssociationCtrl.setEnvironment(environmentName) self.subGoalAssociationCtrl.DeleteAllItems() self.goalAssociationCtrl.Enable() self.subGoalAssociationCtrl.Enable() inheritedEnv = self.environmentList.inheritedEnvironment() if (inheritedEnv != '' and self.theGoalId != None): p = self.dbProxy.inheritedGoalProperties(self.theGoalId,inheritedEnv) self.theEnvironmentDictionary[environmentName] = p self.goalAssociationCtrl.setEnvironment(environmentName) self.goalAssociationCtrl.load(p.goalRefinements()) self.subGoalAssociationCtrl.setEnvironment(environmentName) self.subGoalAssociationCtrl.load(p.subGoalRefinements()) def OnDeleteEnvironment(self,evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 self.goalAssociationCtrl.DeleteAllItems() self.goalAssociationCtrl.setEnvironment('') self.subGoalAssociationCtrl.DeleteAllItems() self.subGoalAssociationCtrl.setEnvironment('') self.goalAssociationCtrl.Disable() self.subGoalAssociationCtrl.Disable() def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[environmentName] = GoalEnvironmentProperties(environmentName,'',self.theGoalDefinition,self.theGoalCategory,self.theGoalPriority,self.theGoalFitCriterion,self.theGoalIssue,self.goalAssociationCtrl.dimensions(),self.subGoalAssociationCtrl.dimensions(),self.theGoalAssets,[]) return self.theEnvironmentDictionary.values()
class AttackerEnvironmentPanel(wx.Panel): def __init__(self, parent, dp): wx.Panel.__init__(self, parent, ATTACKER_PANELENVIRONMENT_ID) self.dbProxy = dp self.theAttackerId = None self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL) mainSizer.Add(environmentListSizer, 0, wx.EXPAND) self.environmentList = EnvironmentListCtrl( self, ATTACKERENVIRONMENT_LISTENVIRONMENTS_ID, self.dbProxy) environmentListSizer.Add(self.environmentList, 1, wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer, 1, wx.EXPAND) rmSizer = wx.BoxSizer(wx.HORIZONTAL) environmentDimSizer.Add(rmSizer, 1, wx.EXPAND) self.roleList = DimensionListCtrl(self, ATTACKERENVIRONMENT_LISTROLES_ID, wx.DefaultSize, 'Role', 'role', self.dbProxy) roleBox = wx.StaticBox(self) roleSizer = wx.StaticBoxSizer(roleBox, wx.HORIZONTAL) roleSizer.Add(self.roleList, 1, wx.EXPAND) rmSizer.Add(roleSizer, 1, wx.EXPAND) self.motiveList = DimensionListCtrl( self, ATTACKERENVIRONMENT_LISTMOTIVES_ID, wx.DefaultSize, 'Motive', 'motivation', self.dbProxy) motiveBox = wx.StaticBox(self) motiveSizer = wx.StaticBoxSizer(motiveBox, wx.HORIZONTAL) motiveSizer.Add(self.motiveList, 1, wx.EXPAND) rmSizer.Add(motiveSizer, 1, wx.EXPAND) capBox = wx.StaticBox(self) capSizer = wx.StaticBoxSizer(capBox, wx.HORIZONTAL) environmentDimSizer.Add(capSizer, 1, wx.EXPAND) self.capabilitiesList = CapabilitiesListCtrl( self, ATTACKERENVIRONMENT_LISTCAPABILITIES_ID, self.dbProxy) capSizer.Add(self.capabilitiesList, 1, wx.EXPAND) self.SetSizer(mainSizer) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) def loadControls(self, attacker): self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) self.theAttackerId = attacker.id() environmentNames = [] for cp in attacker.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in attacker.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentNames.append(environmentName) environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] self.roleList.setEnvironment(environmentName) self.roleList.load(p.roles()) self.motiveList.setEnvironment(environmentName) self.motiveList.load(p.motives()) self.capabilitiesList.setEnvironment(environmentName) self.capabilitiesList.load(p.capabilities()) self.environmentList.Select(0) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.theSelectedIdx = 0 def OnEnvironmentSelected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.roleList.setEnvironment(environmentName) self.roleList.load(p.roles()) self.motiveList.setEnvironment(environmentName) self.motiveList.load(p.motives()) self.capabilitiesList.setEnvironment(environmentName) self.capabilitiesList.load(p.capabilities()) def OnEnvironmentDeselected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = AttackerEnvironmentProperties( environmentName, self.roleList.dimensions(), self.motiveList.dimensions(), self.capabilitiesList.capabilities()) self.roleList.setEnvironment('') self.roleList.DeleteAllItems() self.motiveList.setEnvironment('') self.motiveList.DeleteAllItems() self.capabilitiesList.setEnvironment('') self.capabilitiesList.DeleteAllItems() self.theSelectedIdx = -1 def OnAddEnvironment(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = AttackerEnvironmentProperties( environmentName, [], [], []) self.environmentList.Select(self.theSelectedIdx) self.capabilitiesList.setEnvironment(environmentName) inheritedEnv = self.environmentList.inheritedEnvironment() if (inheritedEnv != '' and self.theAttackerId != None): p = self.dbProxy.inheritedAttackerProperties( self.theAttackerId, inheritedEnv) self.theEnvironmentDictionary[environmentName] = p self.roleList.setEnvironment(environmentName) self.roleList.load(p.roles()) self.motiveList.setEnvironment(environmentName) self.motiveList.load(p.motives()) self.capabilitiesList.setEnvironment(environmentName) self.capabilitiesList.load(p.capabilities()) def OnDeleteEnvironment(self, evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = AttackerEnvironmentProperties( environmentName, self.roleList.dimensions(), self.motiveList.dimensions(), self.capabilitiesList.capabilities()) return self.theEnvironmentDictionary.values()
class PersonaEnvironmentPanel(wx.Panel): def __init__(self, parent, dp): wx.Panel.__init__(self, parent, PERSONA_PANELENVIRONMENT_ID) self.dbProxy = dp self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 self.thePersonaName = '' mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL) mainSizer.Add(environmentListSizer, 0, wx.EXPAND) self.environmentList = EnvironmentListCtrl( self, PERSONA_LISTENVIRONMENTS_ID, self.dbProxy) environmentListSizer.Add(self.environmentList, 1, wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer, 1, wx.EXPAND) nbBox = wx.StaticBox(self, -1) nbSizer = wx.StaticBoxSizer(nbBox, wx.HORIZONTAL) environmentDimSizer.Add(nbSizer, 1, wx.EXPAND) self.notebook = PersonaEnvironmentNotebook(self, self.dbProxy) nbSizer.Add(self.notebook, 1, wx.EXPAND) self.SetSizer(mainSizer) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) self.directCtrl = self.notebook.FindWindowById(PERSONA_CHECKDIRECT_ID) self.roleList = self.notebook.FindWindowById(PERSONA_LISTROLES_ID) self.descriptionCtrl = self.notebook.FindWindowById( PERSONA_TEXTNARRATIVE_ID) self.directCtrl.Disable() self.descriptionCtrl.Disable() self.roleList.Disable() def loadControls(self, persona): self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) self.thePersonaName = persona.name() environmentNames = [] for cp in persona.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in persona.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentNames.append(environmentName) environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] if (p.directFlag() == 'True'): self.directCtrl.SetValue(True) else: self.directCtrl.SetValue(False) self.descriptionCtrl.Set(self.thePersonaName, 'Environment Narrative', p.narrative()) self.descriptionCtrl.setCodes(p.codes('narrative')) self.roleList.setEnvironment(environmentName) self.roleList.load(p.roles()) self.environmentList.Select(0) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.directCtrl.Enable() self.descriptionCtrl.Enable() self.roleList.Enable() self.theSelectedIdx = 0 def OnEnvironmentSelected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] if (p.directFlag() == 'True'): self.directCtrl.SetValue(True) else: self.directCtrl.SetValue(False) self.descriptionCtrl.Set(self.thePersonaName, 'Environment Narrative', p.narrative()) self.descriptionCtrl.setCodes(p.codes('narrative')) self.roleList.setEnvironment(environmentName) self.roleList.load(p.roles()) self.directCtrl.Enable() self.descriptionCtrl.Enable() self.roleList.Enable() def OnEnvironmentDeselected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) envCodebook = {'narrative': self.descriptionCtrl.codes()} self.theEnvironmentDictionary[ environmentName] = PersonaEnvironmentProperties( environmentName, str(self.directCtrl.GetValue()), self.descriptionCtrl.GetValue(), self.roleList.dimensions()) self.directCtrl.SetValue(False) self.descriptionCtrl.Set(self.thePersonaName, 'Environment Narrative', '') self.descriptionCtrl.setCodes({}) self.roleList.setEnvironment('') self.roleList.DeleteAllItems() self.theSelectedIdx = -1 self.directCtrl.Disable() self.descriptionCtrl.Disable() self.roleList.Disable() def OnAddEnvironment(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = PersonaEnvironmentProperties(environmentName) self.environmentList.Select(self.theSelectedIdx) self.directCtrl.SetValue(False) self.descriptionCtrl.Set(self.thePersonaName, 'Environment Narrative', '') self.descriptionCtrl.setCodes({}) self.roleList.setEnvironment(environmentName) self.roleList.DeleteAllItems() self.directCtrl.Enable() self.descriptionCtrl.Enable() self.roleList.Enable() def OnDeleteEnvironment(self, evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 self.directCtrl.SetValue(False) self.descriptionCtrl.Set(self.thePersonaName, 'Environment Narrative', '') self.descriptionCtrl.setCodes({}) self.roleList.setEnvironment('') self.roleList.DeleteAllItems() self.theSelectedIdx = -1 self.directCtrl.Disable() self.descriptionCtrl.Disable() self.roleList.Disable() def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) envCodebook = {'narrative': self.descriptionCtrl.codes()} self.theEnvironmentDictionary[ environmentName] = PersonaEnvironmentProperties( environmentName, str(self.directCtrl.GetValue()), self.descriptionCtrl.GetValue(), self.roleList.dimensions(), envCodebook) return self.theEnvironmentDictionary.values()
class AssetEnvironmentPanel(wx.Panel): def __init__(self,parent,dp): wx.Panel.__init__(self,parent,ASSET_PANELENVIRONMENT_ID) self.dbProxy = dp self.theAssetId = None self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL) mainSizer.Add(environmentListSizer,0,wx.EXPAND) self.environmentList = EnvironmentListCtrl(self,ASSETENVIRONMENT_LISTENVIRONMENTS_ID,self.dbProxy) environmentListSizer.Add(self.environmentList,1,wx.EXPAND) dimBox = wx.StaticBox(self) environmentDimSizer = wx.StaticBoxSizer(dimBox,wx.VERTICAL) mainSizer.Add(environmentDimSizer,1,wx.EXPAND) nbBox = wx.StaticBox(self,-1) nbSizer = wx.StaticBoxSizer(nbBox,wx.HORIZONTAL) environmentDimSizer.Add(nbSizer,1,wx.EXPAND) self.notebook = AssetEnvironmentNotebook(self,self.dbProxy) nbSizer.Add(self.notebook,1,wx.EXPAND) self.propertiesList = self.notebook.FindWindowById(ASSETENVIRONMENT_LISTPROPERTIES_ID) self.associationCtrl = self.notebook.FindWindowById(ASSET_LISTASSOCIATIONS_ID) self.SetSizer(mainSizer) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected) self.propertiesList.Disable() self.associationCtrl.Disable() def loadControls(self,asset): self.theAssetId = asset.id() self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) noOfProperties = len(asset.environmentProperties()) if (noOfProperties > 0): environmentNames = [] for cp in asset.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in asset.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentNames.append(environmentName) environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] self.propertiesList.setEnvironment(environmentName) self.propertiesList.load(p.properties(),p.rationale()) self.associationCtrl.setEnvironment(environmentName) self.associationCtrl.load(p.associations()) self.environmentList.Select(0) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected) self.propertiesList.Enable() self.associationCtrl.Enable() if (noOfProperties > 0): self.theSelectedIdx = 0 def OnEnvironmentSelected(self,evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.propertiesList.setEnvironment(environmentName) self.propertiesList.load(p.properties(),p.rationale()) self.associationCtrl.setEnvironment(environmentName) self.associationCtrl.load(p.associations()) self.propertiesList.Enable() self.associationCtrl.Enable() def OnEnvironmentDeselected(self,evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) syProperties,pRationale = self.propertiesList.properties() self.theEnvironmentDictionary[environmentName] = AssetEnvironmentProperties(environmentName,syProperties,pRationale,self.associationCtrl.dimensions()) self.propertiesList.setEnvironment('') self.propertiesList.DeleteAllItems() self.associationCtrl.setEnvironment('') self.associationCtrl.DeleteAllItems() self.propertiesList.Disable() self.associationCtrl.Disable() self.theSelectedIdx = -1 def OnAddEnvironment(self,evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[environmentName] = AssetEnvironmentProperties(environmentName,[0,0,0,0,0,0,0,0],['None','None','None','None','None','None','None','None']) self.environmentList.Select(self.theSelectedIdx) self.propertiesList.setEnvironment(environmentName) self.propertiesList.DeleteAllItems() self.associationCtrl.setEnvironment(environmentName) self.associationCtrl.DeleteAllItems() self.propertiesList.Enable() self.associationCtrl.Enable() inheritedEnv = self.environmentList.inheritedEnvironment() if (inheritedEnv != '' and self.theAssetId != None): p = self.dbProxy.inheritedAssetProperties(self.theAssetId,inheritedEnv) self.theEnvironmentDictionary[environmentName] = p self.propertiesList.setEnvironment(environmentName) self.propertiesList.load(p.properties(),p.rationale()) self.associationCtrl.setEnvironment(environmentName) self.associationCtrl.load(p.associations()) def OnDeleteEnvironment(self,evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 self.propertiesList.setEnvironment('') self.propertiesList.DeleteAllItems() self.associationCtrl.setEnvironment('') self.associationCtrl.DeleteAllItems() self.propertiesList.Disable() self.associationCtrl.Disable() def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText(self.theSelectedIdx) syProperties,pRationale = self.propertiesList.properties() self.theEnvironmentDictionary[environmentName] = AssetEnvironmentProperties(environmentName,syProperties,pRationale,self.associationCtrl.dimensions()) return self.theEnvironmentDictionary.values()
class GoalEnvironmentPanel(wx.Panel): def __init__(self, parent, dp): wx.Panel.__init__(self, parent, GOAL_PANELENVIRONMENT_ID) self.dbProxy = dp self.theGoalId = None self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL) mainSizer.Add(environmentListSizer, 0, wx.EXPAND) self.environmentList = EnvironmentListCtrl(self, GOAL_LISTENVIRONMENTS_ID, self.dbProxy) environmentListSizer.Add(self.environmentList, 1, wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer, 1, wx.EXPAND) nbBox = wx.StaticBox(self, -1) nbSizer = wx.StaticBoxSizer(nbBox, wx.VERTICAL) environmentDimSizer.Add(nbSizer, 1, wx.EXPAND) self.notebook = GoalEnvironmentNotebook(self, self.dbProxy) nbSizer.Add(self.notebook, 1, wx.EXPAND) self.SetSizer(mainSizer) self.labelCtrl = self.notebook.FindWindowById(GOAL_TEXTLABEL_ID) self.definitionCtrl = self.notebook.FindWindowById( GOAL_TEXTDEFINITION_ID) self.categoryCtrl = self.notebook.FindWindowById(GOAL_COMBOCATEGORY_ID) self.priorityCtrl = self.notebook.FindWindowById(GOAL_COMBOPRIORITY_ID) self.fitCriterionCtrl = self.notebook.FindWindowById( GOAL_TEXTFITCRITERION_ID) self.issueCtrl = self.notebook.FindWindowById(GOAL_TEXTISSUE_ID) self.goalAssociationCtrl = self.notebook.FindWindowById( GOAL_LISTGOALREFINEMENTS_ID) self.subGoalAssociationCtrl = self.notebook.FindWindowById( GOAL_LISTSUBGOALREFINEMENTS_ID) self.cCtrl = self.notebook.FindWindowById(GOAL_LISTCONCERNS_ID) self.caCtrl = self.notebook.FindWindowById( GOAL_LISTCONCERNASSOCIATIONS_ID) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) self.definitionCtrl.Disable() self.categoryCtrl.Disable() self.priorityCtrl.Disable() self.fitCriterionCtrl.Disable() self.issueCtrl.Disable() self.goalAssociationCtrl.Disable() self.subGoalAssociationCtrl.Disable() self.cCtrl.Disable() self.caCtrl.Disable() def loadControls(self, goal): self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) self.theGoalId = goal.id() environmentNames = [] for cp in goal.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in goal.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentNames.append(environmentName) environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] self.labelCtrl.SetValue(p.label()) self.definitionCtrl.SetValue(p.definition()) self.categoryCtrl.SetValue(p.category()) self.priorityCtrl.SetValue(p.priority()) self.fitCriterionCtrl.SetValue(p.fitCriterion()) self.issueCtrl.SetValue(p.issue()) self.goalAssociationCtrl.setEnvironment(environmentName) self.goalAssociationCtrl.load(p.goalRefinements()) self.subGoalAssociationCtrl.setEnvironment(environmentName) self.subGoalAssociationCtrl.load(p.subGoalRefinements()) self.cCtrl.setEnvironment(environmentName) self.cCtrl.load(p.concerns()) self.caCtrl.setEnvironment(environmentName) self.caCtrl.load(p.concernAssociations()) self.environmentList.Select(0) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.definitionCtrl.Enable() self.categoryCtrl.Enable() self.priorityCtrl.Enable() self.fitCriterionCtrl.Enable() self.issueCtrl.Enable() self.goalAssociationCtrl.Enable() self.subGoalAssociationCtrl.Enable() self.cCtrl.Enable() self.caCtrl.Enable() self.theSelectedIdx = 0 def OnEnvironmentSelected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.labelCtrl.SetValue(p.label()) self.definitionCtrl.SetValue(p.definition()) self.categoryCtrl.SetValue(p.category()) self.priorityCtrl.SetValue(p.priority()) self.fitCriterionCtrl.SetValue(p.fitCriterion()) self.issueCtrl.SetValue(p.issue()) self.goalAssociationCtrl.setEnvironment(environmentName) self.goalAssociationCtrl.load(p.goalRefinements()) self.subGoalAssociationCtrl.setEnvironment(environmentName) self.subGoalAssociationCtrl.load(p.subGoalRefinements()) self.cCtrl.setEnvironment(environmentName) self.cCtrl.load(p.concerns()) self.caCtrl.setEnvironment(environmentName) self.caCtrl.load(p.concernAssociations()) self.definitionCtrl.Enable() self.categoryCtrl.Enable() self.priorityCtrl.Enable() self.fitCriterionCtrl.Enable() self.issueCtrl.Enable() self.goalAssociationCtrl.Enable() self.subGoalAssociationCtrl.Enable() self.cCtrl.Enable() self.caCtrl.Enable() def OnEnvironmentDeselected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = GoalEnvironmentProperties( environmentName, self.labelCtrl.GetValue(), self.definitionCtrl.GetValue(), self.categoryCtrl.GetValue(), self.priorityCtrl.GetValue(), self.fitCriterionCtrl.GetValue(), self.issueCtrl.GetValue(), self.goalAssociationCtrl.dimensions(), self.subGoalAssociationCtrl.dimensions(), self.cCtrl.dimensions(), self.caCtrl.dimensions()) self.labelCtrl.SetValue('') self.definitionCtrl.SetValue('') self.categoryCtrl.SetValue('') self.priorityCtrl.SetValue('') self.fitCriterionCtrl.SetValue('') self.issueCtrl.SetValue('') self.goalAssociationCtrl.DeleteAllItems() self.goalAssociationCtrl.setEnvironment('') self.subGoalAssociationCtrl.DeleteAllItems() self.subGoalAssociationCtrl.setEnvironment('') self.cCtrl.DeleteAllItems() self.caCtrl.DeleteAllItems() self.cCtrl.setEnvironment('') self.caCtrl.setEnvironment('') self.theSelectedIdx = -1 self.definitionCtrl.Disable() self.categoryCtrl.Disable() self.priorityCtrl.Disable() self.fitCriterionCtrl.Disable() self.issueCtrl.Disable() self.goalAssociationCtrl.Disable() self.subGoalAssociationCtrl.Disable() self.cCtrl.Disable() self.caCtrl.Disable() def OnAddEnvironment(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = GoalEnvironmentProperties(environmentName) self.environmentList.Select(self.theSelectedIdx) self.labelCtrl.SetValue('') self.definitionCtrl.SetValue('None') self.categoryCtrl.SetValue('') self.priorityCtrl.SetValue('') self.fitCriterionCtrl.SetValue('None') self.issueCtrl.SetValue('None') self.goalAssociationCtrl.setEnvironment(environmentName) self.goalAssociationCtrl.DeleteAllItems() self.subGoalAssociationCtrl.setEnvironment(environmentName) self.subGoalAssociationCtrl.DeleteAllItems() self.cCtrl.setEnvironment(environmentName) self.cCtrl.DeleteAllItems() self.caCtrl.setEnvironment(environmentName) self.caCtrl.DeleteAllItems() self.definitionCtrl.Enable() self.categoryCtrl.Enable() self.priorityCtrl.Enable() self.fitCriterionCtrl.Enable() self.issueCtrl.Enable() self.goalAssociationCtrl.Enable() self.subGoalAssociationCtrl.Enable() self.cCtrl.Enable() self.caCtrl.Enable() inheritedEnv = self.environmentList.inheritedEnvironment() if (inheritedEnv != '' and self.theGoalId != None): p = self.dbProxy.inheritedGoalProperties(self.theGoalId, inheritedEnv) self.theEnvironmentDictionary[environmentName] = p self.labelCtrl.SetValue(p.label()) self.definitionCtrl.SetValue(p.definition()) self.categoryCtrl.SetValue(p.category()) self.priorityCtrl.SetValue(p.priority()) self.fitCriterionCtrl.SetValue(p.fitCriterion()) self.issueCtrl.SetValue(p.issue()) self.goalAssociationCtrl.setEnvironment(environmentName) self.goalAssociationCtrl.load(p.goalRefinements()) self.subGoalAssociationCtrl.setEnvironment(environmentName) self.subGoalAssociationCtrl.load(p.subGoalRefinements()) self.cCtrl.setEnvironment(environmentName) self.caCtrl.setEnvironment(environmentName) self.cCtrl.load(p.concerns()) self.caCtrl.load(p.concernAssociations()) def OnDeleteEnvironment(self, evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 self.labelCtrl.SetValue('') self.definitionCtrl.SetValue('') self.categoryCtrl.SetValue('') self.priorityCtrl.SetValue('') self.fitCriterionCtrl.SetValue('') self.issueCtrl.SetValue('') self.goalAssociationCtrl.DeleteAllItems() self.goalAssociationCtrl.setEnvironment('') self.subGoalAssociationCtrl.DeleteAllItems() self.subGoalAssociationCtrl.setEnvironment('') self.cCtrl.DeleteAllItems() self.cCtrl.setEnvironment('') self.caCtrl.DeleteAllItems() self.caCtrl.setEnvironment('') self.definitionCtrl.Disable() self.categoryCtrl.Disable() self.priorityCtrl.Disable() self.fitCriterionCtrl.Disable() self.issueCtrl.Disable() self.goalAssociationCtrl.Disable() self.subGoalAssociationCtrl.Disable() self.cCtrl.Disable() self.caCtrl.Disable() def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = GoalEnvironmentProperties( environmentName, self.labelCtrl.GetValue(), self.definitionCtrl.GetValue(), self.categoryCtrl.GetValue(), self.priorityCtrl.GetValue(), self.fitCriterionCtrl.GetValue(), self.issueCtrl.GetValue(), self.goalAssociationCtrl.dimensions(), self.subGoalAssociationCtrl.dimensions(), self.cCtrl.dimensions(), self.caCtrl.dimensions()) return self.theEnvironmentDictionary.values()
class UseCaseEnvironmentPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, armid.USECASE_PANELENVIRONMENT_ID) b = Borg() self.dbProxy = b.dbProxy self.theUseCaseId = None self.theUseCaseName = '' self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL) mainSizer.Add(environmentListSizer, 0, wx.EXPAND) self.environmentList = EnvironmentListCtrl( self, armid.USECASE_LISTENVIRONMENTS_ID, self.dbProxy) environmentListSizer.Add(self.environmentList, 1, wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer, 1, wx.EXPAND) nbBox = wx.StaticBox(self, -1) nbBoxSizer = wx.StaticBoxSizer(nbBox, wx.VERTICAL) environmentDimSizer.Add(nbBoxSizer, 1, wx.EXPAND) self.notebook = UseCaseEnvironmentNotebook(self, self.dbProxy) nbBoxSizer.Add(self.notebook, 1, wx.EXPAND) self.preCondCtrl = self.notebook.FindWindowById( armid.USECASE_TEXTPRECONDITION_ID) self.postCondCtrl = self.notebook.FindWindowById( armid.USECASE_TEXTPOSTCONDITION_ID) self.stepsCtrl = self.notebook.FindWindowById( armid.USECASE_PANELFLOW_ID) self.SetSizer(mainSizer) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) self.preCondCtrl.Disable() self.stepsCtrl.Disable() self.postCondCtrl.Disable() self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) def loadControls(self, uc): self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) self.theUseCaseId = uc.id() self.theUseCaseName = uc.name() environmentNames = [] for cp in uc.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in uc.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentNames.append(environmentName) environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] self.preCondCtrl.SetValue(p.preconditions()) self.stepsCtrl.reloadSteps(p.steps()) self.stepsCtrl.setUseCase(self.theUseCaseName) self.postCondCtrl.SetValue(p.postconditions()) self.stepsCtrl.setEnvironment(environmentName) self.preCondCtrl.setEnvironment(environmentName) self.preCondCtrl.setUseCase(self.theUseCaseName) self.postCondCtrl.setEnvironment(environmentName) self.postCondCtrl.setUseCase(self.theUseCaseName) self.environmentList.Select(0) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.preCondCtrl.Enable() self.stepsCtrl.Enable() self.postCondCtrl.Enable() self.theSelectedIdx = 0 def OnEnvironmentSelected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.preCondCtrl.SetValue(p.preconditions()) self.stepsCtrl.reloadSteps(p.steps()) self.postCondCtrl.SetValue(p.postconditions()) self.stepsCtrl.setEnvironment(environmentName) self.preCondCtrl.setEnvironment(environmentName) self.preCondCtrl.setUseCase(self.theUseCaseName) self.postCondCtrl.setEnvironment(environmentName) self.postCondCtrl.setUseCase(self.theUseCaseName) self.preCondCtrl.Enable() self.stepsCtrl.Enable() self.postCondCtrl.Enable() def OnEnvironmentDeselected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = UseCaseEnvironmentProperties( environmentName, self.preCondCtrl.GetValue(), self.stepsCtrl.steps(), self.postCondCtrl.GetValue()) self.preCondCtrl.SetValue('') self.stepsCtrl.clear() self.stepsCtrl.setEnvironment('') self.postCondCtrl.SetValue('') self.preCondCtrl.setEnvironment('') self.preCondCtrl.setUseCase('') self.postCondCtrl.setEnvironment('') self.postCondCtrl.setUseCase('') self.theSelectedIdx = -1 self.preCondCtrl.Disable() self.stepsCtrl.Disable() self.postCondCtrl.Disable() def OnAddEnvironment(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = UseCaseEnvironmentProperties(environmentName) self.environmentList.Select(self.theSelectedIdx) self.preCondCtrl.SetValue('') self.stepsCtrl.setEnvironment(environmentName) self.stepsCtrl.clear() self.postCondCtrl.SetValue('') self.preCondCtrl.setEnvironment(environmentName) self.preCondCtrl.setUseCase(self.theUseCaseName) self.postCondCtrl.setEnvironment(environmentName) self.postCondCtrl.setUseCase(self.theUseCaseName) inheritedEnv = self.environmentList.inheritedEnvironment() if (inheritedEnv != '' and self.theUseCaseId != None): p = self.dbProxy.inheritedUseCaseProperties( self.theUseCaseId, inheritedEnv) self.theEnvironmentDictionary[environmentName] = p self.preCondCtrl.SetValue(p.preconditions()) self.stepsCtrl.reloadSteps(p.steps()) self.stepsCtrl.setEnvironment(environmentName) self.postCondCtrl.SetValue(p.preconditions()) self.preCondCtrl.setEnvironment(environmentName) self.preCondCtrl.setUseCase(self.theUseCaseName) self.postCondCtrl.setEnvironment(environmentName) self.postCondCtrl.setUseCase(self.theUseCaseName) self.preCondCtrl.Enable() self.stepsCtrl.Enable() self.postCondCtrl.Enable() def OnDeleteEnvironment(self, evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 self.preCondCtrl.SetValue('') self.stepsCtrl.clear() self.stepsCtrl.setEnvironment('') self.postCondCtrl.SetValue('') self.preCondCtrl.setEnvironment('') self.preCondCtrl.setUseCase('') self.postCondCtrl.setEnvironment('') self.postCondCtrl.setUseCase('') self.preCondCtrl.Disable() self.stepsCtrl.Disable() self.postCondCtrl.Disable() def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = UseCaseEnvironmentProperties( environmentName, self.preCondCtrl.GetValue(), self.stepsCtrl.steps(), self.postCondCtrl.GetValue()) return self.theEnvironmentDictionary.values()
class CountermeasureEnvironmentPanel(wx.Panel): def __init__(self, parent, dp): wx.Panel.__init__(self, parent, COUNTERMEASURE_PANELENVIRONMENT_ID) self.dbProxy = dp self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL) mainSizer.Add(environmentListSizer, 0, wx.EXPAND) self.environmentList = EnvironmentListCtrl( self, COUNTERMEASURE_LISTENVIRONMENTS_ID, self.dbProxy) environmentListSizer.Add(self.environmentList, 1, wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer, 1, wx.EXPAND) costBox = wx.StaticBox(self, -1, 'Cost') costBoxSizer = wx.StaticBoxSizer(costBox, wx.HORIZONTAL) environmentDimSizer.Add(costBoxSizer, 0, wx.EXPAND) self.costCombo = wx.ComboBox(self, COUNTERMEASURE_COMBOCOST_ID, "", choices=['Low', 'Medium', 'High'], style=wx.CB_READONLY) costBoxSizer.Add(self.costCombo, 1, wx.EXPAND) nbBox = wx.StaticBox(self, -1) nbSizer = wx.StaticBoxSizer(nbBox, wx.HORIZONTAL) environmentDimSizer.Add(nbSizer, 1, wx.EXPAND) self.notebook = CountermeasureEnvironmentNotebook(self, self.dbProxy) nbSizer.Add(self.notebook, 1, wx.EXPAND) self.reqList = self.notebook.FindWindowById( COUNTERMEASURE_LISTREQUIREMENTS_ID) self.targetList = self.notebook.FindWindowById( COUNTERMEASURE_LISTTARGETS_ID) self.propertiesList = self.notebook.FindWindowById( COUNTERMEASURE_LISTPROPERTIES_ID) self.personaList = self.notebook.FindWindowById( COUNTERMEASURE_LISTPERSONAS_ID) self.roleList = self.notebook.FindWindowById( COUNTERMEASURE_LISTROLES_ID) self.reqList.Disable() self.targetList.Disable() self.propertiesList.Disable() self.costCombo.Disable() self.roleList.Disable() self.SetSizer(mainSizer) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) def loadControls(self, countermeasure): self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) environmentNames = [] for cp in countermeasure.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in countermeasure.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentNames.append(environmentName) environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] self.reqList.setEnvironment(environmentName) self.reqList.load(p.requirements()) self.targetList.setEnvironment(environmentName) self.targetList.load(p.targets()) self.propertiesList.setEnvironment(environmentName) self.propertiesList.load(p.properties(), p.rationale()) self.costCombo.SetStringSelection(p.cost()) self.roleList.setEnvironment(environmentName) self.roleList.load(p.roles()) self.personaList.load(p.personas()) self.environmentList.Select(0) self.reqList.Enable() self.targetList.Enable() self.propertiesList.Enable() self.costCombo.Enable() self.roleList.Enable() self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.theSelectedIdx = 0 def OnEnvironmentSelected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.reqList.setEnvironment(environmentName) self.reqList.load(p.requirements()) self.targetList.setEnvironment(environmentName) self.targetList.load(p.targets()) self.propertiesList.setEnvironment(environmentName) self.propertiesList.load(p.properties(), p.rationale()) self.costCombo.SetStringSelection(p.cost()) self.roleList.setEnvironment(environmentName) self.roleList.load(p.roles()) self.personaList.load(p.personas()) self.reqList.Enable() self.targetList.Enable() self.propertiesList.Enable() self.costCombo.Enable() self.roleList.Enable() self.personaList.Enable() def OnEnvironmentDeselected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) syProperties, pRationale = self.propertiesList.properties() properties = CountermeasureEnvironmentProperties( environmentName, self.reqList.dimensions(), self.targetList.targets(), syProperties, pRationale, self.costCombo.GetValue(), self.roleList.dimensions(), self.personaList.dimensions()) self.theEnvironmentDictionary[environmentName] = properties self.reqList.setEnvironment('') self.reqList.DeleteAllItems() self.targetList.setEnvironment('') self.targetList.DeleteAllItems() self.propertiesList.setEnvironment('') self.propertiesList.DeleteAllItems() self.costCombo.SetValue('') self.roleList.setEnvironment('') self.roleList.DeleteAllItems() self.personaList.DeleteAllItems() self.theSelectedIdx = -1 self.reqList.Disable() self.targetList.Disable() self.propertiesList.Disable() self.costCombo.Disable() self.roleList.Disable() def OnAddEnvironment(self, evt): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) syProperties, pRationale = self.propertiesList.properties() properties = CountermeasureEnvironmentProperties( environmentName, self.reqList.dimensions(), self.targetList.targets(), syProperties, pRationale, self.costCombo.GetValue(), self.roleList.dimensions(), self.personaList.dimensions()) self.theEnvironmentDictionary[environmentName] = properties self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = CountermeasureEnvironmentProperties( environmentName) self.reqList.setEnvironment(environmentName) self.reqList.DeleteAllItems() self.targetList.setEnvironment(environmentName) self.targetList.DeleteAllItems() self.propertiesList.setEnvironment(environmentName) self.propertiesList.DeleteAllItems() self.costCombo.SetValue('') self.roleList.setEnvironment(environmentName) self.roleList.DeleteAllItems() self.personaList.DeleteAllItems() self.reqList.Enable() self.targetList.Enable() self.propertiesList.Enable() self.costCombo.Enable() self.roleList.Enable() def OnDeleteEnvironment(self, evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) syProperties, pRationale = self.propertiesList.properties() properties = CountermeasureEnvironmentProperties( environmentName, self.reqList.dimensions(), self.targetList.targets(), syProperties, pRationale, self.costCombo.GetValue(), self.roleList.dimensions(), self.personaList.dimensions()) self.theEnvironmentDictionary[environmentName] = properties for cname in self.environmentList.dimensions(): p = self.theEnvironmentDictionary[cname] if (len(p.requirements()) == 0): exceptionText = 'No requirements selected for environment ' + p.name( ) raise ARM.EnvironmentValidationError(exceptionText) if (len(p.targets()) == 0): exceptionText = 'No targets selected for environment ' + p.name( ) raise ARM.EnvironmentValidationError(exceptionText) if (len(p.cost()) == 0): exceptionText = 'No cost selected for environment ' + p.name() raise ARM.EnvironmentValidationError(exceptionText) if (len(p.roles()) == 0): exceptionText = 'No roles selected for environment ' + p.name() raise ARM.EnvironmentValidationError(exceptionText) return self.theEnvironmentDictionary.values()
class VulnerabilityEnvironmentPanel(wx.Panel): def __init__(self, parent, dp): wx.Panel.__init__(self, parent, armid.VULNERABILITY_PANELENVIRONMENT_ID) self.dbProxy = dp self.theVulId = None self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL) mainSizer.Add(environmentListSizer, 0, wx.EXPAND) self.environmentList = EnvironmentListCtrl( self, armid.VULNERABILITYENVIRONMENT_LISTENVIRONMENTS_ID, self.dbProxy) environmentListSizer.Add(self.environmentList, 1, wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer, 1, wx.EXPAND) sevBox = wx.StaticBox(self) sevSizer = wx.StaticBoxSizer(sevBox, wx.HORIZONTAL) environmentDimSizer.Add(sevSizer, 0, wx.EXPAND) sevSizer.Add(wx.StaticText(self, -1, 'Severity')) sevList = ['Negligible', 'Marginal', 'Critical', 'Catastrophic'] self.sevCtrl = wx.ComboBox( self, armid.VULNERABILITYENVIRONMENT_COMBOSEVERITY_ID, choices=sevList, size=wx.DefaultSize, style=wx.CB_READONLY) sevSizer.Add(self.sevCtrl, 1, wx.EXPAND) aSizer = wx.BoxSizer(wx.HORIZONTAL) environmentDimSizer.Add(aSizer, 1, wx.EXPAND) self.assetList = DimensionListCtrl( self, armid.VULNERABILITYENVIRONMENT_LISTASSETS_ID, wx.DefaultSize, 'Asset', 'asset', self.dbProxy) assetBox = wx.StaticBox(self) assetSizer = wx.StaticBoxSizer(assetBox, wx.HORIZONTAL) assetSizer.Add(self.assetList, 1, wx.EXPAND) aSizer.Add(assetSizer, 1, wx.EXPAND) self.SetSizer(mainSizer) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) def loadControls(self, vulnerability): self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) self.theVulId = vulnerability.id() # We load the environment name control before anything else. Weird stuff happens if we don't do this. Don't ask me why!!! environmentNames = [] if (len(vulnerability.environmentProperties()) > 0): for cp in vulnerability.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in vulnerability.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] self.sevCtrl.SetStringSelection(p.severity()) self.assetList.setEnvironment(environmentName) self.assetList.load(p.assets()) self.environmentList.Select(0) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.theSelectedIdx = 0 def OnEnvironmentSelected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.sevCtrl.SetStringSelection(p.severity()) self.assetList.setEnvironment(environmentName) self.assetList.load(p.assets()) def OnEnvironmentDeselected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = VulnerabilityEnvironmentProperties( environmentName, self.sevCtrl.GetValue(), self.assetList.dimensions()) self.sevCtrl.SetValue('') self.assetList.setEnvironment('') self.assetList.DeleteAllItems() self.theSelectedIdx = -1 def OnAddEnvironment(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = VulnerabilityEnvironmentProperties( environmentName, '', []) self.environmentList.Select(self.theSelectedIdx) self.assetList.setEnvironment(environmentName) inheritedEnv = self.environmentList.inheritedEnvironment() if (inheritedEnv != '' and self.theVulId != None): p = self.dbProxy.inheritedVulnerabilityProperties( self.theVulId, inheritedEnv) self.theEnvironmentDictionary[environmentName] = p self.sevCtrl.SetStringSelection(p.severity()) self.assetList.setEnvironment(environmentName) self.assetList.load(p.assets()) def OnDeleteEnvironment(self, evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = VulnerabilityEnvironmentProperties( environmentName, self.sevCtrl.GetValue(), self.assetList.dimensions()) return self.theEnvironmentDictionary.values()
class MisuseCaseEnvironmentPanel(wx.Panel): def __init__(self, parent, dp): wx.Panel.__init__(self, parent, armid.MISUSECASE_PANELENVIRONMENT_ID) self.dbProxy = dp self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 self.theSelectedRisk = '' self.theSelectedThreat = '' self.theSelectedVulnerability = '' mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL) mainSizer.Add(environmentListSizer, 0, wx.EXPAND) self.environmentList = EnvironmentListCtrl( self, armid.MISUSECASE_LISTENVIRONMENTS_ID, self.dbProxy) self.environmentList.Unbind(wx.EVT_RIGHT_DOWN) environmentListSizer.Add(self.environmentList, 1, wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer, 1, wx.EXPAND) nbBox = wx.StaticBox(self, -1) nbSizer = wx.StaticBoxSizer(nbBox, wx.VERTICAL) environmentDimSizer.Add(nbSizer, 1, wx.EXPAND) self.notebook = MisuseCaseNotebook(self) nbSizer.Add(self.notebook, 1, wx.EXPAND) self.SetSizer(mainSizer) self.objectiveCtrl = self.notebook.FindWindowById( armid.MISUSECASE_TEXTOBJECTIVE_ID) self.attackerList = self.notebook.FindWindowById( armid.MISUSECASE_LISTATTACKERS_ID) self.assetList = self.notebook.FindWindowById( armid.MISUSECASE_LISTASSETS_ID) self.threatCtrl = self.notebook.FindWindowById( armid.MISUSECASE_TEXTTHREAT_ID) self.lhoodCtrl = self.notebook.FindWindowById( armid.MISUSECASE_TEXTLIKELIHOOD_ID) self.vulCtrl = self.notebook.FindWindowById( armid.MISUSECASE_TEXTVULNERABILITY_ID) self.sevCtrl = self.notebook.FindWindowById( armid.MISUSECASE_TEXTSEVERITY_ID) self.ratingCtrl = self.notebook.FindWindowById( armid.MISUSECASE_TEXTSCORE_ID) self.narrativeCtrl = self.notebook.FindWindowById( armid.MISUSECASE_TEXTNARRATIVE_ID) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) self.narrativeCtrl.Disable() def unloadMCComponents(self): self.ratingCtrl.SetValue('') self.threatCtrl.SetValue('') self.lhoodCtrl.SetValue('') self.vulCtrl.SetValue('') self.sevCtrl.SetValue('') self.attackerList.DeleteAllItems() self.assetList.DeleteAllItems() self.objectiveCtrl.SetValue('') def loadMCComponents(self): environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.ratingCtrl.SetValue( self.dbProxy.riskRating(self.theSelectedThreat, self.theSelectedVulnerability, environmentName)) self.threatCtrl.SetValue(self.theSelectedThreat) threatId = self.dbProxy.getDimensionId(self.theSelectedThreat, 'threat') environmentId = self.dbProxy.getDimensionId(environmentName, 'environment') self.lhoodCtrl.SetValue( self.dbProxy.threatLikelihood(threatId, environmentId)) self.vulCtrl.SetValue(self.theSelectedVulnerability) vulId = self.dbProxy.getDimensionId(self.theSelectedVulnerability, 'vulnerability') self.sevCtrl.SetValue( self.dbProxy.vulnerabilitySeverity(vulId, environmentId)) self.attackerList.DeleteAllItems() attackers = self.dbProxy.threatAttackers(threatId, environmentId) attackerSet = set(attackers) for atidx, attacker in enumerate(attackerSet): self.attackerList.InsertStringItem(atidx, attacker) threatenedAssets = self.dbProxy.threatenedAssets( threatId, environmentId) vulnerableAssets = self.dbProxy.vulnerableAssets(vulId, environmentId) objectiveText = 'Exploit vulnerabilities in ' for idx, vulAsset in enumerate(vulnerableAssets): objectiveText += vulAsset if (idx != (len(vulnerableAssets) - 1)): objectiveText += ',' objectiveText += ' to threaten ' for idx, thrAsset in enumerate(threatenedAssets): objectiveText += thrAsset if (idx != (len(threatenedAssets) - 1)): objectiveText += ',' objectiveText += '.' self.objectiveCtrl.SetValue(objectiveText) self.assetList.DeleteAllItems() assetSet = set(threatenedAssets + vulnerableAssets) for asidx, asset in enumerate(assetSet): self.assetList.InsertStringItem(asidx, asset) def loadMisuseCase(self, mc): self.theSelectedRisk = mc.risk() self.theSelectedThreat = mc.threat() self.theSelectedVulnerability = mc.vulnerability() self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) environmentNames = [] for cp in mc.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in mc.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentNames.append(environmentName) environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] self.narrativeCtrl.SetValue(p.narrative()) self.environmentList.Select(0) self.loadMCComponents() self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.narrativeCtrl.Enable() self.theSelectedIdx = 0 def loadRiskComponents(self, threatName, vulName): self.theSelectedThreat = threatName self.theSelectedVulnerability = vulName self.environmentList.Unbind(wx.EVT_LIST_INSERT_ITEM) self.environmentList.Unbind(wx.EVT_LIST_DELETE_ITEM) self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) environments = self.dbProxy.threatVulnerabilityEnvironmentNames( threatName, vulName) for environmentName in environments: self.theEnvironmentDictionary[ environmentName] = MisuseCaseEnvironmentProperties( environmentName) self.environmentList.load(environments) self.environmentList.Select(0) self.theSelectedIdx = 0 self.loadMCComponents() self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) def OnEnvironmentSelected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.narrativeCtrl.SetValue(p.narrative()) self.loadMCComponents() self.narrativeCtrl.Enable() def OnEnvironmentDeselected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = MisuseCaseEnvironmentProperties( environmentName, self.narrativeCtrl.GetValue()) self.narrativeCtrl.SetValue('') self.narrativeCtrl.Disable() self.unloadMCComponents() def OnAddEnvironment(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = MisuseCaseEnvironmentProperties(environmentName) self.environmentList.Select(self.theSelectedIdx) self.loadMCComponents() self.narrativeCtrl.Enable() def OnDeleteEnvironment(self, evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 self.narrativeCtrl.SetValue('') self.narrativeCtrl.Disable() self.unloadMCComponents() def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = MisuseCaseEnvironmentProperties( environmentName, self.narrativeCtrl.GetValue()) return self.theEnvironmentDictionary.values()
class ThreatEnvironmentPanel(wx.Panel): def __init__(self, parent, dp): wx.Panel.__init__(self, parent, armid.THREAT_PANELENVIRONMENT_ID) self.dbProxy = dp self.theThreatId = None self.theEnvironmentDictionary = {} self.theSelectedIdx = -1 mainSizer = wx.BoxSizer(wx.HORIZONTAL) environmentBox = wx.StaticBox(self) environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL) mainSizer.Add(environmentListSizer, 0, wx.EXPAND) self.environmentList = EnvironmentListCtrl( self, armid.THREATENVIRONMENT_LISTENVIRONMENTS_ID, self.dbProxy) environmentListSizer.Add(self.environmentList, 1, wx.EXPAND) environmentDimSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(environmentDimSizer, 1, wx.EXPAND) lhoodBox = wx.StaticBox(self) lhoodSizer = wx.StaticBoxSizer(lhoodBox, wx.HORIZONTAL) environmentDimSizer.Add(lhoodSizer, 0, wx.EXPAND) lhoodSizer.Add(wx.StaticText(self, -1, 'Likelihood')) lhoodList = [ 'Incredible', 'Improbable', 'Remote', 'Occasional', 'Probable', 'Frequent' ] self.lhoodCtrl = wx.ComboBox( self, armid.THREATENVIRONMENT_COMBOLIKELIHOOD_ID, choices=lhoodList, size=wx.DefaultSize, style=wx.CB_READONLY) lhoodSizer.Add(self.lhoodCtrl, 1, wx.EXPAND) aaSizer = wx.BoxSizer(wx.HORIZONTAL) environmentDimSizer.Add(aaSizer, 1, wx.EXPAND) self.attackerList = DimensionListCtrl( self, armid.THREATENVIRONMENT_LISTATTACKERS_ID, wx.DefaultSize, 'Attacker', 'attacker', self.dbProxy) attackerBox = wx.StaticBox(self) attackerSizer = wx.StaticBoxSizer(attackerBox, wx.HORIZONTAL) attackerSizer.Add(self.attackerList, 1, wx.EXPAND) aaSizer.Add(attackerSizer, 1, wx.EXPAND) self.assetList = DimensionListCtrl( self, armid.THREATENVIRONMENT_LISTASSETS_ID, wx.DefaultSize, 'Asset', 'asset', self.dbProxy) assetBox = wx.StaticBox(self) assetSizer = wx.StaticBoxSizer(assetBox, wx.HORIZONTAL) assetSizer.Add(self.assetList, 1, wx.EXPAND) aaSizer.Add(assetSizer, 1, wx.EXPAND) propertiesBox = wx.StaticBox(self) propertiesSizer = wx.StaticBoxSizer(propertiesBox, wx.HORIZONTAL) environmentDimSizer.Add(propertiesSizer, 1, wx.EXPAND) values = self.dbProxy.getDimensionNames('threat_value') valueLookup = ValueDictionary(values) self.propertiesList = PropertiesListCtrl( self, armid.THREATENVIRONMENT_LISTPROPERTIES_ID, valueLookup) propertiesSizer.Add(self.propertiesList, 1, wx.EXPAND) self.SetSizer(mainSizer) self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnAddEnvironment) self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnDeleteEnvironment) def loadControls(self, threat): self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED) self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED) self.theThreatId = threat.id() # We load the environment name control before anything else. Weird stuff happens if we don't do this. Don't ask me why!!! environmentNames = [] if (len(threat.environmentProperties()) > 0): for cp in threat.environmentProperties(): environmentNames.append(cp.name()) self.environmentList.load(environmentNames) for cp in threat.environmentProperties(): environmentName = cp.name() self.theEnvironmentDictionary[environmentName] = cp environmentName = environmentNames[0] p = self.theEnvironmentDictionary[environmentName] self.lhoodCtrl.SetStringSelection(p.likelihood()) self.attackerList.setEnvironment(environmentName) self.attackerList.load(p.attackers()) self.assetList.setEnvironment(environmentName) self.assetList.load(p.assets()) self.propertiesList.setEnvironment(environmentName) self.propertiesList.load(p.properties(), p.rationale()) self.environmentList.Select(0) self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnEnvironmentSelected) self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnEnvironmentDeselected) self.theSelectedIdx = 0 def OnEnvironmentSelected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) p = self.theEnvironmentDictionary[environmentName] self.lhoodCtrl.SetStringSelection(p.likelihood()) self.attackerList.setEnvironment(environmentName) self.attackerList.load(p.attackers()) self.assetList.setEnvironment(environmentName) self.assetList.load(p.assets()) self.propertiesList.setEnvironment(environmentName) self.propertiesList.load(p.properties(), p.rationale()) def OnEnvironmentDeselected(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) syProperties, pRationale = self.propertiesList.properties() self.theEnvironmentDictionary[ environmentName] = ThreatEnvironmentProperties( environmentName, self.lhoodCtrl.GetValue(), self.assetList.dimensions(), self.attackerList.dimensions(), syProperties, pRationale) self.lhoodCtrl.SetValue('') self.attackerList.setEnvironment('') self.attackerList.DeleteAllItems() self.assetList.setEnvironment('') self.assetList.DeleteAllItems() self.propertiesList.setEnvironment('') self.propertiesList.DeleteAllItems() self.theSelectedIdx = -1 def OnAddEnvironment(self, evt): self.theSelectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(self.theSelectedIdx) self.theEnvironmentDictionary[ environmentName] = ThreatEnvironmentProperties( environmentName, '', [], [], [0, 0, 0, 0, 0, 0, 0, 0], [ 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None' ]) self.environmentList.Select(self.theSelectedIdx) self.attackerList.setEnvironment(environmentName) self.assetList.setEnvironment(environmentName) self.propertiesList.setEnvironment(environmentName) inheritedEnv = self.environmentList.inheritedEnvironment() if (inheritedEnv != '' and self.theThreatId != None): p = self.dbProxy.inheritedThreatProperties(self.theThreatId, inheritedEnv) self.theEnvironmentDictionary[environmentName] = p self.lhoodCtrl.SetStringSelection(p.likelihood()) self.attackerList.setEnvironment(environmentName) self.attackerList.load(p.attackers()) self.assetList.setEnvironment(environmentName) self.assetList.load(p.assets()) self.propertiesList.setEnvironment(environmentName) self.propertiesList.load(p.properties(), p.rationale()) def OnDeleteEnvironment(self, evt): selectedIdx = evt.GetIndex() environmentName = self.environmentList.GetItemText(selectedIdx) del self.theEnvironmentDictionary[environmentName] self.theSelectedIdx = -1 def environmentProperties(self): if (self.theSelectedIdx != -1): environmentName = self.environmentList.GetItemText( self.theSelectedIdx) syProperties, pRationale = self.propertiesList.properties() self.theEnvironmentDictionary[ environmentName] = ThreatEnvironmentProperties( environmentName, self.lhoodCtrl.GetValue(), self.assetList.dimensions(), self.attackerList.dimensions(), syProperties, pRationale) return self.theEnvironmentDictionary.values()