Skip to content

Commit 227efe9

Browse files
committed
fix: show success notification when pushing multi-resource editor (redhat-developer#710)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 92f4e7e commit 227efe9

File tree

16 files changed

+681
-122
lines changed

16 files changed

+681
-122
lines changed

Diff for: src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorFocusListener.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ class EditorFocusListener(private val project: Project) : FileEditorManagerListe
6161
editor: FileEditor,
6262
project: Project
6363
) {
64-
ErrorNotification(editor, project).show(
64+
val notification = ErrorNotification(editor, project)
65+
notification.show(
6566
e.message ?: "Undefined error",
66-
e)
67+
e,
68+
{ notification.hide() }
69+
)
6770
}
6871

6972
}

Diff for: src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorResourceState.kt

+71-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
******************************************************************************/
1212
package com.redhat.devtools.intellij.kubernetes.editor
1313

14+
import java.util.Objects
15+
1416
val FILTER_ALL = { _: EditorResource -> true }
1517
val FILTER_TO_PUSH = { editorResource: EditorResource ->
1618
val state = editorResource.getState()
@@ -25,16 +27,66 @@ val FILTER_PUSHED = { editorResource: EditorResource ->
2527
editorResource.getState() is Pushed
2628
}
2729

28-
abstract class EditorResourceState
30+
abstract class EditorResourceState {
31+
override fun equals(other: Any?): Boolean {
32+
if (this === other) {
33+
return true
34+
}
35+
if (javaClass != other?.javaClass) {
36+
return false
37+
}
38+
return true
39+
}
40+
41+
override fun hashCode(): Int {
42+
return Objects.hash()
43+
}
44+
}
2945

3046
class Error(val title: String, val message: String? = null): EditorResourceState() {
3147
constructor(title: String, e: Throwable) : this(title, e.message)
48+
49+
override fun equals(other: Any?): Boolean {
50+
if (this === other) {
51+
return true
52+
}
53+
return other is Error
54+
&& title == other.title
55+
&& message == other.message
56+
}
57+
58+
override fun hashCode(): Int {
59+
return Objects.hash(
60+
title,
61+
message
62+
)
63+
}
3264
}
3365

3466
open class Identical: EditorResourceState()
3567

3668
abstract class Different(val exists: Boolean, val isOutdatedVersion: Boolean): EditorResourceState() {
3769
abstract fun isPush(): Boolean
70+
override fun equals(other: Any?): Boolean {
71+
if (this === other) {
72+
return true
73+
}
74+
if (javaClass != other?.javaClass) {
75+
return false
76+
}
77+
return other is Different
78+
&& other.exists == exists
79+
&& other.isOutdatedVersion == isOutdatedVersion
80+
&& other.isPush() == isPush()
81+
}
82+
83+
override fun hashCode(): Int {
84+
return Objects.hash(
85+
exists,
86+
isOutdatedVersion,
87+
isPush()
88+
)
89+
}
3890
}
3991

4092
open class Modified(exists: Boolean, isOutdatedVersion: Boolean): Different(exists, isOutdatedVersion) {
@@ -43,23 +95,33 @@ open class Modified(exists: Boolean, isOutdatedVersion: Boolean): Different(exis
4395

4496
class DeletedOnCluster: Modified(false, false) {
4597
override fun isPush() = true
46-
4798
}
4899

49100
class Outdated: Different(true, true) {
50101
override fun isPush() = false
51-
52102
}
53103

54104
abstract class Pushed: Identical() {
55105
abstract val updated: Boolean
56-
}
57106

58-
class Created: Pushed() {
59-
override val updated = false
60-
}
61-
class Updated: Pushed() {
62-
override val updated = true
107+
override fun equals(other: Any?): Boolean {
108+
if (this === other) {
109+
return true
110+
}
111+
if (javaClass != other?.javaClass) {
112+
return false
113+
}
114+
return other is Pushed
115+
&& other.updated == updated
116+
}
117+
118+
override fun hashCode(): Int {
119+
return Objects.hashCode(updated)
120+
}
63121
}
64122

123+
class Created(override val updated: Boolean = false) : Pushed()
124+
125+
class Updated(override val updated: Boolean = true): Pushed()
126+
65127
class Pulled: EditorResourceState()

Diff for: src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ResourceEditorFactory.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ open class ResourceEditorFactory protected constructor(
127127
editor.file?.putUserData(ResourceEditor.KEY_RESOURCE_EDITOR, resourceEditor)
128128
resourceEditor
129129
} catch (e: ResourceException) {
130-
ErrorNotification(editor, project).show(e.message ?: "", e.cause?.message)
130+
val notification = ErrorNotification(editor, project)
131+
notification.show(e.message ?: "", e.cause?.message, { notification.hide() })
131132
runAsync { telemetry.error(e).send() }
132133
null
133134
}

Diff for: src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/DeletedNotification.kt

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,41 @@
1010
******************************************************************************/
1111
package com.redhat.devtools.intellij.kubernetes.editor.notification
1212

13+
import com.intellij.icons.AllIcons
1314
import com.intellij.openapi.fileEditor.FileEditor
1415
import com.intellij.openapi.project.Project
1516
import com.intellij.openapi.util.Key
1617
import com.intellij.ui.EditorNotificationPanel
1718
import com.redhat.devtools.intellij.kubernetes.editor.hideNotification
1819
import com.redhat.devtools.intellij.kubernetes.editor.showNotification
1920
import com.redhat.devtools.intellij.kubernetes.model.util.toKindAndName
21+
import icons.Icons
2022
import io.fabric8.kubernetes.api.model.HasMetadata
2123
import javax.swing.JComponent
2224

2325
/**
2426
* An editor (panel) notification that informs about a deleted resource on the cluster.
2527
*/
26-
class DeletedNotification(private val editor: FileEditor, private val project: Project) {
28+
open class DeletedNotification(private val editor: FileEditor, private val project: Project) {
2729

28-
companion object {
30+
private companion object {
2931
private val KEY_PANEL = Key<JComponent>(DeletedNotification::class.java.canonicalName)
3032
}
3133

32-
fun show(resource: HasMetadata) {
33-
editor.showNotification(KEY_PANEL, { createPanel(resource) }, project)
34+
fun show(resource: HasMetadata, closeAction: () -> Unit) {
35+
editor.showNotification(KEY_PANEL, { createPanel(resource, closeAction) }, project)
3436
}
3537

3638
fun hide() {
3739
editor.hideNotification(KEY_PANEL, project)
3840
}
3941

40-
private fun createPanel(resource: HasMetadata): EditorNotificationPanel {
42+
private fun createPanel(resource: HasMetadata, hideAction: () -> Unit): EditorNotificationPanel {
4143
val panel = EditorNotificationPanel()
4244
panel.text = "${toKindAndName(resource)} was deleted on cluster. Push to Cluster?"
45+
panel.icon(Icons.upload)
4346
addPush(false, panel)
44-
addDismiss(panel) {
45-
hide()
46-
}
47-
47+
addHide(panel, hideAction)
4848
return panel
4949
}
5050
}

Diff for: src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/ErrorNotification.kt

+12-9
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,33 @@ import javax.swing.JComponent
2626
*/
2727
class ErrorNotification(private val editor: FileEditor, private val project: Project) {
2828

29-
companion object {
29+
private companion object {
3030
private val KEY_PANEL = Key<JComponent>(ErrorNotification::class.java.canonicalName)
3131
}
3232

33-
fun show(title: String, message: String?) {
34-
editor.showNotification(KEY_PANEL, { createPanel(editor, title, message) }, project)
33+
fun show(title: String, message: String?, closeAction: (() -> Unit)? = null) {
34+
editor.showNotification(KEY_PANEL, { createPanel(editor, title, message, closeAction) }, project)
3535
}
3636

37-
fun show(title: String, e: Throwable) {
38-
editor.showNotification(KEY_PANEL, { createPanel(editor, title, e.message) }, project)
37+
fun show(title: String, e: Throwable, closeAction: (() -> Unit)? = null) {
38+
editor.showNotification(KEY_PANEL, { createPanel(editor, title, e.message, closeAction) }, project)
3939
}
4040

4141
fun hide() {
4242
editor.hideNotification(KEY_PANEL, project)
4343
}
4444

45-
private fun createPanel(editor: FileEditor, title: String, message: String?): EditorNotificationPanel {
45+
private fun createPanel(
46+
editor: FileEditor,
47+
title: String,
48+
message: String?,
49+
closeAction: (() -> Unit)?
50+
): EditorNotificationPanel {
4651
val panel = EditorNotificationPanel()
4752
panel.icon(AllIcons.Ide.FatalError)
4853
panel.text = title
4954
addDetailsAction(message, panel, editor)
50-
addDismiss(panel) {
51-
hide()
52-
}
55+
addHide(panel, closeAction)
5356
return panel
5457
}
5558

Diff for: src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/NotificationActions.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ fun addPull(panel: EditorNotificationPanel) {
1818
panel.createActionLabel("Pull", PullAction.ID)
1919
}
2020

21-
fun addDismiss(panel: EditorNotificationPanel, consumer: () -> Unit) {
22-
panel.createActionLabel("Dismiss", consumer)
21+
fun addHide(panel: EditorNotificationPanel, closeAction: (() -> Unit)?) {
22+
if (closeAction != null) {
23+
panel.setCloseAction(closeAction)
24+
}
2325
}
2426

2527
fun addDiff(panel: EditorNotificationPanel) {

0 commit comments

Comments
 (0)