There is a valid View with some loaded project (just a
second ago I got ProjectViewerEvent). I get the
ProjectViewer using ProjectViewer.getViewer( view ).
Then I do pv.getSelectedNode() and get null as result
(instead of correct VPTProject)
Right after switching projects (when the event fires)
nothing in the tree is selected - thus "getSelectedNode()"
returns null. Only after selecting something it returns a
node - and selecting the Project node makes the project be
returned.
Try evalutating this in a buffer:
projetviewer.ProjectViewer.getViewer(view).getSelectedNode();
To see.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, I could not reply earier (busy at work). In order to
reproduce, could you please take the latest SQL plugin from
CVS and look at the method sql.SqlUtils.getProject( View
view ). There is commented code in it - it reproduces the
situation. (Just comment the existing method body).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You may use getSelectedNode(), but it's not guaranteed to
return something. To check the project, you could use the
getRoot() method of the viewer (see below).
You may use the projectviewer.PVActions.getCurrentProject()
method for that - but it still can return null, if the user
is currently using the "All Projects" view. Also, it has the
advantage of not needing the PV dockable to be instantiated
in the view to work - it would get the "last" project in
that case.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Really. The idea about PVActions.getCurrentProject() is
great. Just 0.02: check viewer.getRoot() for null BEFORE
checking whether is is project. The line
if ( viewer != null )
should be
if ( viewer != null && viewer.getRoot() != null )
This way it works better.
Also, another 0.02. About the XML plugin, unresolved classes
etc (looking at the noted about removing xerces.jar). The
line in ProjectPlugin.start():
No need to check for null: the root is never going to be
null. :-)
About the XML issue, after creating a dependency on the XML
plugin I'm not having any problems anymore. If someone gets
any error they should be reporting it here. :-) Thanks for
the tip, though.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sometimes it is null for me - at jedit startup I got
sometimes NullPointerExceptions from getCurrentProject()
method - which was cured by checking getRoot() for null (I
modified PV locally). So if you could please add it.. -
anyway it does not create any significant burden...
About XML. Even this dependancy (xml plugin) does not cure
the problem with xerces.jar for me. Only addind the
mentioned line to ProjectPlugin.start helped against
ClassNotFound exceptions. The same story was with SQL plugin
- sometimes I got exceptions, sometimes I did not.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: YES
user_id=75113
Dumb question: is there anything selected in the tree?
If you want to get the project, you should try "getRoot()"
(returns the root of the tree - may not be a project always,
so be careful!).
Logged In: YES
user_id=681
Sure there is selected project:)
Logged In: YES
user_id=75113
Sorry, I really can't reproduce this.
Right after switching projects (when the event fires)
nothing in the tree is selected - thus "getSelectedNode()"
returns null. Only after selecting something it returns a
node - and selecting the Project node makes the project be
returned.
Try evalutating this in a buffer:
projetviewer.ProjectViewer.getViewer(view).getSelectedNode();
To see.
Logged In: YES
user_id=681
Sorry, I could not reply earier (busy at work). In order to
reproduce, could you please take the latest SQL plugin from
CVS and look at the method sql.SqlUtils.getProject( View
view ). There is commented code in it - it reproduces the
situation. (Just comment the existing method body).
Logged In: YES
user_id=75113
You may use getSelectedNode(), but it's not guaranteed to
return something. To check the project, you could use the
getRoot() method of the viewer (see below).
You may use the projectviewer.PVActions.getCurrentProject()
method for that - but it still can return null, if the user
is currently using the "All Projects" view. Also, it has the
advantage of not needing the PV dockable to be instantiated
in the view to work - it would get the "last" project in
that case.
Logged In: YES
user_id=681
Really. The idea about PVActions.getCurrentProject() is
great. Just 0.02: check viewer.getRoot() for null BEFORE
checking whether is is project. The line
if ( viewer != null )
should be
if ( viewer != null && viewer.getRoot() != null )
This way it works better.
Also, another 0.02. About the XML plugin, unresolved classes
etc (looking at the noted about removing xerces.jar). The
line in ProjectPlugin.start():
Thread.currentThread().setContextClassLoader(ProjectPlugin.class.getClassLoader()
);
helps perfectly. I had same problem in SQL plugin...
Logged In: NO
No need to check for null: the root is never going to be
null. :-)
About the XML issue, after creating a dependency on the XML
plugin I'm not having any problems anymore. If someone gets
any error they should be reporting it here. :-) Thanks for
the tip, though.
Logged In: YES
user_id=681
Sometimes it is null for me - at jedit startup I got
sometimes NullPointerExceptions from getCurrentProject()
method - which was cured by checking getRoot() for null (I
modified PV locally). So if you could please add it.. -
anyway it does not create any significant burden...
About XML. Even this dependancy (xml plugin) does not cure
the problem with xerces.jar for me. Only addind the
mentioned line to ProjectPlugin.start helped against
ClassNotFound exceptions. The same story was with SQL plugin
- sometimes I got exceptions, sometimes I did not.
Logged In: YES
user_id=681
I hope you don't mind me creating another bug report
regarding the parser issue - I just have a couple of words
more to say about it.