14
14
import org .eclipse .swt .widgets .Composite ;
15
15
import org .eclipse .swt .widgets .Event ;
16
16
import org .eclipse .swt .widgets .Listener ;
17
- import org .eclipse .swt .widgets .Shell ;
18
17
19
18
import io .sloeber .core .api .BoardDescription ;
20
19
import io .sloeber .core .api .CodeDescription ;
24
23
25
24
public class NewSketchWizardCodeSelectionPage extends WizardPage {
26
25
27
- final Shell shell = new Shell ();
26
+ // final Shell shell = new Shell();
28
27
private Composite myParentComposite = null ;
29
- protected LabelCombo myCodeSourceOptionsCombo ;
28
+ protected LabelCombo myCodeSourceOptionsCombo ;
30
29
protected DirectoryFieldEditor myTemplateFolderEditor ;
31
30
protected SampleSelector myExampleEditor = null ;
32
31
protected Button myCheckBoxUseCurrentLinkSample ;
33
- private BoardDescription myBoardDescriptor = null ;
32
+ private BoardDescription myCurrentBoardDesc = null ;
34
33
private CodeDescription myCodedescriptor = CodeDescription .createLastUsed ();
34
+ private NewSketchWizardBoardPage myArduinoPage ;
35
35
36
- // TOFIX disabled the push boarddescriptor
37
-
38
- // public void setBoardDescriptor(BoardDescription boardDescriptor) {
39
- // if (myBoardDescriptor == null) {
40
- // myBoardDescriptor = boardDescriptor;
41
- // }
42
- // handleBoarDescriptorChange();
43
- // }
44
-
45
- public void handleBoarDescriptorChange () {
46
-
47
- if (myExampleEditor != null ) {
48
- myExampleEditor .AddAllExamples (myBoardDescriptor , myCodedescriptor .getExamples ());
49
- }
50
-
36
+ @ Override
37
+ public void setVisible (boolean visible ) {
38
+ super .setVisible (visible );
51
39
validatePage ();
52
40
}
53
41
42
+
54
43
public NewSketchWizardCodeSelectionPage (String pageName ) {
55
44
super (pageName );
56
45
setPageComplete (true );
@@ -112,18 +101,16 @@ public void handleEvent(Event event) {
112
101
SetControls ();// set the controls according to the setting
113
102
114
103
validatePage ();// validate the page
115
- handleBoarDescriptorChange ();
116
-
117
104
setControl (composite );
118
105
119
106
}
120
107
121
108
/**
122
- * @name SetControls() Enables or disables the controls based on the
123
- * Checkbox settings
109
+ * @name SetControls() Enables or disables the controls based on the Checkbox
110
+ * settings
124
111
*/
125
112
protected void SetControls () {
126
- switch (CodeTypes . values ()[ Math . max ( 0 , myCodeSourceOptionsCombo . getSelectionIndex ())] ) {
113
+ switch (getCodeType () ) {
127
114
case None :
128
115
myTemplateFolderEditor .setEnabled (false , myParentComposite );
129
116
myExampleEditor .setEnabled (false );
@@ -155,14 +142,12 @@ protected void SetControls() {
155
142
}
156
143
157
144
/**
158
- * @name validatePage() Check if the user has provided all the info to
159
- * create the project. If so enable the finish button.
145
+ * @name validatePage() Check if the user has provided all the info to create
146
+ * the project. If so enable the finish button.
160
147
*/
161
148
protected void validatePage () {
162
- if (myCodeSourceOptionsCombo == null ) {
163
- return ;
164
- }
165
- switch (CodeTypes .values ()[Math .max (0 , myCodeSourceOptionsCombo .getSelectionIndex ())]) {
149
+
150
+ switch (getCodeType ()) {
166
151
case None :
167
152
case defaultIno :
168
153
case defaultCPP :
@@ -177,6 +162,12 @@ protected void validatePage() {
177
162
setPageComplete (existFile );
178
163
break ;
179
164
case sample :
165
+ BoardDescription mySelectedBoardDesc = myArduinoPage .getBoardDescriptor ();
166
+ if (!mySelectedBoardDesc .equals (myCurrentBoardDesc )) {
167
+ myCurrentBoardDesc = new BoardDescription (mySelectedBoardDesc );
168
+ myExampleEditor .AddAllExamples (myCurrentBoardDesc , myCodedescriptor .getExamples ());
169
+
170
+ }
180
171
setPageComplete (myExampleEditor .isSampleSelected ());
181
172
break ;
182
173
default :
@@ -202,7 +193,7 @@ private void restoreAllSelections() {
202
193
203
194
public CodeDescription getCodeDescription () {
204
195
205
- switch (CodeTypes . values ()[ myCodeSourceOptionsCombo . getSelectionIndex ()] ) {
196
+ switch (getCodeType () ) {
206
197
case None :
207
198
return CodeDescription .createNone ();
208
199
case defaultIno :
@@ -248,4 +239,16 @@ public static String[] getCodeTypeDescriptions() {
248
239
return ret ;
249
240
}
250
241
242
+ private CodeTypes getCodeType () {
243
+ if (myCodeSourceOptionsCombo == null ) {
244
+ return CodeTypes .None ;
245
+ }
246
+ return CodeTypes .values ()[Math .max (0 , myCodeSourceOptionsCombo .getSelectionIndex ())];
247
+ }
248
+
249
+ public void setSketchWizardPage (NewSketchWizardBoardPage arduinoPage ) {
250
+ myArduinoPage = arduinoPage ;
251
+
252
+ }
253
+
251
254
}
0 commit comments