1111import com .intellij .ui .HideableDecorator ;
1212import com .intellij .ui .HyperlinkLabel ;
1313import com .microsoft .azure .toolkit .ide .appservice .model .AzureArtifactConfig ;
14+ import com .microsoft .azure .toolkit .ide .appservice .model .DeploymentSlotConfig ;
1415import com .microsoft .azure .toolkit .ide .appservice .webapp .model .WebAppConfig ;
1516import com .microsoft .azure .toolkit .ide .appservice .webapp .model .WebAppDeployRunConfigurationModel ;
1617import com .microsoft .azure .toolkit .intellij .common .AzureArtifact ;
1718import com .microsoft .azure .toolkit .intellij .common .AzureArtifactComboBox ;
1819import com .microsoft .azure .toolkit .intellij .common .AzureArtifactManager ;
1920import com .microsoft .azure .toolkit .intellij .common .AzureArtifactType ;
21+ import com .microsoft .azure .toolkit .intellij .common .AzureComboBox ;
2022import com .microsoft .azure .toolkit .intellij .common .AzureFormPanel ;
2123import com .microsoft .azure .toolkit .lib .Azure ;
2224import com .microsoft .azure .toolkit .lib .appservice .AzureWebApp ;
3840import java .awt .event .FocusEvent ;
3941import java .awt .event .FocusListener ;
4042import java .awt .event .MouseEvent ;
43+ import java .text .DateFormat ;
44+ import java .text .SimpleDateFormat ;
4145import java .util .Arrays ;
46+ import java .util .Date ;
4247import java .util .List ;
4348import java .util .Objects ;
4449import java .util .Optional ;
@@ -82,14 +87,15 @@ public class WebAppDeployConfigurationPanel extends JPanel implements AzureFormP
8287 public WebAppDeployConfigurationPanel (@ NotNull Project project ) {
8388 super ();
8489 this .project = project ;
90+ $$$setupUI$$$ ();
91+ comboBoxWebApp .addItemListener (e -> loadDeploymentSlot (getSelectedWebApp ()));
8592
8693 final ButtonGroup slotButtonGroup = new ButtonGroup ();
8794 slotButtonGroup .add (rbtNewSlot );
8895 slotButtonGroup .add (rbtExistingSlot );
89- rbtExistingSlot .addActionListener (e -> toggleSlotType (true ));
90- rbtNewSlot .addActionListener (e -> toggleSlotType (false ));
91-
92- chkDeployToSlot .addActionListener (e -> toggleSlotPanel (chkDeployToSlot .isSelected ()));
96+ rbtExistingSlot .addItemListener (e -> toggleSlotType (true ));
97+ rbtNewSlot .addItemListener (e -> toggleSlotType (false ));
98+ chkDeployToSlot .addItemListener (e -> toggleSlotPanel (chkDeployToSlot .isSelected ()));
9399
94100 final Icon informationIcon = AllIcons .General .ContextHelp ;
95101 btnSlotHover .setIcon (informationIcon );
@@ -120,6 +126,9 @@ public void focusLost(FocusEvent focusEvent) {
120126 lblArtifact .setLabelFor (comboBoxArtifact );
121127 lblWebApp .setLabelFor (comboBoxWebApp );
122128
129+ final DateFormat df = new SimpleDateFormat ("yyMMddHHmmss" );
130+ txtNewSlotName .setText (String .format (DEFAULT_SLOT_NAME , df .format (new Date ())));
131+
123132 slotDecorator = new HideableDecorator (pnlSlotHolder , DEPLOYMENT_SLOT , true );
124133 slotDecorator .setContentComponent (pnlSlot );
125134 }
@@ -173,7 +182,6 @@ private void createUIComponents() {
173182 lblNewSlot .addHyperlinkListener (e -> rbtNewSlot .doClick ());
174183
175184 comboBoxWebApp = new WebAppComboBox (project );
176- comboBoxWebApp .addItemListener (e -> loadDeploymentSlot (getSelectedWebApp ()));
177185 comboBoxWebApp .refreshItems ();
178186
179187 comboBoxArtifact = new AzureArtifactComboBox (this .project );
@@ -224,7 +232,25 @@ public void setValue(WebAppDeployRunConfigurationModel data) {
224232 .getAzureArtifactById (AzureArtifactType .valueOf (config .getArtifactType ()), config .getArtifactIdentifier ()))
225233 .ifPresent (artifact -> comboBoxArtifact .setArtifact (artifact ));
226234 // web app
227- Optional .ofNullable (data .getWebAppConfig ()).ifPresent (webApp -> comboBoxWebApp .setValue (webApp ));
235+ Optional .ofNullable (data .getWebAppConfig ()).ifPresent (webApp -> {
236+ comboBoxWebApp .setConfigModel (webApp );
237+ comboBoxWebApp .setValue (new AzureComboBox .ItemReference <>(item -> WebAppConfig .isSameApp (item , webApp )));
238+ toggleSlotPanel (webApp .getDeploymentSlot () != null );
239+ Optional .ofNullable (webApp .getDeploymentSlot ()).ifPresent (slot -> {
240+ chkDeployToSlot .setSelected (true );
241+ rbtNewSlot .setSelected (slot .isNewCreate ());
242+ rbtExistingSlot .setSelected (!slot .isNewCreate ());
243+ toggleSlotType (!slot .isNewCreate ());
244+ if (slot .isNewCreate ()) {
245+ txtNewSlotName .setText (slot .getName ());
246+ cbxSlotConfigurationSource .addItem (slot .getConfigurationSource ());
247+ cbxSlotConfigurationSource .setSelectedItem (slot .getConfigurationSource ());
248+ } else {
249+ cbxSlotName .addItem (slot .getName ());
250+ cbxSlotName .setSelectedItem (slot .getName ());
251+ }
252+ });
253+ });
228254 // configuration
229255 chkToRoot .setSelected (data .isDeployToRoot ());
230256 chkOpenBrowser .setSelected (data .isOpenBrowserAfterDeployment ());
@@ -233,10 +259,19 @@ public void setValue(WebAppDeployRunConfigurationModel data) {
233259 @ Override
234260 public WebAppDeployRunConfigurationModel getValue () {
235261 final AzureArtifact artifact = comboBoxArtifact .getValue ();
236- final AzureArtifactConfig artifactConfig = AzureArtifactConfig .builder ().artifactType (artifact .getType ().name ())
237- .artifactIdentifier (AzureArtifactManager .getInstance (project ).getArtifactIdentifier (artifact )).build ();
262+ final AzureArtifactConfig artifactConfig = artifact == null ? null :
263+ AzureArtifactConfig .builder ().artifactType (artifact .getType ().name ())
264+ .artifactIdentifier (AzureArtifactManager .getInstance (project ).getArtifactIdentifier (artifact )).build ();
265+ final DeploymentSlotConfig slotConfig = chkDeployToSlot .isSelected () ? rbtExistingSlot .isSelected () ?
266+ DeploymentSlotConfig .builder ().newCreate (false ).name (cbxSlotName .getSelectedItem ().toString ()).build () :
267+ DeploymentSlotConfig .builder ().newCreate (true ).name (txtNewSlotName .getText ())
268+ .configurationSource (cbxSlotConfigurationSource .getSelectedItem ().toString ()).build () : null ;
269+ final WebAppConfig webAppConfig = comboBoxWebApp .getValue ();
270+ if (webAppConfig != null ) {
271+ webAppConfig .setDeploymentSlot (slotConfig );
272+ }
238273 return WebAppDeployRunConfigurationModel .builder ()
239- .webAppConfig (comboBoxWebApp . getValue () )
274+ .webAppConfig (webAppConfig )
240275 .artifactConfig (artifactConfig )
241276 .openBrowserAfterDeployment (chkOpenBrowser .isSelected ())
242277 .deployToRoot (chkToRoot .isSelected ())
0 commit comments