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;
 
This button gives a choice of modifying data, based on the positional context.
 
 public class NewDataButton extends TestScenarioButton {
 
     private final ExecutionTrace currentEx;
 
     public NewDataButton(final ExecutionTrace previousEx,
                          final Scenario scenario,
                          final ExecutionTrace currentEx,
                          ScenarioParentWidget scenarioWidget,
                          PackageDataModelOracle dmo) {
         super..NewItem(),
                 previousEx,
                 scenario,
                 scenarioWidget,
                 dmo);
 
         this. = currentEx;
     }
 
     @Override
     protected TestScenarioButtonPopup getPopUp() {
         return new NewInputPopup();
     }
 
     class NewInputPopup extends TestScenarioButtonPopup {
         public NewInputPopup() {
             super(..RuleAsset(),
                     ..NewInput());
 
                     new InsertFactPanel());
 
             List<StringvarsInScope = .getFactNamesInScope(,
                     false);
             //now we do modifies & retracts
             if (varsInScope.size() > 0) {
                         new ModifyFactPanel(varsInScope));
 
                         new ExtractFactPanel(varsInScope));
 
             }
 
                     new ActivateRuleFlowPanel());
         }
 
         class ActivateRuleFlowPanel extends BasePanel<TextBox> {
 
             @Override
             public TextBox getWidget() {
                 return new TextBox();
             }
 
             @Override
             public Fixture getFixture() {
                return new ActivateRuleFlowGroup(.getText());
            }
        }
        class ExtractFactPanel extends ListBoxBasePanel {
            public ExtractFactPanel(List<StringlistItems) {
                super(listItems);
            }
            @Override
            public Fixture getFixture() {
                String factName = .getItemText(.getSelectedIndex());
                return new RetractFact(factName);
            }
        }
        class ModifyFactPanel extends ListBoxBasePanel {
            public ModifyFactPanel(List<StringlistItems) {
                super(listItems);
            }
            @Override
            public Fixture getFixture() {
                String factName = .getItemText(.getSelectedIndex());
                String type = .getVariableTypes().get(factName);
                return new FactData(type,
                        factName,
                        true);
            }
        }
        class InsertFactPanel extends ListBoxBasePanel {
            TextBox factNameTextBox;
            public InsertFactPanel() {
                super(.getFactTypes());
            }
            @Override
            protected void addAddButtonClickHandler() {
                .addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        String factName = ("" + .getText()).trim();
                        if (factName.equals("") || .getText().indexOf(' ') > -1) {
                            Window.alert(..YouMustEnterAValidFactName());
                        } else {
                            if (.isFactNameReserved(factName)) {
                                Window.alert(..TheFactName0IsAlreadyInUsePleaseChooseAnotherName(factName));
                            } else {
                                .insertBetween(,
                                        getFixture());
                                .renderEditor();
                                hide();
                            }
                        }
                    }
                });
            }
            @Override
            protected void initWidgets() {
                 = new TextBox();
                .setVisibleLength(5);
                add();
                add(new SmallLabel(..FactName()));
                add();
                add();
            }
            @Override
            public Fixture getFixture() {
                String factType = .getItemText(.getSelectedIndex());
                FactData factData = new FactData(
                        factType,
                        .getText(),
                        false);
                //Create new Field objects for new Fixture based upon the first existing of the same data-type
                //Only the "first" existing of the same data-type is checked as second, third etc should have been
                //based upon the first if they were all created after this fix for GUVNOR-1139 was implemented.
                List<FactDataexistingFactData = .getFactTypesToFactData().get(factType);
                if (existingFactData != null && existingFactData.size() > 0) {
                    for (Field field : existingFactData.get(0).getFieldData()) {
                        factData.getFieldData().add(
                                new FieldPlaceHolder(field.getName()));
                    }
                }
                return factData;
            }
        }
    }
New to GrepCode? Check out our FAQ X