Search in sources :

Example 1 with SelectSubscriptionsAction

use of com.microsoft.intellij.actions.SelectSubscriptionsAction in project azure-tools-for-java by Microsoft.

the class ServerExplorerToolWindowFactory method addToolbarItems.

private void addToolbarItems(ToolWindow toolWindow, final Project project, final AzureModule azureModule) {
    if (toolWindow instanceof ToolWindowEx) {
        ToolWindowEx toolWindowEx = (ToolWindowEx) toolWindow;
        try {
            Runnable forceRefreshTitleActions = () -> {
                ApplicationManager.getApplication().invokeLater(() -> {
                    try {
                        toolWindowEx.setTitleActions(new AnAction("Refresh", "Refresh Azure Nodes List", null) {

                            @Override
                            public void actionPerformed(AnActionEvent event) {
                                azureModule.load(true);
                            }

                            @Override
                            public void update(AnActionEvent e) {
                                boolean isDarkTheme = DefaultLoader.getUIHelper().isDarkTheme();
                                final String iconPath = isDarkTheme ? RefreshableNode.REFRESH_ICON_DARK : RefreshableNode.REFRESH_ICON_LIGHT;
                                e.getPresentation().setIcon(UIHelperImpl.loadIcon(iconPath));
                            }
                        }, new AzureSignInAction(), new SelectSubscriptionsAction());
                    } catch (Exception e) {
                        AzurePlugin.log(e.getMessage(), e);
                    }
                });
            };
            AuthMethodManager.getInstance().addSignInEventListener(forceRefreshTitleActions);
            AuthMethodManager.getInstance().addSignOutEventListener(forceRefreshTitleActions);
            // Remove the sign in/out listener when project close
            ProjectManager.getInstance().addProjectManagerListener(project, new ProjectManagerListener() {

                @Override
                public void projectClosing(@NotNull Project project) {
                    AuthMethodManager.getInstance().removeSignInEventListener(forceRefreshTitleActions);
                    AuthMethodManager.getInstance().removeSignOutEventListener(forceRefreshTitleActions);
                }
            });
            forceRefreshTitleActions.run();
        } catch (Exception e) {
            AzurePlugin.log(e.getMessage(), e);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) AzureSignInAction(com.microsoft.intellij.actions.AzureSignInAction) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) SelectSubscriptionsAction(com.microsoft.intellij.actions.SelectSubscriptionsAction) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Project (com.intellij.openapi.project.Project)1 ProjectManagerListener (com.intellij.openapi.project.ProjectManagerListener)1 ToolWindowEx (com.intellij.openapi.wm.ex.ToolWindowEx)1 AzureSignInAction (com.microsoft.intellij.actions.AzureSignInAction)1 SelectSubscriptionsAction (com.microsoft.intellij.actions.SelectSubscriptionsAction)1