final RuleSelectionEvent selected) {
final HorizontalPanel horizontalPanel = new HorizontalPanel();
final TextBox ruleNameTextBox = scenarioWidgetComponentCreator.createRuleNameTextBox();
horizontalPanel.add( ruleNameTextBox );
if ( availableRules != null ) {
final ListBox availableRulesBox = scenarioWidgetComponentCreator.createAvailableRulesBox( availableRules );
availableRulesBox.setSelectedIndex( 0 );
if ( availableRulesHandlerRegistration != null ) {
availableRulesHandlerRegistration.removeHandler();
}
final ChangeHandler ruleSelectionCL = scenarioWidgetComponentCreator.createRuleChangeHandler( ruleNameTextBox,
availableRulesBox );
availableRulesHandlerRegistration = availableRulesBox.addChangeHandler( ruleSelectionCL );
horizontalPanel.add( availableRulesBox );
} else {
final Button showList = new Button( constants.showListButton() );
horizontalPanel.add( showList );
showList.addClickHandler( new ClickHandler() {
public void onClick(ClickEvent event) {
horizontalPanel.remove( showList );
final Image busy = new Image( images.searching() );
final Label loading = new SmallLabel( constants.loadingList1() );
horizontalPanel.add( busy );
horizontalPanel.add( loading );
Scheduler scheduler = Scheduler.get();
scheduler.scheduleDeferred( new Command() {
public void execute() {
RepositoryServiceFactory.getPackageService().listRulesInPackage( packageName,
createGenericCallback( horizontalPanel,
ruleNameTextBox,
busy,
loading ) );
}
private GenericCallback<String[]> createGenericCallback(final HorizontalPanel horizontalPanel,
final TextBox ruleNameTextBox,
final Image busy,
final Label loading) {
return new GenericCallback<String[]>() {
public void onSuccess(String[] list) {
availableRules = (list);
final ListBox availableRulesBox = scenarioWidgetComponentCreator.createAvailableRulesBox( list );
final ChangeHandler ruleSelectionCL = new ChangeHandler() {
public void onChange(ChangeEvent event) {
ruleNameTextBox.setText( availableRulesBox.getItemText( availableRulesBox.getSelectedIndex() ) );
}
};
availableRulesHandlerRegistration = availableRulesBox.addChangeHandler( ruleSelectionCL );
availableRulesBox.setSelectedIndex( 0 );
horizontalPanel.add( availableRulesBox );
horizontalPanel.remove( busy );
horizontalPanel.remove( loading );
}