Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Manually creating and firing events from inside another listener
Manually creating and firing events from inside another listener [message #999268] Fri, 11 January 2013 12:36 Go to next message
Maya L. is currently offline Maya L.
Messages: 2
Registered: January 2013
Junior Member
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 Go to previous message
Christoph Keimel is currently offline Christoph Keimel
Messages: 346
Registered: December 2010
Location: Germany
Senior Member
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
Previous Topic:Events not passed up to Shell?
Next Topic:Changing PrinterData's paper size.
Goto Forum:
  


Current Time: Wed Aug 20 05:06:01 EDT 2014

Powered by FUDForum. Page generated in 0.01494 seconds