Skip to content

Commit 4047ce8

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

File tree

15 files changed

+295
-99
lines changed

15 files changed

+295
-99
lines changed

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
}

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

+55-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()
@@ -29,37 +31,81 @@ abstract class EditorResourceState
2931

3032
class Error(val title: String, val message: String? = null): EditorResourceState() {
3133
constructor(title: String, e: Throwable) : this(title, e.message)
34+
35+
override fun equals(other: Any?): Boolean {
36+
if (this === other) {
37+
return true
38+
}
39+
return other is Error
40+
&& title == other.title
41+
&& message == other.message
42+
}
43+
44+
override fun hashCode(): Int {
45+
return Objects.hash(
46+
title,
47+
message
48+
)
49+
}
50+
51+
override fun toString(): String {
52+
return super.toString()
53+
}
3254
}
3355

3456
open class Identical: EditorResourceState()
3557

3658
abstract class Different(val exists: Boolean, val isOutdatedVersion: Boolean): EditorResourceState() {
3759
abstract fun isPush(): Boolean
60+
override fun equals(other: Any?): Boolean {
61+
if (this === other) {
62+
return true
63+
}
64+
return other is Different
65+
&& other.exists == exists
66+
&& other.isOutdatedVersion == isOutdatedVersion
67+
&& other.isPush() == isPush()
68+
}
69+
70+
override fun hashCode(): Int {
71+
return Objects.hash(
72+
exists,
73+
isOutdatedVersion,
74+
isPush()
75+
)
76+
}
3877
}
3978

4079
open class Modified(exists: Boolean, isOutdatedVersion: Boolean): Different(exists, isOutdatedVersion) {
4180
override fun isPush() = true
4281
}
4382

44-
class DeletedOnCluster: Modified(false, false) {
83+
class DeletedOnCluster(): Modified(false, false) {
4584
override fun isPush() = true
46-
4785
}
4886

4987
class Outdated: Different(true, true) {
5088
override fun isPush() = false
51-
5289
}
5390

5491
abstract class Pushed: Identical() {
5592
abstract val updated: Boolean
56-
}
5793

58-
class Created: Pushed() {
59-
override val updated = false
60-
}
61-
class Updated: Pushed() {
62-
override val updated = true
94+
override fun equals(other: Any?): Boolean {
95+
if (this === other) {
96+
return true
97+
}
98+
return other is Pushed
99+
&& other.updated == updated
100+
}
101+
102+
override fun hashCode(): Int {
103+
return Objects.hashCode(updated)
104+
}
63105
}
64106

107+
class Created(override val updated: Boolean = false) : Pushed()
108+
109+
class Updated(override val updated: Boolean = true): Pushed()
110+
65111
class Pulled: EditorResourceState()

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
}

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
}

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

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)