Skip to content

Commit

Permalink
IJMP-1367: added: bubble notification when the cancel is clicked duri…
Browse files Browse the repository at this point in the history
…ng the operation
  • Loading branch information
Nikita Belabotski authored and belobockii committed Sep 22, 2023
1 parent f429d43 commit adc3c02
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private fun formatMessage(code: Int, message: String, errorParams: Map<*, *>?):
*/
class CallException(
val code: Int,
headMessage: String,
val headMessage: String,
val errorParams: Map<*, *>? = null,
override val cause: Throwable? = null
) : Exception(formatMessage(code, headMessage, errorParams))
Expand Down
43 changes: 38 additions & 5 deletions src/main/kotlin/org/zowe/explorer/explorer/Explorer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package org.zowe.explorer.explorer

import com.intellij.ide.BrowserUtil
import com.intellij.notification.Notification
import com.intellij.notification.NotificationAction
import com.intellij.notification.NotificationType
import com.intellij.notification.Notifications
import com.intellij.openapi.Disposable
Expand All @@ -24,6 +25,7 @@ import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.Disposer
import com.intellij.util.messages.Topic
import org.zowe.explorer.config.CONFIGS_CHANGED
Expand All @@ -33,11 +35,13 @@ import org.zowe.explorer.config.connect.ConnectionConfig
import org.zowe.explorer.config.connect.ConnectionConfigBase
import org.zowe.explorer.config.connect.CredentialsListener
import org.zowe.explorer.dataops.DataOpsManager
import org.zowe.explorer.dataops.exceptions.CallException
import org.zowe.explorer.editor.ChangeContentService
import org.zowe.explorer.utils.*
import org.zowe.explorer.utils.crudable.EntityWithUuid
import org.zowe.explorer.utils.crudable.anyEventAdaptor
import org.zowe.explorer.utils.crudable.eventAdapter
import java.lang.RuntimeException
import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.read
import kotlin.concurrent.write
Expand Down Expand Up @@ -193,15 +197,44 @@ abstract class AbstractExplorerBase<Connection: ConnectionConfigBase, U : Workin

/** @see Explorer.reportThrowable */
override fun reportThrowable(t: Throwable, project: Project?) {
if (t is ProcessCanceledException) {
return
lateinit var title: String
lateinit var details: String

if (t is RuntimeException) {
title = "Error in plugin Zowe Explorer"
details = if (t.cause is ProcessCanceledException) {
"Error during operation execution: operation cancelled by user"
} else {
t.message ?: t.toString()
}
} else if (t is CallException) {
title = (t.errorParams?.getOrDefault("message", t.headMessage) as String).replaceFirstChar { it.uppercase() }
if (title.contains(".")) {
title = title.split(".")[0]
}
details = t.errorParams["details"]?.castOrNull<List<String>>()?.joinToString("\n") ?: "Unknown error"
if (details.contains(":")) {
details = details.split(":").last()
}
} else {
title = t.message ?: t.toString()
details = "Unknown error"
}

Notification(
EXPLORER_NOTIFICATION_GROUP_ID,
"Error in plugin Zowe Explorer",
t.message ?: t.toString(),
title,
details,
NotificationType.ERROR
).let {
).addAction(object : NotificationAction("More") {
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
Messages.showErrorDialog(
project,
t.message ?: t.toString(),
title
)
}
}).let {
Notifications.Bus.notify(it)
}
}
Expand Down

0 comments on commit adc3c02

Please sign in to comment.