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