Skip to content

Commit 0f97c3d

Browse files
authored
Merge pull request #5247 from microsoft/qianjin-sqlserver-refactor
[SQL Server] (No.11) Apply common subscrition/region/resource group based on resource-lib and extract common codes between sql server and mysql.
2 parents c0186be + 53cde87 commit 0f97c3d

33 files changed

+218
-256
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
package com.microsoft.azure.toolkit.intellij.common.ui;
7+
8+
import javax.swing.*;
9+
import java.util.Objects;
10+
11+
public class TextFieldUtils {
12+
13+
public static void disableTextBoard(JTextField... fields) {
14+
if (Objects.isNull(fields)) {
15+
return;
16+
}
17+
for (JTextField field : fields) {
18+
field.setBorder(BorderFactory.createEmptyBorder());
19+
}
20+
}
21+
22+
public static void makeTextOpaque(JTextField ... fields) {
23+
if (Objects.isNull(fields)) {
24+
return;
25+
}
26+
for (JTextField field : fields) {
27+
field.setBackground(null);
28+
}
29+
}
30+
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/mysql/AdminUsernameTextField.java renamed to PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/AdminUsernameTextField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*/
5-
package com.microsoft.azure.toolkit.intellij.mysql;
5+
package com.microsoft.azure.toolkit.intellij.database;
66

77
import com.microsoft.azure.toolkit.intellij.common.ValidationDebouncedTextInput;
88
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/mysql/creation/PasswordUtils.java renamed to PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/PasswordUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*/
55

6-
package com.microsoft.azure.toolkit.intellij.mysql.creation;
6+
package com.microsoft.azure.toolkit.intellij.database;
77

88
import com.microsoft.azure.toolkit.intellij.common.AzurePasswordFieldInput;
99
import com.microsoft.azure.toolkit.lib.common.form.AzureFormInput;

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/sqlserver/common/SqlServerRegionComboBox.java renamed to PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/RegionComboBox.java

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,31 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*/
55

6-
package com.microsoft.azure.toolkit.intellij.sqlserver.common;
6+
package com.microsoft.azure.toolkit.intellij.database;
77

8-
import com.microsoft.azure.PagedList;
9-
import com.microsoft.azure.management.resources.Location;
10-
import com.microsoft.azure.management.resources.RegionType;
11-
import com.microsoft.azure.management.resources.Subscription;
128
import com.microsoft.azure.toolkit.intellij.common.AzureComboBox;
9+
import com.microsoft.azure.toolkit.lib.Azure;
10+
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
1311
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;
1412
import com.microsoft.azure.toolkit.lib.common.model.Region;
13+
import com.microsoft.azure.toolkit.lib.common.model.Subscription;
1514
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
16-
import com.microsoft.azure.toolkit.lib.sqlserver.service.AzureSqlServer;
1715
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
16+
import lombok.Getter;
17+
import lombok.Setter;
1818

1919
import java.util.ArrayList;
2020
import java.util.List;
2121
import java.util.Objects;
22-
import java.util.stream.Collectors;
22+
import java.util.function.Function;
2323

24-
/**
25-
* TODO(Qianjin) : extend RegionComboBox
26-
*/
27-
public class SqlServerRegionComboBox extends AzureComboBox<Region> {
28-
29-
private static final String REGION_UNAVAILABLE_MESSAGE = "Your subscription does not have access to create a server "
30-
+ "in the selected region. For the latest information about region availability for your subscription, go to "
31-
+ "aka.ms/sqlcapacity. Please try another region or create a support ticket to request access.";
24+
public class RegionComboBox extends AzureComboBox<Region> {
3225

26+
@Getter
3327
private Subscription subscription;
28+
@Setter
29+
private Function<RegionComboBox, AzureValidationInfo> validateFunction;
30+
3431
private boolean validated;
3532
private AzureValidationInfo validatedInfo;
3633

@@ -56,7 +53,7 @@ protected List<? extends Region> loadItems() {
5653
if (Objects.isNull(subscription)) {
5754
return new ArrayList<>();
5855
}
59-
return loadRegions(subscription);
56+
return Azure.az(AzureAccount.class).listRegions(subscription.getId());
6057
}
6158

6259
@Override
@@ -69,10 +66,10 @@ protected String getItemText(Object item) {
6966

7067
@Override
7168
public void setItem(Region item) {
72-
if (!item.equals(getItem())) {
69+
super.setItem(item);
70+
if (!Objects.equals(item, getItem())) {
7371
validated = false;
7472
}
75-
super.setItem(item);
7673
}
7774

7875
@Override
@@ -83,31 +80,18 @@ public boolean isRequired() {
8380
@NotNull
8481
@Override
8582
public AzureValidationInfo doValidate() {
86-
if (validated && Objects.isNull(validatedInfo)) {
83+
if (Objects.isNull(subscription)) {
84+
return AzureValidationInfo.OK;
85+
}
86+
if (validated && Objects.nonNull(validatedInfo)) {
8787
return validatedInfo;
8888
}
8989
validatedInfo = super.doValidate();
9090
if (AzureValidationInfo.OK.equals(validatedInfo)) {
91-
AzureSqlServer service = com.microsoft.azure.toolkit.lib.Azure.az(AzureSqlServer.class);
92-
if (!service.checkRegionCapability(subscription.subscriptionId(), getValue().getName())) {
93-
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
94-
validatedInfo = builder.input(this).message(REGION_UNAVAILABLE_MESSAGE).type(AzureValidationInfo.Type.ERROR).build();
95-
}
91+
validatedInfo = validateFunction.apply(this);
9692
}
9793
validated = true;
9894
return validatedInfo;
9995
}
10096

101-
/**
102-
* TODO: replace codes after merge andy's code.
103-
*/
104-
private List<Region> loadRegions(Subscription subscription) {
105-
PagedList<Location> locationList = subscription.listLocations();
106-
locationList.loadAll();
107-
return locationList.stream()
108-
.filter((e) -> RegionType.PHYSICAL.equals(e.regionType()))
109-
.map(e -> Region.fromName(e.name()))
110-
.distinct()
111-
.collect(Collectors.toList());
112-
}
11397
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/mysql/ConnectionSecurityPanel.form renamed to PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/ui/ConnectionSecurityPanel.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?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.mysql.ConnectionSecurityPanel">
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.microsoft.azure.toolkit.intellij.database.ui.ConnectionSecurityPanel">
33
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="15" right="0"/>
55
<constraints>

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/mysql/ConnectionSecurityPanel.java renamed to PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/ui/ConnectionSecurityPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*/
55

6-
package com.microsoft.azure.toolkit.intellij.mysql;
6+
package com.microsoft.azure.toolkit.intellij.database.ui;
77

88
import lombok.Getter;
99

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/mysql/ConnectionStringsOutputPanel.form renamed to PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/ui/ConnectionStringsOutputPanel.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?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.mysql.ConnectionStringsOutputPanel">
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.microsoft.azure.toolkit.intellij.database.ui.ConnectionStringsOutputPanel">
33
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/mysql/ConnectionStringsOutputPanel.java renamed to PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/ui/ConnectionStringsOutputPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*/
55

6-
package com.microsoft.azure.toolkit.intellij.mysql;
6+
package com.microsoft.azure.toolkit.intellij.database.ui;
77

88
import lombok.Getter;
99

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/mysql/MySQLPropertyActionPanel.form renamed to PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/ui/MySQLPropertyActionPanel.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?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.mysql.MySQLPropertyActionPanel">
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.microsoft.azure.toolkit.intellij.database.ui.MySQLPropertyActionPanel">
33
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/mysql/MySQLPropertyActionPanel.java renamed to PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/ui/MySQLPropertyActionPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*/
55

6-
package com.microsoft.azure.toolkit.intellij.mysql;
6+
package com.microsoft.azure.toolkit.intellij.database.ui;
77

88
import lombok.Getter;
99

0 commit comments

Comments
 (0)