Salut,
Mon problème du jour est le suivant, je veux récupéré le project courrant dans une classe de validation. Cette classe de validation est appellée lors d un save.
J ai donc le code suivant (qui marche dans d'autres classes) :
mais le problème est que getActiveWorkbenchWindow me renvoye null
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 /** * Gets the current active project. * * @return IProject * The active project */ private IProject getCurrentProject() { IWorkbench iworkbench = PlatformUI.getWorkbench(); if (iworkbench == null) { return null; } IWorkbenchWindow iworkbenchwindow = iworkbench.getActiveWorkbenchWindow(); if (iworkbenchwindow == null) { return null; } IWorkbenchPage iworkbenchpage = iworkbenchwindow.getActivePage(); if (iworkbenchpage == null) { return null; } IEditorPart ieditorpart = iworkbenchpage.getActiveEditor(); return extractProject(ieditorpart); } /** * Extract the project from the editor part. * * @param editor * The active editor * @return IProject * The active project */ private IProject extractProject(IEditorPart editor) { IEditorInput input = editor.getEditorInput(); if (!(input instanceof IFileEditorInput)) return null; return ((IFileEditorInput)input).getFile().getProject(); }
existerait il un autre moyen de récupérer les project courrant
merci
Partager