Skip to content

Commit 4b1ccf5

Browse files
Merge pull request #6872 from microsoft/reference/fixes
Resolve comments and issues in Azure Reference Book
2 parents f031e50 + ea6284a commit 4b1ccf5

File tree

26 files changed

+281
-169
lines changed

26 files changed

+281
-169
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/IntelliJReferenceBookActionContributor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,30 @@ public class IntelliJReferenceBookActionContributor implements IActionsContribut
2525
private static Map<String, String> SERVICE_FEATURE_MAP = new HashMap<>() {
2626
{
2727
put("Microsoft.ContainerService", "Container Service");
28+
put("Microsoft.ContainerService/managedClusters", "Container Service");
2829
put("Microsoft.Resources", "Resource Management");
30+
put("Microsoft.Resources/resourceGroups", "Resource Management");
2931
put("Microsoft.Web", "App Service");
32+
put("Microsoft.Web/sites", "App Service");
3033
put("Microsoft.Compute", "Compute");
34+
put("Microsoft.Compute/virtualMachines", "Compute");
3135
put("Microsoft.ContainerRegistry", "Container Registry");
36+
put("Microsoft.ContainerRegistry/registries", "Container Registry");
3237
put("Microsoft.DBforMySQL", "MySQL");
38+
put("Microsoft.DBforMySQL/servers", "MySQL");
3339
put("Microsoft.DBforPostgreSQL", "PostgreSQL");
40+
put("Microsoft.DBforPostgreSQL/servers", "PostgreSQL");
3441
put("Microsoft.Cache", "Redis");
42+
put("Microsoft.Cache/Redis", "Redis");
3543
put("Microsoft.AppPlatform", "Spring Cloud");
44+
put("Microsoft.AppPlatform/Spring", "Spring Cloud");
3645
put("Microsoft.Sql", "SQL");
46+
put("Microsoft.Sql/servers", "SQL");
3747
put("Microsoft.Storage", "Storage - Blobs");
48+
put("Microsoft.Storage/storageAccounts", "Storage - Blobs");
3849
put("Microsoft.Insights", "Monitor Ingestion");
50+
put("Microsoft.Insights/components", "Monitor Ingestion");
51+
put("Microsoft.DocumentDB/databaseAccounts", "Cosmos DB");
3952
}
4053
};
4154

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/referencebook/AzureSdkArtifactGroupPanel.form

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.microsoft.azure.toolkit.intellij.azuresdk.referencebook.AzureSdkArtifactGroupPanel">
33
<grid id="27dc6" binding="contentPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
44
<constraints>
5-
<xy x="20" y="20" width="471" height="231"/>
5+
<xy x="20" y="20" width="501" height="231"/>
66
</constraints>
77
<properties/>
88
<border type="none"/>
@@ -17,7 +17,7 @@
1717
<secondComponent value="125a2"/>
1818
</properties>
1919
</component>
20-
<grid id="125a2" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
20+
<grid id="125a2" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
2121
<margin top="0" left="0" bottom="0" right="0"/>
2222
<constraints border-constraint="South"/>
2323
<properties/>
@@ -43,49 +43,11 @@
4343
<orientation value="1"/>
4444
</properties>
4545
</component>
46-
<grid id="37fe2" binding="pnlAddDependencies" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
47-
<margin top="0" left="0" bottom="0" right="0"/>
48-
<constraints>
49-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
50-
</constraints>
51-
<properties/>
52-
<border type="none"/>
53-
<children>
54-
<component id="8e45f" class="javax.swing.JLabel">
55-
<constraints>
56-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
57-
</constraints>
58-
<properties>
59-
<text value="Module:"/>
60-
</properties>
61-
</component>
62-
<component id="f15dc" class="com.microsoft.azure.toolkit.intellij.azuresdk.referencebook.components.ModuleComboBox" binding="cbModule" custom-create="true">
63-
<constraints>
64-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
65-
</constraints>
66-
<properties/>
67-
</component>
68-
<component id="e3857" class="javax.swing.JButton" binding="btnAddDependency">
69-
<constraints>
70-
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
71-
</constraints>
72-
<properties>
73-
<text value="Add Dependency"/>
74-
</properties>
75-
</component>
76-
</children>
77-
</grid>
78-
<component id="8cad9" class="javax.swing.JTextPane" binding="paneMessage">
46+
<nested-form id="26c5d" form-file="com/microsoft/azure/toolkit/intellij/azuresdk/referencebook/AzureSdkProjectDependencyPanel.form" binding="pnlAddDependencies" custom-create="true">
7947
<constraints>
80-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
81-
<preferred-size width="150" height="50"/>
82-
</grid>
48+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
8349
</constraints>
84-
<properties>
85-
<editable value="false"/>
86-
<enabled value="false"/>
87-
</properties>
88-
</component>
50+
</nested-form>
8951
</children>
9052
</grid>
9153
<scrollpane id="17b86" class="com.intellij.ui.components.JBScrollPane">

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/referencebook/AzureSdkArtifactGroupPanel.java

Lines changed: 5 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,12 @@
2222
import com.intellij.ui.EditorTextField;
2323
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity;
2424
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity.DependencyType;
25-
import com.microsoft.azure.toolkit.intellij.azuresdk.model.module.GradleProjectModule;
26-
import com.microsoft.azure.toolkit.intellij.azuresdk.model.module.MavenProjectModule;
27-
import com.microsoft.azure.toolkit.intellij.azuresdk.model.module.ProjectModule;
28-
import com.microsoft.azure.toolkit.intellij.azuresdk.referencebook.components.ModuleComboBox;
29-
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
30-
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
31-
import com.microsoft.azure.toolkit.lib.common.messager.IAzureMessage;
32-
import com.microsoft.azure.toolkit.lib.common.messager.IAzureMessager;
33-
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
34-
import com.microsoft.azure.toolkit.lib.common.operation.OperationContext;
35-
import com.microsoft.azure.toolkit.lib.common.task.AzureTask;
36-
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
3725
import com.microsoft.intellij.util.GradleUtils;
3826
import com.microsoft.intellij.util.MavenUtils;
3927
import icons.GradleIcons;
4028
import icons.OpenapiIcons;
4129
import lombok.Getter;
42-
import org.apache.commons.lang.StringUtils;
43-
import org.apache.maven.artifact.versioning.ComparableVersion;
4430
import org.jetbrains.annotations.NotNull;
45-
import org.jetbrains.idea.maven.model.MavenArtifact;
46-
import org.jetbrains.plugins.gradle.model.ExternalDependency;
4731

4832
import javax.annotation.Nonnull;
4933
import javax.annotation.Nullable;
@@ -52,37 +36,28 @@
5236
import java.awt.datatransfer.StringSelection;
5337
import java.util.ArrayList;
5438
import java.util.List;
55-
import java.util.Optional;
5639
import java.util.function.Consumer;
5740

5841
import static com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity.DependencyType.GRADLE;
5942
import static com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity.DependencyType.MAVEN;
6043

6144
public class AzureSdkArtifactGroupPanel {
62-
public static final String DEPENDENCY_ADDED = "Dependency Added";
63-
public static final String ADD_DEPENDENCY = "Add Dependency";
64-
public static final String UPDATE_DEPENDENCY = "Update Dependency";
6545
@Getter
6646
private JPanel contentPanel;
6747
private EditorTextField viewer;
6848
private JPanel artifactsPnl;
6949
private ActionToolbarImpl toolbar;
70-
private JPanel pnlAddDependencies;
71-
private ModuleComboBox cbModule;
72-
private JButton btnAddDependency;
73-
private JTextPane paneMessage;
50+
private AzureSdkProjectDependencyPanel pnlAddDependencies;
7451
private ButtonGroup artifactsGroup;
7552
private final List<AzureSdkArtifactDetailPanel> artifactPnls = new ArrayList<>();
7653
private AzureSdkArtifactEntity pkg;
7754
private String version;
7855
private static DependencyType type = MAVEN;
7956

8057
private final Project project;
81-
private final IAzureMessager messager;
8258

8359
public AzureSdkArtifactGroupPanel(@Nullable Project project) {
8460
this.project = project;
85-
this.messager = new DependencyNotificationMessager();
8661
$$$setupUI$$$();
8762
init();
8863
}
@@ -91,8 +66,6 @@ private void init() {
9166
if (!MavenUtils.isMavenProject(project) && !GradleUtils.isGradleProject(project)) {
9267
pnlAddDependencies.setVisible(false);
9368
}
94-
cbModule.addItemListener(e -> refreshDependencyButton());
95-
btnAddDependency.addActionListener(e -> onAddDependency());
9669
}
9770

9871
public void setData(@Nonnull final List<? extends AzureSdkArtifactEntity> artifacts) {
@@ -118,7 +91,9 @@ private void onPackageOrVersionSelected(AzureSdkArtifactEntity pkg, String versi
11891
this.pkg = pkg;
11992
this.version = version;
12093
this.viewer.setText(pkg.getDependencySnippet(type, version));
121-
refreshDependencyButton();
94+
this.pnlAddDependencies.setPkg(pkg);
95+
this.pnlAddDependencies.setVersion(version);
96+
this.pnlAddDependencies.onSelectModule();
12297
}
12398

12499
private void onDependencyTypeSelected(DependencyType type) {
@@ -175,68 +150,7 @@ private void createUIComponents() {
175150
this.toolbar = this.buildCodeViewerToolbar();
176151
this.toolbar.setForceMinimumSize(true);
177152
this.toolbar.setTargetComponent(this.viewer);
178-
this.cbModule = new ModuleComboBox(this.project);
179-
cbModule.reloadItems();
180-
}
181-
182-
@AzureOperation(name = "sdk.refresh_dependency", type = AzureOperation.Type.ACTION)
183-
private void refreshDependencyButton() {
184-
OperationContext.action().setMessager(messager);
185-
btnAddDependency.setText("Loading...");
186-
btnAddDependency.setEnabled(false);
187-
AzureTaskManager.getInstance().runInBackground("Loading dependencies status", () -> {
188-
final ProjectModule module = cbModule.getValue();
189-
if (module instanceof MavenProjectModule) {
190-
final MavenArtifact mavenDependency = ((MavenProjectModule) module).getMavenDependency(pkg.getGroupId(), pkg.getArtifactId());
191-
final String currentVersion = Optional.ofNullable(mavenDependency).map(MavenArtifact::getVersion).orElse(null);
192-
updateDependencyStatus(module, currentVersion);
193-
} else if (module instanceof GradleProjectModule) {
194-
final ExternalDependency gradleDependency = ((GradleProjectModule) module).getGradleDependency(pkg.getGroupId(), pkg.getArtifactId());
195-
final String currentVersion = Optional.ofNullable(gradleDependency).map(ExternalDependency::getVersion).orElse(null);
196-
updateDependencyStatus(module, currentVersion);
197-
} else {
198-
btnAddDependency.setEnabled(false);
199-
}
200-
});
201-
}
202-
203-
private void updateDependencyStatus(final ProjectModule module, final String currentVersion) {
204-
if (StringUtils.isEmpty(currentVersion)) {
205-
AzureMessager.getMessager().info(AzureString.format("Library %s was not found in module %s", pkg.getArtifactId(), module.getName()));
206-
btnAddDependency.setEnabled(true);
207-
btnAddDependency.setText(ADD_DEPENDENCY);
208-
} else {
209-
AzureMessager.getMessager().info(AzureString.format("Library %s was found in module %s with version %s",
210-
pkg.getArtifactId(), module.getName(), currentVersion));
211-
final ComparableVersion current = new ComparableVersion(currentVersion);
212-
final ComparableVersion targetVersion = new ComparableVersion(version);
213-
btnAddDependency.setText(current.compareTo(targetVersion) >= 0 ? DEPENDENCY_ADDED : UPDATE_DEPENDENCY);
214-
btnAddDependency.setEnabled(current.compareTo(targetVersion) < 0);
215-
}
216-
}
217-
218-
@AzureOperation(name = "sdk.add_dependency", type = AzureOperation.Type.ACTION)
219-
private void onAddDependency() {
220-
OperationContext.action().setMessager(messager);
221-
btnAddDependency.setText("Running...");
222-
btnAddDependency.setEnabled(false);
223-
AzureTaskManager.getInstance().runInBackground(new AzureTask<>("Add dependency", this::addDependency));
224-
}
225-
226-
private void addDependency() {
227-
final ProjectModule module = cbModule.getValue();
228-
try {
229-
if (module instanceof MavenProjectModule) {
230-
DependencyUtils.addOrUpdateMavenDependency((MavenProjectModule) module, pkg, version);
231-
} else if (module instanceof GradleProjectModule) {
232-
DependencyUtils.addOrUpdateGradleDependency((GradleProjectModule) module, pkg, version);
233-
}
234-
btnAddDependency.setText(DEPENDENCY_ADDED);
235-
btnAddDependency.setEnabled(false);
236-
} catch (final Throwable t) {
237-
AzureMessager.getMessager().error(t);
238-
refreshDependencyButton();
239-
}
153+
this.pnlAddDependencies = new AzureSdkProjectDependencyPanel(project);
240154
}
241155

242156
/**
@@ -279,15 +193,6 @@ public void actionPerformed(@NotNull final AnActionEvent e) {
279193
}
280194
}
281195

282-
private class DependencyNotificationMessager implements IAzureMessager {
283-
@Override
284-
public boolean show(IAzureMessage message) {
285-
paneMessage.setText(message.getMessage().toString());
286-
return true;
287-
}
288-
289-
}
290-
291196
// CHECKSTYLE IGNORE check FOR NEXT 1 LINES
292197
public void $$$setupUI$$$() {
293198
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.microsoft.azure.toolkit.intellij.azuresdk.referencebook.AzureSdkProjectDependencyPanel">
3+
<grid id="27dc6" binding="pnlRoot" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="20" y="20" width="500" height="89"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<component id="bdcec" class="javax.swing.JLabel">
12+
<constraints>
13+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
14+
</constraints>
15+
<properties>
16+
<text value="Module:"/>
17+
</properties>
18+
</component>
19+
<component id="26f0a" class="com.microsoft.azure.toolkit.intellij.azuresdk.referencebook.components.ModuleComboBox" binding="cbModule" custom-create="true">
20+
<constraints>
21+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
22+
</constraints>
23+
<properties/>
24+
</component>
25+
<component id="f7a7d" class="javax.swing.JButton" binding="btnAddDependency">
26+
<constraints>
27+
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
28+
<minimum-size width="135" height="-1"/>
29+
<preferred-size width="135" height="-1"/>
30+
<maximum-size width="135" height="-1"/>
31+
</grid>
32+
</constraints>
33+
<properties>
34+
<text value="Add Dependency"/>
35+
</properties>
36+
</component>
37+
<component id="2edf7" class="javax.swing.JTextPane" binding="paneMessage">
38+
<constraints>
39+
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
40+
<preferred-size width="150" height="50"/>
41+
</grid>
42+
</constraints>
43+
<properties>
44+
<editable value="false"/>
45+
<enabled value="false"/>
46+
</properties>
47+
</component>
48+
</children>
49+
</grid>
50+
</form>

0 commit comments

Comments
 (0)