Search in sources :

Example 41 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox in project drools-wb by kiegroup.

the class CompositeFactPatternWidget method showFactTypeSelector.

/**
 * Pops up the fact selector.
 */
protected void showFactTypeSelector(final Widget w) {
    final ListBox box = new ListBox();
    AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
    String[] facts = oracle.getFactTypes();
    box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
    for (int i = 0; i < facts.length; i++) {
        box.addItem(facts[i]);
    }
    box.setSelectedIndex(0);
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.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();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Widget(com.google.gwt.user.client.ui.Widget) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Button(org.gwtbootstrap3.client.ui.Button) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 42 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox in project drools-wb by kiegroup.

the class FromCollectCompositeFactPatternWidget method showFactTypeSelector.

@Override
protected void showFactTypeSelector() {
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
    popup.setTitle(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
    final ListBox box = GWT.create(ListBox.class);
    box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
    for (Map.Entry<String, String> entry : this.getExtraLeftSidePatternFactTypes().entrySet()) {
        box.addItem(entry.getKey(), entry.getValue());
    }
    box.setSelectedIndex(0);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            pattern.setFactPattern(new FactPattern(box.getValue(box.getSelectedIndex())));
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    });
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
    popup.show();
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ListBox(org.gwtbootstrap3.client.ui.ListBox) HashMap(java.util.HashMap) Map(java.util.Map)

Example 43 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox in project drools-wb by kiegroup.

the class FromCollectCompositeFactPatternWidget method showRightPatternSelector.

/**
 * Pops up the fact selector.
 */
protected void showRightPatternSelector(final Widget w) {
    final ListBox box = new ListBox();
    AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
    String[] facts = oracle.getFactTypes();
    box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
    for (int i = 0; i < facts.length; i++) {
        box.addItem(facts[i]);
    }
    box.setSelectedIndex(0);
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            getFromCollectPattern().setRightPattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    });
    final Button freeFormDRLBtn = new Button(GuidedRuleEditorResources.CONSTANTS.FreeFormDrl());
    final Button fromBtn = new Button(HumanReadableConstants.INSTANCE.From());
    final Button fromAccumulateBtn = new Button(HumanReadableConstants.INSTANCE.FromAccumulate());
    final Button fromCollectBtn = new Button(HumanReadableConstants.INSTANCE.FromCollect());
    final Button fromEntryPointBtn = new Button(HumanReadableConstants.INSTANCE.FromEntryPoint());
    ClickHandler btnsClickHandler = new ClickHandler() {

        public void onClick(ClickEvent event) {
            Widget sender = (Widget) event.getSource();
            if (sender == fromBtn) {
                getFromCollectPattern().setRightPattern(new FromCompositeFactPattern());
            } else if (sender == fromAccumulateBtn) {
                getFromCollectPattern().setRightPattern(new FromAccumulateCompositeFactPattern());
            } else if (sender == fromCollectBtn) {
                getFromCollectPattern().setRightPattern(new FromCollectCompositeFactPattern());
            } else if (sender == freeFormDRLBtn) {
                getFromCollectPattern().setRightPattern(new FreeFormLine());
            } else if (sender == fromEntryPointBtn) {
                getFromCollectPattern().setRightPattern(new FromEntryPointFactPattern());
            } else {
                throw new IllegalArgumentException("Unknown sender: " + sender);
            }
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    };
    freeFormDRLBtn.addClickHandler(btnsClickHandler);
    fromBtn.addClickHandler(btnsClickHandler);
    fromAccumulateBtn.addClickHandler(btnsClickHandler);
    fromCollectBtn.addClickHandler(btnsClickHandler);
    fromEntryPointBtn.addClickHandler(btnsClickHandler);
    popup.addAttribute("", freeFormDRLBtn);
    popup.addAttribute("", fromBtn);
    popup.addAttribute("", fromAccumulateBtn);
    popup.addAttribute("", fromCollectBtn);
    popup.addAttribute("", fromEntryPointBtn);
    popup.show();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) Widget(com.google.gwt.user.client.ui.Widget) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Button(org.gwtbootstrap3.client.ui.Button) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 44 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox 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 EditAttributeWidgetFactory editAttributeWidgetFactory = new EditAttributeWidgetFactory(isReadOnly);
    final String attributeName = at.getAttributeName();
    if (attributeName.equals(Attribute.DIALECT.getAttributeName())) {
        final ListBox lb = new ListBox();
        lb.addItem(DIALECTS.get(0));
        lb.addItem(DIALECTS.get(1));
        lb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            lb.addChangeHandler(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.get(1));
        } else if (at.getValue().equals(DIALECTS.get(0))) {
            lb.setSelectedIndex(0);
        } else if (at.getValue().equals(DIALECTS.get(1))) {
            lb.setSelectedIndex(1);
        } else {
            lb.setSelectedIndex(1);
            at.setValue(DIALECTS.get(1));
        }
        editor = lb;
    } else if (Objects.equals(DataType.TYPE_STRING, Attribute.getAttributeDataType(attributeName))) {
        editor = editAttributeWidgetFactory.textBox(at, DataType.TYPE_STRING);
    } else if (Objects.equals(DataType.TYPE_NUMERIC_INTEGER, Attribute.getAttributeDataType(attributeName))) {
        editor = editAttributeWidgetFactory.textBox(at, DataType.TYPE_NUMERIC_INTEGER);
    } else if (Objects.equals(DataType.TYPE_NUMERIC_LONG, Attribute.getAttributeDataType(attributeName))) {
        editor = editAttributeWidgetFactory.textBox(at, DataType.TYPE_NUMERIC_LONG);
    } else if (Objects.equals(DataType.TYPE_BOOLEAN, Attribute.getAttributeDataType(attributeName))) {
        editor = checkBoxEditor(at, isReadOnly);
    } else if (Objects.equals(DataType.TYPE_DATE, Attribute.getAttributeDataType(attributeName))) {
        if (isReadOnly) {
            editor = editAttributeWidgetFactory.textBox(at, DataType.TYPE_STRING);
        } else {
            editor = editAttributeWidgetFactory.datePicker(at, false);
        }
    }
    DirtyableHorizontalPane horiz = GWT.create(DirtyableHorizontalPane.class);
    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) DirtyableHorizontalPane(org.uberfire.ext.widgets.common.client.common.DirtyableHorizontalPane) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 45 with ListBox

use of org.gwtbootstrap3.client.ui.ListBox in project drools-wb by kiegroup.

the class RuleModellerActionSelectorPopup method makeChoicesListBox.

private ListBox makeChoicesListBox(final String filter) {
    choices = GWT.create(ListBox.class);
    choices.setMultipleSelect(true);
    choices.setPixelSize(getChoicesWidth(), getChoicesHeight());
    choices.addKeyUpHandler(new KeyUpHandler() {

        public void onKeyUp(com.google.gwt.event.dom.client.KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                selectSomething();
            }
        }
    });
    final Predicate<String> predicate = (item) -> item.toLowerCase().contains(Objects.isNull(filter) ? "" : filter.toLowerCase());
    boolean itemsAdded = addDSLSentences(predicate);
    if (!onlyShowDSLStatements) {
        itemsAdded = addUpdateNotModify(itemsAdded) || itemsAdded;
        itemsAdded = addGlobals(itemsAdded) || itemsAdded;
        itemsAdded = addRetractions(itemsAdded) || itemsAdded;
        itemsAdded = addModifies(itemsAdded) || itemsAdded;
        itemsAdded = addInsertions(predicate, itemsAdded) || itemsAdded;
        itemsAdded = addLogicalInsertions(predicate, itemsAdded) || itemsAdded;
        itemsAdded = addGlobalCollections(itemsAdded) || itemsAdded;
        itemsAdded = addFreeFormDRL(itemsAdded) || itemsAdded;
        itemsAdded = addCallMethodOn(itemsAdded) || itemsAdded;
        addCustomActionPlugins(itemsAdded);
    }
    return choices;
}
Also used : ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) GuidedRuleEditorResources(org.drools.workbench.screens.guided.rule.client.resources.GuidedRuleEditorResources) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) ListBox(org.gwtbootstrap3.client.ui.ListBox) GWT(com.google.gwt.core.client.GWT) HTML(com.google.gwt.user.client.ui.HTML) Command(com.google.gwt.user.client.Command) ModalFooterOKCancelButtons(org.uberfire.ext.widgets.common.client.common.popups.footers.ModalFooterOKCancelButtons) ModalBody(org.gwtbootstrap3.client.ui.ModalBody) CheckBox(org.gwtbootstrap3.client.ui.CheckBox) InfoPopup(org.uberfire.ext.widgets.common.client.common.InfoPopup) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) IAction(org.drools.workbench.models.datamodel.rule.IAction) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) Collection(java.util.Collection) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) Objects(java.util.Objects) List(java.util.List) Widget(com.google.gwt.user.client.ui.Widget) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) KeyCodes(com.google.gwt.event.dom.client.KeyCodes) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Aggregations

ListBox (org.gwtbootstrap3.client.ui.ListBox)61 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)31 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)30 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)15 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)15 FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)12 Widget (com.google.gwt.user.client.ui.Widget)11 Test (org.junit.Test)11 Button (org.gwtbootstrap3.client.ui.Button)10 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)10 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)9 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)9 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)7 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)7 TextBox (org.gwtbootstrap3.client.ui.TextBox)7 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)6 IsWidget (com.google.gwt.user.client.ui.IsWidget)6 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)6 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)6 DropDownData (org.kie.soup.project.datamodel.oracle.DropDownData)6