| Launching View on double click from a TreeViewer [message #444383] |
Tue, 14 February 2006 16:12  |
Eclipse User |
|
|
|
Originally posted by: pverma.gmail.com
Hi,
I am trying to connect two views as follows. The idea is that a user
double clicks on a tree control containing a Name, and another view shows
up with a text that is "Hello, Name":
View 1
------
Contains a TreeViewer
In createPartControl(), the following code registers the TreeViewer as
selection provider:
getSite().setSelectionProvider(viewer);
A double click event on the TreeViewer launches View 2 using "showView".
View 2
------
In createPartControl(), the following code tries to get the current
selection:
ISelectionProvider provider;
IStructuredSelection selection;
provider = getSite().getSelectionProvider(); //This always returns
NULL!
selection = (IStructuredSelection)provider.getSelection();
On debugging, I see that the value of "provider" that is returned by the
getSelectionProvider() call is always null.
Any suggestion where I am making a mistake?
Thanks.
PS:If I didn't say that earlier: Newbie alert.
|
|
|
|
|
|
|
|
|
| Re: Launching View on double click from a TreeViewer [message #444408 is a reply to message #444395] |
Wed, 15 February 2006 15:00  |
Eclipse User |
|
|
|
Originally posted by: pverma.gmail.com
Rohit wrote:
> for that u can use the second alternative of the hidden view.
The second alternative would not work precisely for the reasons I outlined
in that email. For the second scenario (the context menu) neither of the
approaches would work.
So, here is what I did:
View 1 has a TreeViewer, which is registered as a SelectionProvider, as
below:
getSite().setSelectionProvider(viewer);
View 2 needs to display text based on the selection in View 1, on double
clicking it. Here is what worked for me (code in View 2's
createPartControl()):
IWorkbenchWindow window = getSite().getWorkbenchWindow();
ISelectionService service = window.getSelectionService();
IStructuredSelection sel =
(IStructuredSelection)service.getSelection();
to1 = (TreeObject)sel.getFirstElement();
if(to1 != null)
MessageDialog.openInformation(getSite().getShell(),
"fromView!!", to1.getName());
But everything is not all right. It works perfectly fine the first time.
The second time that I double click on the Tree in View 1, View 2 is
unable to get the selection. The variable "sel" above is null after the
first time that it works perfectly. The variables "window" and "service"
are all right though.
Any ideas where the hitch could be?
Thanks!
|
|
|
Powered by
FUDForum. Page generated in 0.04769 seconds