From 138988eac675e8e50b6428ee6cecb5a57e1f7b08 Mon Sep 17 00:00:00 2001 From: Hanxiao Liu Date: Fri, 14 Aug 2020 17:31:32 +0800 Subject: [PATCH 1/2] Fix webapp deployment target selection issue after create new webapp --- .../slimui/WebAppDeployMvpViewSlim.java | 2 +- .../slimui/WebAppDeployViewPresenterSlim.java | 4 +- .../slimui/WebAppSlimSettingPanel.java | 63 ++++++++++--------- 3 files changed, 37 insertions(+), 32 deletions(-) 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..b1b42a04ff 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); @@ -287,13 +283,18 @@ public synchronized void fillWebApps(List> webAppLists) { cbxWebApp.setEnabled(true); } + private ResourceEx getSelectedWebApp() { + final Object selectedItem = cbxWebApp.getSelectedItem(); + return selectedItem instanceof ResourceEx ? (ResourceEx) selectedItem : null; + } + @Override public synchronized void fillDeploymentSlots(List slotList) { cbxSlotName.removeAllItems(); 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()); @@ -342,12 +343,12 @@ protected JLabel getLblMavenProject() { @Override protected void resetFromConfig(@NotNull WebAppConfiguration configuration) { - refreshWebApps(false); + refreshWebApps(false, configuration.getWebAppId()); if (configuration.getWebAppId() != null && webAppConfiguration.isDeployToSlot()) { 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 +367,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 +381,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()); @@ -396,8 +398,9 @@ 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,19 +425,20 @@ 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); + refreshWebApps(false, webAppConfiguration.getId()); } } else { - refreshWebApps(false); + refreshWebApps(false, webAppConfiguration.getId()); } } private void toggleSlotPanel(boolean slot) { - boolean isDeployToSlot = slot && (selectedWebApp != null); + boolean isDeployToSlot = slot && (getSelectedWebApp() != null); rbtNewSlot.setEnabled(isDeployToSlot); rbtExistingSlot.setEnabled(isDeployToSlot); lblSlotName.setEnabled(isDeployToSlot); @@ -461,11 +466,11 @@ private void createUIComponents() { lblNewSlot.addHyperlinkListener(e -> rbtNewSlot.doClick()); } - private void refreshWebApps(boolean force) { + 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 +508,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) { From 85297c427ebd05006ba9c6793b8dc770cd55626e Mon Sep 17 00:00:00 2001 From: Hanxiao Liu Date: Mon, 17 Aug 2020 16:26:22 +0800 Subject: [PATCH 2/2] Fix method order and add default parameter --- .../slimui/WebAppSlimSettingPanel.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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 b1b42a04ff..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 @@ -283,11 +283,6 @@ public synchronized void fillWebApps(List> webAppLists, final cbxWebApp.setEnabled(true); } - private ResourceEx getSelectedWebApp() { - final Object selectedItem = cbxWebApp.getSelectedItem(); - return selectedItem instanceof ResourceEx ? (ResourceEx) selectedItem : null; - } - @Override public synchronized void fillDeploymentSlots(List slotList) { cbxSlotName.removeAllItems(); @@ -343,7 +338,7 @@ protected JLabel getLblMavenProject() { @Override protected void resetFromConfig(@NotNull WebAppConfiguration configuration) { - refreshWebApps(false, configuration.getWebAppId()); + refreshWebApps(false); if (configuration.getWebAppId() != null && webAppConfiguration.isDeployToSlot()) { toggleSlotPanel(true); chkDeployToSlot.setSelected(true); @@ -394,6 +389,11 @@ 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) { @@ -430,10 +430,10 @@ private void createNewWebApp() { refreshWebApps(true, webApp.id()); } else { // In case created failed - refreshWebApps(false, webAppConfiguration.getId()); + refreshWebApps(false); } } else { - refreshWebApps(false, webAppConfiguration.getId()); + refreshWebApps(false); } } @@ -466,6 +466,10 @@ private void createUIComponents() { lblNewSlot.addHyperlinkListener(e -> rbtNewSlot.doClick()); } + private void refreshWebApps(boolean force) { + refreshWebApps(force, null); + } + private void refreshWebApps(boolean force, String targetId) { cbxWebApp.removeAllItems(); cbxWebApp.setEnabled(false);