Launching View on double click from a TreeViewer [message #444383] |
Tue, 14 February 2006 21: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 #444391 is a reply to message #444386] |
Wed, 15 February 2006 04:59 |
Eclipse User |
|
|
|
Originally posted by: pverma.gmail.com
James Leotta wrote:
> Your second view has to implement ISelectionListener. Implement the
> method selectionChanged() with something like:
> public void selectionChanged(IWorkbenchPart part, ISelection incoming) {
>...
I have a question here. Wouldn't this work only if the view existed
already? When the selection changed, the view would refresh to show
content based on the new selection.
What needs to happen is that when the user double clicks on the tree
control, a new view instance is created in a IFolderlayout, with text
coming from the current selection in the tree control. If the view content
depended on the selection change event, the new view would not get that
event since it did not exist when that event took place.
|
|
|
|
Re: Launching View on double click from a TreeViewer [message #444394 is a reply to message #444393] |
Wed, 15 February 2006 07:29 |
Eclipse User |
|
|
|
Originally posted by: pverma.gmail.com
Rohit wrote:
> if want to open new view every time when you click on the tree then u can
implement the mousedoubleclickevent and display the view when the node is
selected.
> or another way is to first create the hidden view that implementing the
selectionchange and write the code the show the view when any selection happen
Thanks Rohit, those are interesting alternatives. Some thinking aloud: If
the eclipse UI event handling is always single threaded, then the first
method is always reliable i.e. the "mousedoubleclickevent -> View
Construction -> selectionChangedEvent" will always be in that order in
time. So the problem of opening the view on a double click on the tree is
solved.
But assuming I also want to add in a context menu to the tree "Open in new
View", then this mechanism would no longer work for me. i.e.
a)Select a node in the tree
b)right click on the node
c)In the context menu that comes up, choose "Open in new View"
d)The new view shows up
In this case, the selectionChangedEvent would once again *precede* the
view construction.
Thanks!
|
|
|
|
Re: Launching View on double click from a TreeViewer [message #444408 is a reply to message #444395] |
Wed, 15 February 2006 20: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.05764 seconds