Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » findViewReference returning null(findViewReference returning null)
findViewReference returning null [message #554068] Fri, 20 August 2010 02:28 Go to next message
Janusz Dalecki is currently offline Janusz DaleckiFriend
Messages: 63
Registered: January 2010
Location: Sydney
Member
I need to call getSite().getPage().findViewReference inside a createPartControl() method of my editor to get the view itself. The problem is that the call returns me a null pointer. I guess it is because the view has not been instantiated yet.
How can I get a hold of my view inside editor?
Re: findViewReference returning null [message #554095 is a reply to message #554068] Fri, 20 August 2010 07:31 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 20.08.2010 04:28, Janusz Dalecki wrote:
> I need to call getSite().getPage().findViewReference inside a
> createPartControl() method of my editor to get the view itself.

Your description seems to imply that editor and view are
the same, but this is impossible.

> The problem is that the call returns me a null pointer. I guess it is
> because the view has not been instantiated yet.

No. A view reference is a handle for a view, even if that has not been
instantiated yet. If a view with a given ID is part of the RCP
application, findViewReference should return a non-null result.
The idea of IViewReference is that you have an "access point"
independent on whether it already exists. If findViewReference
returns null, chances are good, that you had a typo when
providing the view ID or that you simply forgot to launch
the RCP app with the plugin that provides the view part.

> How can I get a hold of my view inside editor?

I don't now, why an editor an a view should be involved with
each other. This question is independent on whether findViewReference
returns a null result or not.

You can use IWorkbenchPage.showView if you want to ensure that
an available view part is shown.

HTH & Greetings from Bremen,

Daniel Krügler
Re: findViewReference returning null [message #554133 is a reply to message #554068] Fri, 20 August 2010 09:30 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Janusz Dalecki wrote:
> I need to call getSite().getPage().findViewReference inside a
> createPartControl() method of my editor to get the view itself. The
> problem is that the call returns me a null pointer. I guess it is
> because the view has not been instantiated yet.
> How can I get a hold of my view inside editor?
Why not read the Javadoc?

Dani
Re: findViewReference returning null [message #554220 is a reply to message #554095] Fri, 20 August 2010 14:52 Go to previous messageGo to next message
Janusz Dalecki is currently offline Janusz DaleckiFriend
Messages: 63
Registered: January 2010
Location: Sydney
Member
Hi Daniel,
You seem to know the area I am having problem with so much better then me. So first of all, sorry for the confusion about my explanation of the view and editor (I read my explanation again) it does sound like I am implying that they are the same but that is not what I meant - sorry.
I am using CommonNavigator as a view and some home grown file editor.
Inside editor's createPartControl I am trying to get hold of CommonViewer instance (I want to check that some property of the viewer is set to true).
Now the problem is that even before I try to get hold of the viewer there seems to be a problem because if I call:
IViewReference ref = getSite().getPage().findViewReference("CNTest.NavigatorView ");
the 'ref' is null so I can't even call ref.getPart(false) function to get the viewer instance.

However if I check 'Clear' check box in "Debug Configuration" (fresh workspace) to launch my app, then if I click on any file in CommonNavigator viewer, editor is opened for that file and the4 code above inside my createPartControl function works (returns non null 'ref'). Why? I just don't get it.
Re: findViewReference returning null [message #556385 is a reply to message #554220] Wed, 01 September 2010 06:29 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 20.08.2010 16:52, Janusz Dalecki wrote:
> Hi Daniel,
> You seem to know the area I am having problem with so much better then
> me.

It would be nice, if I would, but it turned out, I did not ;-)

> So first of all, sorry for the confusion about my explanation of the
> view and editor (I read my explanation again) it does sound like I am
> implying that they are the same but that is not what I meant - sorry.
> I am using CommonNavigator as a view and some home grown file editor.
> Inside editor's createPartControl I am trying to get hold of
> CommonViewer instance (I want to check that some property of the viewer
> is set to true).
> Now the problem is that even before I try to get hold of the viewer
> there seems to be a problem because if I call:
> IViewReference ref =
> getSite().getPage().findViewReference("CNTest.NavigatorView ");

I assume the space at the end of the ID is a typo, right?

> the 'ref' is null so I can't even call ref.getPart(false) function to
> get the viewer instance.

I was wrong, you need to check the IViewDescriptor *not* the IViewReference:

IViewDescriptor descr =
getSite().getPage().getWorkbenchWindow().getViewRegistry().
find("CNTest.NavigatorView");

HTH & Greetings from Bremen,

Daniel Krügler
Re: findViewReference returning null [message #556711 is a reply to message #556385] Thu, 02 September 2010 12:16 Go to previous messageGo to next message
Janusz Dalecki is currently offline Janusz DaleckiFriend
Messages: 63
Registered: January 2010
Location: Sydney
Member
Hi Daniel,
No matter what I do I go wrong at some point. I have added the code as below ...
IViewDescriptor descr = PlatformUI.getWorkbench().getViewRegistry().find("CNTest.NavigatorView ");
IViewReference ref = getSite().getPage().findViewReference("CNTest.NavigatorView ");
CommonNavigator cn = null;
if(ref == null) {
try {
cn = (CommonNavigator)descr.createView();
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
cn = (CommonNavigator)ref.getPart(false);
}
cn = (CommonNavigator)ref.getPart(true);
CommonViewer cv = cn.getCommonViewer();
... and now when I get cv, it is null, although the creation of CommonNavigator (cn) is successful ( cn is not null).
Maybe accessing the CommonNavigator from editors's createPartControl(Composite parent) is illegal?
What do you think?
Re: findViewReference returning null [message #557274 is a reply to message #556711] Mon, 06 September 2010 11:19 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 02.09.2010 14:16, Janusz Dalecki wrote:
> Hi Daniel,
> No matter what I do I go wrong at some point. I have added the code as
> below ...
> IViewDescriptor descr =
> PlatformUI.getWorkbench().getViewRegistry().find("CNTest.NavigatorView ");
> IViewReference ref =
> getSite().getPage().findViewReference("CNTest.NavigatorView ");
> CommonNavigator cn = null;
> if(ref == null) {
> try {
> cn = (CommonNavigator)descr.createView();
> } catch (CoreException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> } else {
> cn = (CommonNavigator)ref.getPart(false);
> }
> cn = (CommonNavigator)ref.getPart(true);
> CommonViewer cv = cn.getCommonViewer();
> .. and now when I get cv, it is null, although the creation of
> CommonNavigator (cn) is successful ( cn is not null).
> Maybe accessing the CommonNavigator from editors's
> createPartControl(Composite parent) is illegal?
> What do you think?

Your code looks buggy to me, because you attempt to
access a potential null ref value in the last two
lines. Remove this null pointer access and try it
again or try to evaluate the following code instead
of the above one (But it should behave similary):

IWorkbenchPage thePage = getSite().getPage();
IViewPart view = thePage.showView(/your-view-ID/);

If this all fails, you either have missed to specify
an initial layout for the view (either via code
in the perspective definition or xml-based via the
perspectiveExtension extension point), or the
CommonNavigator indeed behaves rather unusual.

HTH & Greetings from Bremen,

Daniel Krügler
Re: findViewReference returning null [message #557631 is a reply to message #557274] Wed, 08 September 2010 11:48 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Daniel Krügler wrote:
>
> IWorkbenchPage thePage = getSite().getPage();
> IViewPart view = thePage.showView(/your-view-ID/);
>

As Daniel points out, the above can access a view in your perspective
(and it will create it if it does not already exist).

findViewReference(*) will return an IViewReference to a view that
"already exists" in your perspective. i.e. there is a tab for it in a
stack already. If there's no tab for it (it was added to the
perspective as a placeholder) then you cannot find it using
findViewReference(*).

PW



--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:ActionSet main menu with submenu
Next Topic:Dropins, target platform and features
Goto Forum:
  


Current Time: Tue Apr 16 08:09:55 GMT 2024

Powered by FUDForum. Page generated in 0.39745 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top