what should be returned by ILinkHelper.findSelection() ? [message #496821] |
Wed, 11 November 2009 13:50 |
Eclipse User |
|
|
|
Originally posted by: yoduderoo.netscape.net
Hi,
Am developing an Eclipse RCP app.
I have implemented my first linkHelper extension. Works fine when I
click on the common navigator view. Correct editor, as programmed in my
ILinkHelper impl, appears.
My problem is the other way: what should I return in
ILinkHelper.findSelection() when one of the editors is clicked?
After findSelection() is fired, there is no selection any longer in my
navigator. I suspect I am returning something unknown which results in
deselecting in common navigator.
Do I have to have the common nav instance and call it directly? Or
should I be able to fired off a generic selection which is understand by
the navigator?
Here is my findSelection() implementation:
public IStructuredSelection findSelection(IEditorInput anInput) {
if (anInput instanceof MyEditorInput) {
MyEditorInput edInput = (MyEditorInput) anInput;
return new StructuredSelection(edInput);
}
return StructuredSelection.EMPTY;
}
Any insight much appreciated!
Thanks,y
|
|
|
Re: what should be returned by ILinkHelper.findSelection() ? [message #496849 is a reply to message #496821] |
Wed, 11 November 2009 14:39 |
Eclipse User |
|
|
|
Originally posted by: yoduderoo.netscape.net
I changed the IEditorInput object to accept the source explorer node.
This is then returned in the selection in findSelection() :
public IStructuredSelection findSelection(IEditorInput anInput) {
if (anInput instanceof MyEditorInput) {
MyEditorInput edInput = (MyEditorInput) anInput;
return new StructuredSelection(edInput.getSourceNode());
}
return StructuredSelection.EMPTY;
}
Now it works. So it seems that an instance of the navigator tree must be
returned.
-y
Yodude wrote:
> Hi,
> Am developing an Eclipse RCP app.
>
> I have implemented my first linkHelper extension. Works fine when I
> click on the common navigator view. Correct editor, as programmed in my
> ILinkHelper impl, appears.
>
> My problem is the other way: what should I return in
> ILinkHelper.findSelection() when one of the editors is clicked?
>
> After findSelection() is fired, there is no selection any longer in my
> navigator. I suspect I am returning something unknown which results in
> deselecting in common navigator.
>
> Do I have to have the common nav instance and call it directly? Or
> should I be able to fired off a generic selection which is understand by
> the navigator?
>
> Here is my findSelection() implementation:
>
> public IStructuredSelection findSelection(IEditorInput anInput) {
> if (anInput instanceof MyEditorInput) {
> MyEditorInput edInput = (MyEditorInput) anInput;
> return new StructuredSelection(edInput);
> }
> return StructuredSelection.EMPTY;
> }
>
>
> Any insight much appreciated!
>
> Thanks,y
|
|
|
Re: what should be returned by ILinkHelper.findSelection() ? [message #496851 is a reply to message #496821] |
Wed, 11 November 2009 14:44 |
Mark Melvin Messages: 118 Registered: July 2009 |
Senior Member |
|
|
Quote: | I have implemented my first linkHelper extension. Works fine when I
click on the common navigator view. Correct editor, as programmed in my
ILinkHelper impl, appears.
My problem is the other way: what should I return in
ILinkHelper.findSelection() when one of the editors is clicked?
|
Hi y,
For synchronizing the other way (finding an item in the Navigator when your editor is clicked), you must return a selection containing the item in the Navigator View you want selected. Most of the time, this will be an IFile (a workspace File) - unless it is some sort of virtual model item you have added to the Navigator View yourself.
Have a look at org.eclipse.ui.internal.navigator.resources.workbench.Resour ceLinkHelper for an example. This is what the default implementation does:
public IStructuredSelection findSelection(IEditorInput anInput) {
IFile file = ResourceUtil.getFile(anInput);
if (file != null) {
return new StructuredSelection(file);
}
return StructuredSelection.EMPTY;
}
The default ResourceLinkHelper implementation should find the selection for you if your editor input is a normal workspace File, which means you don't need to re-implement it yourself (your code can just return StructuredSelection.EMPTY and let the default implementation work). Otherwise, if you have non-File resources you need to find in the navigator, your code will have to track them down in the tree and return those items. I do this in my link helper. But note that you can use a TreePath - which makes it easier for weird object hierarchies you've added to the Navigator view. For example:
return new StructuredSelection(new TreePath(new Object[] {project, myModelItemParent, myModelItemChild}));
I hope this helps,
Mark.
|
|
|
Powered by
FUDForum. Page generated in 0.24062 seconds