1717package io .spring .format .formatter .intellij ;
1818
1919import java .awt .event .MouseEvent ;
20+ import java .util .concurrent .TimeUnit ;
2021
2122import javax .swing .Icon ;
2223
2324import com .intellij .openapi .application .ApplicationManager ;
2425import com .intellij .openapi .project .Project ;
2526import com .intellij .openapi .util .IconLoader ;
26- import com .intellij .openapi .wm .IdeFrame ;
2727import com .intellij .openapi .wm .StatusBar ;
2828import com .intellij .openapi .wm .StatusBarWidget ;
2929import com .intellij .openapi .wm .WindowManager ;
30- import com .intellij .openapi .wm .WindowManagerListener ;
3130import com .intellij .util .Consumer ;
31+ import com .intellij .util .concurrency .AppExecutorUtil ;
3232
3333import io .spring .format .formatter .intellij .codestyle .monitor .Trigger .State ;
3434
@@ -51,7 +51,7 @@ public void update(State state) {
5151 WindowManager windowManager = WindowManager .getInstance ();
5252 final StatusBar statusBar = windowManager .getStatusBar (this .project );
5353 if (statusBar == null ) {
54- windowManager . addListener ( new UpdateOnFrameCreateListener (state ));
54+ AppExecutorUtil . getAppScheduledExecutorService (). schedule (() -> retryUpdate (state ), 1 , TimeUnit . SECONDS );
5555 return ;
5656 }
5757 if (state == State .ACTIVE ) {
@@ -62,6 +62,10 @@ public void update(State state) {
6262 }
6363 }
6464
65+ private void retryUpdate (State state ) {
66+ ApplicationManager .getApplication ().invokeLater (() -> update (state ));
67+ }
68+
6569 private void show (StatusBar statusBar ) {
6670 if (this .widget == null ) {
6771 this .widget = new Widget ();
@@ -76,30 +80,6 @@ private void hide(final StatusBar statusBar) {
7680 }
7781 }
7882
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-
10383 /**
10484 * The {@link StatusBarWidget} component for the status.
10585 */
0 commit comments