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.workbench.screens.testscenario.client;
 
 import java.util.List;
 import java.util.Map;
 
Constraint editor for the VerifyField of the expect part
 
 
     private String                     factType;
     private VerifyField field;
     private final Panel                panel;
     private Scenario scenario;
     private PackageDataModelOracle dmo;
     private ValueChanged               callback;
     private ExecutionTrace executionTrace;
 
     public VerifyFieldConstraintEditor(String factType,
                                        ValueChanged callback,
                                        VerifyField field,
                                        PackageDataModelOracle dmo,
                                        Scenario scenario,
                                        ExecutionTrace executionTrace) {
         this. = field;
         this. = dmo;
         this. = factType;
         this. = callback;
         this. = scenario;
         this. = executionTrace;
          = new SimplePanel();
         refreshEditor();
         initWidget );
     }
 
     private void refreshEditor() {
         String flType = .getFieldType,  .getFieldName());
         .clear();
 
         if ( flType != null && flType.equals. ) ) {
             String[] c = new String[]{"true""false"};
             .addnew EnumDropDown.getExpected(),
                     new DropDownValueChanged() {
                         public void valueChanged(String newText,
                                                  String newValue) {
                             .valueChangednewValue );
                         }
                    },
                    DropDownData.create(c) ) );
        } else if ( flType != null && flType.equals. ) ) {
            final DatePickerTextBox datePicker = new DatePickerTextBox.getExpected() );
            String m = ..ValueFor0.getFieldName() );
            datePicker.setTitlem );
            datePicker.addValueChangednew ValueChanged() {
                public void valueChanged(String newValue) {
                    .setExpectednewValue );
                }
            } );
            .adddatePicker );
        } else {
            Map<StringStringcurrentValueMap = new HashMap<StringString>();
            // TODO fill currentValueMap with values of other VerifyFields (if any)
            DropDownData dropDownData = .getEnums,
                    .getFieldName(),
                    currentValueMap );
            if ( dropDownData != null ) {
                //GUVNOR-1324: Java enums are of type TYPE_COMPARABLE whereas Guvnor enums are not.
                //The distinction here controls whether the EXPECTED value is handled as a true
                //Java enum or a literal with a selection list (i.e. Guvnor enum)
                String dataType = .getFieldType,  .getFieldName() );
                if ( dataType.equals. ) ) {
                    .setNature. );
                } else {
                    .setNature. );
                }
                .addnew EnumDropDown.getExpected(),
                        new DropDownValueChanged() {
                            public void valueChanged(String newText,
                                                     String newValue) {
                                .valueChangednewValue );
                            }
                        },
                        dropDownData ) );
            } else {
                if ( .getExpected() != null && .getExpected().length() > 0 && .getNature() == . ) {
                    if ( .getExpected().charAt( 0 ) == '=' ) {
                        .setNature. );
                    } else {
                        .setNature. );
                    }
                }
                if ( .getNature() == . && isThereABoundVariableToSet() == true ) {
                    Image clickme = ..Edit();
                    clickme.addClickHandlernew ClickHandler() {
                        public void onClick(ClickEvent event) {
                            showTypeChoice( (Widgetevent.getSource(),
                                     );
                        }
                    } );
                    .addclickme );
                } else if ( .getNature() == . ) {
                    .addvariableEditor() );
                } else {
                    .addeditableTextBox,
                            flType,
                            .getFieldName(),
                            .getExpected() ) );
                }
            }
        }
    }
    private Widget variableEditor() {
        List<Stringvars = this..getFactNamesInScopethis.,
                true );
        final ListBox box = new ListBox();
        if ( this..getExpected() == null ) {
            box.addItem..Choose() );
        }
        int j = 0;
        for ( int i = 0; i < vars.size(); i++ ) {
            String var = vars.geti );
            FactData f = .getFactTypes().getvar );
            String fieldType = .getFieldTypethis.,
                    .getFieldName() );
            if ( f.getType().equalsfieldType ) ) {
                if ( box.getItemCount() == 0 ) {
                    box.addItem"..." );
                    j++;
                }
                box.addItem"=" + var );
                if ( this..getExpected() != null && this..getExpected().equals"=" + var ) ) {
                    box.setSelectedIndexj );
                }
                j++;
            }
        }
        box.addChangeHandlernew ChangeHandler() {
            public void onChange(ChangeEvent event) {
                .setExpectedbox.getItemTextbox.getSelectedIndex() ) );
            }
        } );
        return box;
    }
    private static TextBox editableTextBox(final ValueChanged changed,
                                           final String dataType,
                                           String fieldName,
                                           String initialValue) {
        final TextBox tb = TextBoxFactory.getTextBox(dataType);
        tb.setTextinitialValue );
        String m = ..ValueFor0fieldName );
        tb.setTitlem );
        tb.addChangeHandlernew ChangeHandler() {
            public void onChange(ChangeEvent event) {
                changed.valueChangedtb.getText() );
            }
        } );
        return tb;
    }
    private void showTypeChoice(Widget w,
                                final VerifyField con) {
                ..FieldValue() );
        Button lit = new Button..LiteralValue() );
        lit.addClickHandlernew ClickHandler() {
            public void onClick(ClickEvent event) {
                con.setNature. );
                doTypeChosenform );
            }
        } );
                widgetslit,
                        new InfoPopup..LiteralValue(),
                                ..LiteralValTip() ) ) );
        form.addRownew HTML"<hr/>" ) );
        form.addRownew SmallLabel..AdvancedOptions() ) );
        // If we are here, then there must be a bound variable compatible with
        // me
        Button variable = new Button..BoundVariable() );
        variable.addClickHandlernew ClickHandler() {
            public void onClick(ClickEvent event) {
                con.setNature. );
                doTypeChosenform );
            }
        } );
                widgetsvariable,
                        new InfoPopup..ABoundVariable(),
                                ..BoundVariableTip() ) ) );
        form.show();
    }
    private boolean isThereABoundVariableToSet() {
        boolean retour = false;
        List<Stringvars = this..getFactNamesInScope,
                true );
        if ( vars.size() > 0 ) {
            for ( int i = 0; i < vars.size(); i++ ) {
                String var = vars.geti );
                FactData f = .getFactTypes().getvar );
                String fieldType = .getFieldTypethis.,
                        .getFieldName() );
                if ( f.getType().equalsfieldType ) ) {
                    retour = true;
                    break;
                }
            }
        }
        return retour;
    }
    private void doTypeChosen(final FormStylePopup form) {
        refreshEditor();
        form.hide();
    }
    private Panel widgets(Widget left,
                          Widget right) {
        HorizontalPanel panel = new HorizontalPanel();
        panel.addleft );
        panel.addright );
        panel.setWidth"100%" );
        return panel;
    }
New to GrepCode? Check out our FAQ X