Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.drools.workbench.screens.testscenario.client;
  
  import java.util.List;
  import java.util.Map;
  
 
 public class CallMethodWidget extends DirtyableComposite {
 
     protected final ScenarioParentWidget parent;
     protected final Scenario scenario;
     protected final CallMethod mCall;
     protected final String                   factName;
     private final ExecutionTrace executionTrace;
 
     final private DirtyableFlexTable layout;
     private boolean                          isBoundFact = false;
 
     private String[]                         fieldCompletionTexts;
     private String[]                         fieldCompletionValues;
     private String                           variableClass;
 
     private final PackageDataModelOracle dmo;
 
     public CallMethodWidget(String factName,
                             ScenarioParentWidget parent,
                             Scenario scenario,
                             CallMethod mCall,
                             ExecutionTrace executionTrace,
                             PackageDataModelOracle dmo) {
         super();
         this. = factName;
         this. = parent;
         this. = scenario;
         this. = mCall;
         this. = executionTrace;
         this. = dmo;
 
         this. = new DirtyableFlexTable();
 
         .setStyleName"model-builderInner-Background" ); // NON-NLS
 
         if ( dmo.isGlobalVariablemCall.getVariable() ) ) {
 
             List<MethodInfoinfos = dmo.getMethodInfosForGlobalVariablemCall.getVariable() );
             this. = new String[infos.size()];
             this. = new String[infos.size()];
             int i = 0;
             for ( MethodInfo info : infos ) {
                 this.[i] = info.getName();
                 this.[i] = info.getNameWithParameters();
                 i++;
             }
 
             this. = (Stringdmo.getGlobalVariablemCall.getVariable() );
         } else {
             FactData pattern = (FactDatascenario.getFactTypes().getmCall.getVariable() );
             if ( pattern != null ) {
                 List<StringmethodList = dmo.getMethodNamespattern.getType() );
                  = new String[methodList.size()];
                  = new String[methodList.size()];
                 int i = 0;
                 for ( String methodName : methodList ) {
                     [i] = methodName;
                     [i] = methodName;
                     i++;
                 }
                 this. = pattern.getType();
                this. = true;
            }
        }
        doLayout();
        initWidgetthis. );
    }
    private void doLayout() {
        .clear();
        .setWidget( 0,
                          0,
                          getSetterLabel() );
        DirtyableFlexTable inner = new DirtyableFlexTable();
        int i = 0;
        for ( CallFieldValue val : .getCallFieldValues()) {
            inner.setWidgeti,
                             0,
                             fieldSelectorval ) );
            inner.setWidgeti,
                             1,
                             valueEditorval ) );
            i++;
        }
        .setWidget( 0,
                          1,
                          inner );
        .setWidget( 0,
                          2,
                          new DeleteButton() );
    }
    private Widget getSetterLabel() {
        HorizontalPanel horiz = new HorizontalPanel();
        if ( .getState() == . ) {
            Image edit = ..AddFieldToFact();
            edit.addClickHandlernew ClickHandler() {
                public void onClick(ClickEvent event) {
                    Image w = (Imageevent.getSource();
                    showAddFieldPopupw );
                }
            } );
            horiz.addnew SmallLabel( HumanReadable.getActionDisplayName("call") + " [" + .getVariable() + "]" ) ); // NON-NLS
            horiz.addedit );
        } else {
            horiz.addnew SmallLabel( HumanReadable.getActionDisplayName"call" ) + " [" + .getVariable() + "." + .getMethodName() + "]" ) ); // NON-NLS
        }
        return horiz;
    }
    protected void showAddFieldPopup(Widget w) {
        final FormStylePopup popup = new FormStylePopup(..Wizard(),
                                                         ..ChooseAMethodToInvoke() );
        ListBox box = new ListBox();
        box.addItem"..." );
        for ( int i = 0; i < .i++ ) {
            box.addItem[i],
                         [i] );
        }
        box.setSelectedIndex( 0 );
                            box );
        box.addChangeHandlernew ChangeHandler() {
            public void onChange(ChangeEvent event) {
                .setState. );
                ListBox sourceW = (ListBoxevent.getSource();
                String methodName = sourceW.getItemTextsourceW.getSelectedIndex() );
                String methodNameWithParams = sourceW.getValuesourceW.getSelectedIndex() );
                .setMethodNamemethodName );
                List<StringfieldList = new ArrayList<String>();
                fieldList.addAll.getMethodParams,
                                                       methodNameWithParams ) );
                // String fieldType = completions.getFieldType( variableClass,
                // fieldName );
                int i = 0;
                for ( String fieldParameter : fieldList ) {
                    .addFieldValuenew CallFieldValuemethodName,
                                                             String.valueOfi ),
                                                             fieldParameter ) );
                    i++;
                }
                .renderEditor();
                popup.hide();
            }
        } );
        popup.setPopupPositionw.getAbsoluteLeft(),
                                w.getAbsoluteTop() );
        popup.show();
    }
    private Widget valueEditor(final CallFieldValue val) {
        String type = "";
        if ( .isGlobalVariablethis..getVariable() ) ) {
            type = .getGlobalVariablethis..getVariable() );
        } else {
            Map<StringStringmFactTypes = .getVariableTypes();
            type = mFactTypes.getthis..getVariable() );
        }
        DropDownData enums = .getEnums(
                type,
                val.field,
                this..getCallFieldValuesMap()
        );
        return new MethodParameterCallValueEditorval,
                                                   enums,
                                                   ,
                                                   ,
                                                   val.type,
                                                   new Command() {
                                                       public void execute() {
                                                           makeDirty();
                                                       }
                                                   } );
    }

    
This will return a keyboard listener for field setters, which will obey numeric conventions - it will also allow formulas (a formula is when the first value is a "=" which means it is meant to be taken as the user typed)
    public static KeyPressHandler getNumericFilter(final TextBox box) {
        return new KeyPressHandler() {
            public void onKeyPress(KeyPressEvent event) {
                TextBox w = (TextBoxevent.getSource();
                char c = event.getCharCode();
                if ( Character.isLetterc ) && c != '=' && !(box.getText().startsWith"=" )) ) {
                    ((TextBoxw).cancelKey();
                }
            }
        };
    }
    private Widget fieldSelector(final CallFieldValue val) {
        return new SmallLabelval.type );
    }

    
This returns true if the values being set are on a fact.
    public boolean isBoundFact() {
        return ;
    }
    public boolean isDirty() {
        return .hasDirty();
    }
    protected void onDelete() {
        if ( Window.confirm..AreYouSureToRemoveCallMethod() ) ) {
            .removeFixture );
            .renderEditor();
        }
    }
    class DeleteButton extends ImageButton {
        public DeleteButton() {
            super..DeleteItemSmall(),
                   ..RemoveCallMethod() );
            addClickHandlernew ClickHandler() {
                public void onClick(ClickEvent event) {
                    onDelete();
                }
            } );
        }
    }
New to GrepCode? Check out our FAQ X