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");

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

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

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

    this.isFactTypeKnown = completions.containsFactType(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 ActionSetFieldWidget(RuleModeller mod, ActionSetField set, Boolean readOnly) {
    super(mod);
    this.model = set;
    this.layout = new DirtyableFlexTable();

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

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

    if (completions.isGlobalVariable(set.variable)) {
      this.fieldCompletions = completions.getFieldCompletionsForGlobalVariable(set.variable);
      this.variableClass = completions.getGlobalVariable(set.variable);
    } else {
      String type = mod.getModel().getBindingType(set.variable);
      if (type != null) {
        this.fieldCompletions =
            completions.getFieldCompletions(FieldAccessorsAndMutators.MUTATOR, type);
        this.variableClass = type;
        this.isBoundFact = true;
      } else {
        ActionInsertFact patternRhs = mod.getModel().getRhsBoundFact(set.variable);
        if (patternRhs != null) {
          this.fieldCompletions =
              completions.getFieldCompletions(
                  FieldAccessorsAndMutators.MUTATOR, patternRhs.factType);
          this.variableClass = patternRhs.factType;
          this.isBoundFact = true;
        }
      }
    }

    if (this.variableClass == null) {
      throw new IllegalStateException("couldn't find type for variable: " + set.variable);
    }

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

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

    doLayout();

    initWidget(this.layout);
  }
Пример #3
0
  public ActionCallMethodWidget(
      RuleModeller mod, EventBus eventBus, ActionCallMethod set, Boolean readOnly) {
    super(mod, eventBus);
    this.model = set;
    this.layout = new DirtyableFlexTable();

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

    SuggestionCompletionEngine completions = this.getModeller().getSuggestionCompletions();
    if (completions.isGlobalVariable(set.variable)) {

      List<MethodInfo> infos = completions.getMethodInfosForGlobalVariable(set.variable);
      if (infos != null) {
        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 = completions.getGlobalVariable(set.variable);

      } else {
        this.fieldCompletionTexts = new String[0];
        this.fieldCompletionValues = new String[0];
        readOnly = true;
      }

    } else {

      FactPattern pattern = mod.getModel().getLHSBoundFact(set.variable);
      if (pattern != null) {
        List<String> methodList = completions.getMethodNames(pattern.getFactType());
        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.getFactType();
        this.isBoundFact = true;

      } else {
        /*
         * if the call method is applied on a bound variable created in
         * the rhs
         */
        ActionInsertFact patternRhs = mod.getModel().getRHSBoundFact(set.variable);
        if (patternRhs != null) {
          List<String> methodList = completions.getMethodNames(patternRhs.factType);
          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 = patternRhs.factType;
          this.isBoundFact = true;
        } else {
          readOnly = true;
        }
      }
    }

    this.isFactTypeKnown = completions.containsFactType(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);
  }