55import java .util .List ;
66import java .util .Map ;
77
8+ import org .apache .commons .lang3 .StringUtils ;
9+ import org .eclipse .swt .SWT ;
10+ import org .eclipse .swt .graphics .Image ;
11+ import org .eclipse .swt .widgets .Display ;
12+
813import com .microsoft .copilot .eclipse .core .lsp .protocol .CopilotModel ;
914import com .microsoft .copilot .eclipse .ui .i18n .Messages ;
1015import com .microsoft .copilot .eclipse .ui .preferences .ByokPreferencePage ;
1318import com .microsoft .copilot .eclipse .ui .swt .ModelHoverContentProvider ;
1419import com .microsoft .copilot .eclipse .ui .utils .ModelUtils ;
1520import com .microsoft .copilot .eclipse .ui .utils .PreferencesUtils ;
21+ import com .microsoft .copilot .eclipse .ui .utils .SwtUtils ;
1622import com .microsoft .copilot .eclipse .ui .utils .UiUtils ;
1723
1824/**
1925 * Builds model picker dropdown groups for the chat UI.
2026 */
2127public final class ModelPickerGroupsBuilder {
2228
29+ private static Image warningIcon ;
30+
2331 private ModelPickerGroupsBuilder () {
2432 }
2533
@@ -31,8 +39,8 @@ private ModelPickerGroupsBuilder() {
3139 * @param showByokManageOption whether to include the BYOK manage action
3240 * @return grouped dropdown items for the model picker
3341 */
34- public static List <DropdownItemGroup > build (Map <String , CopilotModel > modelMap ,
35- boolean showAddPremiumModelOption , boolean showByokManageOption ) {
42+ public static List <DropdownItemGroup > build (Map <String , CopilotModel > modelMap , boolean showAddPremiumModelOption ,
43+ boolean showByokManageOption ) {
3644 List <CopilotModel > otherModels = new ArrayList <>();
3745 List <CopilotModel > standardModels = new ArrayList <>();
3846 List <CopilotModel > premiumModels = new ArrayList <>();
@@ -79,8 +87,7 @@ public static List<DropdownItemGroup> build(Map<String, CopilotModel> modelMap,
7987 }
8088 if (showByokManageOption ) {
8189 actionItems .add (new DropdownItem .Builder ().label (Messages .chat_actionBar_modelPicker_manageModels )
82- .onAction (ModelPickerGroupsBuilder ::openManageModelsPreferences )
83- .build ());
90+ .onAction (ModelPickerGroupsBuilder ::openManageModelsPreferences ).build ());
8491 }
8592 if (!actionItems .isEmpty ()) {
8693 groups .add (DropdownItemGroup .of (actionItems ));
@@ -93,11 +100,34 @@ private static List<DropdownItem> buildModelDropdownItems(List<CopilotModel> mod
93100 for (CopilotModel model : models ) {
94101 String suffix = ModelUtils .getModelSuffix (model );
95102 items .add (new DropdownItem .Builder ().id (model .getModelName ()).label (model .getModelName ()).suffix (suffix )
96- .hoverProvider (new ModelHoverContentProvider (model )).build ());
103+ .icon ( resolveModelIcon ( model )). hoverProvider (new ModelHoverContentProvider (model )).build ());
97104 }
98105 return items ;
99106 }
100107
108+ private static Image resolveModelIcon (CopilotModel model ) {
109+ if (StringUtils .isBlank (model .getDegradationReason ())) {
110+ return null ;
111+ }
112+ if (warningIcon == null || warningIcon .isDisposed ()) {
113+ warningIcon = UiUtils .isDarkTheme ()
114+ ? UiUtils .buildImageFromPngPath ("/icons/dropdown/dropdown_warning_dark.png" )
115+ : UiUtils .buildImageFromPngPath ("/icons/dropdown/dropdown_warning.png" );
116+ Display display = SwtUtils .getDisplay ();
117+ if (display != null ) {
118+ display .addListener (SWT .Dispose , event -> disposeWarningIcons ());
119+ }
120+ }
121+ return warningIcon ;
122+ }
123+
124+ private static void disposeWarningIcons () {
125+ if (warningIcon != null && !warningIcon .isDisposed ()) {
126+ warningIcon .dispose ();
127+ warningIcon = null ;
128+ }
129+ }
130+
101131 private static void openManageModelsPreferences () {
102132 Map <String , Object > parameters = new HashMap <>();
103133 parameters .put ("com.microsoft.copilot.eclipse.commands.openPreferences.activePageId" , ByokPreferencePage .ID );
0 commit comments