Skip to content

Commit 94492a2

Browse files
author
jantje
committed
When the selection is empty keep the old projects.
Added 2 null tests Unfortunately the formatter ....
1 parent e00b3d7 commit 94492a2

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

io.sloeber.ui/src/io/sloeber/ui/listeners/ProjectExplorerListener.java

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,52 @@
2222
import org.eclipse.ui.PlatformUI;
2323

2424
public class ProjectExplorerListener implements ISelectionListener {
25-
static IProject projects[] = new IProject[0];
25+
static IProject projects[] = new IProject[0];
2626

27-
// public static IProject getActiveProject() {
28-
// return project;
29-
// }
27+
// public static IProject getActiveProject() {
28+
// return project;
29+
// }
3030

31-
public static IProject[] getSelectedProjects() {
32-
return projects;
33-
}
31+
public static IProject[] getSelectedProjects() {
32+
return projects;
33+
}
3434

35-
public static void registerListener() {
36-
IWorkbench wb = PlatformUI.getWorkbench();
37-
IWorkbenchWindow awbw = wb.getActiveWorkbenchWindow();
38-
ISelectionService ss = awbw.getSelectionService();
35+
public static void registerListener() {
36+
IWorkbench wb = PlatformUI.getWorkbench();
37+
IWorkbenchWindow awbw = wb.getActiveWorkbenchWindow();
38+
ISelectionService ss = awbw.getSelectionService();
3939

40-
ProjectExplorerListener selectionListener = new ProjectExplorerListener();
41-
ss.addPostSelectionListener(IPageLayout.ID_PROJECT_EXPLORER, selectionListener);
40+
ProjectExplorerListener selectionListener = new ProjectExplorerListener();
41+
ss.addPostSelectionListener(IPageLayout.ID_PROJECT_EXPLORER, selectionListener);
4242

43-
}
43+
}
4444

45-
@Override
46-
public void selectionChanged(IWorkbenchPart part, ISelection newSelection) {
47-
if (newSelection instanceof IStructuredSelection) {
45+
@Override
46+
public void selectionChanged(IWorkbenchPart part, ISelection newSelection) {
47+
if (!newSelection.isEmpty()) {
48+
if (newSelection instanceof IStructuredSelection) {
4849

49-
List<IProject> allSelectedprojects = new ArrayList<>();
50-
for (Object element : ((IStructuredSelection) newSelection).toList()) {
51-
if (element instanceof IAdaptable) {
52-
@SuppressWarnings("cast") // this is needed for the oracle
53-
// sdk as it needs the cast and
54-
// otherwise I have a warning
55-
IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
56-
if (resource != null) {
57-
allSelectedprojects.add(resource.getProject());
58-
}
50+
List<IProject> allSelectedprojects = new ArrayList<>();
51+
for (Object element : ((IStructuredSelection) newSelection).toList()) {
52+
if (element instanceof IAdaptable) {
53+
@SuppressWarnings("cast") // this is needed for the
54+
// oracle
55+
// sdk as it needs the cast and
56+
// otherwise I have a warning
57+
IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
58+
if (resource != null) {
59+
allSelectedprojects.add(resource.getProject());
60+
}
5961

62+
}
63+
}
64+
if (allSelectedprojects.size() > 0) {
65+
projects = new IProject[allSelectedprojects.size()];
66+
allSelectedprojects.toArray(projects);
67+
}
68+
return;
69+
}
6070
}
61-
}
62-
projects = new IProject[allSelectedprojects.size()];
63-
allSelectedprojects.toArray(projects);
64-
return;
6571
}
6672

67-
}
68-
6973
}

0 commit comments

Comments
 (0)