use of org.obeonetwork.dsl.environment.binding.dialect.ui.treemapper.commands.CreateMappingsCommand in project InformationSystem by ObeoNetwork.
the class BindingTreeEditor method autoBind.
private void autoBind() {
TreeRoot leftRoot = (TreeRoot) treeMapper.getLeftTreeViewer().getInput();
DBoundElement leftRootElement = leftRoot.getElement();
TreeRoot rightRoot = (TreeRoot) treeMapper.getRightTreeViewer().getInput();
DBoundElement rightRootElement = rightRoot.getElement();
// collect candidates to auto bind
List<DBoundElement> leftCandidates = new ArrayList<DBoundElement>();
for (DBoundElement leftItem : leftRootElement.getChildren()) {
if (leftItem.getEdgesAsLeft().isEmpty()) {
leftCandidates.add(leftItem);
}
}
List<DBoundElement> rightCandidates = new ArrayList<DBoundElement>();
for (DBoundElement rightItem : rightRootElement.getChildren()) {
if (rightItem.getEdgesAsRight().isEmpty()) {
rightCandidates.add(rightItem);
}
}
List<DBoundElement> leftElementsToBind = new ArrayList<DBoundElement>();
List<DBoundElement> rightElementsToBind = new ArrayList<DBoundElement>();
while (leftCandidates.isEmpty() == false && rightCandidates.isEmpty() == false) {
DBoundElement left = leftCandidates.remove(0);
for (DBoundElement right : rightCandidates) {
if (getPropertyLabel(left.getTarget()).equals(getPropertyLabel(right.getTarget()))) {
leftElementsToBind.add(left);
rightElementsToBind.add(right);
rightCandidates.remove(right);
break;
}
}
}
if (leftElementsToBind.size() > 0) {
editorManager.execute(new CreateMappingsCommand(getEditingDomain(), getBindingInfo(), leftElementsToBind, rightElementsToBind));
doRefresh();
}
}
Aggregations