diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyViewPart.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyViewPart.java
index 6847964887b..b3c58b30008 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyViewPart.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyViewPart.java
@@ -236,7 +236,6 @@ protected void open(ISelection selection, boolean activate) {
private CancelSearchAction fCancelSearchAction;
private ExpandWithConstructorsAction fExpandWithConstructorsAction;
private RemoveFromViewAction fRemoveFromViewAction;
- private ShowSearchInDialogAction fShowSearchInDialogAction;
private CompositeActionGroup fActionGroups;
private CallHierarchyViewer fCallHierarchyViewer;
private boolean fShowCallDetails;
@@ -245,6 +244,7 @@ protected void open(ISelection selection, boolean activate) {
private boolean fIsPinned;
private PinCallHierarchyViewAction fPinViewAction;
private ShowCallHierarchyFilterDialogAction fFiltersAction;
+ private final SearchInSelectionManager searchInManager;
public CallHierarchyViewPart() {
@@ -252,6 +252,7 @@ public CallHierarchyViewPart() {
fDialogSettings = JavaPlugin.getDefault().getDialogSettings();
+ searchInManager= new SearchInSelectionManager(this);
fIsPinned= false;
}
@@ -719,9 +720,10 @@ private void fillViewMenu() {
fieldSubMenu.add(fToggleFieldModeAction);
}
viewMenu.add(fieldSubMenu);
- viewMenu.add(fShowSearchInDialogAction);
+ viewMenu.add(searchInManager.createSearchInMenu());
}
+
@Override
public void dispose() {
if (fActionGroups != null)
@@ -1040,7 +1042,6 @@ private void makeActions() {
fFocusOnSelectionAction = new FocusOnSelectionAction(this);
fCopyAction= new CopyCallHierarchyAction(this, fClipboard, fCallHierarchyViewer);
fSearchScopeActions = new SearchScopeActionGroup(this, fDialogSettings);
- fShowSearchInDialogAction= new ShowSearchInDialogAction(this, fCallHierarchyViewer);
fFiltersActionGroup = new CallHierarchyFiltersActionGroup(this,
fCallHierarchyViewer);
fHistoryDropDownAction = new HistoryDropDownAction(this);
@@ -1153,7 +1154,7 @@ private void setContentDescription(int includeMask) {
* @since 3.7
*/
private int getIncludeMask() {
- return fShowSearchInDialogAction.getSearchInDialog().getIncludeMask();
+ return this.searchInManager.getIncludeMask();
}
/**
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SearchInDialog.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SearchInDialog.java
deleted file mode 100644
index 8ec35fa27c4..00000000000
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SearchInDialog.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jdt.internal.ui.callhierarchy;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.jface.dialogs.TrayDialog;
-
-import org.eclipse.ui.PlatformUI;
-
-import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
-import org.eclipse.jdt.internal.ui.JavaPlugin;
-import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
-import org.eclipse.jdt.internal.ui.search.SearchMessages;
-
-/**
- * Class to show the Search In dialog.
- *
- * @since 3.7
- */
-class SearchInDialog extends TrayDialog {
-
- private Button[] fIncludeMasks;
-
- private IDialogSettings fSettings;
-
- private int fIncludeMask;
-
- private boolean fIncludeMaskChanged= false;
-
- /**
- * Section ID for the SearchInDialog class.
- */
- private static final String DIALOG_SETTINGS_SECTION= "SearchInDialog"; //$NON-NLS-1$
-
- private static final String SEARCH_IN_SOURCES= "SearchInSources"; //$NON-NLS-1$
-
- private static final String SEARCH_IN_PROJECTS= "SearchInProjects"; //$NON-NLS-1$
-
- private static final String SEARCH_IN_APPLIBS= "SearchInAppLibs"; //$NON-NLS-1$
-
- private static final String SEARCH_IN_JRE= "SearchInJRE"; //$NON-NLS-1$
-
- private String[] fKeys= new String[] { SEARCH_IN_SOURCES, SEARCH_IN_PROJECTS, SEARCH_IN_JRE, SEARCH_IN_APPLIBS };
-
- public SearchInDialog(Shell parentShell) {
- super(parentShell);
- fSettings= JavaPlugin.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS_SECTION);
- if (fSettings == null) {
- fSettings= JavaPlugin.getDefault().getDialogSettings().addNewSection(DIALOG_SETTINGS_SECTION);
- fSettings.put(SEARCH_IN_SOURCES, true);
- fSettings.put(SEARCH_IN_PROJECTS, true);
- fSettings.put(SEARCH_IN_JRE, true);
- fSettings.put(SEARCH_IN_APPLIBS, true);
- }
- fIncludeMask= getInt(fKeys);
- }
-
- /**
- * Returns the integer value of the strings.
- *
- * @param str the array of strings
- * @return the integer value of the strings
- */
- private int getInt(String[] str) {
- boolean value;
- int mask= 0;
- int val= 0;
- for (int i= 0; i < str.length; i++) {
- value= fSettings.getBoolean(str[i]);
- if (value) {
- switch (i) {
- case 0:
- val= JavaSearchScopeFactory.SOURCES;
- break;
- case 1:
- val= JavaSearchScopeFactory.PROJECTS;
- break;
- case 2:
- val= JavaSearchScopeFactory.JRE;
- break;
- case 3:
- val= JavaSearchScopeFactory.LIBS;
- }
- mask|= val;
- }
- }
- return mask;
- }
-
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(CallHierarchyMessages.SearchInDialog_title);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.CALL_HIERARCHY_SEARCH_IN_DIALOG);
- }
-
- @Override
- protected boolean isResizable() {
- return true;
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite composite= (Composite) super.createDialogArea(parent);
-
- Control includeMask= createIncludeMask(composite);
- includeMask.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
-
- return composite;
- }
-
- /**
- * Creates the search in options.
- *
- * @param parent the parent composite
- * @return the group control
- */
- private Control createIncludeMask(Composite parent) {
- Group result= new Group(parent, SWT.NONE);
- result.setText(SearchMessages.SearchPage_searchIn_label);
- result.setLayout(new GridLayout(4, false));
- fIncludeMasks= new Button[] {
- createButton(result, SWT.CHECK, SearchMessages.SearchPage_searchIn_sources, JavaSearchScopeFactory.SOURCES, fSettings.getBoolean(SEARCH_IN_SOURCES)),
- createButton(result, SWT.CHECK, SearchMessages.SearchPage_searchIn_projects, JavaSearchScopeFactory.PROJECTS, fSettings.getBoolean(SEARCH_IN_PROJECTS)),
- createButton(result, SWT.CHECK, SearchMessages.SearchPage_searchIn_jre, JavaSearchScopeFactory.JRE, fSettings.getBoolean(SEARCH_IN_JRE)),
- createButton(result, SWT.CHECK, SearchMessages.SearchPage_searchIn_libraries, JavaSearchScopeFactory.LIBS, fSettings.getBoolean(SEARCH_IN_APPLIBS)),
- };
-
- SelectionAdapter listener= new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateOKStatus();
- }
- };
- for (Button b : fIncludeMasks) {
- b.addSelectionListener(listener);
- }
-
- return result;
- }
-
- /**
- * Updates the enablement of OK button.
- */
- protected void updateOKStatus() {
- boolean isValidMask= getIncludeMask() != 0;
- getButton(OK).setEnabled(isValidMask);
- }
-
- /**
- * Returns the include mask.
- *
- * @return the include mask
- */
- int getIncludeMask() {
- if (fIncludeMasks == null || fIncludeMasks[0].isDisposed())
- return fIncludeMask;
- int mask= 0;
- for (Button button : fIncludeMasks) {
- if (button.getSelection()) {
- mask|= getIntData(button);
- }
- }
- return mask;
- }
-
- /**
- * Returns the value of the given button.
- *
- * @param button the button for which to fetch value
- * @return the value of the button
- */
- private int getIntData(Button button) {
- return ((Integer)button.getData());
- }
-
- /**
- * Creates and returns the button.
- *
- * @param parent the parent composite
- * @param style the style of control to construct
- * @param text the text for the button
- * @param data the widget data
- * @param isSelected the new selection state
- * @return the button created
- */
- private Button createButton(Composite parent, int style, String text, int data, boolean isSelected) {
- Button button= new Button(parent, style);
- button.setText(text);
- button.setData(Integer.valueOf(data));
- button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
- button.setSelection(isSelected);
- return button;
- }
-
- @Override
- protected void okPressed() {
- int mask= getIncludeMask();
- if (mask != fIncludeMask) {
- fIncludeMask= mask;
- for (int i= 0; i < fIncludeMasks.length; i++) {
- fSettings.put(fKeys[i], fIncludeMasks[i].getSelection());
- }
- fIncludeMaskChanged= true;
- } else {
- fIncludeMaskChanged= false;
- }
- super.okPressed();
- }
-
- /**
- * Indicates whether the include mask has changed.
- *
- * @return the includeMaskChanged true
if the include mask has changed,
- * false
otherwise
- */
- public boolean isIncludeMaskChanged() {
- return fIncludeMaskChanged;
- }
-
-}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SearchInSelectionManager.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SearchInSelectionManager.java
new file mode 100644
index 00000000000..bc1546d8ae2
--- /dev/null
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SearchInSelectionManager.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2024 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.ui.callhierarchy;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.dialogs.IDialogSettings;
+
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
+import org.eclipse.jdt.internal.ui.search.SearchMessages;
+
+/**
+ * Class to manage checkboxes in a menu to limit where the search should look for callers.
+ */
+final class SearchInSelectionManager {
+ /**
+ * Section ID for the SearchInDialog class.
+ */
+ private static final String DIALOG_SETTINGS_SECTION= "SearchInDialog"; //$NON-NLS-1$
+
+ enum Search {
+ IN_SOURCES(SearchMessages.SearchPage_searchIn_sources, JavaSearchScopeFactory.SOURCES, "SearchInSources"), //$NON-NLS-1$
+ IN_PROJECTS(SearchMessages.SearchPage_searchIn_projects, JavaSearchScopeFactory.PROJECTS, "SearchInProjects"), //$NON-NLS-1$
+ IN_JRE(SearchMessages.SearchPage_searchIn_jre, JavaSearchScopeFactory.JRE, "SearchInJRE"), //$NON-NLS-1$
+ IN_LIBS(SearchMessages.SearchPage_searchIn_libraries, JavaSearchScopeFactory.LIBS, "SearchInAppLibs"); //$NON-NLS-1$
+
+ final String label;
+
+ final int flag;
+
+ final String settingKey;
+
+ Search(String label, int flag, String settingKey) {
+ this.label= label;
+ this.flag= flag;
+ this.settingKey= settingKey;
+ }
+ }
+
+
+ class SearchInAction extends Action {
+ final Search search;
+
+ SearchInAction(Search search, boolean checked) {
+ super(null, AS_CHECK_BOX);
+ setText(search.label);
+ setChecked(checked);
+ this.search= search;
+ }
+
+ @Override
+ public void run() {
+ setScopeEnabled(search, isChecked());
+ viewPart.refresh();
+ }
+ }
+
+ private final CallHierarchyViewPart viewPart;
+
+ private final IDialogSettings fSettings;
+
+ SearchInSelectionManager(CallHierarchyViewPart viewPart) {
+ this.viewPart= viewPart;
+ IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS_SECTION);
+ if (settings == null) {
+ settings= JavaPlugin.getDefault().getDialogSettings().addNewSection(DIALOG_SETTINGS_SECTION);
+ for (Search setting : Search.values()) {
+ setScopeEnabled(setting, true);
+ }
+ }
+ fSettings= settings;
+ }
+
+ boolean isScopeEnabled(Search searchType) {
+ return fSettings.getBoolean(searchType.settingKey);
+ }
+
+ void setScopeEnabled(Search searchType, boolean flag) {
+ fSettings.put(searchType.settingKey, flag);
+ }
+
+ /**
+ * @return the menu with the various checkboxes.
+ */
+ MenuManager createSearchInMenu() {
+ MenuManager searchInMenu= new MenuManager(CallHierarchyMessages.ShowSearchInDialogAction_text);
+ for (Search search : Search.values()) {
+ searchInMenu.add(new SearchInAction(search, isScopeEnabled(search)));
+ }
+ return searchInMenu;
+ }
+
+ /**
+ * @return the actually selected inclusion mask.
+ */
+ int getIncludeMask() {
+ int mask= 0;
+ for (Search setting : Search.values()) {
+ if (isScopeEnabled(setting)) {
+ mask|= setting.flag;
+ }
+ }
+ return mask;
+ }
+
+}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SelectFieldModeAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SelectFieldModeAction.java
index ce7c09cd25b..05c36c69299 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SelectFieldModeAction.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/SelectFieldModeAction.java
@@ -25,8 +25,8 @@
*/
public class SelectFieldModeAction extends Action {
- private CallHierarchyViewPart fView;
- private int fMode;
+ private final CallHierarchyViewPart fView;
+ private final int fMode;
public SelectFieldModeAction(CallHierarchyViewPart v, int mode) {
super(null, AS_RADIO_BUTTON);
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/ShowSearchInDialogAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/ShowSearchInDialogAction.java
deleted file mode 100644
index e1b9ebfc180..00000000000
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/ShowSearchInDialogAction.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jdt.internal.ui.callhierarchy;
-
-import org.eclipse.core.runtime.Assert;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.window.Window;
-
-/**
- * Action class to create and open the search in dialog.
- *
- * @since 3.7
- */
-public class ShowSearchInDialogAction extends Action {
- private CallHierarchyViewPart fPart;
-
- private SearchInDialog fSearchInDialog;
-
- /**
- * Action to show the SearchInDialog
.
- *
- * @param part the call hierarchy view part
- * @param viewer the call hierarchy viewer
- */
- public ShowSearchInDialogAction(CallHierarchyViewPart part, CallHierarchyViewer viewer) {
- Assert.isNotNull(part);
- Assert.isNotNull(viewer);
- fPart= part;
- fSearchInDialog= new SearchInDialog(fPart.getViewSite().getShell());
- setText(CallHierarchyMessages.ShowSearchInDialogAction_text);
- }
-
- /**
- * Returns the SearchInDialog
.
- *
- * @return the searchInDialog
- */
- public SearchInDialog getSearchInDialog() {
- return fSearchInDialog;
- }
-
- @Override
- public void run() {
- SearchInDialog dialog= getSearchInDialog();
- if (dialog.open() == Window.OK && dialog.isIncludeMaskChanged()) {
- fPart.setInputElements(fPart.getInputElements());
- }
- }
-}