1919import org .apache .commons .lang3 .ObjectUtils ;
2020import org .apache .commons .lang3 .StringUtils ;
2121import org .eclipse .swt .SWT ;
22+ import org .eclipse .swt .custom .CCombo ;
2223import org .eclipse .swt .layout .GridData ;
2324import org .eclipse .swt .layout .GridLayout ;
2425import org .eclipse .swt .widgets .Button ;
2526import org .eclipse .swt .widgets .Composite ;
2627import org .eclipse .swt .widgets .Group ;
2728import org .eclipse .swt .widgets .Label ;
28- import org .eclipse .swt .widgets .Spinner ;
2929
3030import com .azure .resourcemanager .appplatform .models .RuntimeVersion ;
3131import com .microsoft .azure .toolkit .eclipse .common .component .AzureTextInput ;
3535import com .microsoft .azure .toolkit .lib .springcloud .SpringCloudApp ;
3636import com .microsoft .azure .toolkit .lib .springcloud .config .SpringCloudAppConfig ;
3737import com .microsoft .azure .toolkit .lib .springcloud .config .SpringCloudDeploymentConfig ;
38- import org .eclipse .swt .events .DisposeListener ;
39- import org .eclipse .swt .events .DisposeEvent ;
4038
4139public class SpringCloudAppConfigPanel extends Composite implements AzureFormPanel <SpringCloudAppConfig > {
4240 private Button useJava8 ;
4341 private Button useJava11 ;
4442 private Button useJava17 ;
4543 private AzureTextInput txtJvmOptions ;
4644 private AzureTextInput envTable ;
47- private Spinner numCpu ;
48- private Spinner numMemory ;
45+ private CCombo numCpu ;
46+ private CCombo numMemory ;
4947 private AzureSlider numInstance ;
5048
5149 private Consumer <? super SpringCloudAppConfig > listener = (config ) -> {
5250 };
5351 private SpringCloudAppConfig originalConfig ;
5452 private Button toggleEndpoint ;
5553 private Button toggleStorage ;
56- private Label lblRuntime ;
57- private Label lblDisk ;
54+ private Label lblRuntime ;
55+ private Label lblDisk ;
5856
5957 public SpringCloudAppConfigPanel (Composite parent ) {
6058 super (parent , SWT .NONE );
@@ -101,46 +99,56 @@ private void onDataChanged() {
10199
102100 public synchronized void updateForm (@ Nonnull SpringCloudApp app ) {
103101 final String sku = app .getParent ().getSku ();
104- final boolean enterprise = sku .toLowerCase ().startsWith ("e" );
105- this .useJava8 .setVisible (!enterprise );
106- this .useJava11 .setVisible (!enterprise );
107- this .useJava17 .setVisible (!enterprise );
108- this .lblRuntime .setVisible (!enterprise );
109- this .lblDisk .setVisible (!enterprise );
110- this .toggleStorage .setVisible (!enterprise );
102+ final boolean enterprise = sku .toLowerCase ().startsWith ("e" );
103+ this .lblDisk .setVisible (!enterprise );
104+ this .toggleStorage .setVisible (!enterprise );
105+ this .useJava8 .setVisible (!enterprise );
106+ this .useJava11 .setVisible (!enterprise );
107+ this .useJava17 .setVisible (!enterprise );
108+ this .lblRuntime .setVisible (!enterprise );
109+ ((GridData ) this .lblDisk .getLayoutData ()).exclude = enterprise ;
110+ ((GridData ) this .toggleStorage .getLayoutData ()).exclude = enterprise ;
111+ ((GridData ) this .useJava8 .getLayoutData ()).exclude = enterprise ;
112+ ((GridData ) this .useJava11 .getLayoutData ()).exclude = enterprise ;
113+ ((GridData ) this .useJava17 .getLayoutData ()).exclude = enterprise ;
114+ ((GridData ) this .lblRuntime .getLayoutData ()).exclude = enterprise ;
111115 final boolean basic = sku .toLowerCase ().startsWith ("b" );
112- final int cpu = this .numCpu .getSelection ();
113- final int mem = this .numMemory .getSelection ();
114- final int maxCpu = basic ? 1 : 4 ;
115- final int maxMem = basic ? 2 : 8 ;
116- this .numCpu .setSelection (Math .min (cpu , maxCpu ));
117- this .numCpu .setMinimum (1 );
118- this .numCpu .setMaximum (maxCpu );
119- this .numMemory .setSelection (Math .min (mem , maxMem ));
120- this .numMemory .setMinimum (1 );
121- this .numMemory .setMaximum (maxMem );
116+ final Double cpu = numCpu .getItemCount () < 1 || numCpu .getSelectionIndex () < 0 ? 1
117+ : Double .valueOf (numCpu .getItem (numCpu .getSelectionIndex ()));
118+ final Double mem = numMemory .getItemCount () < 1 || numMemory .getSelectionIndex () < 0 ? 1
119+ : Double .valueOf (numMemory .getItem (numMemory .getSelectionIndex ()));
120+ final String [] cpus = basic ? new String [] { "0.5" , "1" } : new String [] { "0.5" , "1" , "2" , "3" , "4" };
121+ final String [] mems = basic ? new String [] { "0.5" , "1" , "2" }
122+ : new String [] { "0.5" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" };
123+ this .numCpu .setItems (cpus );
124+ this .numMemory .setItems (mems );
125+ this .numCpu .setText (
126+ Objects .isNull (cpu ) ? "1" : (cpu > (basic ? 1 : 4 )) ? "1" : cpu < 1 ? "0.5" : "" + cpu .intValue ());
127+ this .numMemory .setText (
128+ Objects .isNull (mem ) ? "1" : (mem > (basic ? 2 : 8 )) ? "1" : mem < 1 ? "0.5" : "" + mem .intValue ());
122129 this .numInstance .setMaximum (basic ? 25 : 500 );
123130 this .numInstance .setMajorTickSpacing (basic ? 5 : 50 );
124131 this .numInstance .setMinorTickSpacing (basic ? 1 : 10 );
125132 this .numInstance .setMinimum (0 );
126133 this .numInstance .redraw ();
134+ this .layout (true , false );
127135 }
128136
129137 public SpringCloudAppConfig getValue (@ Nonnull SpringCloudAppConfig appConfig ) { // get config from form
130138 final SpringCloudDeploymentConfig deploymentConfig = appConfig .getDeployment ();
131- final boolean isEnterpriseTier = this .useJava17 .isVisible ();
132- if (isEnterpriseTier ) {
133- final String javaVersion = this .useJava17 .getSelection () ? RuntimeVersion .JAVA_17 .toString () :
134- this .useJava11 .getSelection () ? RuntimeVersion .JAVA_11 .toString () : RuntimeVersion .JAVA_8 .toString ();
135- deploymentConfig .setRuntimeVersion (javaVersion );
136- deploymentConfig .setEnablePersistentStorage (this .toggleStorage .getSelection ());
137- } else {
138- deploymentConfig .setRuntimeVersion (null );
139- deploymentConfig .setEnablePersistentStorage (false );
140- }
139+ final boolean isEnterpriseTier = this .useJava17 .isVisible ();
140+ if (isEnterpriseTier ) {
141+ final String javaVersion = this .useJava17 .getSelection () ? RuntimeVersion .JAVA_17 .toString () :
142+ this .useJava11 .getSelection () ? RuntimeVersion .JAVA_11 .toString () : RuntimeVersion .JAVA_8 .toString ();
143+ deploymentConfig .setRuntimeVersion (javaVersion );
144+ deploymentConfig .setEnablePersistentStorage (this .toggleStorage .getSelection ());
145+ } else {
146+ deploymentConfig .setRuntimeVersion (null );
147+ deploymentConfig .setEnablePersistentStorage (false );
148+ }
141149 appConfig .setIsPublic (this .toggleEndpoint .getSelection ());
142- deploymentConfig .setCpu (numCpu .getSelection () * 1.0 );
143- deploymentConfig .setMemoryInGB (numMemory .getSelection () * 1.0 );
150+ deploymentConfig .setCpu (Double . valueOf ( numCpu .getItem ( numCpu . getSelectionIndex ())) );
151+ deploymentConfig .setMemoryInGB (Double . valueOf ( numMemory .getItem ( numMemory . getSelectionIndex ())) );
144152 deploymentConfig .setInstanceCount (numInstance .getValue ());
145153 deploymentConfig .setJvmOptions (Optional .ofNullable (this .txtJvmOptions .getText ()).map (String ::trim ).orElse ("" ));
146154 deploymentConfig .setEnvironment (getEnvironmentVariables ());
@@ -159,18 +167,18 @@ public synchronized void setValue(SpringCloudAppConfig config) {
159167 final SpringCloudDeploymentConfig deployment = config .getDeployment ();
160168 this .toggle (this .toggleEndpoint , config .getIsPublic ());
161169 this .toggle (this .toggleStorage , deployment .getEnablePersistentStorage ());
162- this .useJava17 .setSelection (StringUtils .equalsIgnoreCase (deployment .getRuntimeVersion (), RuntimeVersion .JAVA_17 .toString ()));
163- this .useJava11 .setSelection (StringUtils .equalsIgnoreCase (deployment .getRuntimeVersion (), RuntimeVersion .JAVA_11 .toString ()));
164- this .useJava8 .setSelection (StringUtils .equalsIgnoreCase (deployment .getRuntimeVersion (), RuntimeVersion .JAVA_8 .toString ()));
170+ this .useJava17 .setSelection (StringUtils .equalsIgnoreCase (deployment .getRuntimeVersion (), RuntimeVersion .JAVA_17 .toString ()));
171+ this .useJava11 .setSelection (StringUtils .equalsIgnoreCase (deployment .getRuntimeVersion (), RuntimeVersion .JAVA_11 .toString ()));
172+ this .useJava8 .setSelection (StringUtils .equalsIgnoreCase (deployment .getRuntimeVersion (), RuntimeVersion .JAVA_8 .toString ()));
165173
166174 this .txtJvmOptions .setText (deployment .getJvmOptions ());
167175 final Map <String , String > env = deployment .getEnvironment ();
168176 final String strEnv = ObjectUtils .firstNonNull (env , Collections .emptyMap ()).entrySet ().stream ()
169177 .map (e -> String .format ("%s=%s" , e .getKey (), e .getValue ())).collect (Collectors .joining (";" ));
170178 this .envTable .setText (strEnv );
171179
172- this . numCpu . setSelection ( Optional .ofNullable (deployment .getCpu ()).map ( d -> d . intValue ()). orElse ( 1 ));
173- this . numMemory . setSelection ( Optional .ofNullable (deployment .getMemoryInGB ()).map ( d -> d . intValue ()). orElse ( 1 ));
180+ Optional .ofNullable (deployment .getCpu ()).ifPresent ( c -> this . numCpu . setText ( c < 1 ? "0.5" : "1" ));
181+ Optional .ofNullable (deployment .getMemoryInGB ()).ifPresent ( c -> this . numMemory . setText ( c < 1 ? "0.5" : "1" ));
174182 this .numInstance .setValue (Optional .ofNullable (deployment .getInstanceCount ()).orElse (1 ));
175183 }
176184
@@ -213,20 +221,15 @@ private void setupUI() {
213221 lblNewLabel .setText ("Public endpoint:" );
214222
215223 this .toggleEndpoint = new Button (grpConfiguration , SWT .CHECK );
224+ toggleEndpoint .setLayoutData (new GridData (SWT .LEFT , SWT .CENTER , false , false , 3 , 1 ));
216225 toggleEndpoint .setText ("Disabled" );
217- new Label (grpConfiguration , SWT .NONE );
218- new Label (grpConfiguration , SWT .NONE );
219226
220227 this .lblDisk = new Label (grpConfiguration , SWT .NONE );
221- GridData gd_lblDisk = new GridData (SWT .LEFT , SWT .CENTER , false , false , 1 , 1 );
222- gd_lblDisk .widthHint = 100 ;
223- this .lblDisk .setLayoutData (gd_lblDisk );
224- this .lblDisk .setText ("Storage:" );
228+ this .lblDisk .setText ("Storage:" );
225229
226230 this .toggleStorage = new Button (grpConfiguration , SWT .CHECK );
231+ toggleStorage .setLayoutData (new GridData (SWT .LEFT , SWT .CENTER , false , false , 3 , 1 ));
227232 this .toggleStorage .setText ("Disabled" );
228- new Label (grpConfiguration , SWT .NONE );
229- new Label (grpConfiguration , SWT .NONE );
230233
231234 this .lblRuntime = new Label (grpConfiguration , SWT .NONE );
232235 this .lblRuntime .setText ("Runtime:" );
@@ -239,24 +242,24 @@ private void setupUI() {
239242 this .useJava11 = new Button (grpConfiguration , SWT .RADIO );
240243 this .useJava11 .setLayoutData (new GridData (SWT .LEFT , SWT .CENTER , true , false , 1 , 1 ));
241244 this .useJava11 .setText ("Java 11" );
242-
245+
243246 this .useJava17 = new Button (grpConfiguration , SWT .RADIO );
244247 this .useJava17 .setLayoutData (new GridData (SWT .LEFT , SWT .CENTER , true , false , 1 , 1 ));
245248 this .useJava17 .setText ("Java 17" );
246-
247- Label lblJvmOptions = new Label (grpConfiguration , SWT .NONE );
248- lblJvmOptions .setText ("JVM options:" );
249- this .txtJvmOptions . setLabeledBy ( lblJvmOptions );
250-
251- this . txtJvmOptions = new AzureTextInput ( grpConfiguration , SWT . BORDER ) ;
252- this .txtJvmOptions .setLayoutData (new GridData ( SWT . FILL , SWT . CENTER , false , false , 3 , 1 ) );
253-
254- Label lblEnvVariable = new Label ( grpConfiguration , SWT . NONE );
255- lblEnvVariable . setText ( "Env variables:" );
256- this . envTable . setLabeledBy ( lblEnvVariable );
257-
258- this .envTable = new AzureTextInput ( grpConfiguration , SWT .BORDER );
259- this .envTable .setLayoutData ( new GridData ( SWT . FILL , SWT . CENTER , false , false , 3 , 1 ) );
249+
250+ Label lblJvmOptions = new Label (grpConfiguration , SWT .NONE );
251+ lblJvmOptions .setText ("JVM options:" );
252+ this .txtJvmOptions = new AzureTextInput ( grpConfiguration , SWT . BORDER );
253+ GridData gd_txtJvmOptions = new GridData ( SWT . FILL , SWT . CENTER , true , false , 3 , 1 );
254+ gd_txtJvmOptions . minimumWidth = 300 ;
255+ this .txtJvmOptions .setLayoutData (gd_txtJvmOptions );
256+ this . txtJvmOptions . setLabeledBy ( lblJvmOptions );
257+
258+ Label lblEnvVariable = new Label ( grpConfiguration , SWT . NONE );
259+ lblEnvVariable . setText ( "Env variables:" );
260+ this . envTable = new AzureTextInput ( grpConfiguration , SWT . BORDER );
261+ this .envTable . setLayoutData ( new GridData ( SWT . FILL , SWT .CENTER , true , false , 3 , 1 ) );
262+ this .envTable .setLabeledBy ( lblEnvVariable );
260263
261264 Group grpScalingUpout = new Group (this , SWT .NONE );
262265 grpScalingUpout .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false , 1 , 1 ));
@@ -269,15 +272,13 @@ private void setupUI() {
269272 lblVcpu .setLayoutData (gd_lblVcpu );
270273 lblVcpu .setText ("vCPU:" );
271274
272- this .numCpu = new Spinner (grpScalingUpout , SWT .BORDER );
273- numCpu .setSelection (1 );
275+ this .numCpu = new CCombo (grpScalingUpout , SWT .BORDER | SWT .READ_ONLY );
274276 this .numCpu .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false , 1 , 1 ));
275277
276278 Label lblNewLabel_1 = new Label (grpScalingUpout , SWT .NONE );
277279 lblNewLabel_1 .setText ("Memory/GB:" );
278280
279- this .numMemory = new Spinner (grpScalingUpout , SWT .BORDER );
280- numMemory .setSelection (1 );
281+ this .numMemory = new CCombo (grpScalingUpout , SWT .BORDER | SWT .READ_ONLY );
281282 this .numMemory .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false , 1 , 1 ));
282283
283284 Label lblNewLabel_2 = new Label (grpScalingUpout , SWT .NONE );
0 commit comments