예제 #1
0
  public ActionSetFieldWidget(
      RuleModeller mod, EventBus eventBus, ActionSetField set, Boolean readOnly) {
    super(mod, eventBus);
    this.model = set;
    this.layout = new DirtyableFlexTable();

    layout.setStyleName("model-builderInner-Background");

    DataModelOracle completions = this.getModeller().getSuggestionCompletions();

    if (completions.isGlobalVariable(set.getVariable())) {
      this.fieldCompletions = completions.getFieldCompletionsForGlobalVariable(set.getVariable());
      this.variableClass = completions.getGlobalVariable(set.getVariable());
    } else {
      String type = mod.getModel().getLHSBindingType(set.getVariable());
      if (type != null) {
        this.fieldCompletions =
            completions.getFieldCompletions(FieldAccessorsAndMutators.MUTATOR, type);
        this.variableClass = type;
        this.isBoundFact = true;
      } else {
        ActionInsertFact patternRhs = mod.getModel().getRHSBoundFact(set.getVariable());
        if (patternRhs != null) {
          this.fieldCompletions =
              completions.getFieldCompletions(
                  FieldAccessorsAndMutators.MUTATOR, patternRhs.getFactType());
          this.variableClass = patternRhs.getFactType();
          this.isBoundFact = true;
        }
      }
    }

    if (this.variableClass == null) {
      readOnly = true;
      ErrorPopup.showMessage(Constants.INSTANCE.CouldNotFindTheTypeForVariable0(set.getVariable()));
    }

    this.isFactTypeKnown = completions.isFactTypeRecognized(this.variableClass);
    if (readOnly == null) {
      this.readOnly = !this.isFactTypeKnown;
    } else {
      this.readOnly = readOnly;
    }

    if (this.readOnly) {
      layout.addStyleName("editor-disabled-widget");
    }

    doLayout();

    initWidget(this.layout);
  }
  @Override
  protected Widget getCompositeLabel() {

    ClickHandler click =
        new ClickHandler() {

          public void onClick(ClickEvent event) {
            Widget w = (Widget) event.getSource();
            showFactTypeSelector(w);
          }
        };
    String lbl =
        "<div class='form-field'>" + HumanReadable.getCEDisplayName("from entry-point") + "</div>";

    DirtyableFlexTable panel = new DirtyableFlexTable();

    int r = 0;

    if (pattern.getFactPattern() == null) {
      panel.setWidget(
          r,
          0,
          new ClickableLabel(
              "<br> <font color='red'>" + Constants.INSTANCE.clickToAddPatterns() + "</font>",
              click,
              !this.readOnly));
      r++;
    }

    panel.setWidget(r, 0, new HTML(lbl));

    this.txtEntryPoint = new TextBox();
    this.txtEntryPoint.setText(getFromEntryPointPattern().getEntryPointName());
    this.txtEntryPoint.addChangeHandler(
        new ChangeHandler() {

          public void onChange(ChangeEvent event) {
            getFromEntryPointPattern().setEntryPointName(txtEntryPoint.getText());
            setModified(true);
          }
        });
    panel.setWidget(r, 1, this.txtEntryPoint);

    return panel;
  }
  protected Widget getCompositeLabel() {

    ClickHandler click =
        new ClickHandler() {

          public void onClick(ClickEvent event) {
            Widget w = (Widget) event.getSource();
            showFactTypeSelector(w);
          }
        };
    String lbl = "<div class='form-field'>" + HumanReadable.getCEDisplayName("from") + "</div>";

    DirtyableFlexTable panel = new DirtyableFlexTable();

    int r = 0;

    if (pattern.getFactPattern() == null) {
      panel.setWidget(
          r,
          0,
          new ClickableLabel(
              "<br> <font color='red'>" + Constants.INSTANCE.clickToAddPatterns() + "</font>",
              click,
              !this.readOnly));
      r++;
    }

    panel.setWidget(r, 0, new HTML(lbl));
    ExpressionBuilder expressionBuilder =
        new ExpressionBuilder(
            this.getModeller(), this.getEventBus(), this.pattern.getExpression(), this.readOnly);
    expressionBuilder.addOnModifiedCommand(
        new Command() {
          public void execute() {
            setModified(true);
          }
        });
    panel.setWidget(r, 1, expressionBuilder);

    return panel;
  }
예제 #4
0
  public CallMethodWidget(
      String factName,
      ScenarioParentWidget parent,
      Scenario scenario,
      CallMethod mCall,
      ExecutionTrace executionTrace,
      PackageDataModelOracle dmo) {
    super();
    this.factName = factName;
    this.parent = parent;
    this.scenario = scenario;
    this.mCall = mCall;
    this.executionTrace = executionTrace;
    this.dmo = dmo;

    this.layout = new DirtyableFlexTable();

    layout.setStyleName("model-builderInner-Background"); // NON-NLS

    if (dmo.isGlobalVariable(mCall.getVariable())) {

      List<MethodInfo> infos = dmo.getMethodInfosForGlobalVariable(mCall.getVariable());
      this.fieldCompletionTexts = new String[infos.size()];
      this.fieldCompletionValues = new String[infos.size()];
      int i = 0;
      for (MethodInfo info : infos) {
        this.fieldCompletionTexts[i] = info.getName();
        this.fieldCompletionValues[i] = info.getNameWithParameters();
        i++;
      }

      this.variableClass = (String) dmo.getGlobalVariable(mCall.getVariable());
    } else {
      FactData pattern = (FactData) scenario.getFactTypes().get(mCall.getVariable());
      if (pattern != null) {
        List<String> methodList = dmo.getMethodNames(pattern.getType());
        fieldCompletionTexts = new String[methodList.size()];
        fieldCompletionValues = new String[methodList.size()];
        int i = 0;
        for (String methodName : methodList) {
          fieldCompletionTexts[i] = methodName;
          fieldCompletionValues[i] = methodName;
          i++;
        }
        this.variableClass = pattern.getType();
        this.isBoundFact = true;
      }
    }

    doLayout();
    initWidget(this.layout);
  }
예제 #5
0
  private void doLayout() {
    layout.clear();
    layout.setWidget(0, 0, getSetterLabel());
    DirtyableFlexTable inner = new DirtyableFlexTable();
    int i = 0;
    for (CallFieldValue val : mCall.getCallFieldValues()) {

      inner.setWidget(i, 0, fieldSelector(val));
      inner.setWidget(i, 1, valueEditor(val));
      i++;
    }
    layout.setWidget(0, 1, inner);
    layout.setWidget(0, 2, new DeleteButton());
  }
예제 #6
0
  private void doLayout() {
    layout.clear();

    for (int i = 0; i < model.getFieldValues().length; i++) {
      ActionFieldValue val = model.getFieldValues()[i];

      layout.setWidget(i, 0, getSetterLabel());
      layout.setWidget(i, 1, fieldSelector(val));
      layout.setWidget(i, 2, valueEditor(val));
      final int idx = i;
      Image remove = GuidedRuleEditorImages508.INSTANCE.DeleteItemSmall();
      remove.addClickHandler(
          new ClickHandler() {

            public void onClick(ClickEvent event) {
              if (Window.confirm(Constants.INSTANCE.RemoveThisItem())) {
                model.removeField(idx);
                setModified(true);
                getModeller().refreshWidget();

                // Signal possible change in Template variables
                TemplateVariablesChangedEvent tvce =
                    new TemplateVariablesChangedEvent(getModeller().getModel());
                getEventBus().fireEventFromSource(tvce, getModeller().getModel());
              }
            }
          });
      if (!this.readOnly) {
        layout.setWidget(i, 3, remove);
      }
    }

    if (model.getFieldValues().length == 0) {
      HorizontalPanel h = new HorizontalPanel();
      h.add(getSetterLabel());
      if (!this.readOnly) {
        Image image = GuidedRuleEditorImages508.INSTANCE.Edit();
        image.setAltText(Constants.INSTANCE.AddFirstNewField());
        image.setTitle(Constants.INSTANCE.AddFirstNewField());
        image.addClickHandler(
            new ClickHandler() {

              public void onClick(ClickEvent sender) {
                showAddFieldPopup(sender);
              }
            });
        h.add(image);
      }
      layout.setWidget(0, 0, h);
    }

    // layout.setWidget( 0, 1, inner );

  }
예제 #7
0
  public CompositeFactPatternWidget(
      RuleModeller modeller, EventBus eventBus, CompositeFactPattern pattern, Boolean readOnly) {
    super(modeller, eventBus);
    this.completions = modeller.getSuggestionCompletions();
    this.pattern = pattern;

    this.layout = new DirtyableFlexTable();
    this.layout.setStyleName("model-builderInner-Background");

    if (readOnly != null) {
      this.readOnly = readOnly;
      this.isFactTypeKnown = true;
    } else {
      this.readOnly = false;
      this.isFactTypeKnown = true;
      if (this.pattern != null && this.pattern.getPatterns() != null) {
        IFactPattern[] patterns = this.pattern.getPatterns();
        for (int i = 0; i < patterns.length; i++) {
          IFactPattern p = patterns[i];

          // for empty FROM / ACCUMULATE / COLLECT patterns
          if (p.getFactType() == null) {
            continue;
          }

          if (!completions.isFactTypeRecognized(p.getFactType())) {
            this.readOnly = true;
            this.isFactTypeKnown = false;
            break;
          }
        }
      }
    }

    if (this.readOnly) {
      layout.addStyleName("editor-disabled-widget");
    }

    doLayout();
    initWidget(layout);
  }
예제 #8
0
 public boolean isDirty() {
   return layout.hasDirty();
 }
예제 #9
0
  public CallMethodWidget(
      final String factName,
      final ScenarioParentWidget parent,
      final Scenario scenario,
      final CallMethod mCall,
      final ExecutionTrace executionTrace,
      final AsyncPackageDataModelOracle oracle) {
    super();
    this.factName = factName;
    this.parent = parent;
    this.scenario = scenario;
    this.mCall = mCall;
    this.executionTrace = executionTrace;
    this.oracle = oracle;

    this.layout = new DirtyableFlexTable();

    layout.setStyleName("model-builderInner-Background"); // NON-NLS

    if (this.oracle.isGlobalVariable(mCall.getVariable())) {

      this.oracle.getMethodInfosForGlobalVariable(
          mCall.getVariable(),
          new Callback<List<MethodInfo>>() {
            @Override
            public void callback(final List<MethodInfo> infos) {
              CallMethodWidget.this.fieldCompletionTexts = new String[infos.size()];
              CallMethodWidget.this.fieldCompletionValues = new String[infos.size()];
              int i = 0;
              for (MethodInfo info : infos) {
                CallMethodWidget.this.fieldCompletionTexts[i] = info.getName();
                CallMethodWidget.this.fieldCompletionValues[i] = info.getNameWithParameters();
                i++;
              }

              CallMethodWidget.this.variableClass =
                  (String) CallMethodWidget.this.oracle.getGlobalVariable(mCall.getVariable());
            }
          });
    } else {

      final FactData pattern = (FactData) scenario.getFactTypes().get(mCall.getVariable());
      if (pattern != null) {
        this.oracle.getMethodInfos(
            pattern.getType(),
            new Callback<List<MethodInfo>>() {
              @Override
              public void callback(final List<MethodInfo> methodInfos) {
                CallMethodWidget.this.fieldCompletionTexts = new String[methodInfos.size()];
                CallMethodWidget.this.fieldCompletionValues = new String[methodInfos.size()];
                int i = 0;
                for (MethodInfo methodInfo : methodInfos) {
                  CallMethodWidget.this.fieldCompletionTexts[i] = methodInfo.getName();
                  CallMethodWidget.this.fieldCompletionValues[i] =
                      methodInfo.getNameWithParameters();
                  i++;
                }
                CallMethodWidget.this.variableClass = pattern.getType();
                CallMethodWidget.this.isBoundFact = true;
              }
            });
      }
    }

    doLayout();
    initWidget(this.layout);
  }
예제 #10
0
  public void renderEditor() {

    if (this.layout.getWidgetCount() == 2) {
      this.layout.remove(1);
    }

    DirtyableFlexTable editorLayout = scenarioWidgetComponentCreator.createDirtyableFlexTable();
    this.layout.add(editorLayout);
    ScenarioHelper scenarioHelper = new ScenarioHelper();

    List<Fixture> fixtures = scenarioHelper.lumpyMap(getScenario().getFixtures());
    List<ExecutionTrace> listExecutionTrace = scenarioHelper.getExecutionTraceFor(fixtures);

    int layoutRow = 1;
    int executionTraceLine = 0;
    ExecutionTrace previousExecutionTrace = null;
    for (final Fixture fixture : fixtures) {
      if (fixture instanceof ExecutionTrace) {
        ExecutionTrace currentExecutionTrace = (ExecutionTrace) fixture;
        createWidgetForEditorLayout(
            editorLayout,
            layoutRow,
            0,
            scenarioWidgetComponentCreator.createExpectPanel(currentExecutionTrace));

        executionTraceLine++;
        if (executionTraceLine >= listExecutionTrace.size()) {
          executionTraceLine = listExecutionTrace.size() - 1;
        }
        createWidgetForEditorLayout(
            editorLayout,
            layoutRow,
            1,
            scenarioWidgetComponentCreator.createExecutionWidget(currentExecutionTrace));
        editorLayout.setHorizontalAlignmentForFlexCellFormatter(
            layoutRow, 2, HasHorizontalAlignment.ALIGN_LEFT);

        previousExecutionTrace = currentExecutionTrace;

      } else if (fixture instanceof FixturesMap) {
        createWidgetForEditorLayout(
            editorLayout,
            layoutRow,
            0,
            scenarioWidgetComponentCreator.createGivenLabelButton(
                listExecutionTrace, executionTraceLine, previousExecutionTrace));
        layoutRow++;
        createWidgetForEditorLayout(
            editorLayout,
            layoutRow,
            1,
            scenarioWidgetComponentCreator.createGivenPanel(
                listExecutionTrace, executionTraceLine, (FixturesMap) fixture));
      } else if (fixture instanceof CallFixtureMap) {
        createWidgetForEditorLayout(
            editorLayout,
            layoutRow,
            0,
            scenarioWidgetComponentCreator.createCallMethodLabelButton(
                listExecutionTrace, executionTraceLine, previousExecutionTrace));
        layoutRow++;
        createWidgetForEditorLayout(
            editorLayout,
            layoutRow,
            1,
            scenarioWidgetComponentCreator.createCallMethodOnGivenPanel(
                listExecutionTrace, executionTraceLine, (CallFixtureMap) fixture));
      } else {
        FixtureList fixturesList = (FixtureList) fixture;
        Fixture first = fixturesList.get(0);

        if (first instanceof VerifyFact) {
          createWidgetForEditorLayout(
              editorLayout,
              layoutRow,
              1,
              scenarioWidgetComponentCreator.createVerifyFactsPanel(
                  listExecutionTrace, executionTraceLine, fixturesList));
        } else if (first instanceof VerifyRuleFired) {
          createWidgetForEditorLayout(
              editorLayout,
              layoutRow,
              1,
              scenarioWidgetComponentCreator.createVerifyRulesFiredWidget(fixturesList));
        }
      }
      layoutRow++;
    }

    // add more execution sections.
    createWidgetForEditorLayout(
        editorLayout, layoutRow, 0, scenarioWidgetComponentCreator.createAddExecuteButton());
    layoutRow++;
    createWidgetForEditorLayout(
        editorLayout, layoutRow, 0, scenarioWidgetComponentCreator.createSmallLabel());

    // config section
    createWidgetForEditorLayout(
        editorLayout, layoutRow, 1, scenarioWidgetComponentCreator.createConfigWidget());

    layoutRow++;

    // global section
    HorizontalPanel horizontalPanel = scenarioWidgetComponentCreator.createHorizontalPanel();
    createWidgetForEditorLayout(editorLayout, layoutRow, 0, horizontalPanel);

    createWidgetForEditorLayout(
        editorLayout,
        layoutRow,
        1,
        scenarioWidgetComponentCreator.createGlobalPanel(scenarioHelper, previousExecutionTrace));
  }
예제 #11
0
 private void createWidgetForEditorLayout(
     DirtyableFlexTable editorLayout, int layoutRow, int layoutColumn, Widget widget) {
   editorLayout.setWidget(layoutRow, layoutColumn, widget);
 }