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);
}
};
}
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();
});
});
}
}
}
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);
}
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);
}
Aggregations