Skip to content

Commit

Permalink
Fix webapp deployment target selection issue after create new webapp (#…
Browse files Browse the repository at this point in the history
…4553)

* Fix webapp deployment target selection issue after create new webapp

* Fix method order and add default parameter
  • Loading branch information
Flanker32 authored Aug 17, 2020
1 parent 96e377e commit 66e81c6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.List;

public interface WebAppDeployMvpViewSlim extends MvpView {
void fillWebApps(@NotNull List<ResourceEx<WebApp>> webAppLists);
void fillWebApps(@NotNull List<ResourceEx<WebApp>> webAppLists, final String defaultWebAppId);

void fillDeploymentSlots(@NotNull List<DeploymentSlot> slots);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void onLoadDeploymentSlots(final ResourceEx<WebApp> selectedWebApp) {
onLoadDeploymentSlots(selectedWebApp.getSubscriptionId(), selectedWebApp.getResource().id());
}

public void loadWebApps(boolean forceRefresh) {
public void loadWebApps(boolean forceRefresh, String defaultWebAppId) {
Observable.fromCallable(() -> {
List<ResourceEx<WebApp>> result = AzureWebAppMvpModel.getInstance().listAllWebApps(forceRefresh);
return result;
Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public class WebAppSlimSettingPanel extends AzureSettingPanel<WebAppConfiguratio
" content and configurations elements can be swapped between two deployment slots, including the production " +
"slot.";

private ResourceEx<WebApp> selectedWebApp = null;
private WebAppDeployViewPresenterSlim presenter = null;

private JPanel pnlSlotCheckBox;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -257,7 +256,7 @@ public void disposeEditor() {
}

@Override
public synchronized void fillWebApps(List<ResourceEx<WebApp>> webAppLists) {
public synchronized void fillWebApps(List<ResourceEx<WebApp>> webAppLists, final String defaultWebAppId) {
cbxWebApp.removeAllItems();
List<ResourceEx<WebApp>> sortedWebAppLists = webAppLists
.stream()
Expand All @@ -271,14 +270,11 @@ public synchronized void fillWebApps(List<ResourceEx<WebApp>> 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<WebApp> 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);
Expand All @@ -293,7 +289,7 @@ public synchronized void fillDeploymentSlots(List<DeploymentSlot> 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());
Expand Down Expand Up @@ -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);
Expand All @@ -366,20 +362,21 @@ protected void resetFromConfig(@NotNull WebAppConfiguration configuration) {

@Override
protected void apply(@NotNull WebAppConfiguration configuration) {
final ResourceEx<WebApp> 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));
toggleSlotPanel(configuration.isDeployToSlot() && selectedWebApp != null);
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());
Expand All @@ -392,12 +389,18 @@ protected void apply(@NotNull WebAppConfiguration configuration) {
configuration.setOpenBrowserAfterDeployment(chkOpenBrowser.isSelected());
}

private ResourceEx<WebApp> getSelectedWebApp() {
final Object selectedItem = cbxWebApp.getSelectedItem();
return selectedItem instanceof ResourceEx ? (ResourceEx<WebApp>) selectedItem : null;
}

private void selectWebApp() {
Object value = cbxWebApp.getSelectedItem();
if (value != null && value instanceof ResourceEx) {
chkDeployToSlot.setEnabled(true);
selectedWebApp = (ResourceEx<WebApp>) cbxWebApp.getSelectedItem();
presenter.onLoadDeploymentSlots(selectedWebApp);
presenter.onLoadDeploymentSlots((ResourceEx<WebApp>) 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);
Expand All @@ -406,6 +409,7 @@ private void selectWebApp() {
}

private boolean isAbleToDeployToRoot(final String targetName) {
final ResourceEx<WebApp> selectedWebApp = getSelectedWebApp();
if (selectedWebApp == null) {
return false;
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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("<html><div>%s</div><small></small></html>",
message) : message;
message) : message;
}

private String getWebAppLabelText(WebApp webApp) {
Expand Down

0 comments on commit 66e81c6

Please sign in to comment.