Search in sources :

Example 6 with Callback

use of org.uberfire.client.callbacks.Callback in project drools-wb by kiegroup.

the class EnumLoaderUtilitiesTest method checkQueryExpressionDefinitionWithCaching.

@Test
public void checkQueryExpressionDefinitionWithCaching() {
    final Callback<Map<String, String>> callback = (result) -> {
        assertFalse(result.isEmpty());
        assertEquals(2, result.size());
        assertTrue(result.containsKey("one"));
        assertTrue(result.containsKey("two"));
    };
    final String[] fixedList = { "one", "two" };
    final String[] valuePairs = { "param1=a", "param2=b" };
    final DropDownData enumDefinition = DropDownData.create("expression", valuePairs);
    when(enumDropdownService.loadDropDownExpression(any(Path.class), any(String[].class), any(String.class))).thenReturn(fixedList);
    // Call twice to check caching
    enumLoaderUtilities.getEnums(enumDefinition, callback, presenter, onFetchCommand, onFetchCompleteCommand);
    enumLoaderUtilities.getEnums(enumDefinition, callback, presenter, onFetchCommand, onFetchCompleteCommand);
    verify(enumDropdownService, times(1)).loadDropDownExpression(any(Path.class), any(String[].class), any(String.class));
    verify(onFetchCommand, times(1)).execute();
    verify(onFetchCompleteCommand, times(1)).execute();
    verify(enumLoaderUtilities, times(1)).convertDropDownData(any(String[].class));
    verify(view, times(1)).batch();
}
Also used : GuidedDecisionTablePresenter(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter) EnumDropdownService(org.kie.workbench.common.services.shared.enums.EnumDropdownService) CallerMock(org.uberfire.mocks.CallerMock) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.spy(org.mockito.Mockito.spy) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Callback(org.uberfire.client.callbacks.Callback) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Caller(org.jboss.errai.common.client.api.Caller) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) Mockito.any(org.mockito.Mockito.any) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Path(org.uberfire.backend.vfs.Path) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Map(java.util.Map) Test(org.junit.Test)

Example 7 with Callback

use of org.uberfire.client.callbacks.Callback in project drools-wb by kiegroup.

the class EnumLoaderUtilitiesTest method checkFixedListDefinitionWithCaching.

@Test
public void checkFixedListDefinitionWithCaching() {
    final Callback<Map<String, String>> callback = (result) -> {
        assertFalse(result.isEmpty());
        assertEquals(2, result.size());
        assertTrue(result.containsKey("one"));
        assertTrue(result.containsKey("two"));
    };
    final String[] fixedList = { "one", "two" };
    final DropDownData enumDefinition = DropDownData.create(fixedList);
    // Call twice to check caching
    enumLoaderUtilities.getEnums(enumDefinition, callback, presenter, onFetchCommand, onFetchCompleteCommand);
    enumLoaderUtilities.getEnums(enumDefinition, callback, presenter, onFetchCommand, onFetchCompleteCommand);
    verify(enumDropdownService, never()).loadDropDownExpression(any(Path.class), any(String[].class), any(String.class));
    verify(onFetchCommand, never()).execute();
    verify(onFetchCompleteCommand, never()).execute();
    verify(enumLoaderUtilities, times(1)).convertDropDownData(any(String[].class));
}
Also used : GuidedDecisionTablePresenter(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter) EnumDropdownService(org.kie.workbench.common.services.shared.enums.EnumDropdownService) CallerMock(org.uberfire.mocks.CallerMock) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.spy(org.mockito.Mockito.spy) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Callback(org.uberfire.client.callbacks.Callback) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Caller(org.jboss.errai.common.client.api.Caller) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) Mockito.any(org.mockito.Mockito.any) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Path(org.uberfire.backend.vfs.Path) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Map(java.util.Map) Test(org.junit.Test)

Example 8 with Callback

use of org.uberfire.client.callbacks.Callback in project drools-wb by kiegroup.

the class ActionCallMethodWidget method showAddFieldPopup.

protected void showAddFieldPopup(Widget w) {
    final AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.ChooseAMethodToInvoke());
    final ListBox box = new ListBox();
    box.addItem("...");
    for (int i = 0; i < fieldCompletionTexts.length; i++) {
        box.addItem(fieldCompletionValues[i], fieldCompletionTexts[i]);
    }
    box.setSelectedIndex(0);
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.ChooseAMethodToInvoke(), box);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            final String methodNameWithParams = box.getItemText(box.getSelectedIndex());
            oracle.getMethodParams(variableClass, methodNameWithParams, new Callback<List<String>>() {

                @Override
                public void callback(final List<String> methodParameters) {
                    final String methodName = box.getValue(box.getSelectedIndex());
                    model.setMethodName(methodName);
                    model.setState(ActionCallMethod.TYPE_DEFINED);
                    for (String methodParameter : methodParameters) {
                        model.addFieldValue(new ActionFieldFunction(methodName, null, methodParameter));
                    }
                    getModeller().refreshWidget();
                    popup.hide();
                }
            });
        }
    });
    popup.show();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) Callback(org.uberfire.client.callbacks.Callback) 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) ActionFieldFunction(org.drools.workbench.models.datamodel.rule.ActionFieldFunction) List(java.util.List) ListBox(org.gwtbootstrap3.client.ui.ListBox) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)

Example 9 with Callback

use of org.uberfire.client.callbacks.Callback in project drools-wb by kiegroup.

the class ExpressionBuilder method onStartPointChange.

private void onStartPointChange(final String value) {
    setModified(true);
    panel.clear();
    final int dotPos = value.indexOf('.');
    final String prefix = value.substring(0, dotPos);
    final String attrib = value.substring(dotPos + 1);
    if (prefix.equals(VARIABLE_VALUE_PREFIX)) {
        FactPattern fact = getRuleModel().getLHSBoundFact(attrib);
        ExpressionPart variable;
        if (fact != null) {
            variable = new ExpressionVariable(fact.getBoundName(), fact.getFactType());
        } else {
            // if the variable is not bound to a Fact Pattern then it must be bound to a Field
            String lhsBindingType = getRuleModel().getLHSBindingType(attrib);
            variable = new ExpressionFieldVariable(attrib, lhsBindingType);
        }
        expression.appendPart(variable);
        onStartPointChangeUpdateWidget();
    } else if (prefix.equals(GLOBAL_VARIABLE_VALUE_PREFIX)) {
        ExpressionPartHelper.getExpressionPartForGlobalVariable(getDataModelOracle(), attrib, new Callback<ExpressionPart>() {

            @Override
            public void callback(final ExpressionPart part) {
                expression.appendPart(part);
                onStartPointChangeUpdateWidget();
            }
        });
    }
}
Also used : ExpressionFieldVariable(org.drools.workbench.models.datamodel.rule.ExpressionFieldVariable) Callback(org.uberfire.client.callbacks.Callback) ExpressionPart(org.drools.workbench.models.datamodel.rule.ExpressionPart) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable)

Example 10 with Callback

use of org.uberfire.client.callbacks.Callback in project drools-wb by kiegroup.

the class FactPatternsPageViewImpl method initialiseChosenPatterns.

private void initialiseChosenPatterns() {
    chosenPatternsContainer.add(chosenPatternWidget);
    chosenPatternWidget.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
    chosenPatternWidget.setMinimumWidth(270);
    final Label lstEmpty = new Label(GuidedDecisionTableConstants.INSTANCE.DecisionTableWizardNoChosenPatterns());
    lstEmpty.setStyleName(WizardCellListResources.INSTANCE.cellListStyle().cellListEmptyItem());
    chosenPatternWidget.setEmptyListWidget(lstEmpty);
    final MultiSelectionModel<Pattern52> selectionModel = new MultiSelectionModel<Pattern52>(System::identityHashCode);
    chosenPatternWidget.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(final SelectionChangeEvent event) {
            chosenPatternSelections = selectionModel.getSelectedSet();
            chosenTypesSelected(chosenPatternSelections);
        }

        private void chosenTypesSelected(final Set<Pattern52> ps) {
            btnRemove.setEnabled(true);
            if (ps.size() == 1) {
                chosenPatternSelection = ps.iterator().next();
                patternDefinition.setVisible(true);
                validateBinding();
                txtBinding.setEnabled(true);
                txtBinding.setText(chosenPatternSelection.getBoundName());
                txtEntryPoint.setEnabled(true);
                txtEntryPoint.setText(chosenPatternSelection.getEntryPointName());
                enableMoveUpButton();
                enableMoveDownButton();
                presenter.isPatternEvent(chosenPatternSelection, new Callback<Boolean>() {

                    @Override
                    public void callback(final Boolean result) {
                        if (Boolean.TRUE.equals(result)) {
                            ddCEPWindow.setCEPWindow(chosenPatternSelection);
                            cepWindowContainer.setVisible(true);
                        } else {
                            cepWindowContainer.setVisible(false);
                        }
                    }
                });
            } else {
                chosenPatternSelection = null;
                patternDefinition.setVisible(false);
                txtBinding.setEnabled(false);
                txtBinding.setText("");
                txtEntryPoint.setEnabled(false);
                txtEntryPoint.setText("");
                btnMoveUp.setEnabled(false);
                btnMoveDown.setEnabled(false);
                cepWindowContainer.setVisible(false);
            }
        }
    });
}
Also used : Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) Callback(org.uberfire.client.callbacks.Callback) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) Label(org.gwtbootstrap3.client.ui.Label) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Aggregations

Callback (org.uberfire.client.callbacks.Callback)18 Test (org.junit.Test)10 Map (java.util.Map)5 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)3 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)3 GuidedDecisionTablePresenter (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter)3 GuidedDecisionTableView (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView)3 Caller (org.jboss.errai.common.client.api.Caller)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Before (org.junit.Before)3 RunWith (org.junit.runner.RunWith)3 DropDownData (org.kie.soup.project.datamodel.oracle.DropDownData)3 EnumDropdownService (org.kie.workbench.common.services.shared.enums.EnumDropdownService)3 Mock (org.mockito.Mock)3 Mockito.any (org.mockito.Mockito.any)3 Mockito.never (org.mockito.Mockito.never)3 Mockito.spy (org.mockito.Mockito.spy)3 Mockito.times (org.mockito.Mockito.times)3