From 508e7f9d033c7bdf86e37bc6c41a7feaadfe3c0b Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Mon, 14 Oct 2024 14:08:31 +0200 Subject: [PATCH] fix: show success notification when pushing multi-resource editor (#710) Signed-off-by: Andre Dietisheim --- .../kubernetes/editor/EditorFocusListener.kt | 7 +- .../kubernetes/editor/EditorResourceState.kt | 64 ++++++++-- .../editor/ResourceEditorFactory.kt | 3 +- .../notification/DeletedNotification.kt | 18 +-- .../editor/notification/ErrorNotification.kt | 21 +-- .../notification/NotificationActions.kt | 6 +- .../editor/notification/Notifications.kt | 120 +++++++++++++++--- .../editor/notification/PullNotification.kt | 15 ++- .../editor/notification/PulledNotification.kt | 14 +- .../editor/notification/PushNotification.kt | 22 ++-- .../editor/notification/PushedNotification.kt | 16 +-- .../kubernetes/model/util/ResourceUtils.kt | 14 ++ src/main/resources/META-INF/plugin.xml | 2 +- 13 files changed, 239 insertions(+), 83 deletions(-) diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorFocusListener.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorFocusListener.kt index 0cfeda043..1a3f0d13d 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorFocusListener.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorFocusListener.kt @@ -61,9 +61,12 @@ class EditorFocusListener(private val project: Project) : FileEditorManagerListe editor: FileEditor, project: Project ) { - ErrorNotification(editor, project).show( + val notification = ErrorNotification(editor, project) + notification.show( e.message ?: "Undefined error", - e) + e, + { notification.hide() } + ) } } diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorResourceState.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorResourceState.kt index 9a4f02ffe..71c475254 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorResourceState.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorResourceState.kt @@ -11,6 +11,8 @@ ******************************************************************************/ package com.redhat.devtools.intellij.kubernetes.editor +import java.util.Objects + val FILTER_ALL = { _: EditorResource -> true } val FILTER_TO_PUSH = { editorResource: EditorResource -> val state = editorResource.getState() @@ -29,37 +31,81 @@ abstract class EditorResourceState class Error(val title: String, val message: String? = null): EditorResourceState() { constructor(title: String, e: Throwable) : this(title, e.message) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + return other is Error + && title == other.title + && message == other.message + } + + override fun hashCode(): Int { + return Objects.hash( + title, + message + ) + } + + override fun toString(): String { + return super.toString() + } } open class Identical: EditorResourceState() abstract class Different(val exists: Boolean, val isOutdatedVersion: Boolean): EditorResourceState() { abstract fun isPush(): Boolean + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + return other is Different + && other.exists == exists + && other.isOutdatedVersion == isOutdatedVersion + && other.isPush() == isPush() + } + + override fun hashCode(): Int { + return Objects.hash( + exists, + isOutdatedVersion, + isPush() + ) + } } open class Modified(exists: Boolean, isOutdatedVersion: Boolean): Different(exists, isOutdatedVersion) { override fun isPush() = true } -class DeletedOnCluster: Modified(false, false) { +class DeletedOnCluster(): Modified(false, false) { override fun isPush() = true - } class Outdated: Different(true, true) { override fun isPush() = false - } abstract class Pushed: Identical() { abstract val updated: Boolean -} -class Created: Pushed() { - override val updated = false -} -class Updated: Pushed() { - override val updated = true + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + return other is Pushed + && other.updated == updated + } + + override fun hashCode(): Int { + return Objects.hashCode(updated) + } } +class Created(override val updated: Boolean = false) : Pushed() + +class Updated(override val updated: Boolean = true): Pushed() + class Pulled: EditorResourceState() diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ResourceEditorFactory.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ResourceEditorFactory.kt index 40715302a..78e8c121c 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ResourceEditorFactory.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ResourceEditorFactory.kt @@ -127,7 +127,8 @@ open class ResourceEditorFactory protected constructor( editor.file?.putUserData(ResourceEditor.KEY_RESOURCE_EDITOR, resourceEditor) resourceEditor } catch (e: ResourceException) { - ErrorNotification(editor, project).show(e.message ?: "", e.cause?.message) + val notification = ErrorNotification(editor, project) + notification.show(e.message ?: "", e.cause?.message, { notification.hide() }) runAsync { telemetry.error(e).send() } null } diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/DeletedNotification.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/DeletedNotification.kt index 5166283a5..d9f7354e1 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/DeletedNotification.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/DeletedNotification.kt @@ -10,6 +10,7 @@ ******************************************************************************/ package com.redhat.devtools.intellij.kubernetes.editor.notification +import com.intellij.icons.AllIcons import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key @@ -17,34 +18,33 @@ import com.intellij.ui.EditorNotificationPanel import com.redhat.devtools.intellij.kubernetes.editor.hideNotification import com.redhat.devtools.intellij.kubernetes.editor.showNotification import com.redhat.devtools.intellij.kubernetes.model.util.toKindAndName +import icons.Icons import io.fabric8.kubernetes.api.model.HasMetadata import javax.swing.JComponent /** * An editor (panel) notification that informs about a deleted resource on the cluster. */ -class DeletedNotification(private val editor: FileEditor, private val project: Project) { +open class DeletedNotification(private val editor: FileEditor, private val project: Project) { - companion object { + private companion object { private val KEY_PANEL = Key(DeletedNotification::class.java.canonicalName) } - fun show(resource: HasMetadata) { - editor.showNotification(KEY_PANEL, { createPanel(resource) }, project) + fun show(resource: HasMetadata, closeAction: () -> Unit) { + editor.showNotification(KEY_PANEL, { createPanel(resource, closeAction) }, project) } fun hide() { editor.hideNotification(KEY_PANEL, project) } - private fun createPanel(resource: HasMetadata): EditorNotificationPanel { + private fun createPanel(resource: HasMetadata, hideAction: () -> Unit): EditorNotificationPanel { val panel = EditorNotificationPanel() panel.text = "${toKindAndName(resource)} was deleted on cluster. Push to Cluster?" + panel.icon(Icons.upload) addPush(false, panel) - addDismiss(panel) { - hide() - } - + addHide(panel, hideAction) return panel } } \ No newline at end of file diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/ErrorNotification.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/ErrorNotification.kt index 8e5007216..a6226c08c 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/ErrorNotification.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/ErrorNotification.kt @@ -26,30 +26,33 @@ import javax.swing.JComponent */ class ErrorNotification(private val editor: FileEditor, private val project: Project) { - companion object { + private companion object { private val KEY_PANEL = Key(ErrorNotification::class.java.canonicalName) } - fun show(title: String, message: String?) { - editor.showNotification(KEY_PANEL, { createPanel(editor, title, message) }, project) + fun show(title: String, message: String?, closeAction: (() -> Unit)?) { + editor.showNotification(KEY_PANEL, { createPanel(editor, title, message, closeAction) }, project) } - fun show(title: String, e: Throwable) { - editor.showNotification(KEY_PANEL, { createPanel(editor, title, e.message) }, project) + fun show(title: String, e: Throwable, closeAction: (() -> Unit)?) { + editor.showNotification(KEY_PANEL, { createPanel(editor, title, e.message, closeAction) }, project) } fun hide() { editor.hideNotification(KEY_PANEL, project) } - private fun createPanel(editor: FileEditor, title: String, message: String?): EditorNotificationPanel { + private fun createPanel( + editor: FileEditor, + title: String, + message: String?, + closeAction: (() -> Unit)? + ): EditorNotificationPanel { val panel = EditorNotificationPanel() panel.icon(AllIcons.Ide.FatalError) panel.text = title addDetailsAction(message, panel, editor) - addDismiss(panel) { - hide() - } + addHide(panel, closeAction) return panel } diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/NotificationActions.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/NotificationActions.kt index 53e04bfbd..e9dc23225 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/NotificationActions.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/NotificationActions.kt @@ -18,8 +18,10 @@ fun addPull(panel: EditorNotificationPanel) { panel.createActionLabel("Pull", PullAction.ID) } -fun addDismiss(panel: EditorNotificationPanel, consumer: () -> Unit) { - panel.createActionLabel("Dismiss", consumer) +fun addHide(panel: EditorNotificationPanel, closeAction: (() -> Unit)?) { + if (closeAction != null) { + panel.setCloseAction(closeAction) + } } fun addDiff(panel: EditorNotificationPanel) { diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/Notifications.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/Notifications.kt index 6ef6331cb..ddc4b3a30 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/Notifications.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/Notifications.kt @@ -15,11 +15,15 @@ import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.project.Project import com.redhat.devtools.intellij.kubernetes.editor.DeletedOnCluster import com.redhat.devtools.intellij.kubernetes.editor.EditorResource +import com.redhat.devtools.intellij.kubernetes.editor.EditorResourceState import com.redhat.devtools.intellij.kubernetes.editor.Error import com.redhat.devtools.intellij.kubernetes.editor.FILTER_ERROR +import com.redhat.devtools.intellij.kubernetes.editor.FILTER_PUSHED import com.redhat.devtools.intellij.kubernetes.editor.FILTER_TO_PUSH import com.redhat.devtools.intellij.kubernetes.editor.Modified +import com.redhat.devtools.intellij.kubernetes.editor.Pulled import com.redhat.devtools.intellij.kubernetes.editor.Pushed +import com.redhat.devtools.intellij.kubernetes.model.util.HasMetadataIdentifier import io.fabric8.kubernetes.api.model.HasMetadata open class Notifications( @@ -39,6 +43,8 @@ open class Notifications( private val errorNotification: ErrorNotification = ErrorNotification(editor, project), ) { + private val dismissed = mutableMapOf() + fun show(editorResource: EditorResource) { show(editorResource, true) } @@ -48,17 +54,21 @@ open class Notifications( val resource = editorResource.getResource() when { state is Error -> - showError(state.title, state.message) + showError(state) state is Pushed -> showPushed(listOf(editorResource)) + state is Pulled -> + showPulled(resource) + state is DeletedOnCluster && showSyncNotifications -> showDeleted(resource) /** * avoid too many notifications, don't notify outdated + * state is Outdated && showSyncNotification -> showPullNotification(resource) */ @@ -77,53 +87,98 @@ open class Notifications( } fun show(editorResources: Collection, showSyncNotifications: Boolean) { - val toPush = editorResources.filter(FILTER_TO_PUSH) - if (toPush.isNotEmpty() - && showSyncNotifications) { - showPush(false, toPush) + removeUpdatedDismissed(editorResources) + val inError = getNonDismissed(editorResources.filter(FILTER_ERROR)) + val showError = inError.isNotEmpty(); + val pushed = getNonDismissed(editorResources.filter(FILTER_PUSHED)) + val showPushed = pushed.isNotEmpty() + val toPush = getNonDismissed(editorResources.filter(FILTER_TO_PUSH)) + val showToPush = toPush.isNotEmpty() && showSyncNotifications + val dismissAction = { + dismiss(editorResources) + hideAll() + } + + if (!showError + && !showPushed + && !showToPush) { return } - val inError = editorResources.filter(FILTER_ERROR) - if (inError.isNotEmpty()) { - showError(inError) - } else { + runInUI { hideAll() + val error = inError.firstOrNull()?.getState() as? Error + if (error != null) { + errorNotification.show( + error.title, + error.message, + dismissAction) + } + if (showPushed) { + pushedNotification.show( + pushed, + // close action only if there was no error notification + if (showError) null else dismissAction + ) + } + if (showToPush) { + pushNotification.show( + false, + toPush, + // close action only if there was no error nor pushed notification + if (showError || showPushed) null else dismissAction + ) + } } } - fun showError(title: String, message: String?) { + fun showError(error: Error) { runInUI { hideAll() - errorNotification.show(title, message) + errorNotification.show(error.title, error.message) { + errorNotification.hide() + } } } - private fun showError(editorResources: Collection) { + fun showError(title: String, message: String?) { + showError(Error(title, message)) + } + + private fun getError(editorResources: Collection) { val inError = editorResources.filter(FILTER_ERROR) val toDisplay = inError.firstOrNull()?.getState() as? Error ?: return - showError(toDisplay.title, toDisplay.message) + showError(toDisplay) } private fun showPush(showPull: Boolean, editorResources: Collection) { runInUI { // hide & show in the same UI thread runnable avoid flickering hideAll() - pushNotification.show(showPull, editorResources) + pushNotification.show(showPull, editorResources, { + dismiss(editorResources) + hideAll() + }) } } private fun showPushed(editorResources: Collection) { runInUI { // hide & show in the same UI thread runnable avoid flickering - hideAll() - pushedNotification.show(editorResources) + pushedNotification.show(editorResources, { pushedNotification.hide() }) } } private fun showPull(resource: HasMetadata) { runInUI { hideAll() - pullNotification.show(resource) + pullNotification.show(resource, { pullNotification.hide() }) + } + } + + private fun showPulled(resource: HasMetadata) { + runInUI { + hideAll() + pulledNotification.show(resource, { pulledNotification.hide() }) } } @@ -131,7 +186,36 @@ open class Notifications( runInUI { // hide & show in the same UI thread runnable avoid flickering hideAll() - deletedNotification.show(resource) + deletedNotification.show(resource, { deletedNotification.hide() }) + } + } + + private fun dismiss(resources: Collection) { + resources.forEach { resource -> + dismissed.put(HasMetadataIdentifier(resource.getResource()), resource.getState()) + } + } + + private fun isDismissedButUpdated(editorResource: EditorResource): Boolean { + val dismissed = dismissed[HasMetadataIdentifier(editorResource.getResource())] ?: return false + return editorResource.getState() != dismissed + } + + private fun isDismissed(editorResource: EditorResource): Boolean { + return dismissed[HasMetadataIdentifier(editorResource.getResource())] != null + } + + private fun getNonDismissed(editorResources: Collection): Collection { + return editorResources.filter { editorResource -> + !isDismissed(editorResource) + } + } + + private fun removeUpdatedDismissed(editorResources: Collection) { + editorResources.forEach { editorResource -> + if (isDismissedButUpdated(editorResource)) { + dismissed.remove(HasMetadataIdentifier(editorResource.getResource())) + } } } diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PullNotification.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PullNotification.kt index 604215272..888ad6310 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PullNotification.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PullNotification.kt @@ -10,6 +10,7 @@ ******************************************************************************/ package com.redhat.devtools.intellij.kubernetes.editor.notification +import com.intellij.icons.AllIcons import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key @@ -17,6 +18,7 @@ import com.intellij.ui.EditorNotificationPanel import com.redhat.devtools.intellij.kubernetes.editor.hideNotification import com.redhat.devtools.intellij.kubernetes.editor.showNotification import com.redhat.devtools.intellij.kubernetes.model.util.toKindAndName +import icons.Icons import io.fabric8.kubernetes.api.model.HasMetadata import javax.swing.JComponent @@ -26,27 +28,26 @@ import javax.swing.JComponent */ class PullNotification(private val editor: FileEditor, private val project: Project) { - companion object { + private companion object { val KEY_PANEL = Key(PullNotification::class.java.canonicalName) } - fun show(resource: HasMetadata) { - editor.showNotification(KEY_PANEL, { createPanel(resource) }, project) + fun show(resource: HasMetadata, closeAction: (() -> Unit)?) { + editor.showNotification(KEY_PANEL, { createPanel(resource, closeAction) }, project) } fun hide() { editor.hideNotification(KEY_PANEL, project) } - private fun createPanel(resource: HasMetadata): EditorNotificationPanel { + private fun createPanel(resource: HasMetadata, closeAction: (() -> Unit)?): EditorNotificationPanel { val panel = EditorNotificationPanel() panel.text = "${toKindAndName(resource)} changed on cluster. Pull?" + panel.icon(Icons.download) addPull(panel) addPush(true, panel) addDiff(panel) - addDismiss(panel) { - hide() - } + addHide(panel, closeAction) return panel } } \ No newline at end of file diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PulledNotification.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PulledNotification.kt index b2a86e56e..ec79cf9e8 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PulledNotification.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PulledNotification.kt @@ -10,6 +10,7 @@ ******************************************************************************/ package com.redhat.devtools.intellij.kubernetes.editor.notification +import com.intellij.icons.AllIcons import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key @@ -24,19 +25,19 @@ import javax.swing.JComponent */ class PulledNotification(private val editor: FileEditor, private val project: Project) { - companion object { + private companion object { private val KEY_PANEL = Key(PulledNotification::class.java.canonicalName) } - fun show(resource: HasMetadata) { - editor.showNotification(KEY_PANEL, { createPanel(resource) }, project) + fun show(resource: HasMetadata, closeAction: (() -> Unit)?) { + editor.showNotification(KEY_PANEL, { createPanel(resource, closeAction) }, project) } fun hide() { editor.hideNotification(KEY_PANEL, project) } - private fun createPanel(resource: HasMetadata): EditorNotificationPanel { + private fun createPanel(resource: HasMetadata, closeAction: (() -> Unit)?): EditorNotificationPanel { val panel = EditorNotificationPanel() panel.text = "Pulled ${resource.kind} '${resource.metadata.name}' ${ @@ -46,9 +47,8 @@ class PulledNotification(private val editor: FileEditor, private val project: Pr "" } }" - addDismiss(panel) { - hide() - } + panel.icon(AllIcons.RunConfigurations.ShowPassed) + addHide(panel, closeAction) return panel } } \ No newline at end of file diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushNotification.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushNotification.kt index 98c419e79..7d8f1b8fc 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushNotification.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushNotification.kt @@ -10,6 +10,7 @@ ******************************************************************************/ package com.redhat.devtools.intellij.kubernetes.editor.notification +import com.intellij.icons.AllIcons import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key @@ -19,6 +20,7 @@ import com.redhat.devtools.intellij.kubernetes.editor.EditorResource import com.redhat.devtools.intellij.kubernetes.editor.hideNotification import com.redhat.devtools.intellij.kubernetes.editor.showNotification import com.redhat.devtools.intellij.kubernetes.model.util.toKindAndNames +import icons.Icons import javax.swing.JComponent /** @@ -26,11 +28,11 @@ import javax.swing.JComponent */ class PushNotification(private val editor: FileEditor, private val project: Project) { - companion object { + private companion object { val KEY_PANEL = Key(PushNotification::class.java.canonicalName) } - fun show(showPull: Boolean, editorResources: Collection) { + fun show(showPull: Boolean, editorResources: Collection, closeAction: (() -> Unit)?) { val toCreateOrUpdate = editorResources .filter { editorResource -> editorResource.getState() is Different @@ -44,7 +46,7 @@ class PushNotification(private val editor: FileEditor, private val project: Proj && toUpdate.isEmpty()) { return } - editor.showNotification(KEY_PANEL, { createPanel(showPull, toCreate, toUpdate) }, project) + editor.showNotification(KEY_PANEL, { createPanel(showPull, toCreate, toUpdate, closeAction) }, project) } fun hide() { @@ -54,14 +56,16 @@ class PushNotification(private val editor: FileEditor, private val project: Proj private fun createPanel( showPull: Boolean, toCreate: Collection, - toUpdate: Collection + toUpdate: Collection, + closeAction: (() -> Unit)? ): EditorNotificationPanel { val text = createText(toCreate, toUpdate) return createPanel(text, toUpdate.isNotEmpty(), showPull && toUpdate.any { editorResource -> editorResource.isOutdatedVersion() - }) + }, + closeAction) } private fun createText(toCreate: Collection?, toUpdate: Collection?): String { @@ -82,8 +86,9 @@ class PushNotification(private val editor: FileEditor, private val project: Proj .toString() } - private fun createPanel(text: String, existsOnCluster: Boolean, isOutdated: Boolean): EditorNotificationPanel { + private fun createPanel(text: String, existsOnCluster: Boolean, isOutdated: Boolean, closeAction: (() -> Unit)?): EditorNotificationPanel { val panel = EditorNotificationPanel() + panel.icon(Icons.upload) panel.text = text addPush(false, panel) if (isOutdated) { @@ -92,10 +97,7 @@ class PushNotification(private val editor: FileEditor, private val project: Proj if (existsOnCluster) { addDiff(panel) } - addDismiss(panel) { - hide() - } - + addHide(panel, closeAction) return panel } } \ No newline at end of file diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushedNotification.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushedNotification.kt index d9a2d1186..a7cf82aee 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushedNotification.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushedNotification.kt @@ -10,6 +10,7 @@ ******************************************************************************/ package com.redhat.devtools.intellij.kubernetes.editor.notification +import com.intellij.icons.AllIcons import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key @@ -20,6 +21,7 @@ import com.redhat.devtools.intellij.kubernetes.editor.Pushed import com.redhat.devtools.intellij.kubernetes.editor.hideNotification import com.redhat.devtools.intellij.kubernetes.editor.showNotification import com.redhat.devtools.intellij.kubernetes.model.util.toKindAndNames +import icons.Icons import javax.swing.JComponent /** @@ -27,22 +29,22 @@ import javax.swing.JComponent */ class PushedNotification(private val editor: FileEditor, private val project: Project) { - companion object { + private companion object { val KEY_PANEL = Key(PushedNotification::class.java.canonicalName) } - fun show(editorResources: Collection) { + fun show(editorResources: Collection, closeAction: (() -> Unit)?) { if (editorResources.isEmpty()) { return } - editor.showNotification(KEY_PANEL, { createPanel(editorResources) }, project) + editor.showNotification(KEY_PANEL, { createPanel(editorResources, closeAction) }, project) } fun hide() { editor.hideNotification(KEY_PANEL, project) } - private fun createPanel(editorResources: Collection): EditorNotificationPanel { + private fun createPanel(editorResources: Collection, closeAction: (() -> Unit)?): EditorNotificationPanel { val panel = EditorNotificationPanel() val createdOrUpdated = editorResources .filter(FILTER_PUSHED) @@ -52,10 +54,8 @@ class PushedNotification(private val editor: FileEditor, private val project: Pr val created = createdOrUpdated[false] val updated = createdOrUpdated[true] panel.text = createText(created, updated) - addDismiss(panel) { - hide() - } - + panel.icon(AllIcons.RunConfigurations.ShowPassed) + addHide(panel, closeAction) return panel } diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/util/ResourceUtils.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/util/ResourceUtils.kt index 75e2e6637..5c1fe035f 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/util/ResourceUtils.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/util/ResourceUtils.kt @@ -431,4 +431,18 @@ fun String?.toBooleanOrNull(): Boolean? { return null } return this.toBoolean() +} + +data class HasMetadataIdentifier private constructor( + private val kind: String, + private val apiVersion: String, + private val name: String, + private val namespace: String +) { + constructor(resource: HasMetadata) : this( + resource.kind, + resource.apiVersion, + resource.metadata.name, + resource.metadata.namespace + ) } \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index da3780b6d..58f857e5b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -225,7 +225,7 @@ -