diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployMvpViewSlim.java b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployMvpViewSlim.java index 8d86a0a06a..bad8dd3227 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployMvpViewSlim.java +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployMvpViewSlim.java @@ -31,7 +31,7 @@ import java.util.List; public interface WebAppDeployMvpViewSlim extends MvpView { - void fillWebApps(@NotNull List> webAppLists); + void fillWebApps(@NotNull List> webAppLists, final String defaultWebAppId); void fillDeploymentSlots(@NotNull List slots); } diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployViewPresenterSlim.java b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployViewPresenterSlim.java index 507de378de..f948199ebb 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployViewPresenterSlim.java +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployViewPresenterSlim.java @@ -58,7 +58,7 @@ public void onLoadDeploymentSlots(final ResourceEx selectedWebApp) { onLoadDeploymentSlots(selectedWebApp.getSubscriptionId(), selectedWebApp.getResource().id()); } - public void loadWebApps(boolean forceRefresh) { + public void loadWebApps(boolean forceRefresh, String defaultWebAppId) { Observable.fromCallable(() -> { List> result = AzureWebAppMvpModel.getInstance().listAllWebApps(forceRefresh); return result; @@ -69,7 +69,7 @@ public void loadWebApps(boolean forceRefresh) { if (isViewDetached()) { return; } - getMvpView().fillWebApps(webAppList); + getMvpView().fillWebApps(webAppList, defaultWebAppId); }), e -> errorHandler(CANNOT_LIST_WEB_APP, (Exception) e)); } diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppSlimSettingPanel.java b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppSlimSettingPanel.java index da8f3d093d..531141aea8 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppSlimSettingPanel.java +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppSlimSettingPanel.java @@ -76,7 +76,6 @@ public class WebAppSlimSettingPanel extends AzureSettingPanel selectedWebApp = null; private WebAppDeployViewPresenterSlim presenter = null; private JPanel pnlSlotCheckBox; @@ -192,18 +191,18 @@ public void removeActionListener(ActionListener l) { public void focusGained(FocusEvent focusEvent) { btnSlotHover.setBorderPainted(true); MouseEvent phantom = new MouseEvent(btnSlotHover, MouseEvent.MOUSE_ENTERED, System.currentTimeMillis(), - 0, 10, 10, 0, false); + 0, 10, 10, 0, false); IdeTooltipManager.getInstance().eventDispatched(phantom); if (subscription != null) { subscription.unsubscribe(); } subscription = Observable.timer(2, TimeUnit.SECONDS) - .subscribeOn(Schedulers.newThread()) - .subscribe(next -> { - if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == btnSlotHover) { - focusGained(focusEvent); - } - }); + .subscribeOn(Schedulers.newThread()) + .subscribe(next -> { + if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == btnSlotHover) { + focusGained(focusEvent); + } + }); } @Override @@ -257,7 +256,7 @@ public void disposeEditor() { } @Override - public synchronized void fillWebApps(List> webAppLists) { + public synchronized void fillWebApps(List> webAppLists, final String defaultWebAppId) { cbxWebApp.removeAllItems(); List> sortedWebAppLists = webAppLists .stream() @@ -271,14 +270,11 @@ public synchronized void fillWebApps(List> webAppLists) { lblCreateWebApp.setVisible(false); cbxWebApp.setVisible(true); cbxWebApp.addItem(CREATE_NEW_WEBAPP); - // Need calculated target id first or fill combo box will trigger event to change selectedWebApp - final String configurationWebAppId = webAppConfiguration.getWebAppId(); - final String targetId = (StringUtils.isEmpty(configurationWebAppId) && selectedWebApp != null) ? - selectedWebApp.getResource().id() : configurationWebAppId; + final String selectItemId = StringUtils.isNotEmpty(defaultWebAppId) ? defaultWebAppId : webAppConfiguration.getWebAppId(); sortedWebAppLists.forEach(webAppResourceEx -> cbxWebApp.addItem(webAppResourceEx)); final ResourceEx selectWebApp = sortedWebAppLists .stream() - .filter(webAppResourceEx -> StringUtils.equals(webAppResourceEx.getResource().id(), targetId)) + .filter(webAppResourceEx -> StringUtils.equals(webAppResourceEx.getResource().id(), selectItemId)) .findFirst() .orElse(sortedWebAppLists.get(0)); cbxWebApp.setSelectedItem(selectWebApp); @@ -293,7 +289,7 @@ public synchronized void fillDeploymentSlots(List slotList) { cbxSlotConfigurationSource.removeAllItems(); cbxSlotConfigurationSource.addItem(Constants.DO_NOT_CLONE_SLOT_CONFIGURATION); - cbxSlotConfigurationSource.addItem(selectedWebApp.getResource().name()); + cbxSlotConfigurationSource.addItem(getSelectedWebApp().getResource().name()); slotList.stream().filter(slot -> slot != null).forEach(slot -> { cbxSlotName.addItem(slot.name()); cbxSlotConfigurationSource.addItem(slot.name()); @@ -347,7 +343,7 @@ protected void resetFromConfig(@NotNull WebAppConfiguration configuration) { toggleSlotPanel(true); chkDeployToSlot.setSelected(true); final boolean useNewDeploymentSlot = Comparing.equal(configuration.getSlotName(), - Constants.CREATE_NEW_SLOT); + Constants.CREATE_NEW_SLOT); rbtNewSlot.setSelected(useNewDeploymentSlot); rbtExistingSlot.setSelected(!useNewDeploymentSlot); toggleSlotType(!useNewDeploymentSlot); @@ -366,12 +362,13 @@ protected void resetFromConfig(@NotNull WebAppConfiguration configuration) { @Override protected void apply(@NotNull WebAppConfiguration configuration) { + final ResourceEx selectedWebApp = getSelectedWebApp(); + configuration.setWebAppId(selectedWebApp == null ? null : selectedWebApp.getResource().id()); + configuration.setSubscriptionId(selectedWebApp == null ? null : selectedWebApp.getSubscriptionId()); final String targetName = getTargetName(); configuration.setTargetPath(getTargetPath()); configuration.setTargetName(targetName); configuration.setCreatingNew(false); - configuration.setWebAppId(selectedWebApp == null ? null : selectedWebApp.getResource().id()); - configuration.setSubscriptionId(selectedWebApp == null ? null : selectedWebApp.getSubscriptionId()); configuration.setDeployToSlot(chkDeployToSlot.isSelected()); configuration.setSlotPanelVisible(slotDecorator.isExpanded()); chkToRoot.setVisible(isAbleToDeployToRoot(targetName)); @@ -379,7 +376,7 @@ protected void apply(@NotNull WebAppConfiguration configuration) { if (chkDeployToSlot.isSelected()) { configuration.setDeployToSlot(true); configuration.setSlotName(cbxSlotName.getSelectedItem() == null ? "" : - cbxSlotName.getSelectedItem().toString()); + cbxSlotName.getSelectedItem().toString()); if (rbtNewSlot.isSelected()) { configuration.setSlotName(Constants.CREATE_NEW_SLOT); configuration.setNewSlotName(txtNewSlotName.getText()); @@ -392,12 +389,18 @@ protected void apply(@NotNull WebAppConfiguration configuration) { configuration.setOpenBrowserAfterDeployment(chkOpenBrowser.isSelected()); } + private ResourceEx getSelectedWebApp() { + final Object selectedItem = cbxWebApp.getSelectedItem(); + return selectedItem instanceof ResourceEx ? (ResourceEx) selectedItem : null; + } + private void selectWebApp() { Object value = cbxWebApp.getSelectedItem(); if (value != null && value instanceof ResourceEx) { chkDeployToSlot.setEnabled(true); - selectedWebApp = (ResourceEx) cbxWebApp.getSelectedItem(); - presenter.onLoadDeploymentSlots(selectedWebApp); + presenter.onLoadDeploymentSlots((ResourceEx) value); + // Save current selected web app id in webAppConfiguration + webAppConfiguration.setWebAppId(getSelectedWebApp().getResource().id()); } else if (Comparing.equal(CREATE_NEW_WEBAPP, value)) { // Create new web app cbxWebApp.setSelectedItem(null); @@ -406,6 +409,7 @@ private void selectWebApp() { } private boolean isAbleToDeployToRoot(final String targetName) { + final ResourceEx selectedWebApp = getSelectedWebApp(); if (selectedWebApp == null) { return false; } @@ -421,8 +425,9 @@ private void createNewWebApp() { if (dialog.showAndGet()) { final WebApp webApp = dialog.getCreatedWebApp(); if (webApp != null) { + // Set selectedWebApp to null in case user deploy while refreshing web app list webAppConfiguration.setWebAppId(webApp.id()); - refreshWebApps(true); + refreshWebApps(true, webApp.id()); } else { // In case created failed refreshWebApps(false); @@ -433,7 +438,7 @@ private void createNewWebApp() { } private void toggleSlotPanel(boolean slot) { - boolean isDeployToSlot = slot && (selectedWebApp != null); + boolean isDeployToSlot = slot && (getSelectedWebApp() != null); rbtNewSlot.setEnabled(isDeployToSlot); rbtExistingSlot.setEnabled(isDeployToSlot); lblSlotName.setEnabled(isDeployToSlot); @@ -462,10 +467,14 @@ private void createUIComponents() { } private void refreshWebApps(boolean force) { + refreshWebApps(force, null); + } + + private void refreshWebApps(boolean force, String targetId) { cbxWebApp.removeAllItems(); cbxWebApp.setEnabled(false); cbxWebApp.addItem(REFRESHING_WEBAPP); - presenter.loadWebApps(force); + presenter.loadWebApps(force, targetId); } private void updateArtifactConfiguration() { @@ -503,7 +512,7 @@ public void customize(JList list, Object value, int i, boolean b, boolean b1) { private String getStringLabelText(String message) { return comboBox.isPopupVisible() ? String.format("
%s
", - message) : message; + message) : message; } private String getWebAppLabelText(WebApp webApp) {