示例#1
0
  private Widget getSetterLabel() {

    ClickHandler clk =
        new ClickHandler() {

          public void onClick(ClickEvent event) {
            // Widget w = (Widget)event.getSource();
            showAddFieldPopup(event);
          }
        };
    String modifyType = "set";
    if (this.model instanceof ActionUpdateField) {
      modifyType = "modify";
    }

    String type = this.getModeller().getModel().getLHSBindingType(model.getVariable());

    String descFact =
        (type != null) ? type + " <b>[" + model.getVariable() + "]</b>" : model.getVariable();

    String sl =
        Constants.INSTANCE.setterLabel(HumanReadable.getActionDisplayName(modifyType), descFact);
    return new ClickableLabel(
        sl,
        clk,
        !this
            .readOnly); // HumanReadable.getActionDisplayName(modifyType) + " value of <b>[" +
                        // model.variable + "]</b>", clk);
  }
示例#2
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 );

  }
示例#3
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);
  }