Skip to content

Commit f666d2a

Browse files
authored
Merge pull request #5196 from microsoft/bugfix-select-subs-indexoutofbound
Fix bug[1839373] refresh subscription throws exception sometimes
2 parents 94bb3e3 + 83f8868 commit f666d2a

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/ui/SubscriptionsDialog.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class SubscriptionsDialog extends AzureDialogWrapper {
5555
private final Project project;
5656
private JPanel contentPane;
5757
private JPanel panelTable;
58-
private JTable table;
58+
private JBTable table;
5959
private List<SubscriptionDetail> sdl;
6060

6161
private SubscriptionsDialog(List<SubscriptionDetail> sdl, Project project) {
@@ -117,17 +117,14 @@ private void refreshSubscriptions() {
117117
setSubscriptions();
118118
// to notify subscribers
119119
subscriptionManager.setSubscriptionDetails(sdl);
120-
121120
}, (ex) -> {
122-
ex.printStackTrace();
123-
//LOGGER.error("refreshSubscriptions", ex);
124-
ErrorWindow.show(project, ex.getMessage(), "Refresh Subscriptions Error");
125-
});
121+
ex.printStackTrace();
122+
ErrorWindow.show(project, ex.getMessage(), "Refresh Subscriptions Error");
123+
});
126124
}
127125

128126
private void setSubscriptions() {
129127
DefaultTableModel model = (DefaultTableModel) table.getModel();
130-
model.setRowCount(0);
131128
sdl.sort((sub1, sub2) -> {
132129
if (sub1.isSelected() != sub2.isSelected()) {
133130
return sub1.isSelected() ? -1 : 0;
@@ -159,9 +156,19 @@ private void createUIComponents() {
159156
AnActionButton refreshAction = new AnActionButton("Refresh", AllIcons.Actions.Refresh) {
160157
@Override
161158
public void actionPerformed(AnActionEvent anActionEvent) {
159+
this.setEnabled(false);
160+
model.setRowCount(0);
161+
model.fireTableDataChanged();
162+
table.getEmptyText().setText("Refreshing");
162163
AppInsightsClient.createByType(AppInsightsClient.EventType.Subscription, "", "Refresh", null);
163164
final IAzureOperationTitle title = AzureOperationBundle.title("account|subscription.refresh");
164-
final AzureTask task = new AzureTask(project, title, true, SubscriptionsDialog.this::refreshSubscriptions, AzureTask.Modality.ANY);
165+
final AzureTask task = new AzureTask(project, title, true, () -> {
166+
try {
167+
SubscriptionsDialog.this.refreshSubscriptions();
168+
} finally {
169+
this.setEnabled(true);
170+
}
171+
}, AzureTask.Modality.ANY);
165172
AzureTaskManager.getInstance().runInBackground(task);
166173
}
167174
};

0 commit comments

Comments
 (0)