17
17
package io .spring .format .formatter .intellij ;
18
18
19
19
import java .awt .event .MouseEvent ;
20
+ import java .util .concurrent .TimeUnit ;
20
21
21
22
import javax .swing .Icon ;
22
23
23
24
import com .intellij .openapi .application .ApplicationManager ;
24
25
import com .intellij .openapi .project .Project ;
25
26
import com .intellij .openapi .util .IconLoader ;
26
- import com .intellij .openapi .wm .IdeFrame ;
27
27
import com .intellij .openapi .wm .StatusBar ;
28
28
import com .intellij .openapi .wm .StatusBarWidget ;
29
29
import com .intellij .openapi .wm .WindowManager ;
30
- import com .intellij .openapi .wm .WindowManagerListener ;
31
30
import com .intellij .util .Consumer ;
31
+ import com .intellij .util .concurrency .AppExecutorUtil ;
32
32
33
33
import io .spring .format .formatter .intellij .codestyle .monitor .Trigger .State ;
34
34
@@ -51,7 +51,7 @@ public void update(State state) {
51
51
WindowManager windowManager = WindowManager .getInstance ();
52
52
final StatusBar statusBar = windowManager .getStatusBar (this .project );
53
53
if (statusBar == null ) {
54
- windowManager . addListener ( new UpdateOnFrameCreateListener (state ));
54
+ AppExecutorUtil . getAppScheduledExecutorService (). schedule (() -> retryUpdate (state ), 1 , TimeUnit . SECONDS );
55
55
return ;
56
56
}
57
57
if (state == State .ACTIVE ) {
@@ -62,6 +62,10 @@ public void update(State state) {
62
62
}
63
63
}
64
64
65
+ private void retryUpdate (State state ) {
66
+ ApplicationManager .getApplication ().invokeLater (() -> update (state ));
67
+ }
68
+
65
69
private void show (StatusBar statusBar ) {
66
70
if (this .widget == null ) {
67
71
this .widget = new Widget ();
@@ -76,30 +80,6 @@ private void hide(final StatusBar statusBar) {
76
80
}
77
81
}
78
82
79
- /**
80
- * {@link WindowManagerListener} used to defer setting the status if the IDE frame
81
- * isn't available.
82
- */
83
- private class UpdateOnFrameCreateListener implements WindowManagerListener {
84
-
85
- private final State state ;
86
-
87
- UpdateOnFrameCreateListener (State state ) {
88
- this .state = state ;
89
- }
90
-
91
- @ Override
92
- public void frameCreated (IdeFrame frame ) {
93
- WindowManager .getInstance ().removeListener (this );
94
- ApplicationManager .getApplication ().invokeLater (() -> update (this .state ));
95
- }
96
-
97
- @ Override
98
- public void beforeFrameReleased (IdeFrame frame ) {
99
- }
100
-
101
- }
102
-
103
83
/**
104
84
* The {@link StatusBarWidget} component for the status.
105
85
*/
0 commit comments