Search in sources :

Example 16 with SmallLabel

use of org.uberfire.ext.widgets.common.client.common.SmallLabel in project drools-wb by kiegroup.

the class FactPatternWidget method fieldLabel.

/**
 * get the field widget. This may be a simple label, or it may be bound (and
 * show the var name) or a icon to create a binding. It will only show the
 * binding option of showBinding is true.
 */
private Widget fieldLabel(final SingleFieldConstraint con, final HasConstraints hasConstraints, final boolean showBinding, final int padding) {
    HorizontalPanel ab = new HorizontalPanel();
    ab.setStyleName("modeller-field-Label");
    StringBuilder bindingLabel = new StringBuilder();
    if (con.isBound()) {
        bindingLabel.append("<b>[");
        bindingLabel.append(con.getFieldBinding());
        bindingLabel.append("]</b>&nbsp;");
    }
    String fieldName = con.getFieldName();
    bindingLabel.append(fieldName);
    if (bindable && showBinding && !this.readOnly) {
        ClickHandler click = new ClickHandler() {

            public void onClick(final ClickEvent event) {
                // If field name is "this" use parent FactPattern type otherwise we can use the Constraint's field type
                String fieldName = con.getFieldName();
                if (DataType.TYPE_THIS.equals(fieldName)) {
                    getConnectives().getDataModelOracle().getFieldCompletions(pattern.getFactType(), new Callback<ModelField[]>() {

                        @Override
                        public void callback(final ModelField[] fields) {
                            popupCreator.showBindFieldPopup(pattern, con, fields, popupCreator);
                        }
                    });
                } else {
                    getConnectives().getDataModelOracle().getFieldCompletions(con.getFieldType(), new Callback<ModelField[]>() {

                        @Override
                        public void callback(final ModelField[] fields) {
                            popupCreator.showBindFieldPopup(pattern, con, fields, popupCreator);
                        }
                    });
                }
            }
        };
        ClickableLabel cl = new ClickableLabel(bindingLabel.toString(), click, !this.readOnly);
        DOM.setStyleAttribute(cl.getElement(), "marginLeft", "" + padding + "pt");
        ab.add(cl);
    } else {
        ab.add(new SmallLabel(bindingLabel.toString()));
    }
    return ab;
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel)

Example 17 with SmallLabel

use of org.uberfire.ext.widgets.common.client.common.SmallLabel in project drools-wb by kiegroup.

the class FactPatternWidget method predicateEditor.

/**
 * This provides an inline formula editor, not unlike a spreadsheet does.
 */
private Widget predicateEditor(final SingleFieldConstraint c) {
    HorizontalPanel pred = new HorizontalPanel();
    pred.setWidth("100%");
    Image img = new Image(GuidedRuleEditorResources.INSTANCE.images().functionAssets());
    img.setTitle(GuidedRuleEditorResources.CONSTANTS.FormulaBooleanTip());
    pred.add(img);
    if (c.getValue() == null) {
        c.setValue("");
    }
    final TextBox box = new TextBox();
    box.setText(c.getValue());
    if (!this.readOnly) {
        box.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                setModified(true);
                c.setValue(box.getText());
            }
        });
        box.setWidth("100%");
        pred.add(box);
    } else {
        pred.add(new SmallLabel(c.getValue()));
    }
    return pred;
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ExpressionTypeChangeEvent(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ExpressionTypeChangeHandler(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeHandler) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) TextBox(org.gwtbootstrap3.client.ui.TextBox) Image(com.google.gwt.user.client.ui.Image)

Example 18 with SmallLabel

use of org.uberfire.ext.widgets.common.client.common.SmallLabel in project drools-wb by kiegroup.

the class ActionValueEditor method showTypeChoice.

protected void showTypeChoice() {
    final FormStylePopup form = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.FieldValue());
    Button lit = new Button(GuidedRuleEditorResources.CONSTANTS.LiteralValue());
    lit.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            value.setNature(FieldNatureType.TYPE_LITERAL);
            value.setValue("");
            doTypeChosen(form);
        }
    });
    form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.LiteralValue(), GuidedRuleEditorResources.CONSTANTS.Literal(), GuidedRuleEditorResources.CONSTANTS.ALiteralValueMeansTheValueAsTypedInIeItsNotACalculation(), lit);
    if (modeller.isTemplate()) {
        Button templateButton = new Button(GuidedRuleEditorResources.CONSTANTS.TemplateKey());
        templateButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                value.setNature(FieldNatureType.TYPE_TEMPLATE);
                value.setValue("");
                doTypeChosen(form);
            }
        });
        form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.TemplateKey(), GuidedRuleEditorResources.CONSTANTS.TemplateKey(), GuidedRuleEditorResources.CONSTANTS.TemplateKeyTip(), templateButton);
    }
    form.addRow(new HTML("<hr/>"));
    form.addRow(new SmallLabel(GuidedRuleEditorResources.CONSTANTS.AdvancedSection()));
    Button formula = new Button(GuidedRuleEditorResources.CONSTANTS.Formula());
    formula.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            value.setNature(FieldNatureType.TYPE_FORMULA);
            doTypeChosen(form);
        }
    });
    // If there is a bound Facts or Fields that are of the same type as the current variable type, then show a button
    List<String> bindings = getApplicableBindings();
    if (bindings.size() > 0) {
        Button variable = new Button(GuidedRuleEditorResources.CONSTANTS.BoundVariable());
        form.addAttribute(GuidedRuleEditorResources.CONSTANTS.BoundVariable() + ":", variable);
        variable.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                value.setNature(FieldNatureType.TYPE_VARIABLE);
                value.setValue("=");
                doTypeChosen(form);
            }
        });
    }
    form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.Formula(), GuidedRuleEditorResources.CONSTANTS.Formula(), GuidedRuleEditorResources.CONSTANTS.FormulaTip(), formula);
    form.show();
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Button(org.gwtbootstrap3.client.ui.Button) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) HTML(com.google.gwt.user.client.ui.HTML)

Example 19 with SmallLabel

use of org.uberfire.ext.widgets.common.client.common.SmallLabel in project drools-wb by kiegroup.

the class ActionValueEditor method formulaEditor.

/**
 * An editor for formula
 * @return
 */
private Widget formulaEditor() {
    if (this.readOnly) {
        return new SmallLabel(assertValue());
    }
    final TextBox box = new TextBox();
    box.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            value.setValue(event.getValue());
            executeOnChangeCommand();
        }
    });
    // FireEvents as the box could assume a default value
    box.setValue(assertValue(), true);
    attachDisplayLengthHandler(box);
    return box;
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) TextBox(org.gwtbootstrap3.client.ui.TextBox)

Example 20 with SmallLabel

use of org.uberfire.ext.widgets.common.client.common.SmallLabel in project drools-wb by kiegroup.

the class ActionValueEditor method boundVariable.

private Widget boundVariable() {
    // If there is a bound variable that is the same type of the current variable type, then display a list
    ListBox listVariable = new ListBox();
    listVariable.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
    List<String> bindings = getApplicableBindings();
    for (String v : bindings) {
        listVariable.addItem(v);
    }
    // Pre-select applicable item
    if (value.getValue().equals("=")) {
        listVariable.setSelectedIndex(0);
    } else {
        for (int i = 0; i < listVariable.getItemCount(); i++) {
            if (listVariable.getItemText(i).equals(value.getValue().substring(1))) {
                listVariable.setSelectedIndex(i);
            }
        }
    }
    // Add event handler
    if (listVariable.getItemCount() > 0) {
        listVariable.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                ListBox w = (ListBox) event.getSource();
                value.setValue("=" + w.getValue(w.getSelectedIndex()));
                executeOnChangeCommand();
                refresh();
            }
        });
    }
    if (this.readOnly) {
        return new SmallLabel(listVariable.getItemText(listVariable.getSelectedIndex()));
    }
    return listVariable;
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ListBox(org.gwtbootstrap3.client.ui.ListBox) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint)

Aggregations

SmallLabel (org.uberfire.ext.widgets.common.client.common.SmallLabel)32 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)13 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)13 Button (org.gwtbootstrap3.client.ui.Button)12 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)9 HTML (com.google.gwt.user.client.ui.HTML)8 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)7 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)7 Image (com.google.gwt.user.client.ui.Image)7 FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)7 ListBox (org.gwtbootstrap3.client.ui.ListBox)6 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)5 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)5 TextBox (org.gwtbootstrap3.client.ui.TextBox)5 InfoPopup (org.uberfire.ext.widgets.common.client.common.InfoPopup)5 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)4 Widget (com.google.gwt.user.client.ui.Widget)3 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)3 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)3 ClickableLabel (org.uberfire.ext.widgets.common.client.common.ClickableLabel)3