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;
 
 import  com.gwtext.client.util.Format;
 import  org.drools.guvnor.client.common.FormStylePopup;
 import  org.drools.guvnor.client.common.ImageButton;
 import  org.drools.guvnor.client.common.SmallLabel;
 import  org.drools.guvnor.client.common.ValueChanged;
Created by IntelliJ IDEA. User: nheron Date: 7 nov. 2009 Time: 19:31:47 To change this template use File | Settings | File Templates.
 
 public class VerifyFactWidget extends Composite {
     private Grid                       outer;
     private boolean                    showResults;
     private String                     type;
     private SuggestionCompletionEngine sce;
     private Scenario                   scenario;
     private ExecutionTrace             executionTrace;
     private Constants                  constants = ((Constants) GWT.createConstants.class ));
 
     public VerifyFactWidget(final VerifyFact vf,
                             final Scenario sc,
                             final SuggestionCompletionEngine sce,
                             ExecutionTrace executionTrace,
                             boolean showResults) {
          = new Grid( 2,
                           1 );
         .getCellFormatter().setStyleName( 0,
                                                0,
                                                "modeller-fact-TypeHeader" ); //NON-NLS
         .getCellFormatter().setAlignment( 0,
                                                0,
                                                .,
                                                . );
         .setStyleName"modeller-fact-pattern-Widget" ); //NON-NLS
         this. = sce;
         this. = sc;
         this. = executionTrace;
         HorizontalPanel ab = new HorizontalPanel();
         if ( !vf.anonymous ) {
              = (Stringsc.getVariableTypes().getvf.name );
             ab.addnew SmallLabel( Format.format( .scenarioFactTypeHasValues(),
                                                    ,
                                                    vf.name ) ) );
         } else {
              = vf.name;
             ab.addnew SmallLabel( Format.format( .AFactOfType0HasValues(),
                                                    vf.name ) ) );
         }
         this. = showResults;
 
         Image add = new ImageButton( "images/add_field_to_fact.gif",
                                      .AddAFieldToThisExpectation(),
                                      new ClickListener() { //NON-NLS
                                          public void onClick(Widget w) {
 
                                              String[] fields = (String[]) sce.getModelFields );
                                              final FormStylePopup pop = new FormStylePopup( "images/rule_asset.gif",
                                                                                             .ChooseAFieldToAdd() ); //NON-NLS
                                              final ListBox b = new ListBox();
                                              for ( int i = 0; i < fields.lengthi++ ) {
                                                  b.addItemfields[i] );
                                              }
                                              pop.addRow( b );
                                              Button ok = new Button.OK() );
                                              ok.addClickListenernew ClickListener() {
                                                  public void onClick(Widget w) {
                                                      String f = b.getItemTextb.getSelectedIndex() );
                                                      vf.fieldValues.addnew VerifyFieldf,
                                                                                           "",
                                                                                          "==" ) );
                                                     FlexTable data = rendervf );
                                                     .setWidget( 1,
                                                                      0,
                                                                      data );
                                                     pop.hide();
                                                 }
                                             } );
                                             pop.addRow( ok );
                                             pop.show();
                                         }
                                     } );
        ab.addadd );
        .setWidget( 0,
                         0,
                         ab );
        initWidget );
        FlexTable data = rendervf );
        .setWidget( 1,
                         0,
                         data );
    }
    private FlexTable render(final VerifyFact vf) {
        FlexTable data = new FlexTable();
        for ( int i = 0; i < vf.fieldValues.size(); i++ ) {
            final VerifyField fld = (VerifyFieldvf.fieldValues.geti );
            data.setWidgeti,
                            1,
                            new SmallLabel( fld.fieldName + ":" ) );
            data.getFlexCellFormatter().setHorizontalAlignmenti,
                                                                1,
                                                                . );
            final ListBox opr = new ListBox();
            opr.addItem.equalsScenario(),
                         "==" );
            opr.addItem.doesNotEqualScenario(),
                         "!=" );
            if ( fld.operator.equals"==" ) ) {
                opr.setSelectedIndex( 0 );
            } else {
                opr.setSelectedIndex( 1 );
            }
            opr.addChangeListenernew ChangeListener() {
                public void onChange(Widget w) {
                    fld.operator = opr.getValueopr.getSelectedIndex() );
                }
            } );
            data.setWidgeti,
                            2,
                            opr );
            //fix nheron
            Widget cellEditor = new VerifyFieldConstraintEditor,
                                                                 new ValueChanged() {
                                                                     public void valueChanged(String newValue) {
                                                                         fld.expected = newValue;
                                                                     }
                                                                 },
                                                                 fld,
                                                                 ,
                                                                 this.,
                                                                 this. );
            data.setWidgeti,
                            3,
                            cellEditor );
            Image del = new ImageButton( "images/delete_item_small.gif",
                                         .RemoveThisFieldExpectation(),
                                         new ClickListener() {
                                             public void onClick(Widget w) {
                                                 if ( Window.confirm( Format.format( .AreYouSureYouWantToRemoveThisFieldExpectation(),
                                                                                     fld.fieldName ) ) ) {
                                                     vf.fieldValues.removefld );
                                                     FlexTable data = rendervf );
                                                     .setWidget( 1,
                                                                      0,
                                                                      data );
                                                 }
                                             }
                                         } );
            data.setWidgeti,
                            4,
                            del );
            if (  && fld.successResult != null ) {
                if ( !fld.successResult.booleanValue() ) {
                    data.setWidgeti,
                                    0,
                                    new Image"images/warning.gif" ) ); //NON-NLS
                    data.setWidgeti,
                                    5,
                                    new HTML( Format.format( .ActualResult(),
                                                             fld.actualResult ) ) );
                    data.getCellFormatter().addStyleNamei,
                                                          5,
                                                          "testErrorValue" ); //NON-NLS
                } else {
                    data.setWidgeti,
                                    0,
                                    new Image"images/test_passed.png" ) ); //NON-NLS
                }
            }
        }
        return data;
    }
New to GrepCode? Check out our FAQ X