Esempio n. 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);
  }