Search in sources :

Example 1 with ActionInsertFactFieldsPattern

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern in project drools-wb by kiegroup.

the class ActionInsertFactFieldsPage method initialise.

@Override
public void initialise() {
    view.init(this);
    view.setValidator(getValidator());
    patternToActionsMap.clear();
    // Set-up validator for the pattern-to-action mapping voodoo
    getValidator().setPatternToActionInsertFactFieldsMap(patternToActionsMap);
    // Set-up a factory for value editors
    view.setDTCellValueWidgetFactory(DTCellValueWidgetFactory.getInstance(model, oracle, false, allowEmptyValues()));
    // Available types
    final List<String> availableTypes = Arrays.asList(oracle.getFactTypes());
    view.setAvailableFactTypes(availableTypes);
    // Existing ActionInsertFactCols (should be empty for a new Decision Table)
    for (ActionCol52 a : model.getActionCols()) {
        if (a instanceof ActionInsertFactCol52) {
            final ActionInsertFactCol52 aif = (ActionInsertFactCol52) a;
            final ActionInsertFactFieldsPattern p = lookupExistingInsertFactPattern(aif.getBoundName());
            final List<ActionInsertFactCol52> actions = patternToActionsMap.get(p);
            getValidator().addActionPattern(p);
            actions.add(aif);
        }
    }
    view.setChosenPatterns(new ArrayList<ActionInsertFactFieldsPattern>());
    view.setAvailableFields(new ArrayList<AvailableField>());
    view.setChosenFields(new ArrayList<ActionInsertFactCol52>());
    content.setWidget(view);
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ActionInsertFactFieldsPattern(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern)

Example 2 with ActionInsertFactFieldsPattern

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern in project drools-wb by kiegroup.

the class ActionInsertFactFieldsPage method makeResult.

@Override
public void makeResult(final GuidedDecisionTable52 model) {
    // Copy actions to decision table model
    int fi = 1;
    for (Map.Entry<ActionInsertFactFieldsPattern, List<ActionInsertFactCol52>> ps : patternToActionsMap.entrySet()) {
        final ActionInsertFactFieldsPattern p = ps.getKey();
        if (!getValidator().isPatternValid(p)) {
            String binding = NEW_FACT_PREFIX + (fi++);
            p.setBoundName(binding);
            while (!getValidator().isPatternBindingUnique(p)) {
                binding = NEW_FACT_PREFIX + (fi++);
                p.setBoundName(binding);
            }
        }
        final String factType = p.getFactType();
        final String boundName = p.getBoundName();
        final boolean isLogicalInsert = p.isInsertedLogically();
        for (ActionInsertFactCol52 aif : ps.getValue()) {
            aif.setFactType(factType);
            aif.setBoundName(boundName);
            aif.setInsertLogical(isLogicalInsert);
            model.getActionCols().add(aif);
        }
    }
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionInsertFactFieldsPattern(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 3 with ActionInsertFactFieldsPattern

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern in project drools-wb by kiegroup.

the class ActionInsertFactFieldsPageViewImpl method btnAddFactTypesClick.

@UiHandler(value = "btnAddFactTypes")
public void btnAddFactTypesClick(final ClickEvent event) {
    for (String type : availableFactTypesSelections) {
        ActionInsertFactFieldsPattern pattern = new ActionInsertFactFieldsPattern();
        pattern.setFactType(type);
        chosenPatterns.add(pattern);
        presenter.addPattern(pattern);
    }
    setChosenPatterns(chosenPatterns);
    presenter.stateChanged();
}
Also used : ActionInsertFactFieldsPattern(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 4 with ActionInsertFactFieldsPattern

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern in project drools-wb by kiegroup.

the class ActionInsertFactFieldsPageViewImpl method initialiseChosenPatterns.

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

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

        private void chosenPatternsSelected(final Set<ActionInsertFactFieldsPattern> cps) {
            btnRemoveFactTypes.setEnabled(cps.size() > 0);
            fieldDefinition.setVisible(false);
            if (cps.size() == 1) {
                chosenPatternsSelection = cps.iterator().next();
                presenter.selectPattern(chosenPatternsSelection);
                patternDefinition.setVisible(true);
                validateBinding();
                txtBinding.setEnabled(true);
                txtBinding.setVisible(true);
                txtBinding.setText(chosenPatternsSelection.getBoundName());
                chkLogicalInsert.setEnabled(true);
                chkLogicalInsert.setVisible(true);
                chkLogicalInsert.setValue(chosenPatternsSelection.isInsertedLogically());
            } else {
                chosenPatternsSelection = null;
                setAvailableFields(new ArrayList<AvailableField>());
                setChosenFields(new ArrayList<ActionInsertFactCol52>());
                patternDefinition.setVisible(false);
                txtBinding.setEnabled(false);
                txtBinding.setVisible(false);
                txtBinding.setText("");
                chkLogicalInsert.setEnabled(false);
                chkLogicalInsert.setVisible(false);
            }
        }
    });
}
Also used : ActionInsertFactFieldsPattern(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) Label(org.gwtbootstrap3.client.ui.Label) ArrayList(java.util.ArrayList) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Example 5 with ActionInsertFactFieldsPattern

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern in project drools-wb by kiegroup.

the class ActionInsertFactFieldsPage method lookupExistingInsertFactPattern.

private ActionInsertFactFieldsPattern lookupExistingInsertFactPattern(final String boundName) {
    for (ActionInsertFactFieldsPattern p : patternToActionsMap.keySet()) {
        if (p.getBoundName().equals(boundName)) {
            return p;
        }
    }
    final ActionInsertFactFieldsPattern p = new ActionInsertFactFieldsPattern();
    patternToActionsMap.put(p, new ArrayList<ActionInsertFactCol52>());
    return p;
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionInsertFactFieldsPattern(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern)

Aggregations

ActionInsertFactFieldsPattern (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern)7 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)4 UiHandler (com.google.gwt.uibinder.client.UiHandler)2 ArrayList (java.util.ArrayList)2 MultiSelectionModel (com.google.gwt.view.client.MultiSelectionModel)1 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Map (java.util.Map)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)1 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)1 Label (org.gwtbootstrap3.client.ui.Label)1 Test (org.junit.Test)1