Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MySQL Experience] (No.4) add link dialog related ui codes. #4965

Merged
merged 7 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public abstract class AzureComboBox<T> extends ComboBox<T> implements AzureFormI
private boolean required;
private Object value;
private boolean valueNotSet = true;
@Setter
private boolean forceDisable;
private String label;

public AzureComboBox() {
Expand Down Expand Up @@ -190,7 +192,7 @@ protected void setLoading(final boolean loading) {
this.setEnabled(false);
this.setEditor(this.loadingSpinner);
} else {
this.setEnabled(true);
this.setEnabled(forceDisable ? false : true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!forceDisable

this.setEditor(this.inputEditor);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

package com.microsoft.azure.toolkit.intellij.common;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

public class ModuleComboBox extends AzureComboBox<Module> {

private final Project project;

public ModuleComboBox(Project project) {
super(true);
this.project = project;
}

@Override
protected List<? extends Module> loadItems() throws Exception {
return Arrays.asList(ModuleManager.getInstance(project).getModules());
}

@Override
protected String getItemText(Object item) {
if (item instanceof Module) {
return ((Module) item).getName();
} else {
return StringUtils.EMPTY;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

package com.microsoft.azure.toolkit.intellij.link.mysql;

import com.microsoft.azure.management.mysql.v2020_01_01.Server;
import com.microsoft.azure.management.mysql.v2020_01_01.implementation.DatabaseInner;
import com.microsoft.azure.management.mysql.v2020_01_01.implementation.MySQLManager;
import com.microsoft.azure.management.resources.Subscription;
import com.microsoft.azure.toolkit.intellij.common.AzureComboBox;
import com.microsoft.azuretools.authmanage.AuthMethodManager;
import com.microsoft.azuretools.sdkmanage.AzureManager;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class DatabaseComboBox extends AzureComboBox<DatabaseInner> {

@Setter
private Subscription subscription;
private Server server;

public DatabaseComboBox() {
super(false);
}

public void setServer(Server server) {
if (Objects.equals(server, this.server)) {
return;
}
this.server = server;
if (server == null) {
this.clear();
return;
}
this.refreshItems();
}

@Override
protected String getItemText(Object item) {
if (item instanceof DatabaseInner) {
return ((DatabaseInner) item).name();
}
return super.getItemText(item);
}

@Override
protected List<? extends DatabaseInner> loadItems() throws Exception {
if (subscription == null) {
return new ArrayList<>();
}
AzureManager manager = AuthMethodManager.getInstance().getAzureManager();
if (manager == null) {
return new ArrayList<>();
}
final MySQLManager mySQLManager = manager.getMySQLManager(subscription.subscriptionId());
return mySQLManager.databases().inner().listByServer(server.resourceGroupName(), server.name());
}

@Override
public boolean isRequired() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

package com.microsoft.azure.toolkit.intellij.link.mysql;

import com.microsoft.azure.management.mysql.v2020_01_01.Server;
import com.microsoft.azure.management.mysql.v2020_01_01.implementation.MySQLManager;
import com.microsoft.azure.management.resources.Subscription;
import com.microsoft.azure.toolkit.intellij.common.AzureComboBox;
import com.microsoft.azuretools.authmanage.AuthMethodManager;
import com.microsoft.azuretools.sdkmanage.AzureManager;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class ServerComboBox extends AzureComboBox<Server> {

private Subscription subscription;

public ServerComboBox() {
super(true);
}

public void setSubscription(Subscription subscription) {
if (Objects.equals(subscription, this.subscription)) {
return;
}
this.subscription = subscription;
if (subscription == null) {
this.clear();
return;
}
this.refreshItems();
}

@Override
protected String getItemText(Object item) {
if (item instanceof Server) {
return ((Server) item).name();
}
return super.getItemText(item);
}

@Override
protected List<? extends Server> loadItems() throws Exception {
if (subscription == null) {
return new ArrayList<>();
}
AzureManager manager = AuthMethodManager.getInstance().getAzureManager();
if (manager == null) {
return new ArrayList<>();
}
final MySQLManager mySQLManager = manager.getMySQLManager(subscription.subscriptionId());
return mySQLManager.servers().list();
}

@Override
public boolean isRequired() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

package com.microsoft.azure.toolkit.intellij.link.mysql;

import com.microsoft.azure.management.mysql.v2020_01_01.Server;
import com.microsoft.azure.toolkit.intellij.common.AzureComboBox;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class UsernameComboBox extends AzureComboBox<String> {

private static final String SEPARATOR = "@";

private Server server;

public UsernameComboBox() {
super(false);
}

public void setServer(Server server) {
if (Objects.equals(server, this.server)) {
return;
}
this.server = server;
if (server == null) {
this.clear();
return;
}
this.refreshItems();
}

@Override
protected List<? extends String> loadItems() {
if (server == null) {
return new ArrayList<>();
}
List<String> usernames = new ArrayList<>();
usernames.add(server.administratorLogin() + SEPARATOR + server.name());
return usernames;
}

@Override
public boolean isRequired() {
return true;
}
}