Skip to content

Commit 27c66d7

Browse files
SougandhSnoopur2507
authored andcommitted
Fix ClassCastException when switching tabs
This commit resolves an exception that occurs when Control.getParent() returns a CTabFolder instead of a TabItem. This fix ensures that the Module Dependencies Tab view is displayed correctly. Fixes : #2146
1 parent 766628b commit 27c66d7

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathBasePage.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -20,6 +20,8 @@
2020
import java.util.Set;
2121

2222
import org.eclipse.swt.SWT;
23+
import org.eclipse.swt.custom.CTabFolder;
24+
import org.eclipse.swt.custom.CTabItem;
2325
import org.eclipse.swt.widgets.Composite;
2426
import org.eclipse.swt.widgets.Control;
2527
import org.eclipse.swt.widgets.Shell;
@@ -405,11 +407,20 @@ public BuildPathBasePage switchToTab(Class<? extends BuildPathBasePage> tabClass
405407
JavaPlugin.logErrorMessage("Page does not support tab switching: "+this.getClass()); //$NON-NLS-1$
406408
return null;
407409
}
408-
TabFolder tabFolder= (TabFolder) fSWTControl.getParent();
409-
for (TabItem tabItem : tabFolder.getItems()) {
410-
if (tabClass.isInstance(tabItem.getData())) {
411-
tabFolder.setSelection(tabItem);
412-
return (BuildPathBasePage) tabItem.getData();
410+
if(fSWTControl.getParent() instanceof TabFolder tabFolder) {
411+
for (TabItem tabItem : tabFolder.getItems()) {
412+
if (tabClass.isInstance(tabItem.getData())) {
413+
tabFolder.setSelection(tabItem);
414+
return (BuildPathBasePage) tabItem.getData();
415+
}
416+
}
417+
}
418+
if(fSWTControl.getParent() instanceof CTabFolder cTabFolder) {
419+
for (CTabItem ctabItem : cTabFolder.getItems()) {
420+
if (tabClass.isInstance(ctabItem.getData())) {
421+
cTabFolder.setSelection(ctabItem);
422+
return (BuildPathBasePage) ctabItem.getData();
423+
}
413424
}
414425
}
415426
return null;

0 commit comments

Comments
 (0)