use of org.kie.workbench.common.dmn.api.definition.model.Relation in project kie-wb-common by kiegroup.
the class MoveRowsCommandTest method setup.
@Before
public void setup() {
this.relation = new Relation();
this.uiModel = new DMNGridData();
doReturn(ruleManager).when(handler).getRuleManager();
doReturn(0).when(uiRowNumberColumn).getIndex();
doReturn(1).when(uiModelColumn1).getIndex();
addRelationColumn(II1);
addRelationColumn(II2);
addRelationRow(II1);
addRelationRow(II2);
addUiModelColumn(uiRowNumberColumn);
addUiModelColumn(uiModelColumn1);
addUiModelRow(0);
addUiModelRow(1);
}
use of org.kie.workbench.common.dmn.api.definition.model.Relation in project kie-wb-common by kiegroup.
the class DeleteRelationRowCommandTest method setup.
@Before
public void setup() {
this.relation = new Relation();
this.rowList = new List();
this.relation.getRow().add(rowList);
this.uiModel = new BaseGridData();
this.uiModel.appendRow(new BaseGridRow());
this.uiModel.appendColumn(uiRowNumberColumn);
this.uiModelMapper = new RelationUIModelMapper(() -> uiModel, () -> Optional.of(relation), listSelector, DEFAULT_HEIGHT);
makeCommand(0);
doReturn(ruleManager).when(handler).getRuleManager();
doReturn(0).when(uiRowNumberColumn).getIndex();
doReturn(1).when(uiModelColumn).getIndex();
}
use of org.kie.workbench.common.dmn.api.definition.model.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);
CommandUtils.moveComponentWidths(Relation.STATIC_COLUMNS + relativeIndex, Relation.STATIC_COLUMNS + relativeOldIndex, relation.getComponentWidths(), Collections.singletonList(oldIndex));
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));
}
};
}
use of org.kie.workbench.common.dmn.api.definition.model.Relation in project kie-wb-common by kiegroup.
the class RelationGrid method initialiseUiColumns.
@Override
public void initialiseUiColumns() {
int uiColumnIndex = 0;
final RowNumberColumn rowNumberColumn = new RowNumberColumn();
rowNumberColumn.setWidth(getAndSetInitialWidth(uiColumnIndex++, rowNumberColumn.getWidth()));
if (getExpression().get().isPresent()) {
model.appendColumn(rowNumberColumn);
final Relation e = getExpression().get().get();
for (int index = 0; index < e.getColumn().size(); index++) {
final GridColumn relationColumn = makeRelationColumn(uiColumnIndex++, e.getColumn().get(index));
model.appendColumn(relationColumn);
}
}
getRenderer().setColumnRenderConstraint((isSelectionLayer, gridColumn) -> true);
}
use of org.kie.workbench.common.dmn.api.definition.model.Relation in project kie-wb-common by kiegroup.
the class RelationGrid method doAfterHeaderSelectionChange.
@Override
public void doAfterHeaderSelectionChange(final int uiHeaderRowIndex, final int uiHeaderColumnIndex) {
if (getExpression().get().isPresent()) {
final Relation relation = getExpression().get().get();
final RelationUIModelMapperHelper.RelationSection section = RelationUIModelMapperHelper.getSection(relation, uiHeaderColumnIndex);
if (section == RelationUIModelMapperHelper.RelationSection.INFORMATION_ITEM) {
final int iiIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, uiHeaderColumnIndex);
final InformationItem domainObject = relation.getColumn().get(iiIndex);
fireDomainObjectSelectionEvent(domainObject);
return;
}
}
super.doAfterHeaderSelectionChange(uiHeaderRowIndex, uiHeaderColumnIndex);
}
Aggregations