Manually creating and firing events from inside another listener [message #999268] |
Fri, 11 January 2013 12:36  |
Eclipse User |
|
|
|
Hi all,
I have an object with a TreeViewer wrapped inside it, which has a modified TreeListener that resolves EMF proxies using a ComposedAdapterFactory when a TreeExpansionEvent is handled. I would like the same modified expansion to take place when a selection in the TreeViewer is double-clicked on. I have manually created a TreeExpansionEvent and called the modified TreeListener's treeExpanded() from inside the DoubleClickListener; I also tried to add the event to the the Display and system EventQueues. In both cases, the debugger goes through the TreeListener's code, calls on the ComposedAdapterFactory's getChildren() and resolves the proxies, but unlike when the twistie is opened on the tree, double clicking and firing an event does not eventually lead to any OS calls and so the tree doesn't actually expand.
Does anyone have any idea on what I could do to make the double click trigger the tree expansion? The TreeViewer is in an inner class.
Here is the doubleClickListener; There's also a variation I tried without the runnable and simply calls the TreeListener, mtvl
@Override
public void doubleClick(DoubleClickEvent event) {
treeViewer.getDisplay();
Object selectedFirstElement = (EObject) ((TreeSelection) workloadViewer.getSelection()).getFirstElement();
Display.getCurrent().syncExec(new Runnable() {
@Override
public void run() {
final TreeExpansionEvent te = new TreeExpansionEvent(treeViewer.getTreeViewer(), treeViewer.getSelection().getFirstElement());
mtvl.treeExpanded(te);
}});
Thanks!
|
|
|
Re: Manually creating and firing events from inside another listener [message #1000193 is a reply to message #999268] |
Mon, 14 January 2013 03:30  |
Eclipse User |
|
|
|
Hi Maya
I handle the expansion and collapse on double click like this:
viewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (!selection.isEmpty()) {
Object element = selection.getFirstElement();
if (viewer.getExpandedState(element))
viewer.collapseToLevel(element, AbstractTreeViewer.ALL_LEVELS);
else
viewer.expandToLevel(element, 1);
}
}
});
Hope this helps.
Greetings
Christoph
|
|
|
Powered by
FUDForum. Page generated in 0.08623 seconds