Search in sources :

Example 16 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.

the class EditActionUpdatePopup method initialiseBoundTypes.

private void initialiseBoundTypes() {
    // Extract all bindings available on the path to the root
    final Map<String, TypeNode> bindings = new TreeMap<String, TypeNode>();
    Node parent = clone.getParent();
    while (parent != null) {
        if (parent instanceof TypeNode) {
            final TypeNode tn = (TypeNode) parent;
            if (tn.isBound()) {
                bindings.put(tn.getBinding(), tn);
            }
        }
        parent = parent.getParent();
    }
    bindingListBox.setEnabled(!bindings.isEmpty());
    if (bindings.isEmpty()) {
        bindingListBox.addItem(GuidedDecisionTreeConstants.INSTANCE.noBindings());
        return;
    }
    // Add them to the ListBox
    int selectedIndex = 0;
    final BoundNode boundNode = clone.getBoundNode();
    for (String binding : bindings.keySet()) {
        bindingListBox.addItem(binding);
        if (boundNode != null) {
            if (binding.equals(boundNode.getBinding())) {
                selectedIndex = bindingListBox.getItemCount() - 1;
            }
        }
    }
    // Attach event handler before we set the selected index in case we're selecting the first item
    bindingListBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(final ChangeEvent event) {
            final String binding = bindingListBox.getItemText(bindingListBox.getSelectedIndex());
            clone.setBoundNode(bindings.get(binding));
            clone.getFieldValues().clear();
            initialiseFieldValues();
        }
    });
    bindingListBox.setSelectedIndex(selectedIndex);
}
Also used : 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) BoundNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) BoundNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode) TreeMap(java.util.TreeMap)

Example 17 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.

the class CEPWindowOperatorsDropdown method getDropDown.

// Actual drop-down
private Widget getDropDown() {
    String selected = "";
    String selectedText = "";
    box = new ListBox();
    box.setEnabled(!isReadOnly);
    box.addItem(HumanReadableConstants.INSTANCE.noCEPWindow(), "");
    for (int i = 0; i < operators.size(); i++) {
        String op = operators.get(i);
        box.addItem(HumanReadable.getOperatorDisplayName(op), op);
        if (op.equals(hcw.getWindow().getOperator())) {
            selected = op;
            selectedText = HumanReadable.getOperatorDisplayName(op);
            box.setSelectedIndex(i + 1);
        }
    }
    selectItem(hcw.getWindow().getOperator());
    // Fire event to ensure parent Widgets correct their state depending on selection
    final HasValueChangeHandlers<OperatorSelection> source = this;
    final OperatorSelection selection = new OperatorSelection(selected, selectedText);
    Scheduler.get().scheduleFinally(new Command() {

        public void execute() {
            operatorChanged(selection);
            ValueChangeEvent.fire(source, selection);
        }
    });
    // Signal parent Widget whenever a change happens
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            String selected = box.getValue(box.getSelectedIndex());
            String selectedText = box.getItemText(box.getSelectedIndex());
            OperatorSelection selection = new OperatorSelection(selected, selectedText);
            operatorChanged(selection);
            ValueChangeEvent.fire(source, selection);
        }
    });
    return box;
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) Command(com.google.gwt.user.client.Command) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 18 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.

the class ConstraintValueEditor method variableEditor.

private Widget variableEditor() {
    if (this.readOnly) {
        return new SmallLabel(this.constraint.getValue());
    }
    final ListBox box = new ListBox();
    box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
    List<String> bindingsInScope = this.model.getBoundVariablesInScope(this.constraint);
    for (String var : bindingsInScope) {
        final String binding = var;
        helper.isApplicableBindingsInScope(var, new Callback<Boolean>() {

            @Override
            public void callback(final Boolean result) {
                if (Boolean.TRUE.equals(result)) {
                    box.addItem(binding);
                    if (ConstraintValueEditor.this.constraint.getValue() != null && ConstraintValueEditor.this.constraint.getValue().equals(binding)) {
                        box.setSelectedIndex(box.getItemCount() - 1);
                    }
                }
            }
        });
    }
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            executeOnValueChangeCommand();
            int selectedIndex = box.getSelectedIndex();
            if (selectedIndex > 0) {
                constraint.setValue(box.getItemText(selectedIndex));
            } else {
                constraint.setValue(null);
            }
        }
    });
    return box;
}
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)

Example 19 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.

the class RuleAttributeWidget method getEditorWidget.

private Widget getEditorWidget(final RuleAttribute at, final int idx, final boolean isReadOnly) {
    Widget editor = null;
    final String attributeName = at.getAttributeName();
    if (attributeName.equals(RULEFLOW_GROUP_ATTR) || attributeName.equals(AGENDA_GROUP_ATTR) || attributeName.equals(ACTIVATION_GROUP_ATTR) || attributeName.equals(TIMER_ATTR) || attributeName.equals(CALENDARS_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    at.setValue(tb.getValue());
                }
            });
        }
        tb.setValue(at.getValue());
        editor = tb;
    } else if (attributeName.equals(SALIENCE_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_INTEGER);
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    at.setValue(tb.getValue());
                }
            });
        }
        tb.setValue(at.getValue());
        editor = tb;
    } else if (attributeName.equals(DURATION_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_LONG);
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    at.setValue(tb.getValue());
                }
            });
        }
        tb.setValue(at.getValue());
        editor = tb;
    } else if (attributeName.equals(NO_LOOP_ATTR) || attributeName.equals(LOCK_ON_ACTIVE_ATTR) || attributeName.equals(AUTO_FOCUS_ATTR) || attributeName.equals(ENABLED_ATTR)) {
        editor = checkBoxEditor(at, isReadOnly);
    } else if (attributeName.equals(DATE_EFFECTIVE_ATTR) || attributeName.equals(DATE_EXPIRES_ATTR)) {
        if (isReadOnly) {
            final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
            tb.setValue(at.getValue());
            tb.setEnabled(false);
        } else {
            final DatePicker datePicker = new DatePicker(false);
            // Wire up update handler
            datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {

                @Override
                public void onValueChange(final ValueChangeEvent<Date> event) {
                    final Date date = datePicker.getValue();
                    final String sDate = (date == null ? null : DATE_FORMATTER.format(datePicker.getValue()));
                    at.setValue(sDate);
                }
            });
            datePicker.setFormat(DATE_FORMAT);
            datePicker.setValue(assertDateValue(at));
            editor = datePicker;
        }
    } else if (attributeName.equals(DIALECT_ATTR)) {
        final ListBox lb = new ListBox();
        lb.addItem(DIALECTS[0]);
        lb.addItem(DIALECTS[1]);
        lb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            lb.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(ChangeEvent event) {
                    final int selectedIndex = lb.getSelectedIndex();
                    if (selectedIndex < 0) {
                        return;
                    }
                    at.setValue(lb.getValue(selectedIndex));
                }
            });
        }
        if (at.getValue() == null || at.getValue().isEmpty()) {
            lb.setSelectedIndex(1);
            at.setValue(DIALECTS[1]);
        } else if (at.getValue().equals(DIALECTS[0])) {
            lb.setSelectedIndex(0);
        } else if (at.getValue().equals(DIALECTS[1])) {
            lb.setSelectedIndex(1);
        } else {
            lb.setSelectedIndex(1);
            at.setValue(DIALECTS[1]);
        }
        editor = lb;
    }
    DirtyableHorizontalPane horiz = new DirtyableHorizontalPane();
    if (editor != null) {
        horiz.add(editor);
        if (!isReadOnly) {
            horiz.add(getRemoveIcon(idx));
        }
    }
    return horiz;
}
Also used : IsWidget(com.google.gwt.user.client.ui.IsWidget) Widget(com.google.gwt.user.client.ui.Widget) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) TextBox(org.gwtbootstrap3.client.ui.TextBox) Date(java.util.Date) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) 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) DirtyableHorizontalPane(org.uberfire.ext.widgets.common.client.common.DirtyableHorizontalPane) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 20 with ChangeHandler

use of com.google.gwt.event.dom.client.ChangeHandler in project drools-wb by kiegroup.

the class PopupCreator method showPatternPopup.

/**
 * This shows a popup allowing you to add field constraints to a pattern
 * (its a popup).
 */
public void showPatternPopup(final FactPattern fp, final SingleFieldConstraint con, final boolean isNested) {
    final String factType = getFactType(fp, con);
    String title = (con == null) ? GuidedRuleEditorResources.CONSTANTS.ModifyConstraintsFor0(fp.getFactType()) : GuidedRuleEditorResources.CONSTANTS.AddSubFieldConstraint();
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), title);
    final ListBox box = new ListBox();
    box.addItem("...");
    this.oracle.getFieldCompletions(factType, FieldAccessorsAndMutators.ACCESSOR, new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            for (int i = 0; i < fields.length; i++) {
                // You can't use "this" in a nested accessor
                final String fieldName = fields[i].getName();
                if (!isNested || !fieldName.equals(DataType.TYPE_THIS)) {
                    box.addItem(fieldName);
                }
            }
        }
    });
    box.setSelectedIndex(0);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            String fieldName = box.getItemText(box.getSelectedIndex());
            if ("...".equals(fieldName)) {
                return;
            }
            String fieldType = oracle.getFieldType(factType, fieldName);
            fp.addConstraint(new SingleFieldConstraint(factType, fieldName, fieldType, con));
            modeller.refreshWidget();
            popup.hide();
        }
    });
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.AddARestrictionOnAField(), box);
    final ListBox composites = new ListBox();
    composites.addItem("...");
    composites.addItem(GuidedRuleEditorResources.CONSTANTS.AllOfAnd(), CompositeFieldConstraint.COMPOSITE_TYPE_AND);
    composites.addItem(GuidedRuleEditorResources.CONSTANTS.AnyOfOr(), CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    composites.setSelectedIndex(0);
    composites.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            CompositeFieldConstraint comp = new CompositeFieldConstraint();
            comp.setCompositeJunctionType(composites.getValue(composites.getSelectedIndex()));
            fp.addConstraint(comp);
            modeller.refreshWidget();
            popup.hide();
        }
    });
    InfoPopup infoComp = new InfoPopup(GuidedRuleEditorResources.CONSTANTS.MultipleFieldConstraints(), GuidedRuleEditorResources.CONSTANTS.MultipleConstraintsTip1());
    HorizontalPanel horiz = new HorizontalPanel();
    horiz.add(composites);
    horiz.add(infoComp);
    if (con == null) {
        popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.MultipleFieldConstraint(), horiz);
    }
    if (con == null) {
        // NON-NLS
        popup.addRow(new SmallLabel("<i>" + GuidedRuleEditorResources.CONSTANTS.AdvancedOptionsColon() + "</i>"));
        Button predicate = new Button(GuidedRuleEditorResources.CONSTANTS.NewFormula());
        predicate.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                SingleFieldConstraint con = new SingleFieldConstraint();
                con.setConstraintValueType(SingleFieldConstraint.TYPE_PREDICATE);
                fp.addConstraint(con);
                modeller.refreshWidget();
                popup.hide();
            }
        });
        popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.AddANewFormulaStyleExpression(), predicate);
        final Button expressionEditorButton = makeExpressionEditorButton(fp, popup);
        popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.ExpressionEditor(), expressionEditorButton);
        doBindingEditor(popup);
    }
    popup.show();
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Button(org.gwtbootstrap3.client.ui.Button) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) InfoPopup(org.uberfire.ext.widgets.common.client.common.InfoPopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Aggregations

ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)123 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)123 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)48 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)48 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)34 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)31 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)31 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)31 ListBox (org.gwtbootstrap3.client.ui.ListBox)31 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)29 ArrayList (java.util.ArrayList)26 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)21 PerunError (cz.metacentrum.perun.webgui.model.PerunError)17 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)16 HTML (com.google.gwt.user.client.ui.HTML)14 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)14 HashMap (java.util.HashMap)13 ListBox (com.google.gwt.user.client.ui.ListBox)12 FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)12 Map (java.util.Map)11