Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 JBoss Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.drools.guvnor.client.qa.testscenarios;
 
 import  com.google.gwt.core.client.GWT;
 import  com.google.gwt.user.client.Window;
 import  com.google.gwt.user.client.ui.*;
 import  org.drools.guvnor.client.common.FormStylePopup;
 import  org.drools.guvnor.client.common.ImageButton;
 
 import java.util.List;

Created by IntelliJ IDEA. User: nheron Date: 7 nov. 2009 Time: 19:33:37 To change this template use File | Settings | File Templates.
 
 public class ConfigWidget extends Composite {
     private final Constants constants = ((Constants) GWT.create( Constants.class ));
 
     public ConfigWidget(final Scenario sc,
                         final String packageName,
                         final ScenarioWidget scWidget) {
 
         final ListBox box = new ListBox( true );
 
         for ( int i = 0; i < sc.rules.size(); i++ ) {
             box.addItem( (Stringsc.rules.geti ) );
         }
         HorizontalPanel filter = new HorizontalPanel();
 
         final Image add = new ImageButton( "images/new_item.gif",
                                            .AddANewRule() );
         add.addClickListener( new ClickListener() {
             public void onClick(Widget w) {
                 showRulePopupw,
                                box,
                                packageName,
                                sc.rules,
                                scWidget );
             }
         } );
 
         final Image remove = new ImageButton( "images/trash.gif",
                                               .RemoveSelectedRule() );
         remove.addClickListener( new ClickListener() {
             public void onClick(Widget w) {
                 if ( box.getSelectedIndex() == -1 ) {
                     Window.alert( .PleaseChooseARuleToRemove() );
                 } else {
                     String r = box.getItemText( box.getSelectedIndex() );
                     sc.rules.remover );
                     box.removeItem( box.getSelectedIndex() );
                 }
             }
         } );
         VerticalPanel actions = new VerticalPanel();
         actions.add( add );
         actions.add( remove );
 
         final ListBox drop = new ListBox();
         drop.addItem( .AllowTheseRulesToFire(),
                       "inc" ); //NON-NLS
         drop.addItem( .PreventTheseRulesFromFiring(),
                       "exc" ); //NON-NLS
         drop.addItem( .AllRulesMayFire() );
         drop.addChangeListener( new ChangeListener() {
             public void onChange(Widget w) {
                 String s = drop.getValue( drop.getSelectedIndex() );
                 if ( s.equals"inc" ) ) { //NON-NLS
                     sc.inclusive = true;
                     add.setVisible( true );
                     remove.setVisible( true );
                     box.setVisible( true );
                 } else if ( s.equals"exc" ) ) { //NON-NLS
                     sc.inclusive = false;
                     add.setVisible( true );
                     remove.setVisible( true );
                     box.setVisible( true );
                 } else {
                     sc.rules.clear();
                    box.clear();
                    box.setVisible( false );
                    add.setVisible( false );
                    remove.setVisible( false );
                }
            }
        } );
        if ( sc.rules.size() > 0 ) {
            drop.setSelectedIndex( (sc.inclusive) ? 0 : 1 );
        } else {
            drop.setSelectedIndex( 2 );
            box.setVisible( false );
            add.setVisible( false );
            remove.setVisible( false );
        }
        filter.add( drop );
        filter.add( box );
        filter.add( actions );
        initWidget( filter );
    }
    private void showRulePopup(Widget w,
                               final ListBox box,
                               String packageName,
                               final List filterList,
                               ScenarioWidget scw) {
        final FormStylePopup pop = new FormStylePopup( "images/rule_asset.gif",
                                                       .SelectRule() ); //NON-NLS
        Widget ruleSelector = scw.getRuleSelectionWidgetpackageName,
                                                          new RuleSelectionEvent() {
                                                              public void ruleSelected(String r) {
                                                                  filterList.addr );
                                                                  box.addItem( r );
                                                                  pop.hide();
                                                              }
                                                          } );
        pop.addRow( ruleSelector );
        pop.show();
    }
New to GrepCode? Check out our FAQ X