use of org.obeonetwork.dsl.environment.binding.dialect.ui.treemapper.TreeRoot in project InformationSystem by ObeoNetwork.
the class BindingTreeEditor method createPartControl.
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
setUpUndoRedoActionHandler();
sashForm = new SashForm(parent, SWT.VERTICAL);
sashForm.setSashWidth(3);
parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
editorManager = new BindingTreeEditorManager(getEditingDomain(), accessor);
BindingTreeSemanticSupport treeSemanticSupport = new BindingTreeSemanticSupport(getBindingInfo(), editorManager);
treeMapper = new BindingTreeMapper(sashForm, treeSemanticSupport);
getSite().setSelectionProvider(treeMapper);
treeMapper.getLeftTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof StructuredSelection) {
StructuredSelection strSelection = (StructuredSelection) event.getSelection();
@SuppressWarnings("unchecked") Collection<DBoundElement> selectedElements = (Collection<DBoundElement>) strSelection.toList();
populateLTRMappingDetails(selectedElements);
}
}
});
treeMapper.getRightTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof StructuredSelection) {
StructuredSelection strSelection = (StructuredSelection) event.getSelection();
@SuppressWarnings("unchecked") Collection<DBoundElement> selectedElements = (Collection<DBoundElement>) strSelection.toList();
populateRTLMappingDetails(selectedElements);
}
}
});
TreeDataProvider treeDataProvider = new TreeDataProvider(getBindingInfo());
DBoundElement left = treeDataProvider.getLeftRoot();
DBoundElement right = treeDataProvider.getRightRoot();
List<DBindingEdge> edges = treeDataProvider.getEdges();
treeMapper.setInput(new TreeRoot(left), new TreeRoot(right), edges);
createBindingGroupDetails(sashForm);
grpDetailsLTR.setText(getBindingDetailsLabel(left, right));
grpDetailsRTL.setText(getBindingDetailsLabel(right, left));
sashForm.setWeights(new int[] { 70, 30 });
// Expand the first levels on the two trees
treeMapper.getLeftTreeViewer().expandToLevel(2);
treeMapper.getRightTreeViewer().expandToLevel(2);
revealBoundElements(edges);
}
use of org.obeonetwork.dsl.environment.binding.dialect.ui.treemapper.TreeRoot in project InformationSystem by ObeoNetwork.
the class BindingTreeEditor method doRefresh.
public void doRefresh() {
TreeDataProvider treeDataProvider = new TreeDataProvider(getBindingInfo());
DBoundElement left = treeDataProvider.getLeftRoot();
DBoundElement right = treeDataProvider.getRightRoot();
List<DBindingEdge> edges = treeDataProvider.getEdges();
treeMapper.setInput(new TreeRoot(left), new TreeRoot(right), edges);
treeMapper.refresh();
treeMapper.getLeftTreeViewer().expandToLevel(2);
treeMapper.getRightTreeViewer().expandToLevel(2);
}
use of org.obeonetwork.dsl.environment.binding.dialect.ui.treemapper.TreeRoot 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