Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Confused about IProject and IJavaProject
Confused about IProject and IJavaProject [message #696950] Fri, 15 July 2011 07:50 Go to next message
Tam Gom is currently offline Tam GomFriend
Messages: 36
Registered: July 2011
Member
Hello Everyone!

Currently I'm writing a plug-in where the user can select projects from the Package Explorer.

I acquire the selected items this way:
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);

At some point I try to use the selection's items as IProject objects but I get an error that IJavaProject cannot be casted to IProject. And indeed, I see in the debugger that the object is IJavaProject.
Object obj = selection.iterator().next(); 
IProject project = (IProject) obj;
No problem, I can easily get the IProject object from IJavaProject but the code above actually worked a few months ago.

In another case I try to do something similar and in the selection I have IJavaProject and IProject objects at the same time, so I have to check their types every time.
for (Object o : selection.toList()) {
     if (o instanceof IJavaProject) {
          projects.add(((IJavaProject)o).getProject());
     } else if (o instanceof IProject) {
          projects.add((IProject) o);
     }
}


And the most confusing for me is that there are Java projects (projects that were checked out from an SVN repository as new Java projects) and they are IProject objects even though I expect them to be IJavaProject objects.

So could somebody please explain to me what the deal is with IJavaProject and IProject and how I should handle selections properly?

Thank you very much!
Re: Confused about IProject and IJavaProject [message #698501 is a reply to message #696950] Tue, 19 July 2011 15:09 Go to previous message
Tam Gom is currently offline Tam GomFriend
Messages: 36
Registered: July 2011
Member
Ok, the above problem can be solved by IAdaptable if anybody is interested.


Now I have another problem and it's related to IProject and IJavaProject again. I have created my own PropertyTester. Here's how I defined it in my plugin.xml:

<extension 
          point="org.eclipse.core.expressions.propertyTesters">
      <propertyTester
         id="my.plugin.MyPropertyTester"
         type="org.eclipse.core.resources.IProject"
         namespace="my.plugin"
         properties="isProject"
         class="my.plugin.MyPropertyTester">
      </propertyTester>
</extension>


The problem here is that the type attribute restricts when the property tester is called. So if a project in the package explorer is an IProject object there's no problem but my property tester is not called when it's an IJavaProject.
I can't find a way to define two different types as restriction for a property tester or any other solution.

Any ideas?
Previous Topic:Find out different versions of installed plugin
Next Topic:p2:contributing -vm argument to launcher INI file
Goto Forum:
  


Current Time: Fri Apr 26 05:02:08 GMT 2024

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

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

Back to the top