Skip to content

Commit 45e12a3

Browse files
authored
Merge pull request #4343 from Flanker32/hanxiao/removeOptionPane
Use IntelliJ Messages API to replace JOptionPane
2 parents 0195d5c + 870bbbd commit 45e12a3

File tree

22 files changed

+995
-780
lines changed

22 files changed

+995
-780
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azuretools/ijidea/actions/AzureSignInAction.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import com.intellij.openapi.diagnostic.Logger;
2828
import com.intellij.openapi.project.Project;
2929
import com.intellij.openapi.wm.WindowManager;
30-
import com.microsoft.azuretools.authmanage.AuthMethodManager;
3130
import com.microsoft.azuretools.authmanage.AuthMethod;
31+
import com.microsoft.azuretools.authmanage.AuthMethodManager;
3232
import com.microsoft.azuretools.authmanage.models.AuthMethodDetails;
3333
import com.microsoft.azuretools.ijidea.ui.ErrorWindow;
3434
import com.microsoft.azuretools.ijidea.ui.SignInWindow;
@@ -38,6 +38,7 @@
3838
import com.microsoft.azuretools.telemetrywrapper.Operation;
3939
import com.microsoft.intellij.helpers.UIHelperImpl;
4040
import com.microsoft.intellij.serviceexplorer.azure.SignInOutAction;
41+
import com.microsoft.tooling.msservices.components.DefaultLoader;
4142
import org.jetbrains.annotations.NotNull;
4243
import org.jetbrains.annotations.Nullable;
4344

@@ -119,12 +120,11 @@ public static void onAzureSignIn(Project project) {
119120
AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
120121
boolean isSignIn = authMethodManager.isSignedIn();
121122
if (isSignIn) {
122-
int res = JOptionPane.showConfirmDialog(frame,
123-
getSignOutWarningMessage(authMethodManager),
124-
"Azure Sign Out",
125-
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
126-
new ImageIcon("icons/azure.png"));
127-
if (res == JOptionPane.OK_OPTION) {
123+
boolean res = DefaultLoader.getUIHelper().showYesNoDialog(frame.getRootPane(),
124+
getSignOutWarningMessage(authMethodManager),
125+
"Azure Sign Out",
126+
new ImageIcon("icons/azure.png"));
127+
if (res) {
128128
EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
129129
authMethodManager.signOut();
130130
});
@@ -140,7 +140,9 @@ public static void onAzureSignIn(Project project) {
140140

141141
public static boolean doSignIn(AuthMethodManager authMethodManager, Project project) throws Exception {
142142
boolean isSignIn = authMethodManager.isSignedIn();
143-
if (isSignIn) return true;
143+
if (isSignIn) {
144+
return true;
145+
}
144146
SignInWindow w = SignInWindow.go(authMethodManager.getAuthMethodDetails(), project);
145147
if (w != null) {
146148
AuthMethodDetails authMethodDetailsUpdated = w.getAuthMethodDetails();

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azuretools/ijidea/ui/NotificationWindow.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
package com.microsoft.azuretools.ijidea.ui;
2424

25+
import com.intellij.icons.AllIcons;
2526
import com.intellij.openapi.application.ApplicationManager;
27+
import com.intellij.openapi.ui.Messages;
2628
import com.microsoft.azuretools.authmanage.interact.INotification;
2729

2830
import javax.swing.*;
@@ -37,10 +39,7 @@ public void deliver(String subject, String message) {
3739
@Override
3840
public void run() {
3941
JPanel panel = new JPanel();
40-
JOptionPane.showMessageDialog(panel,
41-
message,
42-
subject,
43-
JOptionPane.INFORMATION_MESSAGE);
42+
Messages.showMessageDialog(panel, message, subject, AllIcons.General.Information);
4443
}
4544
});
4645

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azuretools/ijidea/ui/SignInWindow.java

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,24 @@
3232
import com.intellij.openapi.progress.Task;
3333
import com.intellij.openapi.project.Project;
3434
import com.intellij.openapi.ui.DialogWrapper;
35+
import com.intellij.openapi.ui.Messages;
3536
import com.intellij.openapi.vfs.LocalFileSystem;
3637
import com.intellij.openapi.vfs.VirtualFile;
3738
import com.microsoft.azuretools.adauth.AuthCanceledException;
3839
import com.microsoft.azuretools.adauth.StringUtils;
39-
import com.microsoft.azuretools.authmanage.AuthMethod;
40-
import com.microsoft.azuretools.authmanage.AuthMethodManager;
41-
import com.microsoft.azuretools.authmanage.BaseADAuthManager;
42-
import com.microsoft.azuretools.authmanage.CommonSettings;
43-
import com.microsoft.azuretools.authmanage.SubscriptionManager;
40+
import com.microsoft.azuretools.authmanage.*;
4441
import com.microsoft.azuretools.authmanage.models.AuthMethodDetails;
4542
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
4643
import com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager;
47-
import com.microsoft.azuretools.telemetrywrapper.ErrorType;
48-
import com.microsoft.azuretools.telemetrywrapper.EventType;
49-
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
50-
import com.microsoft.azuretools.telemetrywrapper.Operation;
51-
import com.microsoft.azuretools.telemetrywrapper.TelemetryManager;
44+
import com.microsoft.azuretools.telemetrywrapper.*;
5245
import com.microsoft.intellij.ui.components.AzureDialogWrapper;
5346
import com.microsoft.intellij.util.PluginUtil;
47+
import com.microsoft.tooling.msservices.components.DefaultLoader;
5448
import org.jdesktop.swingx.JXHyperlink;
5549
import org.jetbrains.annotations.NotNull;
5650
import org.jetbrains.annotations.Nullable;
5751

58-
import javax.swing.ButtonGroup;
59-
import javax.swing.JButton;
60-
import javax.swing.JComponent;
61-
import javax.swing.JLabel;
62-
import javax.swing.JOptionPane;
63-
import javax.swing.JPanel;
64-
import javax.swing.JRadioButton;
65-
import javax.swing.JTextField;
52+
import javax.swing.*;
6653
import java.awt.event.ActionEvent;
6754
import java.awt.event.ActionListener;
6855
import java.net.URI;
@@ -71,10 +58,7 @@
7158
import java.util.List;
7259
import java.util.Map;
7360

74-
import static com.microsoft.azuretools.telemetry.TelemetryConstants.ACCOUNT;
75-
import static com.microsoft.azuretools.telemetry.TelemetryConstants.SIGNIN;
76-
import static com.microsoft.azuretools.telemetry.TelemetryConstants.signInDCProp;
77-
import static com.microsoft.azuretools.telemetry.TelemetryConstants.signInSPProp;
61+
import static com.microsoft.azuretools.telemetry.TelemetryConstants.*;
7862

7963
public class SignInWindow extends AzureDialogWrapper {
8064
private static final Logger LOGGER = Logger.getInstance(SignInWindow.class);
@@ -324,7 +308,8 @@ public void run() {
324308
}
325309

326310
authFileTextField.setText(path);
327-
PluginUtil.displayInfoDialog("Authentication File Created", String.format("Your credentials have been exported to %s, please keep the authentication file safe", path));
311+
PluginUtil.displayInfoDialog("Authentication File Created", String.format(
312+
"Your credentials have been exported to %s, please keep the authentication file safe", path));
328313
} catch (Exception ex) {
329314
ex.printStackTrace();
330315
//LOGGER.error("doCreateServicePrincipal", ex);
@@ -355,11 +340,10 @@ protected void doOKAction() {
355340
EventUtil.logEvent(EventType.info, ACCOUNT, SIGNIN, signInSPProp, null);
356341
String authPath = authFileTextField.getText();
357342
if (StringUtils.isNullOrWhiteSpace(authPath)) {
358-
JOptionPane.showMessageDialog(
359-
contentPane,
360-
"Select authentication file",
361-
"Sign in dialog info",
362-
JOptionPane.INFORMATION_MESSAGE);
343+
DefaultLoader.getUIHelper().showMessageDialog(contentPane,
344+
"Select authentication file",
345+
"Sign in dialog info",
346+
Messages.getInformationIcon());
363347
return;
364348
}
365349

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azuretools/ijidea/ui/SrvPriSettingsDialog.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
2626
import com.intellij.openapi.project.Project;
2727
import com.intellij.openapi.ui.DialogWrapper;
28+
import com.intellij.openapi.ui.Messages;
2829
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
2930
import com.intellij.ui.table.JBTable;
3031
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
3132
import com.microsoft.intellij.ui.components.AzureDialogWrapper;
33+
import com.microsoft.tooling.msservices.components.DefaultLoader;
3234
import org.jetbrains.annotations.Nullable;
3335

3436
import javax.swing.*;
@@ -54,17 +56,16 @@ public List<SubscriptionDetail> getSubscriptionDetails() {
5456
}
5557

5658
DefaultTableModel model = new DefaultTableModel() {
57-
final Class[] columnClass = new Class[] {
58-
Boolean.class, String.class, String.class
59+
final Class[] columnClass = new Class[]{
60+
Boolean.class, String.class, String.class
5961
};
6062
@Override
6163
public boolean isCellEditable(int row, int col) {
6264
return (col == 0);
6365
}
6466

6567
@Override
66-
public Class<?> getColumnClass(int columnIndex)
67-
{
68+
public Class<?> getColumnClass(int columnIndex) {
6869
return columnClass[columnIndex];
6970
}
7071
};
@@ -140,20 +141,20 @@ protected void doOKAction() {
140141
int rc = model.getRowCount();
141142
int unselectedCount = 0;
142143
for (int ri = 0; ri < rc; ++ri) {
143-
boolean selected = (boolean)model.getValueAt(ri, 0);
144-
if (!selected) unselectedCount++;
144+
boolean selected = (boolean) model.getValueAt(ri, 0);
145+
if (!selected) {
146+
unselectedCount++;
147+
}
145148
}
146149

147150
if (unselectedCount == rc) {
148-
JOptionPane.showMessageDialog(contentPane,
149-
"Please select at least one subscription",
150-
"Subscription Dialog Status",
151-
JOptionPane.INFORMATION_MESSAGE);
151+
DefaultLoader.getUIHelper().showMessageDialog(contentPane, "Please select at least one subscription",
152+
"Subscription Dialog Status", Messages.getInformationIcon());
152153
return;
153154
}
154155

155156
for (int ri = 0; ri < rc; ++ri) {
156-
boolean selected = (boolean)model.getValueAt(ri, 0);
157+
boolean selected = (boolean) model.getValueAt(ri, 0);
157158
this.sdl.get(ri).setSelected(selected);
158159
}
159160

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.intellij.openapi.diagnostic.Logger;
2828
import com.intellij.openapi.project.Project;
2929
import com.intellij.openapi.ui.DialogWrapper;
30+
import com.intellij.openapi.ui.Messages;
3031
import com.intellij.ui.AnActionButton;
3132
import com.intellij.ui.ToolbarDecorator;
3233
import com.intellij.ui.table.JBTable;
@@ -39,6 +40,7 @@
3940
import com.microsoft.azuretools.telemetrywrapper.EventType;
4041
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
4142
import com.microsoft.intellij.ui.components.AzureDialogWrapper;
43+
import com.microsoft.tooling.msservices.components.DefaultLoader;
4244
import org.jetbrains.annotations.NotNull;
4345
import org.jetbrains.annotations.Nullable;
4446

@@ -120,10 +122,10 @@ private void refreshSubscriptions() {
120122
subscriptionManager.setSubscriptionDetails(sdl);
121123

122124
}, (ex) -> {
123-
ex.printStackTrace();
124-
//LOGGER.error("refreshSubscriptions", ex);
125-
ErrorWindow.show(project, ex.getMessage(), "Refresh Subscriptions Error");
126-
});
125+
ex.printStackTrace();
126+
//LOGGER.error("refreshSubscriptions", ex);
127+
ErrorWindow.show(project, ex.getMessage(), "Refresh Subscriptions Error");
128+
});
127129
}
128130

129131
private void setSubscriptions() {
@@ -206,10 +208,9 @@ protected void doOKAction() {
206208
}
207209

208210
if (unselectedCount == rc) {
209-
JOptionPane.showMessageDialog(contentPane,
210-
"Please select at least one subscription",
211-
"Subscription dialog info",
212-
JOptionPane.INFORMATION_MESSAGE);
211+
DefaultLoader.getUIHelper().showMessageDialog(
212+
contentPane, "Please select at least one subscription",
213+
"Subscription dialog info", Messages.getInformationIcon());
213214
return;
214215
}
215216

@@ -228,7 +229,7 @@ protected String getDimensionServiceKey() {
228229

229230
private class SubscriptionTableModel extends DefaultTableModel {
230231
final Class[] columnClass = new Class[]{
231-
Boolean.class, String.class, String.class
232+
Boolean.class, String.class, String.class
232233
};
233234

234235
@Override

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azuretools/ijidea/ui/WarSelectDialog.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424

2525
import com.intellij.openapi.project.Project;
2626
import com.intellij.openapi.ui.DialogWrapper;
27+
import com.intellij.openapi.ui.Messages;
2728
import com.intellij.packaging.artifacts.Artifact;
2829
import com.microsoft.intellij.ui.components.AzureDialogWrapper;
30+
import com.microsoft.tooling.msservices.components.DefaultLoader;
2931
import org.jetbrains.annotations.Nullable;
3032

3133
import javax.swing.*;
@@ -85,13 +87,11 @@ protected Action[] createActions() {
8587

8688
@Override
8789
protected void doOKAction() {
88-
DefaultTableModel tableModel = (DefaultTableModel)table.getModel();
90+
DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
8991
int i = table.getSelectedRow();
9092
if (i < 0) {
91-
JOptionPane.showMessageDialog(contentPane,
92-
"Please select an artifact",
93-
"Select Artifact Status",
94-
JOptionPane.INFORMATION_MESSAGE);
93+
DefaultLoader.getUIHelper().showMessageDialog(contentPane, "Please select an artifact", "Select Artifact "
94+
+ "Status", Messages.getInformationIcon());
9595
return;
9696
}
9797
selectedArtifact = artifactList.get(i);

0 commit comments

Comments
 (0)