Search in sources :

Example 1 with CreateMappingsCommand

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();
    }
}
Also used : CreateMappingsCommand(org.obeonetwork.dsl.environment.binding.dialect.ui.treemapper.commands.CreateMappingsCommand) TreeRoot(org.obeonetwork.dsl.environment.binding.dialect.ui.treemapper.TreeRoot) ArrayList(java.util.ArrayList) DBoundElement(org.obeonetwork.dsl.environment.bindingdialect.DBoundElement)

Aggregations

ArrayList (java.util.ArrayList)1 TreeRoot (org.obeonetwork.dsl.environment.binding.dialect.ui.treemapper.TreeRoot)1 CreateMappingsCommand (org.obeonetwork.dsl.environment.binding.dialect.ui.treemapper.commands.CreateMappingsCommand)1 DBoundElement (org.obeonetwork.dsl.environment.bindingdialect.DBoundElement)1