Search in sources :

Example 6 with VetoException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException in project drools-wb by kiegroup.

the class AttributeColumnConfigRow method init.

public void init(final AttributeCol52 attributeColumn, final GuidedDecisionTableModellerView.Presenter presenter) {
    view.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    view.addColumnLabel(attributeColumn);
    final AttributeCol52 originalColumn = attributeColumn;
    if (Objects.equals(attributeColumn.getAttribute(), Attribute.SALIENCE.getAttributeName())) {
        useRowNumberCheckBox = view.addUseRowNumberCheckBox(attributeColumn, presenter.isActiveDecisionTableEditable(), (event) -> {
            final AttributeCol52 editedColumn = originalColumn.cloneColumn();
            editedColumn.setUseRowNumber(useRowNumberCheckBox.getValue());
            reverseOrderCheckBox.setEnabled(useRowNumberCheckBox.getValue());
            try {
                final Optional<GuidedDecisionTableView.Presenter> dtPresenter = presenter.getActiveDecisionTable();
                if (dtPresenter.isPresent()) {
                    dtPresenter.get().updateColumn(originalColumn, editedColumn);
                }
            } catch (VetoException veto) {
                presenter.getView().showGenericVetoMessage();
            }
        });
        view.add(new Span("("));
        reverseOrderCheckBox = view.addReverseOrderCheckBox(attributeColumn, presenter.isActiveDecisionTableEditable(), (event) -> {
            final AttributeCol52 editedColumn = originalColumn.cloneColumn();
            editedColumn.setReverseOrder(reverseOrderCheckBox.getValue());
            try {
                final Optional<GuidedDecisionTableView.Presenter> dtPresenter = presenter.getActiveDecisionTable();
                if (dtPresenter.isPresent()) {
                    dtPresenter.get().updateColumn(originalColumn, editedColumn);
                }
            } catch (VetoException veto) {
                presenter.getView().showGenericVetoMessage();
            }
        });
        view.add(new Span(")"));
    }
    view.addDefaultValue(attributeColumn, presenter.isActiveDecisionTableEditable(), (event) -> {
        final AttributeCol52 editedColumn = originalColumn.cloneColumn();
        editedColumn.setDefaultValue(event.getEditedDefaultValue());
        try {
            final Optional<GuidedDecisionTableView.Presenter> dtPresenter = presenter.getActiveDecisionTable();
            if (dtPresenter.isPresent()) {
                dtPresenter.get().updateColumn(originalColumn, editedColumn);
            }
        } catch (VetoException veto) {
            presenter.getView().showGenericVetoMessage();
        }
    });
    hideColumnCheckBox = view.addHideColumnCheckBox(attributeColumn, (event) -> {
        final AttributeCol52 editedColumn = originalColumn.cloneColumn();
        editedColumn.setHideColumn(hideColumnCheckBox.getValue());
        try {
            final Optional<GuidedDecisionTableView.Presenter> dtPresenter = presenter.getActiveDecisionTable();
            if (dtPresenter.isPresent()) {
                dtPresenter.get().updateColumn(originalColumn, editedColumn);
            }
        } catch (VetoException veto) {
            presenter.getView().showGenericVetoMessage();
        }
    });
    addRemoveAttributeButton(attributeColumn, presenter);
}
Also used : AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) GuidedDecisionTableModellerView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableModellerView) Objects(java.util.Objects) Inject(javax.inject.Inject) Span(org.gwtbootstrap3.client.ui.html.Span) Attribute(org.drools.workbench.models.datamodel.rule.Attribute) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) Widget(com.google.gwt.user.client.ui.Widget) Dependent(javax.enterprise.context.Dependent) HasVerticalAlignment(com.google.gwt.user.client.ui.HasVerticalAlignment) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) Optional(java.util.Optional) CheckBox(org.gwtbootstrap3.client.ui.CheckBox) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) Optional(java.util.Optional) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) Span(org.gwtbootstrap3.client.ui.html.Span)

Example 7 with VetoException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException in project drools-wb by kiegroup.

the class ActionWorkItemInsertFactColumnSynchronizer method append.

@Override
public void append(final ColumnMetaData metaData) throws VetoException {
    // Check operation is supported
    if (!handlesAppend(metaData)) {
        return;
    }
    final ActionWorkItemInsertFactCol52 column = (ActionWorkItemInsertFactCol52) metaData.getColumn();
    final String workItemName = column.getWorkItemName();
    model.getActionCols().stream().filter(c -> c instanceof ActionWorkItemCol52).map(c -> ((ActionWorkItemCol52) c)).filter(c -> c.getWorkItemDefinition().getName().equals(workItemName)).findFirst().ifPresent(c -> findLastIndexOfWorkItemColumn(c).ifPresent(index -> {
        model.getActionCols().add(index + 1, column);
        synchroniseAppendColumn(column);
    }));
}
Also used : ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) List(java.util.List) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) Dependent(javax.enterprise.context.Dependent) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) Collections(java.util.Collections) BaseColumnFieldDiffImpl(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiffImpl) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52)

Example 8 with VetoException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException in project drools-wb by kiegroup.

the class ActionWorkItemSetFieldColumnSynchronizer method append.

@Override
public void append(final ColumnMetaData metaData) throws VetoException {
    // Check operation is supported
    if (!handlesAppend(metaData)) {
        return;
    }
    final ActionWorkItemSetFieldCol52 column = (ActionWorkItemSetFieldCol52) metaData.getColumn();
    final String workItemName = column.getWorkItemName();
    model.getActionCols().stream().filter(c -> c instanceof ActionWorkItemCol52).map(c -> ((ActionWorkItemCol52) c)).filter(c -> c.getWorkItemDefinition().getName().equals(workItemName)).findFirst().ifPresent(p -> findLastIndexOfWorkItemColumn(p).ifPresent(index -> {
        model.getActionCols().add(index + 1, column);
        synchroniseAppendColumn(column);
    }));
}
Also used : ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) List(java.util.List) Dependent(javax.enterprise.context.Dependent) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) Collections(java.util.Collections) BaseColumnFieldDiffImpl(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiffImpl) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52)

Example 9 with VetoException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException in project drools-wb by kiegroup.

the class ActionColumnSynchronizer method doMoveActionFragment.

protected void doMoveActionFragment(final List<MoveColumnToMetaData> metaData) throws VetoException {
    final MoveColumnToMetaData md = metaData.get(0);
    final BaseColumn firstColumnInFragment = md.getColumn();
    final BaseColumn lastColumnInFragment = metaData.get(metaData.size() - 1).getColumn();
    final int srcColumnFirstIndex = model.getExpandedColumns().indexOf(firstColumnInFragment);
    final int srcColumnLastIndex = model.getExpandedColumns().indexOf(lastColumnInFragment);
    final List<ActionCol52> srcModelFragmentColumns = IntStream.rangeClosed(srcColumnFirstIndex, srcColumnLastIndex).mapToObj(i -> model.getExpandedColumns().get(i)).map(column -> (ActionCol52) column).collect(Collectors.toList());
    final int srcModelFragmentColumnsCount = srcModelFragmentColumns.size();
    if (srcModelFragmentColumnsCount == 0) {
        throw new ModelSynchronizer.MoveVetoException();
    }
    if (srcModelFragmentColumnsCount != metaData.size()) {
        throw new ModelSynchronizer.MoveVetoException();
    }
    final int tgtColumnIndex = md.getTargetColumnIndex();
    final int tgtActionIndex = findTargetActionIndex(md);
    final List<BaseColumn> allModelColumns = model.getExpandedColumns();
    moveModelData(tgtColumnIndex, allModelColumns.indexOf(srcModelFragmentColumns.get(0)), allModelColumns.indexOf(srcModelFragmentColumns.get(0)) + srcModelFragmentColumnsCount - 1);
    // Moving left
    if (tgtColumnIndex < srcColumnFirstIndex) {
        final AtomicInteger offset = new AtomicInteger(0);
        srcModelFragmentColumns.forEach(column -> {
            model.getActionCols().remove(column);
            model.getActionCols().add(tgtActionIndex + offset.getAndIncrement(), column);
        });
    }
    // Moving right
    if (tgtColumnIndex > srcColumnFirstIndex) {
        srcModelFragmentColumns.forEach(column -> {
            model.getActionCols().remove(column);
            model.getActionCols().add(tgtActionIndex, column);
        });
    }
}
Also used : IntStream(java.util.stream.IntStream) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) ColumnMetaData(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.impl.BaseColumnSynchronizer.ColumnMetaData) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) OptionalInt(java.util.OptionalInt) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ModelSynchronizer(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Dependent(javax.enterprise.context.Dependent) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) Collections(java.util.Collections) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)

Example 10 with VetoException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCanBeDeletedWithNoAction.

@Test
public void checkBRLFragmentConditionCanBeDeletedWithNoAction() throws VetoException {
    final BRLConditionColumn column = new BRLConditionColumn();
    final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    final BRLConditionVariableColumn columnV1 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
    column.getChildColumns().add(columnV0);
    column.getChildColumns().add(columnV1);
    column.setHeader("col1");
    columnV0.setHeader("col1v0");
    columnV1.setHeader("col1v1");
    modelSynchronizer.appendColumn(column);
    try {
        modelSynchronizer.deleteColumn(column);
    } catch (VetoException veto) {
        fail("Deletion should have been permitted.");
    }
    assertEquals(3, model.getExpandedColumns().size());
    assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
    assertTrue(model.getExpandedColumns().get(1) instanceof RuleNameColumn);
    assertTrue(model.getExpandedColumns().get(2) instanceof DescriptionCol52);
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) RuleNameColumn(org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Aggregations

VetoException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException)24 Test (org.junit.Test)14 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)13 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)13 RuleNameColumn (org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn)13 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)8 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)7 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)7 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)6 Dependent (javax.enterprise.context.Dependent)5 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)5 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)5 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)5 VetoDeletePatternInUseException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException)5 List (java.util.List)4 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)4 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)4 Command (com.google.gwt.user.client.Command)3 Collections (java.util.Collections)3 ActionWorkItemCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52)3