use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method testUpdate1.
@Test
public void testUpdate1() throws VetoException {
// Single Column, single variable
final BRLConditionColumn column = spy(new BRLConditionColumn());
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);
assertEquals(4, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(4, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(3) instanceof IntegerUiColumn);
assertEquals(2, uiModel.getColumns().get(3).getHeaderMetaData().size());
assertEquals("$age", uiModel.getColumns().get(3).getHeaderMetaData().get(1).getTitle());
final BRLConditionColumn edited = new BRLConditionColumn();
final BRLConditionVariableColumn editedColumnV0 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
edited.getChildColumns().add(editedColumnV0);
edited.setHideColumn(true);
edited.setHeader("updated");
editedColumnV0.setHeader("updated");
List<BaseColumnFieldDiff> diffs = modelSynchronizer.updateColumn(column, edited);
assertEquals(5, // header, hide, field name, field type, binding
diffs.size());
verify(column).diff(edited);
assertEquals(4, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(4, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(3) instanceof StringUiColumn);
assertEquals("updated", uiModel.getColumns().get(3).getHeaderMetaData().get(0).getTitle());
assertEquals(false, uiModel.getColumns().get(3).isVisible());
assertEquals(2, uiModel.getColumns().get(3).getHeaderMetaData().size());
assertEquals("$name", uiModel.getColumns().get(3).getHeaderMetaData().get(1).getTitle());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff in project drools-wb by kiegroup.
the class AttributeColumnSynchronizerTest method testUpdate1.
@Test
public void testUpdate1() throws VetoException {
final AttributeCol52 column = spy(new AttributeCol52());
column.setAttribute(Attribute.SALIENCE.getAttributeName());
modelSynchronizer.appendColumn(column);
final AttributeCol52 edited = new AttributeCol52();
edited.setWidth(column.getWidth());
edited.setAttribute(Attribute.ENABLED.getAttributeName());
List<BaseColumnFieldDiff> diffs = modelSynchronizer.updateColumn(column, edited);
assertEquals(1, diffs.size());
verify(column).diff(edited);
assertEquals(1, model.getAttributeCols().size());
assertEquals(Attribute.ENABLED.getAttributeName(), model.getAttributeCols().get(0).getAttribute());
assertEquals(4, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(3) instanceof BooleanUiColumn);
assertEquals(Attribute.ENABLED.getAttributeName(), uiModel.getColumns().get(3).getHeaderMetaData().get(0).getTitle());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff in project drools-wb by kiegroup.
the class ActionSetFieldColumnSynchronizer method update.
@Override
public List<BaseColumnFieldDiff> update(final ColumnMetaData originalMetaData, final ColumnMetaData editedMetaData) throws VetoException {
// Check operation is supported
if (!(handlesUpdate(originalMetaData) && handlesUpdate(editedMetaData))) {
return Collections.emptyList();
}
// Get differences between original and edited column
final ActionSetFieldCol52 originalColumn = (ActionSetFieldCol52) originalMetaData.getColumn();
final ActionSetFieldCol52 editedColumn = (ActionSetFieldCol52) editedMetaData.getColumn();
final List<BaseColumnFieldDiff> diffs = originalColumn.diff(editedColumn);
update(originalColumn, editedColumn);
final boolean isHideUpdated = BaseColumnFieldDiffImpl.hasChanged(ActionSetFieldCol52.FIELD_HIDE_COLUMN, diffs);
final boolean isHeaderUpdated = BaseColumnFieldDiffImpl.hasChanged(ActionSetFieldCol52.FIELD_HEADER, diffs);
final boolean isBoundNameUpdated = BaseColumnFieldDiffImpl.hasChanged(ActionSetFieldCol52.FIELD_BOUND_NAME, diffs);
final boolean isFactFieldUpdated = BaseColumnFieldDiffImpl.hasChanged(ActionSetFieldCol52.FIELD_FACT_FIELD, diffs);
if (isBoundNameUpdated || isFactFieldUpdated) {
clearColumnData(originalColumn);
} else {
cleanColumnData(originalColumn, editedColumn, diffs);
}
synchroniseUpdateColumn(originalColumn);
if (isHideUpdated) {
setColumnVisibility(originalColumn, originalColumn.isHideColumn());
}
if (isHeaderUpdated) {
setColumnHeader(originalColumn, originalColumn.getHeader());
}
return diffs;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff in project drools-wb by kiegroup.
the class ActionWorkItemInsertFactColumnSynchronizer method update.
@Override
public List<BaseColumnFieldDiff> update(final ColumnMetaData originalMetaData, final ColumnMetaData editedMetaData) throws VetoException {
// Check operation is supported
if (!(handlesUpdate(originalMetaData) && handlesUpdate(editedMetaData))) {
return Collections.emptyList();
}
// Get differences between original and edited column
final ActionWorkItemInsertFactCol52 originalColumn = (ActionWorkItemInsertFactCol52) originalMetaData.getColumn();
final ActionWorkItemInsertFactCol52 editedColumn = (ActionWorkItemInsertFactCol52) editedMetaData.getColumn();
final List<BaseColumnFieldDiff> diffs = originalColumn.diff(editedColumn);
update(originalColumn, editedColumn);
// ActionWorkItem columns are always represented with a BooleanUiColumn
final boolean isHideUpdated = BaseColumnFieldDiffImpl.hasChanged(ActionWorkItemInsertFactCol52.FIELD_HIDE_COLUMN, diffs);
final boolean isHeaderUpdated = BaseColumnFieldDiffImpl.hasChanged(ActionWorkItemInsertFactCol52.FIELD_HEADER, diffs);
if (isHideUpdated) {
setColumnVisibility(originalColumn, originalColumn.isHideColumn());
}
if (isHeaderUpdated) {
setColumnHeader(originalColumn, originalColumn.getHeader());
}
return diffs;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizer method update.
@Override
public List<BaseColumnFieldDiff> update(final ColumnMetaData originalMetaData, final ColumnMetaData editedMetaData) throws VetoException {
// Check operation is supported
if (!(handlesUpdate(originalMetaData) && handlesUpdate(editedMetaData))) {
return Collections.emptyList();
}
// Check whether any discarded bindings were used. If so veto the update.
final BRLConditionColumn originalColumn = (BRLConditionColumn) originalMetaData.getColumn();
final BRLConditionColumn editedColumn = (BRLConditionColumn) editedMetaData.getColumn();
final Set<String> originalBindings = getPatternBindings(originalColumn);
final Set<String> editedBindings = getPatternBindings(editedColumn);
originalBindings.removeAll(editedBindings);
for (String binding : originalBindings) {
if (rm.isBoundFactUsed(binding)) {
throw new VetoUpdatePatternInUseException();
}
}
final List<BaseColumnFieldDiff> diffs = originalColumn.diff(editedColumn);
// Copy existing data for re-use if applicable
final Map<String, List<DTCellValue52>> originalColumnsData = new HashMap<>();
for (BRLConditionVariableColumn variable : originalColumn.getChildColumns()) {
int iColumnIndex = model.getExpandedColumns().indexOf(variable);
final List<DTCellValue52> originalColumnData = new ArrayList<>();
final String key = makeUpdateBRLConditionColumnKey(variable);
for (List<DTCellValue52> row : model.getData()) {
originalColumnData.add(row.get(iColumnIndex));
}
originalColumnsData.put(key, originalColumnData);
}
// Insert new columns setting data from that above, if applicable. Column visibility is handled here too.
model.getConditions().add(model.getConditions().indexOf(originalColumn), editedColumn);
for (BRLConditionVariableColumn childModelColumn : editedColumn.getChildColumns()) {
final String key = makeUpdateBRLConditionColumnKey(childModelColumn);
if (originalColumnsData.containsKey(key)) {
final List<DTCellValue52> originalColumnData = originalColumnsData.get(key);
synchroniseAppendColumn(childModelColumn, originalColumnData);
} else {
synchroniseAppendColumn(childModelColumn);
}
}
// Delete columns for the original definition
doDelete(originalColumn);
// Signal patterns changed event to Decision Table Widget
final BoundFactsChangedEvent pce = new BoundFactsChangedEvent(rm.getLHSBoundFacts());
eventBus.fireEvent(pce);
return diffs;
}
Aggregations