7
7
import java .util .HashMap ;
8
8
import java .util .List ;
9
9
import java .util .Map ;
10
+ import java .util .Objects ;
10
11
import java .util .concurrent .CompletableFuture ;
11
12
import java .util .concurrent .ExecutionException ;
12
13
13
14
import org .eclipse .jface .dialogs .Dialog ;
14
15
import org .eclipse .jface .dialogs .IDialogConstants ;
15
16
import org .eclipse .swt .SWT ;
17
+ import org .eclipse .swt .events .MouseAdapter ;
18
+ import org .eclipse .swt .events .MouseEvent ;
16
19
import org .eclipse .swt .events .SelectionAdapter ;
17
20
import org .eclipse .swt .events .SelectionEvent ;
18
21
import org .eclipse .swt .graphics .Font ;
34
37
import software .aws .toolkits .eclipse .amazonq .util .Constants ;
35
38
import software .aws .toolkits .eclipse .amazonq .util .PluginLogger ;
36
39
import software .aws .toolkits .eclipse .amazonq .util .ThreadingUtils ;
40
+ import software .aws .toolkits .eclipse .amazonq .util .ToolkitNotification ;
37
41
import software .aws .toolkits .eclipse .amazonq .views .model .Customization ;
42
+ import org .eclipse .mylyn .commons .ui .dialogs .AbstractNotificationPopup ;
38
43
39
44
public final class CustomizationDialog extends Dialog {
40
45
@@ -45,7 +50,7 @@ public final class CustomizationDialog extends Dialog {
45
50
private Font boldFont ;
46
51
private List <Customization > customizationsResponse ;
47
52
private ResponseSelection responseSelection ;
48
- private String selectedCustomisationArn ;
53
+ private Customization selectedCustomization ;
49
54
50
55
public enum ResponseSelection {
51
56
AMAZON_Q_FOUNDATION_DEFAULT ,
@@ -80,6 +85,10 @@ private final class CustomRadioButton extends Composite {
80
85
public Button getRadioButton () {
81
86
return radioButton ;
82
87
}
88
+
89
+ public Label getTextLabel () {
90
+ return textLabel ;
91
+ }
83
92
}
84
93
85
94
public CustomizationDialog (final Shell parentShell ) {
@@ -102,12 +111,19 @@ public ResponseSelection getResponseSelection() {
102
111
return this .responseSelection ;
103
112
}
104
113
105
- public void setSelectedCustomizationArn (final String arn ) {
106
- this .selectedCustomisationArn = arn ;
114
+ public void setSelectedCustomization (final Customization customization ) {
115
+ this .selectedCustomization = customization ;
116
+ }
117
+
118
+ public Customization getSelectedCustomization () {
119
+ return this .selectedCustomization ;
107
120
}
108
121
109
- public String getSelectedCustomizationArn () {
110
- return this .selectedCustomisationArn ;
122
+ private void showNotification (final String customizationName ) {
123
+ AbstractNotificationPopup notification = new ToolkitNotification (Display .getCurrent (),
124
+ Constants .IDE_CUSTOMIZATION_NOTIFICATION_TITLE ,
125
+ String .format (Constants .IDE_CUSTOMIZATION_NOTIFICATION_BODY_TEMPLATE , customizationName ));
126
+ notification .open ();
111
127
}
112
128
113
129
@ Override
@@ -118,16 +134,17 @@ protected void createButtonsForButtonBar(final Composite parent) {
118
134
119
135
@ Override
120
136
protected void okPressed () {
121
- PluginLogger .info (String .format ("Select pressed with responseSelection:%s and selectedArn:%s" , this .responseSelection , this .selectedCustomisationArn ));
122
137
if (this .responseSelection .equals (ResponseSelection .AMAZON_Q_FOUNDATION_DEFAULT )) {
123
138
PluginStore .remove (Constants .CUSTOMIZATION_STORAGE_INTERNAL_KEY );
124
- } else if (this .selectedCustomisationArn != null ) {
125
- PluginStore .put (Constants .CUSTOMIZATION_STORAGE_INTERNAL_KEY , this .selectedCustomisationArn );
139
+ Display .getCurrent ().asyncExec (() -> showNotification (Constants .DEFAULT_Q_FOUNDATION_DISPLAY_NAME ));
140
+ } else if (Objects .nonNull (this .getSelectedCustomization ()) && StringUtils .isNotBlank (this .getSelectedCustomization ().getName ())) {
141
+ PluginStore .putObject (Constants .CUSTOMIZATION_STORAGE_INTERNAL_KEY , this .getSelectedCustomization ());
126
142
Map <String , Object > updatedSettings = new HashMap <>();
127
143
Map <String , String > internalMap = new HashMap <>();
128
- internalMap .put (Constants .LSP_CUSTOMIZATION_CONFIGURATION_KEY , this .selectedCustomisationArn );
144
+ internalMap .put (Constants .LSP_CUSTOMIZATION_CONFIGURATION_KEY , this .getSelectedCustomization (). getArn () );
129
145
updatedSettings .put (Constants .LSP_CONFIGURATION_KEY , internalMap );
130
146
ThreadingUtils .executeAsyncTask (() -> CustomizationUtil .triggerChangeConfigurationNotification (updatedSettings ));
147
+ Display .getCurrent ().asyncExec (() -> showNotification (String .format ("%s customization" , this .getSelectedCustomization ().getName ())));
131
148
}
132
149
super .okPressed ();
133
150
}
@@ -179,10 +196,10 @@ private void updateComboOnUIThread(final List<Customization> customizations) {
179
196
int defaultSelectedDropdownIndex = -1 ;
180
197
for (int index = 0 ; index < customizations .size (); index ++) {
181
198
addFormattedOption (combo , customizations .get (index ).getName (), customizations .get (index ).getDescription ());
182
- combo .setData (String .format ("%s" , index ), customizations .get (index ). getArn () );
199
+ combo .setData (String .format ("%s" , index ), customizations .get (index ));
183
200
if (this .responseSelection .equals (ResponseSelection .CUSTOMIZATION )
184
- && StringUtils . isNotBlank (this .selectedCustomisationArn )
185
- && this .selectedCustomisationArn .equals (customizations .get (index ).getArn ())) {
201
+ && Objects . nonNull (this .getSelectedCustomization () )
202
+ && this .getSelectedCustomization (). getArn () .equals (customizations .get (index ).getArn ())) {
186
203
defaultSelectedDropdownIndex = index ;
187
204
}
188
205
}
@@ -197,9 +214,9 @@ private void updateComboOnUIThread(final List<Customization> customizations) {
197
214
public void widgetSelected (final SelectionEvent e ) {
198
215
int selectedIndex = combo .getSelectionIndex ();
199
216
String selectedOption = combo .getItem (selectedIndex );
200
- String selectedCustomizationArn = (String ) combo .getData (String .valueOf (selectedIndex ));
201
- CustomizationDialog .this .selectedCustomisationArn = selectedCustomizationArn ;
202
- PluginLogger .info (String .format ("Selected option:%s with arn:%s" , selectedOption , selectedCustomizationArn ));
217
+ Customization selectedCustomization = (Customization ) combo .getData (String .valueOf (selectedIndex ));
218
+ CustomizationDialog .this .setSelectedCustomization ( selectedCustomization ) ;
219
+ PluginLogger .info (String .format ("Selected option:%s with arn:%s" , selectedOption , selectedCustomization . getArn () ));
203
220
}
204
221
});
205
222
}
@@ -254,7 +271,17 @@ protected Control createDialogArea(final Composite parent) {
254
271
public void widgetSelected (final SelectionEvent e ) {
255
272
customizationButton .getRadioButton ().setSelection (false );
256
273
responseSelection = ResponseSelection .AMAZON_Q_FOUNDATION_DEFAULT ;
257
- selectedCustomisationArn = null ;
274
+ setSelectedCustomization (null );
275
+ combo .setEnabled (false );
276
+ }
277
+ });
278
+ defaultAmazonQFoundationButton .getTextLabel ().addMouseListener (new MouseAdapter () {
279
+ @ Override
280
+ public void mouseDown (final MouseEvent e ) {
281
+ customizationButton .getRadioButton ().setSelection (false );
282
+ defaultAmazonQFoundationButton .getRadioButton ().setSelection (true );
283
+ responseSelection = ResponseSelection .AMAZON_Q_FOUNDATION_DEFAULT ;
284
+ setSelectedCustomization (null );
258
285
combo .setEnabled (false );
259
286
}
260
287
});
@@ -266,6 +293,15 @@ public void widgetSelected(final SelectionEvent e) {
266
293
combo .setEnabled (true );
267
294
}
268
295
});
296
+ customizationButton .getTextLabel ().addMouseListener (new MouseAdapter () {
297
+ @ Override
298
+ public void mouseDown (final MouseEvent e ) {
299
+ defaultAmazonQFoundationButton .getRadioButton ().setSelection (false );
300
+ customizationButton .getRadioButton ().setSelection (true );
301
+ responseSelection = ResponseSelection .CUSTOMIZATION ;
302
+ combo .setEnabled (true );
303
+ }
304
+ });
269
305
createDropdownForCustomizations (container );
270
306
createSeparator (container );
271
307
return container ;
0 commit comments