77import java .io .IOException ;
88import java .nio .file .Path ;
99
10+ import org .eclipse .jface .dialogs .MessageDialog ;
1011import org .eclipse .swt .SWT ;
1112import org .eclipse .swt .widgets .Display ;
1213import org .eclipse .swt .widgets .MessageBox ;
@@ -39,7 +40,7 @@ public class EimJsonUiChangeHandler implements EimJsonChangeListener
3940{
4041 private Preferences preferences ;
4142 private EimJson eimJson ;
42-
43+
4344 public EimJsonUiChangeHandler (Preferences preferences )
4445 {
4546 this .preferences = preferences ;
@@ -51,29 +52,29 @@ public void onJsonFileChanged(Path file)
5152 int response = displayMessageToUser ();
5253 handleUserResponse (response );
5354 }
54-
55+
5556 public int displayMessageToUser ()
5657 {
57- final int [] response = new int [] {- 1 };
58+ final int [] response = new int [] { - 1 };
5859 Display display = Display .getDefault ();
5960 display .syncExec (() -> {
6061 Shell shell = display .getActiveShell ();
6162 if (shell == null )
6263 {
6364 shell = new Shell (display );
6465 }
65- MessageBox messageBox = new MessageBox (shell , SWT . ICON_WARNING | SWT . YES | SWT . NO );
66- messageBox . setText ( Messages .EimJsonChangedMsgTitle );
67- messageBox . setMessage ( Messages .EimJsonChangedMsgDetail );
68- response [0 ] = messageBox .open ();
66+ MessageDialog messageDialog = new MessageDialog (shell , Messages . EimJsonChangedMsgTitle , null ,
67+ Messages .EimJsonChangedMsgDetail , MessageDialog . WARNING , 0 ,
68+ new String [] { Messages . MsgYes , Messages .MsgNo } );
69+ response [0 ] = messageDialog .open ();
6970 });
70-
71+
7172 return response [0 ];
7273 }
7374
7475 public void handleUserResponse (int response )
7576 {
76- if (response == SWT . YES )
77+ if (response == 0 )
7778 {
7879 try
7980 {
@@ -83,61 +84,62 @@ public void handleUserResponse(int response)
8384 // only one entry in eimJson so we can simply refresh the IDE environment with that.
8485 setupToolsInIde ();
8586 }
86- else
87+ else
8788 {
8889 // multiple entries in json so launch manager for user to handle this
8990 launchEspIdfManager ();
9091 }
9192 }
92- catch (IOException | PartInitException e )
93+ catch (
94+ IOException
95+ | PartInitException e )
9396 {
9497 Logger .log (e );
9598 }
9699 }
97-
100+
98101 EimJsonStateChecker checker = new EimJsonStateChecker (preferences );
99102 checker .updateLastSeenTimestamp ();
100103 }
101-
104+
102105 private void loadEimJson () throws IOException
103106 {
104107 EimIdfConfiguratinParser eimIdfConfiguratinParser = new EimIdfConfiguratinParser ();
105108 eimJson = eimIdfConfiguratinParser .getEimJson (true );
106109 }
107-
108-
109-
110+
110111 private void setupToolsInIde ()
111112 {
112- SetupToolsInIde setupToolsInIde = new SetupToolsInIde (eimJson .getIdfInstalled ().get (0 ), eimJson , getConsoleStream (true ), getConsoleStream (false ));
113+ SetupToolsInIde setupToolsInIde = new SetupToolsInIde (eimJson .getIdfInstalled ().get (0 ), eimJson ,
114+ getConsoleStream (true ), getConsoleStream (false ));
113115 setupToolsInIde .schedule ();
114116 }
115-
117+
116118 private void launchEspIdfManager () throws PartInitException
117119 {
118120 Display .getDefault ().asyncExec (() -> {
119- IWorkbenchWindow activeww = EclipseHandler .getActiveWorkbenchWindow ();
120- if (activeww != null && activeww .getActivePage () != null )
121- {
122- try
123- {
124- IDE .openEditor (activeww .getActivePage (), new EimEditorInput (eimJson ),
125- ESPIDFManagerEditor . EDITOR_ID , true );
126- }
127- catch (PartInitException e )
128- {
129- Logger .log ("Failed to open ESP-IDF Manager Editor." );
130- Logger .log (e );
131- }
132- }
133- else
134- {
135- Logger .log ("Cannot open ESP-IDF Manager Editor. No active workbench window yet." );
136- }
137- });
121+ IWorkbenchWindow activeww = EclipseHandler .getActiveWorkbenchWindow ();
122+ if (activeww != null && activeww .getActivePage () != null )
123+ {
124+ try
125+ {
126+ IDE .openEditor (activeww .getActivePage (), new EimEditorInput (eimJson ), ESPIDFManagerEditor . EDITOR_ID ,
127+ true );
128+ }
129+ catch (PartInitException e )
130+ {
131+ Logger .log ("Failed to open ESP-IDF Manager Editor." );
132+ Logger .log (e );
133+ }
134+ }
135+ else
136+ {
137+ Logger .log ("Cannot open ESP-IDF Manager Editor. No active workbench window yet." );
138+ }
139+ });
138140
139141 }
140-
142+
141143 private MessageConsoleStream getConsoleStream (boolean errorStream )
142144 {
143145 IDFConsole idfConsole = new IDFConsole ();
0 commit comments