use of org.kie.workbench.common.dmn.api.definition.v1_1.Relation in project kie-wb-common by kiegroup.
the class RelationGridTest method testInitialiseUiModel.
@Test
public void testInitialiseUiModel() throws Exception {
relation.getColumn().add(new InformationItem() {
{
getName().setValue("first column header");
}
});
final String firstRowValue = "first column value 1";
final String secondRowValue = "first column value 2";
relation.getRow().add(new List() {
{
getExpression().add(new LiteralExpression() {
{
setText(firstRowValue);
}
});
}
});
relation.getRow().add(new List() {
{
getExpression().add(new LiteralExpression() {
{
setText(secondRowValue);
}
});
}
});
expression = Optional.of(relation);
setupGrid(0);
assertEquals(2, grid.getModel().getRowCount());
assertEquals(firstRowValue, grid.getModel().getRow(0).getCells().get(1).getValue().getValue());
assertEquals(secondRowValue, grid.getModel().getRow(1).getCells().get(1).getValue().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Relation in project kie-wb-common by kiegroup.
the class RelationUIModelMapperHelperTest method testGetInformationItemIndex.
@Test
public void testGetInformationItemIndex() {
relation.getColumn().add(new InformationItem());
relation.getColumn().add(new InformationItem());
assertEquals(0, getInformationItemIndex(relation, 1));
assertEquals(1, getInformationItemIndex(relation, 2));
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Relation in project kie-wb-common by kiegroup.
the class RelationUIModelMapperHelperTest method testGetSectionRowNumberColumnWhenInformationItemPresent.
@Test
public void testGetSectionRowNumberColumnWhenInformationItemPresent() {
relation.getColumn().add(new InformationItem());
assertEquals(RelationSection.ROW_INDEX, getSection(relation, 0));
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Relation in project kie-wb-common by kiegroup.
the class RelationPropertyConverter method wbFromDMN.
public static Relation wbFromDMN(final org.kie.dmn.model.v1_1.Relation dmn) {
Id id = new Id(dmn.getId());
Description description = new Description(dmn.getDescription());
QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
List<org.kie.dmn.model.v1_1.InformationItem> column = dmn.getColumn();
List<org.kie.dmn.model.v1_1.List> row = dmn.getRow();
List<InformationItem> convertedColumn = column.stream().map(InformationItemPropertyConverter::wbFromDMN).collect(Collectors.toList());
List<org.kie.workbench.common.dmn.api.definition.v1_1.List> convertedRow = row.stream().map(ListPropertyConverter::wbFromDMN).collect(Collectors.toList());
Relation result = new Relation(id, description, typeRef, convertedColumn, convertedRow);
return result;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Relation in project kie-wb-common by kiegroup.
the class MoveColumnsCommand method newGraphCommand.
@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
return new AbstractGraphCommand() {
@Override
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
return isColumnInValidSection() ? GraphCommandResultBuilder.SUCCESS : GraphCommandResultBuilder.FAILED;
}
private boolean isColumnInValidSection() {
final RelationSection section = RelationUIModelMapperHelper.getSection(relation, index);
return section == RelationSection.INFORMATION_ITEM;
}
@Override
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
return moveInformationItems(index);
}
@Override
public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
return moveInformationItems(oldIndex);
}
private CommandResult<RuleViolation> moveInformationItems(final int index) {
final RelationSection section = RelationUIModelMapperHelper.getSection(relation, index);
if (section == RelationSection.INFORMATION_ITEM) {
final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
final int relativeIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, index);
final int relativeOldIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, oldIndex);
final java.util.List<Integer> informationItemIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).map(i -> RelationUIModelMapperHelper.getInformationItemIndex(relation, i)).collect(Collectors.toList());
moveInformationItems(relativeIndex, relativeOldIndex, relation.getColumn(), informationItemIndexesToMove);
updateRowsData(relativeIndex, relativeOldIndex, relation.getRow(), informationItemIndexesToMove);
return GraphCommandResultBuilder.SUCCESS;
} else {
return GraphCommandResultBuilder.FAILED;
}
}
private <T> void moveInformationItems(final int relativeIndex, final int relativeOldIndex, final java.util.List<T> informationItems, final java.util.List<Integer> informationItemIndexesToMove) {
final java.util.List<T> informationItemsToMove = informationItemIndexesToMove.stream().map(informationItems::get).collect(Collectors.toList());
informationItems.removeAll(informationItemsToMove);
if (relativeIndex < relativeOldIndex) {
informationItems.addAll(relativeIndex, informationItemsToMove);
} else if (relativeIndex > relativeOldIndex) {
informationItems.addAll(relativeIndex - informationItemsToMove.size() + 1, informationItemsToMove);
}
}
private void updateRowsData(final int relativeIndex, final int relativeOldIndex, final java.util.List<List> rows, final java.util.List<Integer> informationItemIndexesToMove) {
rows.forEach(row -> moveInformationItems(relativeIndex, relativeOldIndex, row.getExpression(), informationItemIndexesToMove));
}
};
}
Aggregations