private void applySettings ( ) { container . reset ( ) ; infoPanel . reset ( ) ; // create the list of options. List < String > options = new ArrayList <> ( Arrays . asList ( OPTIONS_ARRAY ) ) ; if ( cbNullOption . isSelected ( ) ) { options . add ( 0 , "" ) ; } // create the dropdown. final WDropdown dropdown = new WDropdown ( options ) ; // set the dropdown type. dropdown . setType ( ( DropdownType ) rbsDDType . getSelected ( ) ) ; // set the selected option if applicable. String selected = ( String ) rgDefaultOption . getSelected ( ) ; if ( selected != null && ! NONE . equals ( selected ) ) { dropdown . setSelected ( selected ) ; } // set the width. if ( nfWidth . getValue ( ) != null ) { dropdown . setOptionWidth ( nfWidth . getValue ( ) . intValue ( ) ) ; } // set the tool tip. if ( tfToolTip . getText ( ) != null && tfToolTip . getText ( ) . length ( ) > 0 ) { dropdown . setToolTip ( tfToolTip . getText ( ) ) ; } // set misc options. dropdown . setVisible ( cbVisible . isSelected ( ) ) ; dropdown . setDisabled ( cbDisabled . isSelected ( ) ) ; // add the action for action on change, ajax and subordinate. if ( cbActionOnChange . isSelected ( ) || cbAjax . isSelected ( ) || cbSubmitOnChange . isSelected ( ) ) { final WStyledText info = new WStyledText ( ) ; info . setWhitespaceMode ( WhitespaceMode . PRESERVE ) ; infoPanel . add ( info ) ; dropdown . setActionOnChange ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { String selectedOption = ( String ) dropdown . getSelected ( ) ; info . setText ( selectedOption ) ; } } ) ; } // this has to be below the set action on change so it is // not over written. dropdown . setSubmitOnChange ( cbSubmitOnChange . isSelected ( ) ) ; // add the ajax target. if ( cbAjax . isSelected ( ) ) { WAjaxControl update = new WAjaxControl ( dropdown ) ; update . addTarget ( infoPanel ) ; container . add ( update ) ; } // add the subordinate stuff. if ( rbsDDType . getValue ( ) == WDropdown . DropdownType . COMBO ) { //This is to work around a WComponent Subordinate logic flaw. cbSubordinate . setSelected ( false ) ; } if ( cbSubordinate . isSelected ( ) ) { WComponentGroup < SubordinateTarget > group = new WComponentGroup <> ( ) ; container . add ( group ) ; WSubordinateControl control = new WSubordinateControl ( ) ; container . add ( control ) ; for ( String option : OPTIONS_ARRAY ) { buildSubordinatePanel ( dropdown , option , group , control ) ; } // add a rule for none selected. Rule rule = new Rule ( ) ; control . addRule ( rule ) ; rule . setCondition ( new Equal ( dropdown , "" ) ) ; rule . addActionOnTrue ( new Hide ( group ) ) ; } WFieldLayout flay = new WFieldLayout ( ) ; flay . setLabelWidth ( 25 ) ; container . add ( flay ) ; flay . addField ( "Configured dropdown" , dropdown ) ; flay . addField ( ( WLabel ) null , new WButton ( "Submit" ) ) ; }
Apply the settings from the control table to the drop down .