Skip to content

Commit 88d3181

Browse files
Merge pull request #5049 from microsoft/referencebook/ui-fix
azure sdk reference book UI fixes
2 parents 5913d08 + 6e04fb6 commit 88d3181

File tree

6 files changed

+129
-37
lines changed

6 files changed

+129
-37
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ group 'com.microsoft.azuretools'
88
intellij {
99
version = intellij_version
1010
downloadSources = Boolean.valueOf(true)
11+
plugins = ['java', 'maven', 'gradle']
1112
}
1213

1314
repositories {

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import lombok.Setter;
1212

1313
import java.util.Map;
14+
import java.util.Objects;
1415

1516
@Getter
1617
@Setter
@@ -23,8 +24,20 @@ public class AzureSdkArtifactEntity {
2324
private String versionPreview;
2425
private String type;
2526
private Map<String, String> links;
27+
private Map<String, String> dependencyPattern;
2628

27-
public String generateMavenDependencySnippet(String version) {
29+
public String getDependencySnippet(DependencyType type, String version) {
30+
final String strType = type.getName().toLowerCase();
31+
if (Objects.nonNull(dependencyPattern) && dependencyPattern.containsKey(strType)) {
32+
return dependencyPattern.get(strType);
33+
}
34+
return getDefaultDependencySnippet(type, version);
35+
}
36+
37+
private String getDefaultDependencySnippet(final DependencyType type, final String version) {
38+
if (DependencyType.GRADLE == type) {
39+
return String.format("implementation '%s:%s:%s'", this.groupId, this.artifactId, version);
40+
}
2841
return String.join("",
2942
"<dependency>\n",
3043
" <groupId>", this.groupId, "</groupId>\n",
@@ -34,13 +47,22 @@ public String generateMavenDependencySnippet(String version) {
3447
);
3548
}
3649

37-
public String getLink(String type) {
38-
return this.links.get(type);
39-
}
40-
4150
public static class Type {
4251
public static final String SPRING = "spring";
4352
public static final String CLIENT = "client";
4453
public static final String MANAGEMENT = "mgmt";
4554
}
55+
56+
@Getter
57+
public enum DependencyType {
58+
MAVEN("Maven", "xml"), GRADLE("Gradle", "gradle");
59+
60+
private final String name;
61+
private final String fileExt;
62+
63+
DependencyType(final String name, final String fileExt) {
64+
this.name = name;
65+
this.fileExt = fileExt;
66+
}
67+
}
4668
}

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

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
import com.intellij.openapi.actionSystem.DefaultActionGroup;
1515
import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl;
1616
import com.intellij.openapi.editor.impl.DocumentImpl;
17+
import com.intellij.openapi.fileTypes.FileType;
18+
import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx;
1719
import com.intellij.openapi.ide.CopyPasteManager;
1820
import com.intellij.openapi.project.Project;
1921
import com.intellij.openapi.project.ProjectManager;
2022
import com.intellij.ui.EditorTextField;
2123
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity;
24+
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity.DependencyType;
25+
import icons.GradleIcons;
26+
import icons.OpenapiIcons;
2227
import lombok.Getter;
2328
import org.jetbrains.annotations.NotNull;
2429

@@ -28,6 +33,10 @@
2833
import java.awt.datatransfer.StringSelection;
2934
import java.util.ArrayList;
3035
import java.util.List;
36+
import java.util.function.Consumer;
37+
38+
import static com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity.DependencyType.GRADLE;
39+
import static com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity.DependencyType.MAVEN;
3140

3241
public class AzureSdkArtifactGroupPanel {
3342
@Getter
@@ -37,6 +46,9 @@ public class AzureSdkArtifactGroupPanel {
3746
private ActionToolbarImpl toolbar;
3847
private ButtonGroup artifactsGroup;
3948
private final List<AzureSdkArtifactDetailPanel> artifactPnls = new ArrayList<>();
49+
private AzureSdkArtifactEntity pkg;
50+
private String version;
51+
private DependencyType type = MAVEN;
4052

4153
public void setData(@Nonnull final List<? extends AzureSdkArtifactEntity> artifacts) {
4254
this.clear();
@@ -58,7 +70,15 @@ private void clear() {
5870
}
5971

6072
private void onPackageOrVersionSelected(AzureSdkArtifactEntity pkg, String version) {
61-
this.viewer.setText(pkg.generateMavenDependencySnippet(version));
73+
this.pkg = pkg;
74+
this.version = version;
75+
this.viewer.setText(pkg.getDependencySnippet(type, version));
76+
}
77+
78+
private void onDependencyTypeSelected(DependencyType type) {
79+
this.type = type;
80+
final FileType fileType = FileTypeManagerEx.getInstance().getFileTypeByExtension(type.getFileExt());
81+
this.viewer.setNewDocumentAndFileType(fileType, new DocumentImpl(pkg.getDependencySnippet(type, version)));
6282
}
6383

6484
private EditorTextField buildCodeViewer() {
@@ -81,6 +101,7 @@ public void actionPerformed(@NotNull final AnActionEvent e) {
81101
CopyPasteManager.getInstance().setContents(new StringSelection(viewer.getText()));
82102
}
83103
});
104+
group.add(new DependencyTypeSelector(this::onDependencyTypeSelected));
84105
return new ActionToolbarImpl(ActionPlaces.TOOLBAR, group, false);
85106
}
86107

@@ -109,4 +130,44 @@ private void createUIComponents() {
109130
this.toolbar.setForceMinimumSize(true);
110131
this.toolbar.setTargetComponent(this.viewer);
111132
}
133+
134+
/**
135+
* referred com.intellij.application.options.schemes.AbstractSchemesPanel.ShowSchemesActionsListAction
136+
*
137+
* @see com.intellij.application.options.schemes.AbstractSchemesPanel
138+
*/
139+
private static class DependencyTypeSelector extends DefaultActionGroup {
140+
private final Consumer<? super DependencyType> onTypeSelected;
141+
private DependencyType selectedType;
142+
143+
private DependencyTypeSelector(Consumer<? super DependencyType> onTypeSelected) {
144+
super();
145+
setPopup(true);
146+
this.onTypeSelected = onTypeSelected;
147+
final AnAction maven = createAction(MAVEN.getName(), OpenapiIcons.RepositoryLibraryLogo, () -> this.setSelectedType(MAVEN));
148+
final AnAction gradle = createAction(GRADLE.getName(), GradleIcons.Gradle, () -> this.setSelectedType(GRADLE));
149+
this.addAll(maven, gradle);
150+
}
151+
152+
private void setSelectedType(DependencyType type) {
153+
this.selectedType = type;
154+
this.onTypeSelected.accept(type);
155+
}
156+
157+
@Override
158+
public void update(@NotNull final AnActionEvent e) {
159+
final Icon icon = GRADLE == selectedType ? GradleIcons.Gradle : OpenapiIcons.RepositoryLibraryLogo;
160+
e.getPresentation().setIcon(icon);
161+
}
162+
163+
private AnAction createAction(final String name, final Icon icon, final Runnable onSelected) {
164+
return new AnAction(name, null, icon) {
165+
@Override
166+
public void actionPerformed(@NotNull final AnActionEvent e) {
167+
onSelected.run();
168+
}
169+
};
170+
}
171+
}
172+
112173
}

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

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
package com.microsoft.azure.toolkit.intellij.azuresdk.referencebook;
77

8+
import com.intellij.icons.AllIcons;
89
import com.intellij.ui.HyperlinkLabel;
910
import com.intellij.ui.components.JBLabel;
1011
import com.intellij.ui.components.JBTabbedPane;
1112
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkArtifactEntity;
1213
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity;
1314
import com.microsoft.azure.toolkit.intellij.common.SwingUtils;
14-
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
1515
import lombok.Getter;
1616
import org.apache.commons.collections4.CollectionUtils;
1717

@@ -20,6 +20,10 @@
2020
import java.util.Optional;
2121

2222
public class AzureSdkFeatureDetailPanel {
23+
private final static String SPRING_TIP = "Spring libraries help you interact with already-provisioned services using native Spring idiomatic expressions.";
24+
private final static String MANAGEMENT_TIP = "Management libraries help you create, provision and otherwise manage Azure resources.";
25+
private final static String CLIENT_TIP = "Client libraries help you interact with already-provisioned services.";
26+
2327
private JBLabel titleLabel;
2428
private JPanel descPanel;
2529
@Getter
@@ -29,17 +33,17 @@ public class AzureSdkFeatureDetailPanel {
2933
private JBLabel descLabel;
3034

3135
public void setData(final AzureSdkFeatureEntity feature) {
32-
AzureTaskManager.getInstance().runLater(() -> {
33-
this.titleLabel.setText(feature.getName());
34-
SwingUtils.setTextAndEnableAutoWrap(this.descLabel, feature.getDescription());
35-
36-
Optional.ofNullable(feature.getMsdocs()).ifPresent(link -> {
37-
this.featureDocLink.setHyperlinkText("Product documentation");
38-
this.featureDocLink.setHyperlinkTarget(link);
39-
});
36+
this.titleLabel.setText(feature.getName());
37+
SwingUtils.setTextAndEnableAutoWrap(this.descLabel, feature.getDescription());
4038

41-
this.buildTabs(feature);
39+
this.featureDocLink.setVisible(false);
40+
Optional.ofNullable(feature.getMsdocs()).ifPresent(link -> {
41+
this.featureDocLink.setHyperlinkText("Product documentation");
42+
this.featureDocLink.setHyperlinkTarget(link);
43+
this.featureDocLink.setVisible(true);
4244
});
45+
46+
this.buildTabs(feature);
4347
}
4448

4549
private void buildTabs(AzureSdkFeatureEntity feature) {
@@ -48,19 +52,25 @@ private void buildTabs(AzureSdkFeatureEntity feature) {
4852
final List<AzureSdkArtifactEntity> managementArtifacts = feature.getArtifacts(AzureSdkArtifactEntity.Type.MANAGEMENT);
4953
this.tabPane.removeAll();
5054
if (CollectionUtils.isNotEmpty(clientArtifacts)) {
51-
final AzureSdkArtifactGroupPanel clientPanel = new AzureSdkArtifactGroupPanel();
52-
this.tabPane.insertTab("Client SDK", null, clientPanel.getContentPanel(), "", this.tabPane.getTabCount());
53-
clientPanel.setData(clientArtifacts);
55+
this.addGroup("Client SDK", CLIENT_TIP, clientArtifacts);
5456
}
5557
if (CollectionUtils.isNotEmpty(springArtifacts)) {
56-
final AzureSdkArtifactGroupPanel springPanel = new AzureSdkArtifactGroupPanel();
57-
this.tabPane.insertTab("Spring SDK", null, springPanel.getContentPanel(), "", this.tabPane.getTabCount());
58-
springPanel.setData(springArtifacts);
58+
this.addGroup("Spring", SPRING_TIP, springArtifacts);
5959
}
6060
if (CollectionUtils.isNotEmpty(managementArtifacts)) {
61-
final AzureSdkArtifactGroupPanel managementSdkPanel = new AzureSdkArtifactGroupPanel();
62-
this.tabPane.insertTab("Management SDK", null, managementSdkPanel.getContentPanel(), "", this.tabPane.getTabCount());
63-
managementSdkPanel.setData(managementArtifacts);
61+
this.addGroup("Management SDK", MANAGEMENT_TIP, managementArtifacts);
6462
}
6563
}
64+
65+
private void addGroup(final String title, final String tooltip, final List<? extends AzureSdkArtifactEntity> clientArtifacts) {
66+
final int index = this.tabPane.getTabCount();
67+
final AzureSdkArtifactGroupPanel clientPanel = new AzureSdkArtifactGroupPanel();
68+
this.tabPane.insertTab(title, null, clientPanel.getContentPanel(), "", index);
69+
clientPanel.setData(clientArtifacts);
70+
final JLabel tabHeader = (JLabel) this.tabPane.getTabComponentAt(index);
71+
tabHeader.setIcon(AllIcons.General.ContextHelp);
72+
tabHeader.setToolTipText(tooltip);
73+
tabHeader.setHorizontalTextPosition(SwingConstants.LEFT);
74+
tabHeader.repaint();
75+
}
6676
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
package com.microsoft.azure.toolkit.intellij.azuresdk.referencebook;
77

88
import com.intellij.ui.components.JBScrollPane;
9-
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity;
109
import lombok.Getter;
1110

1211
import javax.swing.*;
1312
import java.awt.*;
14-
import java.util.List;
1513

1614
public class AzureSdkReferenceBookPanel {
1715
@Getter
@@ -24,7 +22,7 @@ public class AzureSdkReferenceBookPanel {
2422
public AzureSdkReferenceBookPanel() {
2523
this.contentPanel.setPreferredSize(new Dimension(800, 600));
2624
this.initListeners();
27-
this.servicesTreePanel.reload();
25+
this.servicesTreePanel.refresh();
2826
}
2927

3028
private void initListeners() {

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@
3737
import org.apache.commons.lang3.StringUtils;
3838
import org.jetbrains.annotations.NotNull;
3939

40-
import javax.annotation.Nonnull;
4140
import javax.swing.*;
4241
import javax.swing.tree.DefaultMutableTreeNode;
4342
import javax.swing.tree.DefaultTreeModel;
43+
import javax.swing.tree.TreePath;
4444
import javax.swing.tree.TreeSelectionModel;
4545
import java.io.IOException;
4646
import java.util.Arrays;
4747
import java.util.List;
4848
import java.util.Objects;
49+
import java.util.Optional;
4950
import java.util.function.Consumer;
5051

5152
public class AzureSdkTreePanel implements TextDocumentListenerAdapter {
@@ -60,6 +61,7 @@ public class AzureSdkTreePanel implements TextDocumentListenerAdapter {
6061
private SearchTextField searchBox;
6162
private DefaultTreeModel model;
6263
private List<? extends AzureSdkServiceEntity> services;
64+
private TreePath lastNodePath;
6365

6466
public AzureSdkTreePanel() {
6567
this.initEventListeners();
@@ -71,6 +73,7 @@ private void initEventListeners() {
7173
this.tree.addTreeSelectionListener(e -> {
7274
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.tree.getLastSelectedPathComponent();
7375
if (Objects.nonNull(node) && node.isLeaf() && node.getUserObject() instanceof AzureSdkFeatureEntity) {
76+
this.lastNodePath = TreeUtil.getPathFromRoot(node);
7477
selectFeature((AzureSdkFeatureEntity) node.getUserObject());
7578
}
7679
});
@@ -92,22 +95,19 @@ private void filter(final String text) {
9295
this.loadData(this.services, filters);
9396
}
9497

95-
public void reload() {
98+
public void refresh() {
9699
final AzureSdkLibraryService service = AzureSdkLibraryService.getInstance();
97100
try {
98101
service.reloadAzureSDKArtifacts();
99-
this.setData(service.getServices());
102+
this.services = service.getServices();
103+
this.filter.debounce();
104+
Optional.ofNullable(this.lastNodePath).ifPresent(p -> TreeUtil.selectPath(this.tree, p));
100105
} catch (final IOException e) {
101106
//TODO: messager.warning(...)
102107
e.printStackTrace();
103108
}
104109
}
105110

106-
public void setData(@Nonnull final List<? extends AzureSdkServiceEntity> services) {
107-
this.services = services;
108-
this.loadData(this.services);
109-
}
110-
111111
private void loadData(final List<? extends AzureSdkServiceEntity> services, String... filters) {
112112
final DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.model.getRoot();
113113
root.removeAllChildren();
@@ -176,7 +176,7 @@ public final void actionPerformed(@NotNull final AnActionEvent e) {
176176
this.loading = true;
177177
ActivityTracker.getInstance().inc();
178178
AzureTaskManager.getInstance().runLater(() -> {
179-
AzureSdkTreePanel.this.reload();
179+
AzureSdkTreePanel.this.refresh();
180180
this.loading = false;
181181
});
182182
}

0 commit comments

Comments
 (0)