use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools-wb by kiegroup.
the class ActionSetFieldColumnSynchronizer method isActionSetFieldFragment.
private boolean isActionSetFieldFragment(final List<? extends MetaData> metaData) {
if (!metaData.stream().allMatch((c) -> (c instanceof MoveColumnToMetaData))) {
return false;
}
if (!metaData.stream().map(c -> (MoveColumnToMetaData) c).allMatch(c -> c.getColumn() instanceof ActionSetFieldCol52)) {
return false;
}
final BaseColumn firstColumnInFragment = ((MoveColumnToMetaData) metaData.get(0)).getColumn();
final BaseColumn lastColumnInFragment = ((MoveColumnToMetaData) metaData.get(metaData.size() - 1)).getColumn();
final int firstColumnIndex = model.getExpandedColumns().indexOf(firstColumnInFragment);
final int lastColumnIndex = model.getExpandedColumns().indexOf(lastColumnInFragment);
return lastColumnIndex - firstColumnIndex == metaData.size() - 1;
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools-wb by kiegroup.
the class ActionSetFieldColumnSynchronizerTest method testUpdate.
@Test
public void testUpdate() throws VetoException {
// Add a Pattern to be updated
final Pattern52 pattern = new Pattern52();
pattern.setBoundName("$a");
pattern.setFactType("Applicant");
final ConditionCol52 condition = new ConditionCol52();
condition.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
condition.setHeader("col1");
condition.setFactField("age");
condition.setOperator("==");
modelSynchronizer.appendColumn(pattern, condition);
final ActionSetFieldCol52 column = spy(new ActionSetFieldCol52());
column.setHeader("col1");
column.setBoundName("$a");
column.setFactField("age");
modelSynchronizer.appendColumn(column);
final ActionSetFieldCol52 edited = new ActionSetFieldCol52();
edited.setWidth(column.getWidth());
edited.setBoundName("$a");
edited.setFactField("name");
edited.setHideColumn(true);
edited.setHeader("updated");
List<BaseColumnFieldDiff> diffs = modelSynchronizer.updateColumn(column, edited);
assertEquals(3, diffs.size());
verify(column).diff(edited);
assertEquals(1, model.getConditions().size());
assertEquals(1, model.getActionCols().size());
assertEquals(4, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(3) instanceof StringUiColumn);
assertEquals("updated", uiModel.getColumns().get(3).getHeaderMetaData().get(1).getTitle());
assertEquals(false, uiModel.getColumns().get(3).isVisible());
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools-wb by kiegroup.
the class ActionSetFieldColumnSynchronizerTest method testMoveColumnTo_MoveRight.
@Test
public void testMoveColumnTo_MoveRight() throws VetoException {
// Add a Pattern to be updated
final Pattern52 pattern = new Pattern52();
pattern.setBoundName("$a");
pattern.setFactType("Applicant");
final ConditionCol52 condition = new ConditionCol52();
condition.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
condition.setHeader("col1");
condition.setFactField("age");
condition.setOperator("==");
modelSynchronizer.appendColumn(pattern, condition);
final ActionSetFieldCol52 column1 = new ActionSetFieldCol52();
column1.setBoundName("$a");
column1.setFactField("age");
column1.setHeader("age");
final ActionSetFieldCol52 column2 = new ActionSetFieldCol52();
column2.setBoundName("$a");
column2.setFactField("name");
column2.setHeader("name");
modelSynchronizer.appendColumn(column1);
modelSynchronizer.appendColumn(column2);
modelSynchronizer.appendRow();
uiModel.setCellValue(0, 3, new BaseGridCellValue<Integer>(45));
uiModel.setCellValue(0, 4, new BaseGridCellValue<String>("Smurf"));
assertEquals(2, model.getActionCols().size());
assertEquals(column1, model.getActionCols().get(0));
assertEquals(column2, model.getActionCols().get(1));
assertEquals(45, model.getData().get(0).get(3).getNumericValue());
assertEquals("Smurf", model.getData().get(0).get(4).getStringValue());
assertEquals(5, uiModel.getColumns().size());
final GridColumn<?> uiModelColumn1_1 = uiModel.getColumns().get(3);
final GridColumn<?> uiModelColumn2_1 = uiModel.getColumns().get(4);
assertEquals("$a", uiModelColumn1_1.getHeaderMetaData().get(0).getTitle());
assertEquals("age", uiModelColumn1_1.getHeaderMetaData().get(1).getTitle());
assertEquals("$a", uiModelColumn2_1.getHeaderMetaData().get(0).getTitle());
assertEquals("name", uiModelColumn2_1.getHeaderMetaData().get(1).getTitle());
assertTrue(uiModelColumn1_1 instanceof IntegerUiColumn);
assertTrue(uiModelColumn2_1 instanceof StringUiColumn);
assertEquals(3, uiModelColumn1_1.getIndex());
assertEquals(4, uiModelColumn2_1.getIndex());
assertEquals(45, uiModel.getRow(0).getCells().get(uiModelColumn1_1.getIndex()).getValue().getValue());
assertEquals("Smurf", uiModel.getRow(0).getCells().get(uiModelColumn2_1.getIndex()).getValue().getValue());
uiModel.moveColumnTo(4, uiModelColumn1_1);
assertEquals(2, model.getActionCols().size());
assertEquals(column2, model.getActionCols().get(0));
assertEquals(column1, model.getActionCols().get(1));
assertEquals("Smurf", model.getData().get(0).get(3).getStringValue());
assertEquals(45, model.getData().get(0).get(4).getNumericValue());
assertEquals(5, uiModel.getColumns().size());
final GridColumn<?> uiModelColumn1_2 = uiModel.getColumns().get(3);
final GridColumn<?> uiModelColumn2_2 = uiModel.getColumns().get(4);
assertEquals("$a", uiModelColumn1_2.getHeaderMetaData().get(0).getTitle());
assertEquals("name", uiModelColumn1_2.getHeaderMetaData().get(1).getTitle());
assertEquals("$a", uiModelColumn2_2.getHeaderMetaData().get(0).getTitle());
assertEquals("age", uiModelColumn2_2.getHeaderMetaData().get(1).getTitle());
assertTrue(uiModelColumn1_2 instanceof StringUiColumn);
assertTrue(uiModelColumn2_2 instanceof IntegerUiColumn);
assertEquals(4, uiModelColumn1_2.getIndex());
assertEquals(3, uiModelColumn2_2.getIndex());
assertEquals("Smurf", uiModel.getRow(0).getCells().get(uiModelColumn1_2.getIndex()).getValue().getValue());
assertEquals(45, uiModel.getRow(0).getCells().get(uiModelColumn2_2.getIndex()).getValue().getValue());
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCannotBeUpdatedWhenBindingIsUsedInAction.
@Test
public void checkBRLFragmentConditionCannotBeUpdatedWhenBindingIsUsedInAction() 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 {
final BRLConditionColumn editedColumn = new BRLConditionColumn();
editedColumn.setDefinition(Collections.singletonList(new FactPattern("Applicant") {
{
setBoundName("$a2");
}
}));
final BRLConditionVariableColumn editedColumnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
editedColumn.getChildColumns().add(editedColumnV0);
editedColumn.setHeader("col1");
editedColumnV0.setHeader("col1v0");
modelSynchronizer.updateColumn(column, editedColumn);
fail("Deletion of the column should have been vetoed.");
} catch (VetoUpdatePatternInUseException veto) {
// This is expected
} catch (VetoException veto) {
fail("VetoUpdatePatternInUseException was expected.");
}
assertEquals(4, model.getExpandedColumns().size());
assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
assertTrue(model.getExpandedColumns().get(1) instanceof DescriptionCol52);
assertEquals(columnV0, model.getExpandedColumns().get(2));
assertEquals(action, model.getExpandedColumns().get(3));
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCanBeUpdatedWithNewConstraintOnBoundPatternUsedInAction.
@Test
public void checkBRLFragmentConditionCanBeUpdatedWithNewConstraintOnBoundPatternUsedInAction() 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 {
final BRLConditionColumn editedColumn = new BRLConditionColumn();
editedColumn.setDefinition(Collections.singletonList(new FactPattern("Applicant") {
{
setBoundName("$a");
}
}));
final BRLConditionVariableColumn editedColumnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
final BRLConditionVariableColumn editedColumnV1 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
editedColumn.getChildColumns().add(editedColumnV0);
editedColumn.getChildColumns().add(editedColumnV1);
editedColumn.setHeader("col1");
editedColumnV0.setHeader("col1v0");
editedColumnV1.setHeader("col1v1");
modelSynchronizer.updateColumn(column, editedColumn);
assertEquals(5, model.getExpandedColumns().size());
assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
assertTrue(model.getExpandedColumns().get(1) instanceof DescriptionCol52);
assertEquals(editedColumnV0, model.getExpandedColumns().get(2));
assertEquals(editedColumnV1, model.getExpandedColumns().get(3));
assertEquals(action, model.getExpandedColumns().get(4));
} catch (VetoException veto) {
fail("VetoUpdatePatternInUseException was not expected.");
}
}
Aggregations