use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException in project drools-wb by kiegroup.
the class ConditionColumnSynchronizerTest method checkConditionCannotBeDeletedWhenFieldBindingIsUsedInAction.
@Test
public void checkConditionCannotBeDeletedWhenFieldBindingIsUsedInAction() throws VetoException {
final Pattern52 pattern = boundApplicantPattern("$a");
final ConditionCol52 condition = ageEqualsCondition();
condition.setBinding("$age");
final BRLActionColumn action = actionCallMethod("$age");
modelSynchronizer.appendColumn(pattern, condition);
modelSynchronizer.appendColumn(action);
try {
modelSynchronizer.deleteColumn(condition);
fail("Deletion of the column should have been vetoed.");
} catch (VetoDeletePatternInUseException veto) {
// This is expected
} catch (VetoException veto) {
fail("VetoDeletePatternInUseException was expected.");
}
assertEquals(5, model.getExpandedColumns().size());
assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
assertTrue(model.getExpandedColumns().get(1) instanceof RuleNameColumn);
assertTrue(model.getExpandedColumns().get(2) instanceof DescriptionCol52);
assertEquals(condition, model.getExpandedColumns().get(3));
assertEquals(action.getChildColumns().get(0), model.getExpandedColumns().get(4));
}
use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCannotBeDeletedWithAction.
@Test
public void checkBRLFragmentConditionCannotBeDeletedWithAction() throws VetoException {
final BRLConditionColumn column = new BRLConditionColumn();
column.setDefinition(Collections.singletonList(new FactPattern("Applicant") {
{
setBoundName("$a");
}
}));
final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
column.getChildColumns().add(columnV0);
column.setHeader("col1");
columnV0.setHeader("col1v0");
modelSynchronizer.appendColumn(column);
final ActionSetFieldCol52 action = new ActionSetFieldCol52() {
{
setBoundName("$a");
setFactField("age");
setHeader("action1");
}
};
modelSynchronizer.appendColumn(action);
try {
modelSynchronizer.deleteColumn(column);
fail("Deletion of the column should have been vetoed.");
} catch (VetoDeletePatternInUseException veto) {
// This is expected
} catch (VetoException veto) {
fail("VetoDeletePatternInUseException was expected.");
}
assertEquals(5, model.getExpandedColumns().size());
assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
assertTrue(model.getExpandedColumns().get(1) instanceof RuleNameColumn);
assertTrue(model.getExpandedColumns().get(2) instanceof DescriptionCol52);
assertEquals(columnV0, model.getExpandedColumns().get(3));
assertEquals(action, model.getExpandedColumns().get(4));
}
use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException in project drools-wb by kiegroup.
the class ColumnManagementView method renderColumn.
HorizontalPanel renderColumn(final ActionCol52 actionColumn) {
HorizontalPanel action = newHorizontalPanel();
final ColumnLabelWidget actionLabel = makeColumnLabel(actionColumn);
action.add(actionLabel);
final FlowPanel buttons = new FlowPanel() {
{
add(editAnchor((clickEvent) -> {
presenter.getActiveDecisionTable().ifPresent(dt -> dt.editAction(actionColumn));
}));
if (presenter.isActiveDecisionTableEditable()) {
add(deleteAnchor(actionColumn.getHeader(), () -> {
try {
final Optional<GuidedDecisionTableView.Presenter> dtPresenter = presenter.getActiveDecisionTable();
if (dtPresenter.isPresent()) {
dtPresenter.get().deleteColumn(actionColumn);
}
} catch (VetoDeletePatternInUseException veto) {
presenter.getView().showUnableToDeleteColumnMessage(actionColumn);
} catch (VetoException veto) {
presenter.getView().showGenericVetoMessage();
}
}));
}
}
};
action.add(buttons);
return action;
}
use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizer method delete.
@Override
public void delete(final ColumnMetaData metaData) throws VetoException {
// Check operation is supported
if (!handlesDelete(metaData)) {
return;
}
if (metaData.getColumn() instanceof BRLConditionColumn) {
final BRLConditionColumn column = (BRLConditionColumn) metaData.getColumn();
// If Pattern has been updated and there was only one child column then original Pattern will be deleted
final Set<String> bindings = getPatternBindings(column);
for (String binding : bindings) {
if (rm.isBoundFactUsed(binding)) {
throw new VetoDeletePatternInUseException();
}
}
doDelete(column);
} else if (metaData.getColumn() instanceof BRLConditionVariableColumn) {
doDelete((BRLConditionVariableColumn) metaData.getColumn());
}
}
use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException in project drools-wb by kiegroup.
the class ConditionColumnSynchronizer method delete.
@Override
public void delete(final ColumnMetaData metaData) throws VetoException {
// Check operation is supported
if (!handlesDelete(metaData)) {
return;
}
final ConditionCol52 column = (ConditionCol52) metaData.getColumn();
final int columnIndex = model.getExpandedColumns().indexOf(column);
final Pattern52 pattern = model.getPattern(column);
// Check if pattern change can be applied to model
if (!isPotentialConditionDeletionSafe(column)) {
throw new VetoDeletePatternInUseException();
}
if (!isPotentialPatternDeletionSafe(pattern)) {
throw new VetoDeletePatternInUseException();
}
// Perform deletion
pattern.getChildColumns().remove(column);
// Remove pattern if it contains zero conditions
if (pattern.getChildColumns().isEmpty()) {
model.getConditions().remove(pattern);
// Signal patterns changed event to Decision Table Widget
final BoundFactsChangedEvent bfce = new BoundFactsChangedEvent(rm.getLHSBoundFacts());
eventBus.fireEvent(bfce);
}
synchroniseDeleteColumn(columnIndex);
}
Aggregations