Search in sources :

Example 1 with RuleModellerWidget

use of org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget in project drools-wb by kiegroup.

the class RuleModeller method renderRhs.

/**
 * Do all the widgets for the RHS.
 */
private void renderRhs(final RuleModel model) {
    for (int i = 0; i < model.rhs.length; i++) {
        DirtyableVerticalPane widget = new DirtyableVerticalPane();
        widget.setWidth("100%");
        IAction action = model.rhs[i];
        // if lockRHS() set the widget RO, otherwise let them decide.
        Boolean readOnly = this.lockRHS() ? true : null;
        RuleModellerWidget w = getWidgetFactory().getWidget(this, eventBus, action, readOnly);
        w.addOnModifiedCommand(this.onWidgetModifiedCommand);
        widget.add(wrapRHSWidget(model, i, w));
        widget.add(spacerWidget());
        layout.setWidget(currentLayoutRow, 0, new DirtyableHorizontalPane());
        layout.setWidget(currentLayoutRow, 1, new DirtyableHorizontalPane());
        layout.setWidget(currentLayoutRow, 2, this.wrapLineNumber(i + 1, false));
        layout.getFlexCellFormatter().setHorizontalAlignment(currentLayoutRow, 2, HasHorizontalAlignment.ALIGN_CENTER);
        layout.getFlexCellFormatter().setVerticalAlignment(currentLayoutRow, 2, HasVerticalAlignment.ALIGN_MIDDLE);
        layout.setWidget(currentLayoutRow, 3, widget);
        layout.getFlexCellFormatter().setHorizontalAlignment(currentLayoutRow, 3, HasHorizontalAlignment.ALIGN_LEFT);
        layout.getFlexCellFormatter().setVerticalAlignment(currentLayoutRow, 3, HasVerticalAlignment.ALIGN_TOP);
        layout.getFlexCellFormatter().setWidth(currentLayoutRow, 3, "100%");
        layout.getRowFormatter().addStyleName(currentLayoutRow, (i % 2 == 0 ? GuidedRuleEditorResources.INSTANCE.css().evenRow() : GuidedRuleEditorResources.INSTANCE.css().oddRow()));
        if (!w.isFactTypeKnown()) {
            addInvalidPatternIcon();
            addFactTypeKnownValueChangeHandler(w, currentLayoutRow);
        }
        final int index = i;
        if (!(this.lockRHS() || w.isReadOnly())) {
            this.addActionsButtonsToLayout(GuidedRuleEditorResources.CONSTANTS.AddAnActionBelow(), new ClickHandler() {

                public void onClick(ClickEvent event) {
                    showActionSelector(index + 1);
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                    model.moveRhsItemDown(index);
                    refreshWidget();
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                    model.moveRhsItemUp(index);
                    refreshWidget();
                }
            });
        }
        this.rhsWidgets.add(w);
        currentLayoutRow++;
    }
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) IAction(org.drools.workbench.models.datamodel.rule.IAction) DirtyableVerticalPane(org.uberfire.ext.widgets.common.client.common.DirtyableVerticalPane) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) DirtyableHorizontalPane(org.uberfire.ext.widgets.common.client.common.DirtyableHorizontalPane) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget)

Example 2 with RuleModellerWidget

use of org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget 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)

Example 3 with RuleModellerWidget

use of org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget in project drools-wb by kiegroup.

the class RuleModeller method renderLhs.

/**
 * Builds all the condition widgets.
 */
private void renderLhs(final RuleModel model) {
    for (int i = 0; i < model.lhs.length; i++) {
        DirtyableVerticalPane vert = new DirtyableVerticalPane();
        vert.setWidth("100%");
        // if lockLHS() set the widget RO, otherwise let them decide.
        Boolean readOnly = this.lockLHS() ? true : null;
        IPattern pattern = model.lhs[i];
        final RuleModellerWidget widget = getWidgetFactory().getWidget(this, eventBus, pattern, readOnly);
        widget.addOnModifiedCommand(this.onWidgetModifiedCommand);
        vert.add(wrapLHSWidget(model, i, widget));
        vert.add(spacerWidget());
        layout.setWidget(currentLayoutRow, 0, new DirtyableHorizontalPane());
        layout.setWidget(currentLayoutRow, 1, new DirtyableHorizontalPane());
        layout.setWidget(currentLayoutRow, 2, this.wrapLineNumber(i + 1, true));
        layout.getFlexCellFormatter().setHorizontalAlignment(currentLayoutRow, 2, HasHorizontalAlignment.ALIGN_CENTER);
        layout.getFlexCellFormatter().setVerticalAlignment(currentLayoutRow, 2, HasVerticalAlignment.ALIGN_MIDDLE);
        layout.setWidget(currentLayoutRow, 3, vert);
        layout.getFlexCellFormatter().setHorizontalAlignment(currentLayoutRow, 3, HasHorizontalAlignment.ALIGN_LEFT);
        layout.getFlexCellFormatter().setVerticalAlignment(currentLayoutRow, 3, HasVerticalAlignment.ALIGN_TOP);
        layout.getFlexCellFormatter().setWidth(currentLayoutRow, 3, "100%");
        layout.getRowFormatter().addStyleName(currentLayoutRow, (i % 2 == 0 ? GuidedRuleEditorResources.INSTANCE.css().evenRow() : GuidedRuleEditorResources.INSTANCE.css().oddRow()));
        if (!widget.isFactTypeKnown()) {
            addInvalidPatternIcon();
            addFactTypeKnownValueChangeHandler(widget, currentLayoutRow);
        }
        final int index = i;
        if (!(this.lockLHS() || widget.isReadOnly())) {
            this.addActionsButtonsToLayout(GuidedRuleEditorResources.CONSTANTS.AddAConditionBelow(), new ClickHandler() {

                public void onClick(ClickEvent event) {
                    showConditionSelector(index + 1);
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                    model.moveLhsItemDown(index);
                    refreshWidget();
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                    model.moveLhsItemUp(index);
                    refreshWidget();
                }
            });
        }
        this.lhsWidgets.add(widget);
        currentLayoutRow++;
    }
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) DirtyableVerticalPane(org.uberfire.ext.widgets.common.client.common.DirtyableVerticalPane) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) DirtyableHorizontalPane(org.uberfire.ext.widgets.common.client.common.DirtyableHorizontalPane) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget)

Aggregations

RuleModellerWidget (org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 IAction (org.drools.workbench.models.datamodel.rule.IAction)2 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)2 EventBus (com.google.gwt.event.shared.EventBus)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