Skip to content

Commit b35deff

Browse files
enabling refreshing connections/deployment targets/environment variables manually from local files.
1 parent 0b7c8d1 commit b35deff

File tree

6 files changed

+165
-18
lines changed

6 files changed

+165
-18
lines changed

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

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
package com.microsoft.azure.toolkit.intellij.connector;
77

8-
import com.google.common.util.concurrent.Futures;
8+
import com.google.common.util.concurrent.SettableFuture;
99
import com.intellij.ide.projectView.ProjectView;
1010
import com.intellij.ide.util.PropertiesComponent;
11-
import com.google.common.util.concurrent.SettableFuture;
1211
import com.intellij.openapi.actionSystem.AnActionEvent;
1312
import com.intellij.openapi.module.Module;
1413
import com.intellij.openapi.module.ModuleManager;
@@ -17,6 +16,9 @@
1716
import com.microsoft.azure.toolkit.ide.common.action.ResourceCommonActionsContributor;
1817
import com.microsoft.azure.toolkit.ide.common.icon.AzureIcons;
1918
import com.microsoft.azure.toolkit.intellij.connector.dotazure.AzureModule;
19+
import com.microsoft.azure.toolkit.intellij.connector.dotazure.ConnectionManager;
20+
import com.microsoft.azure.toolkit.intellij.connector.dotazure.DeploymentTargetManager;
21+
import com.microsoft.azure.toolkit.intellij.connector.dotazure.Profile;
2022
import com.microsoft.azure.toolkit.lib.common.action.Action;
2123
import com.microsoft.azure.toolkit.lib.common.action.ActionGroup;
2224
import com.microsoft.azure.toolkit.lib.common.action.AzureActionManager;
@@ -33,7 +35,6 @@
3335
import java.util.Objects;
3436
import java.util.Optional;
3537
import java.util.concurrent.ExecutionException;
36-
import java.util.concurrent.Future;
3738
import java.util.stream.Collectors;
3839
import java.util.stream.Stream;
3940

@@ -46,7 +47,9 @@ public class ResourceConnectionActionsContributor implements IActionsContributor
4647

4748
public static final Action.Id<AzureModule> CONNECT_TO_MODULE = Action.Id.of("user/connector.connect_to_module");
4849
public static final Action.Id<AzureModule> REFRESH_MODULE = Action.Id.of("user/connector.refresh_module");
49-
public static final Action.Id<AzureModule> REFRESH_MODULE_CONNECTIONS = Action.Id.of("user/connector.refresh_module_connections");
50+
public static final Action.Id<ConnectionManager> REFRESH_MODULE_CONNECTIONS = Action.Id.of("user/connector.refresh_module_connections");
51+
public static final Action.Id<DeploymentTargetManager> REFRESH_MODULE_TARGETS = Action.Id.of("user/connector.refresh_module_targets");
52+
public static final Action.Id<Connection<?, ?>> REFRESH_ENVIRONMENT_VARIABLES = Action.Id.of("user/connector.refresh_environment_variables");
5053
public static final Action.Id<AzureModule> HIDE_AZURE = Action.Id.of("user/connector.hide_azure_root");
5154

5255
public static final Action.Id<Pair<String, String>> COPY_ENV_PAIR = Action.Id.of("user/connector.copy_env_pair");
@@ -65,15 +68,40 @@ public void registerActions(AzureActionManager am) {
6568
new Action<>(REFRESH_MODULE)
6669
.withLabel("Refresh")
6770
.withIcon(AzureIcons.Action.REFRESH.getIconPath())
68-
.withHandler((module, e) -> refreshModule(module))
71+
.withHandler((module, e) -> {
72+
Optional.ofNullable(module.getDefaultProfile()).ifPresent(Profile::reload);
73+
AzureEventBus.emit("connector.refreshed.module_root", module);
74+
})
6975
.withShortcut(am.getIDEDefaultShortcuts().refresh())
7076
.withAuthRequired(false)
7177
.register(am);
7278

7379
new Action<>(REFRESH_MODULE_CONNECTIONS)
7480
.withLabel("Refresh")
7581
.withIcon(AzureIcons.Action.REFRESH.getIconPath())
76-
.withHandler((module, e) -> refreshModuleConnections(module))
82+
.withHandler((connectionManager, e) -> {
83+
connectionManager.reload();
84+
AzureEventBus.emit("connector.module_connections_changed", connectionManager);
85+
})
86+
.withShortcut(am.getIDEDefaultShortcuts().refresh())
87+
.withAuthRequired(false)
88+
.register(am);
89+
90+
new Action<>(REFRESH_MODULE_TARGETS)
91+
.withLabel("Refresh")
92+
.withIcon(AzureIcons.Action.REFRESH.getIconPath())
93+
.withHandler((targetManager, e) -> {
94+
targetManager.reload();
95+
AzureEventBus.emit("connector.module_targets_changed", targetManager);
96+
})
97+
.withShortcut(am.getIDEDefaultShortcuts().refresh())
98+
.withAuthRequired(false)
99+
.register(am);
100+
101+
new Action<>(REFRESH_ENVIRONMENT_VARIABLES)
102+
.withLabel("Refresh")
103+
.withIcon(AzureIcons.Action.REFRESH.getIconPath())
104+
.withHandler((targetManager, e) -> AzureEventBus.emit("connector.connection_environment_variables_changed", targetManager))
77105
.withShortcut(am.getIDEDefaultShortcuts().refresh())
78106
.withAuthRequired(false)
79107
.register(am);
@@ -203,14 +231,6 @@ public void registerActions(AzureActionManager am) {
203231
}
204232
}
205233

206-
private void refreshModuleConnections(AzureModule module) {
207-
AzureEventBus.emit("connector.refreshed.module_connections", module);
208-
}
209-
210-
private void refreshModule(AzureModule module) {
211-
AzureEventBus.emit("connector.refreshed.module_root", module);
212-
}
213-
214234
@AzureOperation(value = "user/connector.remove_connection.resource", params = "connection.getResource()")
215235
private static void removeConnection(Connection<?, ?> connection, AnActionEvent e) {
216236
final Project project = Objects.requireNonNull(e.getProject());

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.jdom.Element;
1818

1919
import javax.annotation.Nonnull;
20+
import javax.annotation.Nullable;
2021
import java.io.IOException;
2122
import java.util.LinkedHashSet;
2223
import java.util.List;
@@ -64,6 +65,11 @@ public List<String> getTargets() {
6465
return this.targetAppIds.stream().toList();
6566
}
6667

68+
@Nullable
69+
public VirtualFile getTargetsFile() {
70+
return this.profile.getProfileDir().findChild(TARGETS_FILE);
71+
}
72+
6773
@ExceptionNotification
6874
@AzureOperation("boundary/connector.save_target_apps")
6975
synchronized void save() throws IOException {

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.microsoft.azure.toolkit.lib.common.action.Action;
1919
import com.microsoft.azure.toolkit.lib.common.action.ActionGroup;
2020
import com.microsoft.azure.toolkit.lib.common.action.IActionGroup;
21+
import com.microsoft.azure.toolkit.lib.common.event.AzureEvent;
22+
import com.microsoft.azure.toolkit.lib.common.event.AzureEventBus;
2123
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
2224
import lombok.extern.slf4j.Slf4j;
2325
import org.apache.commons.collections4.CollectionUtils;
@@ -33,16 +35,25 @@
3335
public class ConnectionsNode extends AbstractAzureFacetNode<ConnectionManager> {
3436

3537
private final Action<?> editAction;
38+
private final AzureEventBus.EventListener eventListener;
3639

3740
public ConnectionsNode(@Nonnull final Project project, @Nonnull ConnectionManager manager) {
3841
super(project, manager);
42+
this.eventListener = new AzureEventBus.EventListener(this::onEvent);
43+
AzureEventBus.on("connector.module_connections_changed", eventListener);
3944
this.editAction = new Action<>(Action.Id.of("user/connector.edit_connections_in_editor"))
4045
.withLabel("Open In Editor")
4146
.withIcon(AzureIcons.Action.EDIT.getIconPath())
4247
.withHandler(ignore -> AzureTaskManager.getInstance().runLater(() -> this.navigate(true)))
4348
.withAuthRequired(false);
4449
}
4550

51+
private void onEvent(@Nonnull final AzureEvent azureEvent) {
52+
if (Objects.equals(azureEvent.getSource(), this.getValue())) {
53+
this.updateChildren();
54+
}
55+
}
56+
4657
@Override
4758
@Nonnull
4859
public Collection<? extends AbstractAzureFacetNode<?>> buildChildren() {
@@ -63,9 +74,10 @@ protected void buildView(@Nonnull final PresentationData presentation) {
6374
final List<Connection<?, ?>> connections = Optional.ofNullable(getValue())
6475
.map(ConnectionManager::getConnections).orElse(Collections.emptyList());
6576
final boolean isConnectionValid = connections.stream().allMatch(Connection::isValidConnection);
66-
presentation.addText("Resource connections", AzureFacetRootNode.getTextAttributes(isConnectionValid));
77+
//noinspection DialogTitleCapitalization
78+
presentation.addText("Resource Connections", AzureFacetRootNode.getTextAttributes(isConnectionValid));
6779
presentation.setIcon(AllIcons.Nodes.HomeFolder);
68-
presentation.setTooltip("The dependent/connected resources.");
80+
presentation.setTooltip("The dependent/connected Azure resources.");
6981
}
7082

7183
@Nullable
@@ -98,11 +110,22 @@ private VirtualFile getConnectionsFile() {
98110
.orElse(null);
99111
}
100112

113+
@Override
114+
public boolean isAlwaysExpand() {
115+
return true;
116+
}
117+
101118
@Override
102119
public @Nonnull LeafState getLeafState() {
103120
return LeafState.NEVER;
104121
}
105122

123+
@Override
124+
public void dispose() {
125+
super.dispose();
126+
AzureEventBus.off("connector.module_connections_changed", eventListener);
127+
}
128+
106129
public String toString() {
107130
return "Resource Connections";
108131
}

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

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,56 @@
55

66
package com.microsoft.azure.toolkit.intellij.connector.projectexplorer;
77

8+
import com.intellij.codeInsight.navigation.NavigationUtil;
89
import com.intellij.icons.AllIcons;
910
import com.intellij.ide.projectView.PresentationData;
1011
import com.intellij.openapi.project.Project;
12+
import com.intellij.openapi.vfs.VirtualFile;
13+
import com.intellij.psi.PsiManager;
1114
import com.intellij.ui.tree.LeafState;
1215
import com.microsoft.azure.toolkit.ide.common.IExplorerNodeProvider;
1316
import com.microsoft.azure.toolkit.ide.common.component.Node;
17+
import com.microsoft.azure.toolkit.ide.common.icon.AzureIcons;
1418
import com.microsoft.azure.toolkit.intellij.connector.dotazure.DeploymentTargetManager;
1519
import com.microsoft.azure.toolkit.intellij.explorer.AzureExplorer;
1620
import com.microsoft.azure.toolkit.lib.Azure;
21+
import com.microsoft.azure.toolkit.lib.common.action.Action;
22+
import com.microsoft.azure.toolkit.lib.common.action.ActionGroup;
23+
import com.microsoft.azure.toolkit.lib.common.action.IActionGroup;
24+
import com.microsoft.azure.toolkit.lib.common.event.AzureEvent;
25+
import com.microsoft.azure.toolkit.lib.common.event.AzureEventBus;
1726
import com.microsoft.azure.toolkit.lib.common.model.AbstractAzResource;
27+
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
1828

1929
import javax.annotation.Nonnull;
30+
import javax.annotation.Nullable;
31+
import java.util.Arrays;
2032
import java.util.Collection;
2133
import java.util.Objects;
2234
import java.util.Optional;
2335

36+
import static com.microsoft.azure.toolkit.intellij.connector.ResourceConnectionActionsContributor.REFRESH_MODULE_TARGETS;
37+
2438
public class DeploymentTargetsNode extends AbstractAzureFacetNode<DeploymentTargetManager> {
2539

40+
private final AzureEventBus.EventListener eventListener;
41+
private final Action<Object> editAction;
42+
2643
public DeploymentTargetsNode(@Nonnull Project project, @Nonnull DeploymentTargetManager manager) {
2744
super(project, manager);
45+
this.eventListener = new AzureEventBus.EventListener(this::onEvent);
46+
AzureEventBus.on("connector.module_targets_changed", eventListener);
47+
this.editAction = new Action<>(Action.Id.of("user/connector.edit_targets_in_editor"))
48+
.withLabel("Open In Editor")
49+
.withIcon(AzureIcons.Action.EDIT.getIconPath())
50+
.withHandler(ignore -> AzureTaskManager.getInstance().runLater(() -> this.navigate(true)))
51+
.withAuthRequired(false);
52+
}
53+
54+
private void onEvent(@Nonnull final AzureEvent azureEvent) {
55+
if (Objects.equals(azureEvent.getSource(), this.getValue())) {
56+
this.updateChildren();
57+
}
2858
}
2959

3060
@Override
@@ -42,19 +72,63 @@ public Collection<? extends AbstractAzureFacetNode<?>> buildChildren() {
4272
protected void buildView(@Nonnull final PresentationData presentation) {
4373
presentation.setIcon(AllIcons.Nodes.Deploy);
4474
presentation.setPresentableText("Deployment Targets");
45-
presentation.setTooltip("The Azure services that this project was deployed to.");
75+
presentation.setTooltip("The Azure computing services that this module was deployed to.");
4676
}
4777

4878
private AbstractAzureFacetNode<?> createResourceNode(@Nonnull final AbstractAzResource<?, ?, ?> app) {
4979
final Node<?> node = AzureExplorer.manager.createNode(app, null, IExplorerNodeProvider.ViewType.APP_CENTRIC);
5080
return new ResourceNode(this.getProject(), node, this);
5181
}
5282

83+
@Nullable
84+
@Override
85+
public IActionGroup getActionGroup() {
86+
return new ActionGroup(Arrays.asList(
87+
REFRESH_MODULE_TARGETS,
88+
"---",
89+
editAction,
90+
"---",
91+
"Actions.DeployFunction",
92+
"Actions.DeploySpringCloud",
93+
"Actions.WebDeployAction"
94+
), new Action.View("Deploy to Azure", AzureIcons.Action.DEPLOY.getIconPath(), true, null));
95+
}
96+
97+
@Override
98+
public void navigate(boolean requestFocus) {
99+
Optional.ofNullable(getTargetsFile())
100+
.map(f -> PsiManager.getInstance(getProject()).findFile(f))
101+
.map(f -> NavigationUtil.openFileWithPsiElement(f, requestFocus, requestFocus));
102+
}
103+
104+
@Override
105+
public boolean canNavigateToSource() {
106+
return Objects.nonNull(getTargetsFile());
107+
}
108+
109+
@Nullable
110+
private VirtualFile getTargetsFile() {
111+
return Optional.ofNullable(getValue())
112+
.map(DeploymentTargetManager::getTargetsFile)
113+
.orElse(null);
114+
}
115+
116+
@Override
117+
public boolean isAlwaysExpand() {
118+
return true;
119+
}
120+
53121
@Override
54122
public int getWeight() {
55123
return DEFAULT_WEIGHT - 1;
56124
}
57125

126+
@Override
127+
public void dispose() {
128+
super.dispose();
129+
AzureEventBus.off("connector.module_targets_changed", eventListener);
130+
}
131+
58132
@Override
59133
public String toString() {
60134
return "Deployment Targets";

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.microsoft.azure.toolkit.lib.common.action.Action;
2121
import com.microsoft.azure.toolkit.lib.common.action.ActionGroup;
2222
import com.microsoft.azure.toolkit.lib.common.action.IActionGroup;
23+
import com.microsoft.azure.toolkit.lib.common.event.AzureEvent;
24+
import com.microsoft.azure.toolkit.lib.common.event.AzureEventBus;
2325
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
2426
import lombok.extern.slf4j.Slf4j;
2527
import org.apache.commons.lang3.StringUtils;
@@ -32,19 +34,30 @@
3234
import java.util.Objects;
3335
import java.util.Optional;
3436

37+
import static com.microsoft.azure.toolkit.intellij.connector.ResourceConnectionActionsContributor.REFRESH_ENVIRONMENT_VARIABLES;
38+
3539
@Slf4j
3640
public class EnvironmentVariablesNode extends AbstractAzureFacetNode<Connection<?, ?>> {
3741
private final Action<?> editAction;
42+
private final AzureEventBus.EventListener eventListener;
3843

3944
public EnvironmentVariablesNode(@Nonnull Project project, @Nonnull Connection<?, ?> connection) {
4045
super(project, connection);
46+
this.eventListener = new AzureEventBus.EventListener(this::onEvent);
47+
AzureEventBus.on("connector.connection_environment_variables_changed", eventListener);
4148
this.editAction = new Action<>(Action.Id.of("user/connector.edit_envs_in_editor"))
4249
.withLabel("Open In Editor")
4350
.withIcon(AzureIcons.Action.EDIT.getIconPath())
4451
.withHandler(ignore -> AzureTaskManager.getInstance().runLater(() -> this.navigate(true)))
4552
.withAuthRequired(false);
4653
}
4754

55+
private void onEvent(@Nonnull final AzureEvent azureEvent) {
56+
if (Objects.equals(azureEvent.getSource(), this.getValue())) {
57+
this.updateChildren();
58+
}
59+
}
60+
4861
@Override
4962
@Nonnull
5063
public Collection<? extends AbstractAzureFacetNode<?>> buildChildren() {
@@ -79,12 +92,19 @@ public Object getData(@Nonnull String dataId) {
7992
@Override
8093
public IActionGroup getActionGroup() {
8194
return new ActionGroup(
82-
editAction,
95+
REFRESH_ENVIRONMENT_VARIABLES,
8396
"---",
97+
editAction,
8498
ResourceConnectionActionsContributor.COPY_ENV_VARS
8599
);
86100
}
87101

102+
@Override
103+
public void dispose() {
104+
super.dispose();
105+
AzureEventBus.off("connector.connection_environment_variables_changed", eventListener);
106+
}
107+
88108
@Override
89109
public String toString() {
90110
return "Environment Variables";

Utils/azure-toolkit-ide-libs/azure-toolkit-ide-common-lib/src/main/resources/bundles/com/microsoft/azure/toolkit/operation.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,15 @@ user/connector.remove_connection=remove selected resource connection
497497
user/connector.fix_connection=fix resource connection with invalid configuration
498498
user/connector.edit_connection_in_editor=edit module connection in editor
499499
user/connector.edit_connections_in_editor=edit module connections in editor
500+
user/connector.edit_targets_in_editor=edit deployment targets in editor
500501
user/connector.edit_env_in_editor=edit connection environment variable in editor
501502
user/connector.edit_envs_in_editor=edit connection environment variables in editor
502503
user/connector.connect_to_module=add/edit Azure resource connection of selected module
503504
user/connector.refresh_module=refresh modules
504505
user/connector.refresh_module_connections=refresh Azure resource connections of selected module
506+
user/connector.refresh_module_targets=refresh deployment targets of selected module
507+
user/connector.refresh_environment_variables=refresh environment variables
508+
user/connector.hide_azure_root=hide 'Azure' node
505509
user/connector.copy_env_pair=copy environment variable key/value pair
506510
user/connector.copy_env_key=copy environment variable key
507511
user/connector.copy_env_variables=copy all environment variable key/value pairs

0 commit comments

Comments
 (0)