/** Pops up the fact selector. */ protected void showFactTypeSelector(final Widget w) { PackageDataModelOracle completions = this.getModeller().getSuggestionCompletions(); final ListBox box = new ListBox(); String[] facts = completions.getFactTypes(); box.addItem(Constants.INSTANCE.Choose()); for (int i = 0; i < facts.length; i++) { box.addItem(facts[i]); } box.setSelectedIndex(0); final FormStylePopup popup = new FormStylePopup(); popup.setTitle(Constants.INSTANCE.NewFactPattern()); popup.addAttribute(Constants.INSTANCE.chooseFactType(), box); box.addChangeHandler( new ChangeHandler() { public void onChange(ChangeEvent event) { pattern.setFactPattern(new FactPattern(box.getItemText(box.getSelectedIndex()))); setModified(true); getModeller().refreshWidget(); popup.hide(); } }); popup.show(); }
protected void showAddFieldPopup(ClickEvent w) { final DataModelOracle completions = this.getModeller().getSuggestionCompletions(); final FormStylePopup popup = new FormStylePopup( GuidedRuleEditorImages508.INSTANCE.Wizard(), Constants.INSTANCE.AddAField()); final ListBox box = new ListBox(); box.addItem("..."); for (int i = 0; i < fieldCompletions.length; i++) { box.addItem(fieldCompletions[i]); } box.setSelectedIndex(0); popup.addAttribute(Constants.INSTANCE.AddField(), box); box.addChangeHandler( new ChangeHandler() { public void onChange(ChangeEvent event) { String fieldName = box.getItemText(box.getSelectedIndex()); String fieldType = completions.getFieldType(variableClass, fieldName); model.addFieldValue(new ActionFieldValue(fieldName, "", fieldType)); setModified(true); getModeller().refreshWidget(); popup.hide(); } }); popup.show(); }
/** Pops up the fact selector. */ protected void showFactTypeSelector(final Widget w) { final ListBox box = new ListBox(); DataModelOracle completions = this.getModeller().getSuggestionCompletions(); String[] facts = completions.getFactTypes(); box.addItem(Constants.INSTANCE.Choose()); for (int i = 0; i < facts.length; i++) { box.addItem(facts[i]); } box.setSelectedIndex(0); final FormStylePopup popup = new FormStylePopup(); popup.setTitle(Constants.INSTANCE.NewFactPattern()); popup.addAttribute(Constants.INSTANCE.chooseFactType(), box); box.addChangeHandler( new ChangeHandler() { public void onChange(ChangeEvent event) { pattern.addFactPattern(new FactPattern(box.getItemText(box.getSelectedIndex()))); setModified(true); getModeller().refreshWidget(); popup.hide(); } }); final Button fromBtn = new Button(HumanReadableConstants.INSTANCE.From()); final Button fromAccumulateBtn = new Button(HumanReadableConstants.INSTANCE.FromAccumulate()); final Button fromCollectBtn = new Button(HumanReadableConstants.INSTANCE.FromCollect()); ClickHandler btnsClickHandler = new ClickHandler() { public void onClick(ClickEvent event) { Widget sender = (Widget) event.getSource(); if (sender == fromBtn) { pattern.addFactPattern(new FromCompositeFactPattern()); } else if (sender == fromAccumulateBtn) { pattern.addFactPattern(new FromAccumulateCompositeFactPattern()); } else if (sender == fromCollectBtn) { pattern.addFactPattern(new FromCollectCompositeFactPattern()); } else { throw new IllegalArgumentException("Unknown sender: " + sender); } setModified(true); getModeller().refreshWidget(); popup.hide(); } }; fromBtn.addClickHandler(btnsClickHandler); fromAccumulateBtn.addClickHandler(btnsClickHandler); fromCollectBtn.addClickHandler(btnsClickHandler); popup.addAttribute("", fromBtn); popup.addAttribute("", fromAccumulateBtn); popup.addAttribute("", fromCollectBtn); popup.show(); }
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 ); }
/** Wraps a RuleModellerWidget with an icon to delete the pattern */ private Widget wrapLHSWidget(final CompositeFactPattern model, int i, RuleModellerWidget w) { DirtyableHorizontalPane horiz = new DirtyableHorizontalPane(); final Image remove = GuidedRuleEditorImages508.INSTANCE.DeleteItemSmall(); remove.setTitle( Constants.INSTANCE.RemoveThisENTIREConditionAndAllTheFieldConstraintsThatBelongToIt()); final int idx = i; remove.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { if (Window.confirm(Constants.INSTANCE.RemoveThisEntireConditionQ())) { if (pattern.removeFactPattern(idx)) { getModeller().refreshWidget(); } } } }); horiz.setWidth("100%"); w.setWidth("100%"); horiz.add(w); if (!(getModeller().lockLHS() || w.isReadOnly())) { horiz.add(remove); } return horiz; }
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); }
protected Widget addRemoveButton(Widget w, ClickHandler listener) { DirtyableHorizontalPane horiz = new DirtyableHorizontalPane(); final Image remove = GuidedRuleEditorImages508.INSTANCE.DeleteItemSmall(); remove.setAltText(Constants.INSTANCE.RemoveThisBlockOfData()); remove.setTitle(Constants.INSTANCE.RemoveThisBlockOfData()); remove.addClickHandler(listener); horiz.setWidth("100%"); w.setWidth("100%"); horiz.add(w); if (!this.readOnly) { horiz.add(remove); } return horiz; }
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); }
protected Widget getCompositeLabel() { ClickHandler click = new ClickHandler() { public void onClick(ClickEvent event) { Widget w = (Widget) event.getSource(); showFactTypeSelector(w); } }; String lbl = HumanReadable.getCEDisplayName(pattern.getType()); if (pattern.getPatterns() == null || pattern.getPatterns().length == 0) { lbl += " <font color='red'>" + Constants.INSTANCE.clickToAddPatterns() + "</font>"; } return new ClickableLabel(lbl + ":", click, !this.readOnly); }
@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; }