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;

Created by IntelliJ IDEA. User: nheron Date: 8 nov. 2009 Time: 19:12:24 To change this template use File | Settings | File Templates.
 
 
 import java.util.List;
 import java.util.Map;
 
 import  org.drools.guvnor.client.common.DirtyableComposite;
 import  org.drools.guvnor.client.common.DropDownValueChanged;
 import  org.drools.guvnor.client.common.FormStylePopup;
 import  org.drools.guvnor.client.common.InfoPopup;
 import  org.drools.guvnor.client.common.SmallLabel;
 import  org.drools.guvnor.client.common.ValueChanged;
 import  org.drools.guvnor.client.modeldriven.ui.ActionValueEditor;
 import  org.drools.guvnor.client.modeldriven.ui.DatePickerTextBox;
 
 import  com.gwtext.client.util.Format;

Constraint editor for the VerifyField of the expect part

Author(s):
Nicolas Heron
 
 public class VerifyFieldConstraintEditor extends DirtyableComposite {
     private String                     factType;
     private VerifyField                field;
     private final Panel                panel;
     private Scenario                   scenario;
     private SuggestionCompletionEngine sce;
     private ValueChanged               callback;
     private Constants                  constants = ((Constants) GWT.createConstants.class ));
     private ExecutionTrace             executionTrace;
 
     public VerifyFieldConstraintEditor(String factType,
                                        ValueChanged callback,
                                        VerifyField field,
                                        SuggestionCompletionEngine sce,
                                        Scenario scenario,
                                        ExecutionTrace executionTrace) {
         this. = field;
         this. = sce;
         this. = factType;
         this. = callback;
         this. = scenario;
         this. = executionTrace;
          = new SimplePanel();
         refreshEditor();
         initWidget );
     }
 
     private void refreshEditor() {
         String key =  + "." + .;
         String flType = .getFieldTypekey );
         .clear();
         if ( flType.equals. ) ) {
             final TextBox box = editableTextBox,
                                                 .,
                                                 . );
            box.addKeyboardListener( ActionValueEditor.getNumericFilter( box ) );
            .addbox );
        } else if ( flType.equals. ) ) {
            String[] c = new String[]{"true""false"};
            .addnew EnumDropDown.,
                                         new DropDownValueChanged() {
                                             public void valueChanged(String newText,
                                                                      String newValue) {
                                                 .valueChanged( newValue );
                                             }
                                         },
                                         DropDownData.createc ) ) );
        } else if (flType != null && flType.equals(.)) {           
            final DatePickerTextBox datePicker = new DatePickerTextBox( . );
            String m = Format.format(((Constants) GWT.create(Constants.class)).ValueFor0(),
            		.);
            datePicker.setTitle(m);
            datePicker.addValueChanged(new ValueChanged() {
                public void valueChanged(String newValue) {
                	. = newValue;
                }
            });
             .add(datePicker);
        } else {
            String[] enums = .getDataEnumListkey );
            if ( enums != null ) {
                .addnew EnumDropDown.,
                                             new DropDownValueChanged() {
                                                 public void valueChanged(String newText,
                                                                          String newValue) {
                                                     .valueChanged( newValue );
                                                 }
                                             },
                                             DropDownData.createenums ) ) );
            } else {
                if ( . != null && ..length() > 0 && . == . ) {
                    //  GUVNOR-337
                    if ( ..charAt( 0 ) == '=' ) {
                        . = .;
                    } else {
                        . = .;
                    }
                }
                if ( . == . && isThereABoundVariableToSet() == true ) {
                    Image clickme = new Image"images/edit.gif" ); // NON-NLS
                    clickme.addClickListenernew ClickListener() {
                        public void onClick(Widget w) {
                            showTypeChoicew,
                                             );
                        }
                    } );
                    .addclickme );
                } else if ( . == . ) {
                    .addvariableEditor() );
                } else {
                    .addeditableTextBox,
                                                .,
                                                . ) );
                }
            }
        }
    }
    private Widget variableEditor() {
        // sce.
        List vars = this..getFactNamesInScopethis.,
                                                       true );
        final ListBox box = new ListBox();
        if ( this.. == null ) {
            box.addItem.Choose() );
        }
        int j = 0;
        for ( int i = 0; i < vars.size(); i++ ) {
            String var = (Stringvars.geti );
            Map m = this..getVariableTypes();
            FactData f = (FactData.getFactTypes().getvar );
            String fieldType = .getFieldTypethis.,
                                                 . );
            if ( f.type.equalsfieldType ) ) {
                if ( box.getItemCount() == 0 ) {
                    box.addItem"..." );
                    j++;
                }
                box.addItem"=" + var );
                if ( this.. != null && this...equals"=" + var ) ) {
                    box.setSelectedIndexj );
                }
                j++;
            }
        }
        box.addChangeListenernew ChangeListener() {
            public void onChange(Widget w) {
                . = box.getItemTextbox.getSelectedIndex() );
            }
        } );
        return box;
    }
    private static TextBox editableTextBox(final ValueChanged changed,
                                           String fieldName,
                                           String initialValue) {
        // Fixme nheron
        final TextBox tb = new TextBox();
        tb.setTextinitialValue );
        String m = Format.format( ((Constants) GWT.createConstants.class )).ValueFor0(),
                                  fieldName );
        tb.setTitlem );
        tb.addChangeListenernew ChangeListener() {
            public void onChange(Widget w) {
                changed.valueChanged( tb.getText() );
            }
        } );
        return tb;
    }
    private void showTypeChoice(Widget w,
                                final VerifyField con) {
        final FormStylePopup form = new FormStylePopup( "images/newex_wiz.gif",
                                                        .FieldValue() );
        Button lit = new Button.LiteralValue() );
        lit.addClickListenernew ClickListener() {
            public void onClick(Widget w) {
                con.nature = .;
                doTypeChosenform );
            }
        } );
        form.addAttribute( .LiteralValue() + ":",
                           widgetslit,
                                    new InfoPopup( .LiteralValue(),
                                                   .LiteralValTip() ) ) );
        form.addRow( new HTML"<hr/>" ) );
        form.addRow( new SmallLabel( .AdvancedOptions() ) );
        // If we are here, then there must be a bound variable compatible with
        // me
        Button variable = new Button.BoundVariable() );
        variable.addClickListenernew ClickListener() {
            public void onClick(Widget w) {
                con.nature = .;
                doTypeChosenform );
            }
        } );
        form.addAttribute( .AVariable(),
                           widgetsvariable,
                                    new InfoPopup( .ABoundVariable(),
                                                   .BoundVariableTip() ) ) );
        form.show();
    }
    private boolean isThereABoundVariableToSet() {
        boolean retour = false;
        List vars = this..getFactNamesInScope,
                                                       true );
        if ( vars.size() > 0 ) {
            for ( int i = 0; i < vars.size(); i++ ) {
                String var = (Stringvars.geti );
                Map m = this..getVariableTypes();
                FactData f = (FactData.getFactTypes().getvar );
                String fieldType = .getFieldTypethis.,
                                                     . );
                if ( f.type.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