Skip to content

Commit 4644e7a

Browse files
committed
feat: [New billing] Implement model picker category badge.
1 parent 7bf4cd0 commit 4644e7a

4 files changed

Lines changed: 118 additions & 1 deletion

File tree

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/CopilotModel.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class CopilotModel {
2222
private CopilotModelBilling billing;
2323
private String degradationReason;
2424
private String providerName;
25+
private String modelPickerCategory;
2526

2627
/**
2728
* Policy for the model.
@@ -169,6 +170,14 @@ public void setProviderName(String providerName) {
169170
this.providerName = providerName;
170171
}
171172

173+
public String getModelPickerCategory() {
174+
return modelPickerCategory;
175+
}
176+
177+
public void setModelPickerCategory(String modelPickerCategory) {
178+
this.modelPickerCategory = modelPickerCategory;
179+
}
180+
172181
@Override
173182
public boolean equals(Object obj) {
174183
if (this == obj) {
@@ -185,14 +194,15 @@ public boolean equals(Object obj) {
185194
&& Objects.equals(degradationReason, other.degradationReason) && Objects.equals(id, other.id)
186195
&& isChatDefault == other.isChatDefault && isChatFallback == other.isChatFallback
187196
&& Objects.equals(modelFamily, other.modelFamily) && Objects.equals(modelName, other.modelName)
197+
&& Objects.equals(modelPickerCategory, other.modelPickerCategory)
188198
&& Objects.equals(modelPolicy, other.modelPolicy) && preview == other.preview
189199
&& Objects.equals(providerName, other.providerName) && Objects.equals(scopes, other.scopes);
190200
}
191201

192202
@Override
193203
public int hashCode() {
194204
return Objects.hash(billing, capabilities, degradationReason, id, isChatDefault, isChatFallback, modelFamily,
195-
modelName, modelPolicy, preview, providerName, scopes);
205+
modelName, modelPickerCategory, modelPolicy, preview, providerName, scopes);
196206
}
197207

198208
@Override
@@ -210,6 +220,7 @@ public String toString() {
210220
builder.append("billing", billing);
211221
builder.append("degradationReason", degradationReason);
212222
builder.append("providerName", providerName);
223+
builder.append("modelPickerCategory", modelPickerCategory);
213224
return builder.toString();
214225
}
215226

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.microsoft.copilot.eclipse.ui.swt;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.eclipse.swt.SWT;
5+
import org.eclipse.swt.graphics.Color;
6+
import org.eclipse.swt.graphics.GC;
7+
import org.eclipse.swt.graphics.Point;
8+
import org.eclipse.swt.layout.GridData;
9+
import org.eclipse.swt.widgets.Composite;
10+
import org.eclipse.swt.widgets.Display;
11+
12+
/**
13+
* A custom-painted badge widget that displays a model picker category label with a rounded border in the category's
14+
* theme color.
15+
*/
16+
public class CategoryBadge extends Composite {
17+
18+
private static final int HORIZONTAL_PADDING = 6;
19+
private static final int VERTICAL_PADDING = 1;
20+
21+
/**
22+
* Creates a category badge for the given category string. Returns {@code null} if the category has no known color
23+
* mapping.
24+
*
25+
* @param parent the parent composite
26+
* @param category the raw category value from the API (e.g. "powerful")
27+
* @return the badge composite, or {@code null} if the category is unrecognised
28+
*/
29+
public static CategoryBadge create(Composite parent, String category) {
30+
Color badgeColor = getCategoryColor(parent.getDisplay(), category);
31+
if (badgeColor == null) {
32+
return null;
33+
}
34+
return new CategoryBadge(parent, category, badgeColor);
35+
}
36+
37+
private CategoryBadge(Composite parent, String category, Color badgeColor) {
38+
super(parent, SWT.NONE);
39+
setLayoutData(new GridData(SWT.LEFT, SWT.NONE, false, false));
40+
41+
String displayText = StringUtils.capitalize(category);
42+
43+
GC gc = new GC(this);
44+
Point textExtent = gc.textExtent(displayText);
45+
gc.dispose();
46+
47+
int badgeWidth = textExtent.x + 2 * HORIZONTAL_PADDING;
48+
int badgeHeight = textExtent.y + 2 * VERTICAL_PADDING;
49+
GridData gd = (GridData) getLayoutData();
50+
gd.widthHint = badgeWidth;
51+
gd.heightHint = badgeHeight;
52+
53+
addPaintListener(e -> {
54+
e.gc.setAntialias(SWT.ON);
55+
e.gc.setForeground(badgeColor);
56+
e.gc.drawRoundRectangle(0, 0, badgeWidth - 1, badgeHeight - 1,
57+
badgeHeight, badgeHeight);
58+
e.gc.drawText(displayText, HORIZONTAL_PADDING, VERTICAL_PADDING, true);
59+
});
60+
}
61+
62+
private static Color getCategoryColor(Display display, String category) {
63+
if ("Powerful".equalsIgnoreCase(category)) {
64+
return CssConstants.getCategoryPowerfulColor(display);
65+
} else if ("Versatile".equalsIgnoreCase(category)) {
66+
return CssConstants.getCategoryVersatileColor(display);
67+
} else if ("Lightweight".equalsIgnoreCase(category)) {
68+
return CssConstants.getCategoryLightweightColor(display);
69+
}
70+
return null;
71+
}
72+
}

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/swt/CssConstants.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,36 @@ public static Color getPopupBgColor(Display display) {
8080
return new Color(display, 255, 255, 255);
8181
}
8282

83+
/**
84+
* Returns the color for the "Powerful" model picker category badge.
85+
*/
86+
public static Color getCategoryPowerfulColor(Display display) {
87+
if (UiUtils.isDarkTheme()) {
88+
return new Color(display, 116, 167, 220); // #74A7DC
89+
}
90+
return new Color(display, 15, 108, 189); // #0F6CBD
91+
}
92+
93+
/**
94+
* Returns the color for the "Versatile" model picker category badge.
95+
*/
96+
public static Color getCategoryVersatileColor(Display display) {
97+
if (UiUtils.isDarkTheme()) {
98+
return new Color(display, 222, 225, 229); // #DEE1E5
99+
}
100+
return new Color(display, 97, 97, 97); // #616161
101+
}
102+
103+
/**
104+
* Returns the color for the "Lightweight" model picker category badge.
105+
*/
106+
public static Color getCategoryLightweightColor(Display display) {
107+
if (UiUtils.isDarkTheme()) {
108+
return new Color(display, 110, 185, 110); // #6EB96E
109+
}
110+
return new Color(display, 16, 124, 16); // #107C10
111+
}
112+
83113
/**
84114
* Get the focused background color for dropdown popup items based on the current theme.
85115
*/

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/swt/ModelHoverContentProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public ModelHoverContentProvider(CopilotModel model) {
4444
public void configureHover(Composite parent, DropdownItem item) {
4545
renderHeader(parent, item);
4646

47+
if (StringUtils.isNotBlank(model.getModelPickerCategory())) {
48+
CategoryBadge.create(parent, model.getModelPickerCategory());
49+
}
50+
4751
// Degradation warning
4852
if (StringUtils.isNotBlank(model.getDegradationReason())) {
4953
addWarningRow(parent, model.getDegradationReason());

0 commit comments

Comments
 (0)