Beispiel #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);
  }
  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);
  }