Skip to content

Commit 09c0ff3

Browse files
set IntellijAzureMessager as the default messager
1 parent eea88a0 commit 09c0ff3

File tree

6 files changed

+77
-124
lines changed

6 files changed

+77
-124
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/IntellijAzureMessager.java

Lines changed: 0 additions & 74 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
package com.microsoft.azure.toolkit.intellij.common.messager;
7+
8+
import com.intellij.notification.Notification;
9+
import com.intellij.notification.NotificationType;
10+
import com.intellij.notification.Notifications;
11+
import com.intellij.openapi.ui.MessageDialogBuilder;
12+
import com.microsoft.azure.toolkit.intellij.common.handler.IntelliJAzureExceptionHandler;
13+
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
14+
import com.microsoft.azure.toolkit.lib.common.messager.IAzureMessager;
15+
import org.apache.commons.lang3.ArrayUtils;
16+
17+
import javax.annotation.Nonnull;
18+
19+
public class IntellijAzureMessager implements IAzureMessager {
20+
private static final String NOTIFICATION_GROUP_ID = "Azure Plugin";
21+
private static final String DEFAULT_MESSAGE_TITLE = "Azure";
22+
23+
private void showNotification(@Nonnull String title, @Nonnull String message, NotificationType type) {
24+
Notifications.Bus.notify(new Notification(NOTIFICATION_GROUP_ID, title, message, type));
25+
}
26+
27+
private String getTitle(String... title) {
28+
if (ArrayUtils.isEmpty(title)) {
29+
return DEFAULT_MESSAGE_TITLE;
30+
}
31+
return title[0];
32+
}
33+
34+
public boolean confirm(@Nonnull String message, String title) {
35+
return MessageDialogBuilder.yesNo(getTitle(title), message).guessWindowAndAsk();
36+
}
37+
38+
public void alert(@Nonnull String message, String title) {
39+
MessageDialogBuilder.okCancel(getTitle(title), message).guessWindowAndAsk();
40+
}
41+
42+
public void success(@Nonnull String message, String title) {
43+
this.showNotification(getTitle(title), message, NotificationType.INFORMATION);
44+
}
45+
46+
public void info(@Nonnull String message, String title) {
47+
this.showNotification(getTitle(title), message, NotificationType.INFORMATION);
48+
}
49+
50+
public void warning(@Nonnull String message, String title) {
51+
this.showNotification(getTitle(title), message, NotificationType.WARNING);
52+
}
53+
54+
public void error(@Nonnull String message, String title) {
55+
this.showNotification(getTitle(title), message, NotificationType.ERROR);
56+
}
57+
58+
public void error(@Nonnull Throwable throwable, String title) {
59+
IntelliJAzureExceptionHandler.getInstance().handleException(throwable);
60+
}
61+
62+
public void error(@Nonnull Throwable throwable, @Nonnull String message, String title) {
63+
final AzureToolkitRuntimeException wrapped = new AzureToolkitRuntimeException(message, throwable);
64+
IntelliJAzureExceptionHandler.getInstance().handleException(wrapped);
65+
}
66+
67+
public String value(String val) {
68+
return val;
69+
}
70+
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/lib/common/AzureMessager.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-resource-connector-lib/src/main/java/com/microsoft/azure/toolkit/intellij/connector/ConnectorDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import com.microsoft.azure.toolkit.intellij.common.AzureComboBoxSimple;
1616
import com.microsoft.azure.toolkit.intellij.common.AzureDialog;
1717
import com.microsoft.azure.toolkit.intellij.common.AzureFormJPanel;
18-
import com.microsoft.azure.toolkit.lib.common.AzureMessager;
1918
import com.microsoft.azure.toolkit.lib.common.form.AzureForm;
2019
import com.microsoft.azure.toolkit.lib.common.form.AzureFormInput;
20+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
2121
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
2222
import lombok.Getter;
2323
import org.jetbrains.annotations.Nullable;
@@ -120,7 +120,7 @@ protected void saveConnection(Connection<R, C> connection) {
120120
connectionManager.addConnection(connection);
121121
final String message = String.format("The connection between %s and %s has been successfully created.",
122122
resource.toString(), consumer.toString());
123-
AzureMessager.getInstance().success(message);
123+
AzureMessager.getMessager().success(message);
124124
}
125125
});
126126
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/connector/mysql/MySQLDatabaseResourceConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.microsoft.azure.toolkit.intellij.connector.ResourceManager;
2626
import com.microsoft.azure.toolkit.intellij.connector.mysql.component.PasswordDialog;
2727
import com.microsoft.azure.toolkit.intellij.webapp.runner.webappconfig.WebAppConfiguration;
28-
import com.microsoft.azure.toolkit.lib.common.AzureMessager;
28+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
2929
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
3030
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle;
3131
import com.microsoft.azure.toolkit.lib.common.operation.IAzureOperationTitle;
@@ -128,7 +128,7 @@ private static Optional<String> loadPassword(@Nonnull final Module module, @Nonn
128128
return Optional.of(saved);
129129
}
130130
if (result.getErrorCode() != ACCESS_DENIED_ERROR_CODE) {
131-
AzureMessager.getInstance().warning("Azure Resource Connector", result.getMessage());
131+
AzureMessager.getMessager().warning(result.getMessage(), "Azure Resource Connector");
132132
}
133133
return Optional.empty();
134134
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,16 @@
1515
import com.microsoft.azure.cosmosspark.serverexplore.cosmossparknode.CosmosSparkClusterOps;
1616
import com.microsoft.azure.hdinsight.common.HDInsightHelperImpl;
1717
import com.microsoft.azure.hdinsight.common.HDInsightLoader;
18-
import com.microsoft.azure.toolkit.intellij.common.IntellijAzureMessager;
1918
import com.microsoft.azure.toolkit.intellij.common.handler.IntelliJAzureExceptionHandler;
19+
import com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager;
2020
import com.microsoft.azure.toolkit.intellij.common.operation.IntellijAzureOperationTitleProvider;
2121
import com.microsoft.azure.toolkit.intellij.common.task.IntellijAzureTaskManager;
22-
import com.microsoft.azure.toolkit.lib.common.AzureMessager;
22+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
2323
import com.microsoft.azure.toolkit.lib.common.task.AzureRxTaskManager;
2424
import com.microsoft.azure.toolkit.lib.common.exception.AzureExceptionHandler;
2525
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
26-
import com.microsoft.azuretools.authmanage.AuthMethodManager;
2726
import com.microsoft.azuretools.authmanage.CommonSettings;
2827
import com.microsoft.azuretools.azurecommons.util.FileUtil;
29-
import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel;
3028
import com.microsoft.azuretools.core.mvp.ui.base.AppSchedulerProvider;
3129
import com.microsoft.azuretools.core.mvp.ui.base.MvpUIHelperFactory;
3230
import com.microsoft.azuretools.core.mvp.ui.base.SchedulerProviderFactory;
@@ -77,7 +75,7 @@ public void appFrameCreated(@NotNull List<String> commandLineArgs) {
7775
AzureTaskManager.register(new IntellijAzureTaskManager());
7876
AzureRxTaskManager.register();
7977
AzureExceptionHandler.register(IntelliJAzureExceptionHandler.getInstance());
80-
AzureMessager.register(IntellijAzureMessager.getInstance());
78+
AzureMessager.setDefaultMessager(new IntellijAzureMessager());
8179
IntellijAzureOperationTitleProvider.register();
8280
Node.setNode2Actions(NodeActionsMap.node2Actions);
8381
SchedulerProviderFactory.getInstance().init(new AppSchedulerProvider());

0 commit comments

Comments
 (0)