diff --git a/src/main/kotlin/com/bridgecrew/ui/actions/CheckovScanAction.kt b/src/main/kotlin/com/bridgecrew/ui/actions/CheckovScanAction.kt index cc9940b..292016d 100644 --- a/src/main/kotlin/com/bridgecrew/ui/actions/CheckovScanAction.kt +++ b/src/main/kotlin/com/bridgecrew/ui/actions/CheckovScanAction.kt @@ -28,7 +28,6 @@ object CheckovScanAction : AnAction(), DumbAware { val project = actionEvent.project if (actionEvent.presentation.icon == AllIcons.Actions.Execute) { isExecuteState = false - update(actionEvent) project!!.service().fullScanButtonWasPressed() project.service().scanProject(project) } else { @@ -37,7 +36,6 @@ object CheckovScanAction : AnAction(), DumbAware { project?.service()?.cancelFullScan(project) } updateIcon() - update(actionEvent) } override fun update(e: AnActionEvent) { diff --git a/src/main/kotlin/com/bridgecrew/ui/actions/FixAction.kt b/src/main/kotlin/com/bridgecrew/ui/actions/FixAction.kt index c963d14..6482576 100644 --- a/src/main/kotlin/com/bridgecrew/ui/actions/FixAction.kt +++ b/src/main/kotlin/com/bridgecrew/ui/actions/FixAction.kt @@ -10,6 +10,7 @@ import com.bridgecrew.services.scan.CheckovScanService import com.bridgecrew.settings.CheckovGlobalState import com.bridgecrew.utils.navigateToFile import com.intellij.ide.DataManager +import com.intellij.openapi.actionSystem.DataKey import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.editor.Document @@ -28,35 +29,36 @@ class FixAction(private val buttonInstance: JButton, val result: BaseCheckovResu init { DataManager.getInstance().dataContextFromFocusAsync.then { dataContext -> - val project = dataContext.getData("project") as Project - val connection = project.messageBus.connect() - val inScanMsg = "Scan in progress. Please wait for completion before retrying." - buttonInstance.isEnabled = !CheckovGlobalState.scanInProgress - connection.subscribe(CheckovScanListener.SCAN_TOPIC, object : CheckovScanListener { - override fun fileScanningStarted() { - buttonInstance.isEnabled = false - buttonInstance.toolTipText = inScanMsg - CheckovGlobalState.scanInProgress = true - } - - override fun projectScanningStarted() { - buttonInstance.isEnabled = false - buttonInstance.toolTipText = inScanMsg - CheckovGlobalState.scanInProgress = true - } - - override fun scanningFinished(scanSourceType: CheckovScanService.ScanSourceType) { - buttonInstance.isEnabled = true - buttonInstance.toolTipText = "" - CheckovGlobalState.scanInProgress = false - } - - override fun fullScanFailed() { - buttonInstance.isEnabled = true - buttonInstance.toolTipText = "" - CheckovGlobalState.scanInProgress = false - } - }) + dataContext.getData(DataKey.create("project"))?.let { + val connection = it.messageBus.connect() + val inScanMsg = "Scan in progress. Please wait for completion before retrying." + buttonInstance.isEnabled = !CheckovGlobalState.scanInProgress + connection.subscribe(CheckovScanListener.SCAN_TOPIC, object : CheckovScanListener { + override fun fileScanningStarted() { + buttonInstance.isEnabled = false + buttonInstance.toolTipText = inScanMsg + CheckovGlobalState.scanInProgress = true + } + + override fun projectScanningStarted() { + buttonInstance.isEnabled = false + buttonInstance.toolTipText = inScanMsg + CheckovGlobalState.scanInProgress = true + } + + override fun scanningFinished(scanSourceType: CheckovScanService.ScanSourceType) { + buttonInstance.isEnabled = true + buttonInstance.toolTipText = "" + CheckovGlobalState.scanInProgress = false + } + + override fun fullScanFailed() { + buttonInstance.isEnabled = true + buttonInstance.toolTipText = "" + CheckovGlobalState.scanInProgress = false + } + }) + } } } @@ -89,12 +91,12 @@ class FixAction(private val buttonInstance: JButton, val result: BaseCheckovResu val endOffset = document.getLineEndOffset(endLine) DataManager.getInstance().dataContextFromFocusAsync.then { dataContext -> - val project = dataContext.getData("project") as Project - - WriteCommandAction.runWriteCommandAction(project) { - document.replaceString(startOffset, endOffset, result.fixDefinition!!) - FileDocumentManager.getInstance().saveDocument(document) - navigateToFile(project, virtualFile, result.codeDiffFirstLine) + dataContext.getData(DataKey.create("project"))?.let { + WriteCommandAction.runWriteCommandAction(it) { + document.replaceString(startOffset, endOffset, result.fixDefinition!!) + FileDocumentManager.getInstance().saveDocument(document) + navigateToFile(it, virtualFile, result.codeDiffFirstLine) + } } } @@ -131,12 +133,13 @@ class FixAction(private val buttonInstance: JButton, val result: BaseCheckovResu private fun showSCAFixModal(fixCommand: FixCommand, isSuccess: Boolean) { DataManager.getInstance().dataContextFromFocusAsync.then { dataContext -> - val project = dataContext.getData("project") as Project - Messages.showInfoMessage( - project, - buildModalMessage(fixCommand, isSuccess), - "SCA Fix - Additional Action Required" - ) + dataContext.getData(DataKey.create("project"))?.let { + Messages.showInfoMessage( + it, + buildModalMessage(fixCommand, isSuccess), + "SCA Fix - Additional Action Required" + ) + } } } diff --git a/src/main/kotlin/com/bridgecrew/ui/actions/FocusOnFileInTree.kt b/src/main/kotlin/com/bridgecrew/ui/actions/FocusOnFileInTree.kt index 7c629b8..a1aebdf 100644 --- a/src/main/kotlin/com/bridgecrew/ui/actions/FocusOnFileInTree.kt +++ b/src/main/kotlin/com/bridgecrew/ui/actions/FocusOnFileInTree.kt @@ -3,6 +3,7 @@ package com.bridgecrew.ui.actions import com.bridgecrew.ui.CheckovToolWindowManagerPanel import com.bridgecrew.utils.PANELTYPE import com.intellij.ide.DataManager +import com.intellij.openapi.actionSystem.DataKey import com.intellij.openapi.components.service import com.intellij.openapi.project.Project import java.awt.event.ActionEvent @@ -12,9 +13,9 @@ class FocusOnFileInTree(val filePath: String) : ActionListener { override fun actionPerformed(e: ActionEvent?) { DataManager.getInstance().dataContextFromFocusAsync.then { dataContext -> - val project = dataContext.getData("project") as Project - project.service() - .loadMainPanel(PANELTYPE.CHECKOV_FILE_SCAN_FINISHED, filePath) + dataContext.getData(DataKey.create("project")) + ?.service() + ?.loadMainPanel(PANELTYPE.CHECKOV_FILE_SCAN_FINISHED, filePath) } } }