Skip to content

Commit 34267a3

Browse files
inputs are not set with values of selected account when open from explorer.
1 parent 4811148 commit 34267a3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cosmos/src/main/java/com/microsoft/azure/toolkit/intellij/cosmos/IntelliJCosmosActionsContributorForUltimate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.function.BiConsumer;
2828

2929
import static com.microsoft.azure.toolkit.intellij.cosmos.dbtools.AzureCosmosDbAccountParamEditor.KEY_COSMOS_ACCOUNT_ID;
30+
import static com.microsoft.azure.toolkit.intellij.cosmos.dbtools.AzureCosmosDbAccountParamEditor.KEY_FROM_AZURE_EXPLORER;
3031

3132
public class IntelliJCosmosActionsContributorForUltimate implements IActionsContributor {
3233
@Override
@@ -46,6 +47,7 @@ private void openDatabaseTool(Project project, CosmosDBAccount account) {
4647
final LocalDataSourceManager manager = LocalDataSourceManager.getInstance(project);
4748
final DbDataSource newElement = ((DbPsiFacadeImpl) facade).createDataSourceWrapperElement(ds, manager);
4849
ds.setAdditionalProperty(KEY_COSMOS_ACCOUNT_ID, account.getId());
50+
ds.setAdditionalProperty(KEY_FROM_AZURE_EXPLORER, String.valueOf(true));
4951
DataSourceManagerDialog.showDialog(facade, newElement, null, null, null);
5052
}
5153
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cosmos/src/main/java/com/microsoft/azure/toolkit/intellij/cosmos/dbtools/AzureCosmosDbAccountParamEditor.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
public class AzureCosmosDbAccountParamEditor extends ParamEditorBase<AzureCosmosDbAccountParamEditor.CosmosDbAccountComboBox> {
6565
public static final String KEY_COSMOS_ACCOUNT_ID = "AZURE_COSMOS_ACCOUNT";
66+
public static final String KEY_FROM_AZURE_EXPLORER = "FROM_EXPLORER";
6667
public static final String NO_ACCOUNT_TIPS_TEMPLATE = "<html>No Azure Cosmos DB accounts (%s). You can <a href=''>create one</a> first.</html>";
6768
public static final String NOT_SIGNIN_TIPS = "<html><a href=\"\">Sign in</a> to select an existing Azure Cosmos DB account.</html>";
6869
private final DatabaseAccountKind kind;
@@ -76,13 +77,19 @@ public class AzureCosmosDbAccountParamEditor extends ParamEditorBase<AzureCosmos
7677
public AzureCosmosDbAccountParamEditor(@Nonnull DatabaseAccountKind kind, @Nonnull String label, @Nonnull DataInterchange interchange) {
7778
super(new CosmosDbAccountComboBox(kind), interchange, FieldSize.LARGE, label);
7879
this.kind = kind;
79-
this.accountId = interchange.getProperty(KEY_COSMOS_ACCOUNT_ID);
80+
final String accountId = interchange.getProperty(KEY_COSMOS_ACCOUNT_ID);
81+
// inputs will be fill with values from account if `this.accountId` is null;
82+
// fill inputs with values from account if it is from azure explorer
83+
// don't change values of inputs if it's modifying an existing data source
84+
if (Objects.isNull(interchange.getProperty(KEY_FROM_AZURE_EXPLORER)) && Objects.nonNull(accountId)) {
85+
this.accountId = accountId;
86+
}
8087
final CosmosDbAccountComboBox combox = this.getEditorComponent();
8188
combox.addValueChangedListener(this::setAccount);
8289
interchange.addPersistentProperty(KEY_COSMOS_ACCOUNT_ID);
83-
if (StringUtils.isNotBlank(this.accountId)) {
90+
if (StringUtils.isNotBlank(accountId)) {
8491
interchange.putProperty(KEY_COSMOS_ACCOUNT_ID, null);
85-
combox.setValue(new AzureComboBox.ItemReference<>(i -> i.getId().equals(this.accountId)));
92+
combox.setValue(new AzureComboBox.ItemReference<>(i -> i.getId().equals(accountId)));
8693
}
8794

8895
interchange.addPropertyChangeListener((evt -> onPropertiesChanged(evt.getPropertyName(), evt.getNewValue())), this);

0 commit comments

Comments
 (0)