1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
public class MyProject
{
// Class members
private IProject currentProject;
/**************************************************************************
* Constructor
*************************************************************************/
public ProjectCompilationUnits()
{
findCurrentOpenProject();
}
/**************************************************************************
* Accessor
*************************************************************************/
public IProject getCurrentProject() { return currentProject; }
/**************************************************************************
* FindCurrentOpenProject
*
* Search for a open project. Open project is the current in use.
*************************************************************************/
private void findCurrentOpenProject()
{
/* Get the list of projects. It's the root Java element that *
* corresponding to the workspace. Give access to the projects list. */
IJavaModel root = JavaCore.create( ResourcesPlugin.getWorkspace().getRoot() );
IJavaProject[] allProjects;
try
{
allProjects = root.getJavaProjects(); // Get all projects
}
catch( JavaModelException e )
{
System.out.println(e.toString());
return;
}
/* Search the current open project and stop when he find */
for( IJavaProject project : allProjects )
if(project.isOpen())
{
// currentProject est déclaré de type IProject
currentProject = project.getProject();
return;
}
}
} // Fin classe
-----------------------
Dans ta méthode:
//Trouver le project actuel
MyProject project = new MyProject();
if( project.getCurrentProject() != null )
{
//recuperation d'un fichier
IFile f = project.getCurrentProject().getFile("images/monimage.jpg");
//creation de l'image a partir de l'url
Image m = new Image(null,urlImage.getLocation().toString());
monLabel.setIcon(m);
} |
Partager