|
11 | 11 | import com.intellij.ui.SimpleTextAttributes; |
12 | 12 | import com.intellij.ui.tree.LeafState; |
13 | 13 | import com.microsoft.azure.toolkit.ide.common.component.Node; |
| 14 | +import com.microsoft.azure.toolkit.ide.common.icon.AzureIcons; |
14 | 15 | import com.microsoft.azure.toolkit.intellij.common.IntelliJAzureIcons; |
15 | 16 | import com.microsoft.azure.toolkit.lib.common.action.Action; |
| 17 | +import com.microsoft.azure.toolkit.lib.common.action.ActionGroup; |
16 | 18 | import com.microsoft.azure.toolkit.lib.common.action.IActionGroup; |
| 19 | +import com.microsoft.azure.toolkit.lib.common.model.AbstractAzResource; |
| 20 | +import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager; |
17 | 21 | import lombok.EqualsAndHashCode; |
18 | 22 | import lombok.extern.slf4j.Slf4j; |
19 | 23 | import org.apache.commons.lang3.StringUtils; |
@@ -88,7 +92,25 @@ public void onClicked(Object event) { |
88 | 92 | @Override |
89 | 93 | @Nullable |
90 | 94 | public IActionGroup getActionGroup() { |
91 | | - return Optional.ofNullable(getValue()).map(Node::getActions).orElse(null); |
| 95 | + IActionGroup group = Optional.ofNullable(getValue()).map(Node::getActions).orElse(null); |
| 96 | + final Object value = this.getValue().getValue(); |
| 97 | + if (this.parent instanceof DeploymentTargetsNode targets && value instanceof AbstractAzResource<?, ?, ?> resource) { |
| 98 | + final AzureTaskManager tm = AzureTaskManager.getInstance(); |
| 99 | + final Action<Object> removeTarget = new Action<>(Action.Id.of("user/connector.remove_target.app")) |
| 100 | + .withLabel("Remove") |
| 101 | + .withIdParam(this.getValue().getLabel()) |
| 102 | + .withIcon(AzureIcons.Action.DELETE.getIconPath()) |
| 103 | + .withHandler(ignore -> tm.runLater(() -> tm.write(() -> targets.getValue().getProfile().removeApp(resource).save()))) |
| 104 | + .withAuthRequired(false); |
| 105 | + if (group != null) { |
| 106 | + group = new ActionGroup(); |
| 107 | + group.appendActions(removeTarget, "---"); |
| 108 | + group.appendActions(group.getActions()); |
| 109 | + } else { |
| 110 | + group = new ActionGroup(removeTarget); |
| 111 | + } |
| 112 | + } |
| 113 | + return group; |
92 | 114 | } |
93 | 115 |
|
94 | 116 | @Override |
|
0 commit comments