7
7
import java .io .IOException ;
8
8
import java .nio .file .Path ;
9
9
10
+ import org .eclipse .jface .dialogs .MessageDialog ;
10
11
import org .eclipse .swt .SWT ;
11
12
import org .eclipse .swt .widgets .Display ;
12
13
import org .eclipse .swt .widgets .MessageBox ;
@@ -39,7 +40,7 @@ public class EimJsonUiChangeHandler implements EimJsonChangeListener
39
40
{
40
41
private Preferences preferences ;
41
42
private EimJson eimJson ;
42
-
43
+
43
44
public EimJsonUiChangeHandler (Preferences preferences )
44
45
{
45
46
this .preferences = preferences ;
@@ -51,29 +52,29 @@ public void onJsonFileChanged(Path file)
51
52
int response = displayMessageToUser ();
52
53
handleUserResponse (response );
53
54
}
54
-
55
+
55
56
public int displayMessageToUser ()
56
57
{
57
- final int [] response = new int [] {- 1 };
58
+ final int [] response = new int [] { - 1 };
58
59
Display display = Display .getDefault ();
59
60
display .syncExec (() -> {
60
61
Shell shell = display .getActiveShell ();
61
62
if (shell == null )
62
63
{
63
64
shell = new Shell (display );
64
65
}
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 ();
69
70
});
70
-
71
+
71
72
return response [0 ];
72
73
}
73
74
74
75
public void handleUserResponse (int response )
75
76
{
76
- if (response == SWT . YES )
77
+ if (response == 0 )
77
78
{
78
79
try
79
80
{
@@ -83,61 +84,62 @@ public void handleUserResponse(int response)
83
84
// only one entry in eimJson so we can simply refresh the IDE environment with that.
84
85
setupToolsInIde ();
85
86
}
86
- else
87
+ else
87
88
{
88
89
// multiple entries in json so launch manager for user to handle this
89
90
launchEspIdfManager ();
90
91
}
91
92
}
92
- catch (IOException | PartInitException e )
93
+ catch (
94
+ IOException
95
+ | PartInitException e )
93
96
{
94
97
Logger .log (e );
95
98
}
96
99
}
97
-
100
+
98
101
EimJsonStateChecker checker = new EimJsonStateChecker (preferences );
99
102
checker .updateLastSeenTimestamp ();
100
103
}
101
-
104
+
102
105
private void loadEimJson () throws IOException
103
106
{
104
107
EimIdfConfiguratinParser eimIdfConfiguratinParser = new EimIdfConfiguratinParser ();
105
108
eimJson = eimIdfConfiguratinParser .getEimJson (true );
106
109
}
107
-
108
-
109
-
110
+
110
111
private void setupToolsInIde ()
111
112
{
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 ));
113
115
setupToolsInIde .schedule ();
114
116
}
115
-
117
+
116
118
private void launchEspIdfManager () throws PartInitException
117
119
{
118
120
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
+ });
138
140
139
141
}
140
-
142
+
141
143
private MessageConsoleStream getConsoleStream (boolean errorStream )
142
144
{
143
145
IDFConsole idfConsole = new IDFConsole ();
0 commit comments