Search in sources :

Example 1 with RuleModellerActionPlugin

use of org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin in project drools-wb by kiegroup.

the class GuidedRuleEditorPresenter method getModelSuccessCallback.

private RemoteCallback<GuidedEditorContent> getModelSuccessCallback() {
    return new RemoteCallback<GuidedEditorContent>() {

        @Override
        public void callback(final GuidedEditorContent content) {
            // Path is set to null when the Editor is closed (which can happen before async calls complete).
            if (versionRecordManager.getCurrentPath() == null) {
                return;
            }
            GuidedRuleEditorPresenter.this.model = content.getModel();
            final PackageDataModelOracleBaselinePayload dataModel = content.getDataModel();
            oracle = oracleFactory.makeAsyncPackageDataModelOracle(versionRecordManager.getCurrentPath(), model, dataModel);
            resetEditorPages(content.getOverview());
            addSourcePage();
            addImportsTab(importsWidget);
            List<RuleModellerActionPlugin> actionPlugins = new ArrayList<>();
            actionPluginInstance.forEach(actionPlugins::add);
            view.setContent(model, actionPlugins, oracle, getRuleNamesService(), isReadOnly, isDSLEnabled);
            importsWidget.setContent(oracle, model.getImports(), isReadOnly);
            view.hideBusyIndicator();
            createOriginalHash(model);
        }
    };
}
Also used : PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) ArrayList(java.util.ArrayList) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Example 2 with RuleModellerActionPlugin

use of org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin in project drools-wb by kiegroup.

the class RuleModellerActionSelectorPopup method addCustomActionPlugins.

private void addCustomActionPlugins() {
    if (actionPlugins != null) {
        for (RuleModellerActionPlugin actionPlugin : actionPlugins) {
            final IAction iAction = actionPlugin.createIAction(ruleModeller);
            actionPlugin.addPluginToActionList(ruleModeller, () -> {
                choices.addItem(actionPlugin.getActionAddDescription(), actionPlugin.getId());
                cmds.put(actionPlugin.getId(), () -> {
                    model.addRhsItem(iAction, Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
                    hide();
                });
            });
        }
    }
}
Also used : IAction(org.drools.workbench.models.datamodel.rule.IAction) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin)

Example 3 with RuleModellerActionPlugin

use of org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin in project drools-wb by kiegroup.

the class GuidedRuleEditorPresenterTest method testLoadContentSuccess.

@Test
public void testLoadContentSuccess() throws Exception {
    final RuleModellerActionPlugin pluginOne = mock(RuleModellerActionPlugin.class);
    final RuleModellerActionPlugin pluginTwo = mock(RuleModellerActionPlugin.class);
    doAnswer(invocationOnMock -> {
        final Consumer<RuleModellerActionPlugin> consumer = invocationOnMock.getArgumentAt(0, Consumer.class);
        consumer.accept(pluginOne);
        consumer.accept(pluginTwo);
        return null;
    }).when(actionPluginInstance).forEach(any());
    presenter.loadContent();
    verify(kieEditorWrapperView).clear();
    verify(kieEditorWrapperView).addMainEditorPage(view);
    verify(kieEditorWrapperView).addOverviewPage(any(), any());
    verify(kieEditorWrapperView).addImportsTab(any());
    verify(kieEditorWrapperView).addSourcePage(any());
    verify(oracleFactory).makeAsyncPackageDataModelOracle(resourcePath, ruleModel, payload);
    verify(overviewWidgetPresenter).setContent(overview, resourcePath);
    verify(importsWidgetPresenter).setContent(oracle, imports, false);
    verify(view).hideBusyIndicator();
    verify(view).setContent(eq(ruleModel), pluginsListCaptor.capture(), eq(oracle), eq(ruleNamesServiceCaller), eq(false), eq(false));
    Assertions.assertThat(pluginsListCaptor.getValue()).containsExactly(pluginOne, pluginTwo);
}
Also used : RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) Test(org.junit.Test)

Example 4 with RuleModellerActionPlugin

use of org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin in project drools-wb by kiegroup.

the class RuleModellerWidgetFactory method getWidget.

public RuleModellerWidget getWidget(RuleModeller ruleModeller, EventBus eventBus, IAction action, Boolean readOnly) {
    if (action instanceof ActionCallMethod) {
        return new ActionCallMethodWidget(ruleModeller, eventBus, (ActionCallMethod) action, readOnly);
    }
    if (action instanceof ActionSetField) {
        return new ActionSetFieldWidget(ruleModeller, eventBus, (ActionSetField) action, readOnly);
    }
    if (action instanceof ActionInsertFact) {
        return new ActionInsertFactWidget(ruleModeller, eventBus, (ActionInsertFact) action, readOnly);
    }
    if (action instanceof ActionRetractFact) {
        return new ActionRetractFactWidget(ruleModeller, eventBus, (ActionRetractFact) action, readOnly);
    }
    if (action instanceof DSLSentence) {
        RuleModellerWidget w = new DSLSentenceWidget(ruleModeller, eventBus, (DSLSentence) action, readOnly);
        return w;
    }
    if (action instanceof FreeFormLine) {
        return new FreeFormLineWidget(ruleModeller, eventBus, (FreeFormLine) action, readOnly);
    }
    if (action instanceof ActionGlobalCollectionAdd) {
        return new GlobalCollectionAddWidget(ruleModeller, eventBus, (ActionGlobalCollectionAdd) action, readOnly);
    }
    // All hardcoded action widgets have been checked, perform a plugin lookup
    List<RuleModellerActionPlugin> matchingActionPlugins = actionPlugins.stream().filter(p -> p.accept(action)).collect(Collectors.toList());
    if (matchingActionPlugins.size() > 1) {
        throw new IllegalStateException("Ambigious " + RuleModellerActionPlugin.class.getName() + " implementations for action " + action);
    }
    if (matchingActionPlugins.size() == 1) {
        RuleModellerActionPlugin actionPlugin = matchingActionPlugins.get(0);
        RuleModellerWidget ruleModellerWidget = actionPlugin.createWidget(ruleModeller, eventBus, action, readOnly);
        return ruleModellerWidget;
    }
    // NON-NLS
    throw new RuntimeException("I don't know what type of action is: " + action);
}
Also used : ExpressionBuilder(org.drools.workbench.screens.guided.rule.client.widget.ExpressionBuilder) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.CompositeFactPatternWidget) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) FromCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromCompositeFactPatternWidget) ActionCallMethodWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionCallMethodWidget) ActionInsertFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionInsertFactWidget) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromEntryPointFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromEntryPointFactPatternWidget) PortablePreconditions(org.kie.soup.commons.validation.PortablePreconditions) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) ActionSetFieldWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionSetFieldWidget) GlobalCollectionAddWidget(org.drools.workbench.screens.guided.rule.client.widget.GlobalCollectionAddWidget) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) IAction(org.drools.workbench.models.datamodel.rule.IAction) EventBus(com.google.gwt.event.shared.EventBus) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) FactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FactPatternWidget) Collection(java.util.Collection) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget) FreeFormLineWidget(org.drools.workbench.screens.guided.rule.client.widget.FreeFormLineWidget) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Collectors(java.util.stream.Collectors) FromCollectCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromCollectCompositeFactPatternWidget) ActionRetractFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionRetractFactWidget) List(java.util.List) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) FromAccumulateCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromAccumulateCompositeFactPatternWidget) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) DSLSentenceWidget(org.drools.workbench.screens.guided.rule.client.widget.DSLSentenceWidget) Collections(java.util.Collections) GlobalCollectionAddWidget(org.drools.workbench.screens.guided.rule.client.widget.GlobalCollectionAddWidget) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) ActionInsertFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionInsertFactWidget) ActionCallMethodWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionCallMethodWidget) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget) DSLSentenceWidget(org.drools.workbench.screens.guided.rule.client.widget.DSLSentenceWidget) FreeFormLineWidget(org.drools.workbench.screens.guided.rule.client.widget.FreeFormLineWidget) ActionSetFieldWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionSetFieldWidget) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) ActionRetractFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionRetractFactWidget)

Aggregations

RuleModellerActionPlugin (org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin)4 IAction (org.drools.workbench.models.datamodel.rule.IAction)2 EventBus (com.google.gwt.event.shared.EventBus)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)1 ActionGlobalCollectionAdd (org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd)1 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)1 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)1 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)1 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)1 DSLSentence (org.drools.workbench.models.datamodel.rule.DSLSentence)1 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)1 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)1 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)1 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)1 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)1